Skip to content

Commit

Permalink
Merge pull request #58 from dexonsmith/expected-win-probability-glicko-2
Browse files Browse the repository at this point in the history
Update `expected_win_probability` to match math in `glicko_update`
  • Loading branch information
anoek authored Jan 13, 2024
2 parents baa4911 + b16fe3d commit 38ce1c4
Showing 1 changed file with 6 additions and 18 deletions.
24 changes: 6 additions & 18 deletions goratings/math/glicko2.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,27 +61,15 @@ def expand_deviation_because_no_games_played(self, n_periods: int = 1) -> "Glick
return self

def expected_win_probability(self, white: "Glicko2Entry", handicap_adjustment: float, ignore_g: bool = False) -> float:
# Implementation as defined by: http://www.glicko.net/glicko/glicko.pdf
q = 0.0057565

# Implementation extracted from glicko2_update below.
if not ignore_g:
def g(rd: float) -> float:
def g() -> float:
return 1
else:
def g(rd: float) -> float:
return 1 / sqrt(1 + 3 * q ** 2 * (self.deviation ** 2) / pi ** 2)

E = 1 / (
1
+ (
10
** (
-g(sqrt(self.deviation ** 2 + white.deviation ** 2))
* (self.rating + handicap_adjustment - white.rating)
/ 400
)
)
)
def g() -> float:
return 1 / sqrt(1 + (3 * white.phi ** 2) / (pi ** 2))

E = 1 / (1 + exp(-g() * (self.rating + handicap_adjustment - white.rating) / GLICKO2_SCALE))
return E


Expand Down

0 comments on commit 38ce1c4

Please sign in to comment.