1
0
mirror of https://github.com/avitex/elixir-glicko synced 2024-11-24 12:09:58 +00:00
This commit is contained in:
avitex 2017-11-16 12:45:12 +11:00
parent c96d357812
commit 7d46daf078

View File

@ -75,7 +75,8 @@ defmodule Glicko do
# Calculation of the estimated variance of the player's rating based on game outcomes # Calculation of the estimated variance of the player's rating based on game outcomes
defp calc_variance_estimate(%{player: player, results: results}) do defp calc_variance_estimate(%{player: player, results: results}) do
Enum.reduce(results, 0.0, fn result, acc -> results
|> Enum.reduce(0.0, fn result, acc ->
tmp_e = calc_e(player, result) tmp_e = calc_e(player, result)
acc + :math.pow(result.opponent_rating_deviation_g, 2) * tmp_e * (1 - tmp_e) acc + :math.pow(result.opponent_rating_deviation_g, 2) * tmp_e * (1 - tmp_e)
end) end)
@ -98,7 +99,7 @@ defmodule Glicko do
end end
defp calc_new_player_volatility(%{a: a}) do defp calc_new_player_volatility(%{a: a}) do
:math.exp(a/2) :math.exp(a / 2)
end end
defp calc_results_effect(%{player: player, results: results}) do defp calc_results_effect(%{player: player, results: results}) do
@ -112,7 +113,7 @@ defmodule Glicko do
end end
defp calc_new_player_rating_deviation(ctx) do defp calc_new_player_rating_deviation(ctx) do
1/:math.sqrt(1/:math.pow(ctx.prerating_period, 2) + 1/ctx.variance_estimate) 1 / :math.sqrt(1 / :math.pow(ctx.prerating_period, 2) + 1 / ctx.variance_estimate)
end end
defp calc_prerating_period(ctx) do defp calc_prerating_period(ctx) do
@ -137,9 +138,9 @@ defmodule Glicko do
fc = calc_f(ctx, c) fc = calc_f(ctx, c)
{a, fa} = {a, fa} =
if fc * fb < 0 do if fc * fb < 0 do
{b, fb} {b, fb}
else else
{a, fa / 2} {a, fa / 2}
end end
iterative_algorithm_body(ctx, a, c, fa, fc) iterative_algorithm_body(ctx, a, c, fa, fc)
else else