Crates.io | glicko_2 |
lib.rs | glicko_2 |
version | 1.0.0 |
source | src |
created_at | 2022-03-04 05:22:01.060565 |
updated_at | 2022-03-04 05:25:35.613928 |
description | Glicko2 is an iterative algorithm for ranking opponents or teams in 1v1 games. |
homepage | |
repository | https://github.com/ReagentX/glicko2 |
max_upload_size | |
id | 543356 |
size | 64,085 |
Glicko2 is an iterative algorithm for ranking opponents or teams in 1v1 games. This is a zero-dependency Rust library implementing this algorithm.
Add the following to your Cargo.toml
:
[dependencies]
glicko_2 = "1.0.0"
The most common usage is to update a series of matches for each team, but this library provides many other convenience methods.
use glicko_2::{Rating, Tuning, game::Outcome, algorithm};
/// Tune the rating values, here we use the default
let tuning = Tuning::default();
/// Create a Rating struct for each team
let mut team_to_update = Rating::new(&tuning);
let mut opponent_1 = Rating::new(&tuning);
let mut opponent_2 = Rating::new(&tuning);
let mut opponent_3 = Rating::new(&tuning);
let mut opponent_4 = Rating::new(&tuning);
/// Rate our team against a vector of matchup results
algorithm::rate(
&mut team_to_update,
vec![(Outcome::Win, &mut opponent_1),
(Outcome::Loss, &mut opponent_2),
(Outcome::Draw, &mut opponent_3),
]
);
/// Opponent 4 did not play, so their rating must be decayed
opponent_4.decay();
/// Print our updated rating
println!("{:?}", team_to_update); // { mu: 1500.0, phi: 255.40, sigma: 0.0059, is_scaled: false }
use glicko_2::{Rating, Tuning, game};
/// Tune the rating values, here we use the default
let tuning = Tuning::default();
/// Create a Rating struct for each team
let mut rating_1 = Rating::new(&tuning);
let mut rating_2 = Rating::new(&tuning);
/// Get odds (percent chance team_1 beats team_2)
let odds = game::odds(&mut rating_1, &mut rating_2);
println!("{}", odds); // 0.5, perfect odds since both teams have the same rating
use glicko_2::{Rating, Tuning, game};
/// Tune the rating values, here we use the defaults
let tuning = Tuning::default();
/// Create a Rating struct for each team
let mut rating_1 = Rating::new(&tuning);
let mut rating_2 = Rating::new(&tuning);
/// Get odds (the advantage team 1 has over team 2)
let quality = game::quality(&mut rating_1, &mut rating_2);
println!("{}", quality); // 1.0, perfect matchup since both teams have the same rating
use glicko_2::{Rating, Tuning, game};
/// Tune the rating values, here we use the defaults
let tuning = Tuning::default();
/// Create a Rating struct for each team
let mut rating_1 = Rating::new(&tuning);
let mut rating_2 = Rating::new(&tuning);
/// Update ratings for team_1 beating team_2
game::compete(&mut rating_1, &mut rating_2, false);
/// Print our updated ratings
println!("{:?}", rating_1); // { mu: 1646.47, phi: 307.84, sigma: 0.0059, is_scaled: false }
println!("{:?}", rating_2); // { mu: 1383.42, phi: 306.83, sigma: 0.0059, is_scaled: false }
Each side of a 1v1 competition is assigned a rating and a rating deviation. The rating represents the skill of a player or team, and the rating deviation measures confidence in the rating value.
A team or player's rating deviation decreases with results and increases during periods of inactivity. Rating deviation also depends on volatility, or how consistent a player or team's performance is.
Thus, a confidence interval represents a team's or player's skill: a player with a rating of 1300
and a rating deviation of 25
means the player's real strength lies between 1350
and 1250
with 95% confidence.
Since time is a factor in rating deviation, the algorithm assumes all matches within a rating period were played concurrently and use the same values for uncertainty.
{10..15}
matches per team per period1500
and 350
respectively0.06
{0.3..1.2}
Mark Glickman developed the Glicko2 algorithm. His paper is available here.