mirror of
https://github.com/avitex/elixir-glicko
synced 2024-12-22 08:29:57 +00:00
Add rating_interval
This commit is contained in:
parent
1e6fc408e4
commit
6bafa2be0b
@ -107,6 +107,27 @@ defmodule Glicko.Player do
|
||||
volatility: volatility,
|
||||
])
|
||||
|
||||
@doc """
|
||||
A convenience function for summarizing a player's strength as a 95%
|
||||
confidence interval.
|
||||
|
||||
The lowest value in the interval is the player's rating minus twice the RD,
|
||||
and the highest value is the player's rating plus twice the RD.
|
||||
The volatility measure does not appear in the calculation of this interval.
|
||||
|
||||
An example would be if a player's rating is 1850 and the RD is 50,
|
||||
the interval would range from 1750 to 1950. We would then say that we're 95%
|
||||
confident that the player's actual strength is between 1750 and 1950.
|
||||
|
||||
When a player has a low RD, the interval would be narrow, so that we would
|
||||
be 95% confident about a player’s strength being in a small interval of values.
|
||||
"""
|
||||
@spec rating_interval(player :: t) :: {rating_low :: float, rating_high :: float}
|
||||
def rating_interval(player), do: {
|
||||
player.rating - player.rating_deviation * 2,
|
||||
player.rating + player.rating_deviation * 2,
|
||||
}
|
||||
|
||||
@doc """
|
||||
Scales a players rating.
|
||||
"""
|
||||
|
@ -57,4 +57,14 @@ defmodule Glicko.PlayerTest do
|
||||
test "scale rating deviation v2 -> v1" do
|
||||
assert_in_delta Player.scale_rating_deviation_to(1.0, :v1), 173.7178, 0.1
|
||||
end
|
||||
|
||||
test "rating interval" do
|
||||
assert {rating_low, rating_high} =
|
||||
[rating: 1850, rating_deviation: 50]
|
||||
|> Player.new_v2
|
||||
|> Player.rating_interval
|
||||
|
||||
assert_in_delta rating_low, 1750, 0.1
|
||||
assert_in_delta rating_high, 1950, 0.1
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user