Skip to content

Commit

Permalink
Use 2 * beta instead of scaling by total player count.
Browse files Browse the repository at this point in the history
Fixes #145

Signed-off-by: Vivek Joshy <[email protected]>
  • Loading branch information
vivekjoshy committed Nov 2, 2024
1 parent 9e5c72b commit 1fbc1b1
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 69 deletions.
17 changes: 5 additions & 12 deletions openskill/models/weng_lin/bradley_terry_full.py
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,6 @@ def predict_win(self, teams: List[List[BradleyTerryFullRating]]) -> List[float]:
self._check_teams(teams)

n = len(teams)
total_player_count = sum(len(team) for team in teams)

# 2 Player Case
if n == 2:
Expand All @@ -848,11 +847,7 @@ def predict_win(self, teams: List[List[BradleyTerryFullRating]]) -> List[float]:
b = teams_ratings[1]
result = phi_major(
(a.mu - b.mu)
/ math.sqrt(
total_player_count * self.beta**2
+ a.sigma_squared
+ b.sigma_squared
)
/ math.sqrt(2 * self.beta**2 + a.sigma_squared + b.sigma_squared)
)
return [result, 1 - result]

Expand All @@ -866,8 +861,7 @@ def predict_win(self, teams: List[List[BradleyTerryFullRating]]) -> List[float]:
sigma_b = pair_b_subset[0].sigma_squared
pairwise_probabilities.append(
phi_major(
(mu_a - mu_b)
/ math.sqrt(total_player_count * self.beta**2 + sigma_a + sigma_b)
(mu_a - mu_b) / math.sqrt(2 * self.beta**2 + sigma_a + sigma_b)
)
)

Expand Down Expand Up @@ -912,11 +906,11 @@ def predict_draw(self, teams: List[List[BradleyTerryFullRating]]) -> float:
pairwise_probabilities.append(
phi_major(
(draw_margin - mu_a + mu_b)
/ math.sqrt(total_player_count * self.beta**2 + sigma_a + sigma_b)
/ math.sqrt(2 * self.beta**2 + sigma_a + sigma_b)
)
- phi_major(
(mu_b - mu_a - draw_margin)
/ math.sqrt(total_player_count * self.beta**2 + sigma_a + sigma_b)
/ math.sqrt(2 * self.beta**2 + sigma_a + sigma_b)
)
)

Expand All @@ -936,7 +930,6 @@ def predict_rank(
self._check_teams(teams)

n = len(teams)
total_player_count = sum(len(team) for team in teams)
team_ratings = self._calculate_team_ratings(teams)

win_probabilities = []
Expand All @@ -947,7 +940,7 @@ def predict_rank(
team_win_probability += phi_major(
(team_i.mu - team_j.mu)
/ math.sqrt(
total_player_count * self.beta**2
2 * self.beta**2
+ team_i.sigma_squared
+ team_j.sigma_squared
)
Expand Down
17 changes: 5 additions & 12 deletions openskill/models/weng_lin/bradley_terry_part.py
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,6 @@ def predict_win(self, teams: List[List[BradleyTerryPartRating]]) -> List[float]:
self._check_teams(teams)

n = len(teams)
total_player_count = sum(len(team) for team in teams)

# 2 Player Case
if n == 2:
Expand All @@ -856,11 +855,7 @@ def predict_win(self, teams: List[List[BradleyTerryPartRating]]) -> List[float]:
b = teams_ratings[1]
result = phi_major(
(a.mu - b.mu)
/ math.sqrt(
total_player_count * self.beta**2
+ a.sigma_squared
+ b.sigma_squared
)
/ math.sqrt(2 * self.beta**2 + a.sigma_squared + b.sigma_squared)
)
return [result, 1 - result]

Expand All @@ -874,8 +869,7 @@ def predict_win(self, teams: List[List[BradleyTerryPartRating]]) -> List[float]:
sigma_b = pair_b_subset[0].sigma_squared
pairwise_probabilities.append(
phi_major(
(mu_a - mu_b)
/ math.sqrt(total_player_count * self.beta**2 + sigma_a + sigma_b)
(mu_a - mu_b) / math.sqrt(2 * self.beta**2 + sigma_a + sigma_b)
)
)

Expand Down Expand Up @@ -920,11 +914,11 @@ def predict_draw(self, teams: List[List[BradleyTerryPartRating]]) -> float:
pairwise_probabilities.append(
phi_major(
(draw_margin - mu_a + mu_b)
/ math.sqrt(total_player_count * self.beta**2 + sigma_a + sigma_b)
/ math.sqrt(2 * self.beta**2 + sigma_a + sigma_b)
)
- phi_major(
(mu_b - mu_a - draw_margin)
/ math.sqrt(total_player_count * self.beta**2 + sigma_a + sigma_b)
/ math.sqrt(2 * self.beta**2 + sigma_a + sigma_b)
)
)

Expand All @@ -944,7 +938,6 @@ def predict_rank(
self._check_teams(teams)

n = len(teams)
total_player_count = sum(len(team) for team in teams)
team_ratings = self._calculate_team_ratings(teams)

win_probabilities = []
Expand All @@ -955,7 +948,7 @@ def predict_rank(
team_win_probability += phi_major(
(team_i.mu - team_j.mu)
/ math.sqrt(
total_player_count * self.beta**2
2 * self.beta**2
+ team_i.sigma_squared
+ team_j.sigma_squared
)
Expand Down
17 changes: 5 additions & 12 deletions openskill/models/weng_lin/plackett_luce.py
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,6 @@ def predict_win(self, teams: List[List[PlackettLuceRating]]) -> List[float]:
self._check_teams(teams)

n = len(teams)
total_player_count = sum(len(team) for team in teams)

# 2 Player Case
if n == 2:
Expand All @@ -848,11 +847,7 @@ def predict_win(self, teams: List[List[PlackettLuceRating]]) -> List[float]:
b = teams_ratings[1]
result = phi_major(
(a.mu - b.mu)
/ math.sqrt(
total_player_count * self.beta**2
+ a.sigma_squared
+ b.sigma_squared
)
/ math.sqrt(2 * self.beta**2 + a.sigma_squared + b.sigma_squared)
)
return [result, 1 - result]

Expand All @@ -866,8 +861,7 @@ def predict_win(self, teams: List[List[PlackettLuceRating]]) -> List[float]:
sigma_b = pair_b_subset[0].sigma_squared
pairwise_probabilities.append(
phi_major(
(mu_a - mu_b)
/ math.sqrt(total_player_count * self.beta**2 + sigma_a + sigma_b)
(mu_a - mu_b) / math.sqrt(2 * self.beta**2 + sigma_a + sigma_b)
)
)

Expand Down Expand Up @@ -912,11 +906,11 @@ def predict_draw(self, teams: List[List[PlackettLuceRating]]) -> float:
pairwise_probabilities.append(
phi_major(
(draw_margin - mu_a + mu_b)
/ math.sqrt(total_player_count * self.beta**2 + sigma_a + sigma_b)
/ math.sqrt(2 * self.beta**2 + sigma_a + sigma_b)
)
- phi_major(
(mu_b - mu_a - draw_margin)
/ math.sqrt(total_player_count * self.beta**2 + sigma_a + sigma_b)
/ math.sqrt(2 * self.beta**2 + sigma_a + sigma_b)
)
)

Expand All @@ -936,7 +930,6 @@ def predict_rank(
self._check_teams(teams)

n = len(teams)
total_player_count = sum(len(team) for team in teams)
team_ratings = self._calculate_team_ratings(teams)

win_probabilities = []
Expand All @@ -947,7 +940,7 @@ def predict_rank(
team_win_probability += phi_major(
(team_i.mu - team_j.mu)
/ math.sqrt(
total_player_count * self.beta**2
2 * self.beta**2
+ team_i.sigma_squared
+ team_j.sigma_squared
)
Expand Down
16 changes: 5 additions & 11 deletions openskill/models/weng_lin/thurstone_mosteller_full.py
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,6 @@ def predict_win(
self._check_teams(teams)

n = len(teams)
total_player_count = sum(len(team) for team in teams)

# 2 Player Case
if n == 2:
Expand All @@ -889,11 +888,7 @@ def predict_win(
b = teams_ratings[1]
result = phi_major(
(a.mu - b.mu)
/ math.sqrt(
total_player_count * self.beta**2
+ a.sigma_squared
+ b.sigma_squared
)
/ math.sqrt(2 * self.beta**2 + a.sigma_squared + b.sigma_squared)
)
return [result, 1 - result]

Expand All @@ -907,8 +902,7 @@ def predict_win(
sigma_b = pair_b_subset[0].sigma_squared
pairwise_probabilities.append(
phi_major(
(mu_a - mu_b)
/ math.sqrt(total_player_count * self.beta**2 + sigma_a + sigma_b)
(mu_a - mu_b) / math.sqrt(2 * self.beta**2 + sigma_a + sigma_b)
)
)

Expand Down Expand Up @@ -953,11 +947,11 @@ def predict_draw(self, teams: List[List[ThurstoneMostellerFullRating]]) -> float
pairwise_probabilities.append(
phi_major(
(draw_margin - mu_a + mu_b)
/ math.sqrt(total_player_count * self.beta**2 + sigma_a + sigma_b)
/ math.sqrt(2 * self.beta**2 + sigma_a + sigma_b)
)
- phi_major(
(mu_b - mu_a - draw_margin)
/ math.sqrt(total_player_count * self.beta**2 + sigma_a + sigma_b)
/ math.sqrt(2 * self.beta**2 + sigma_a + sigma_b)
)
)

Expand Down Expand Up @@ -989,7 +983,7 @@ def predict_rank(
team_win_probability += phi_major(
(team_i.mu - team_j.mu)
/ math.sqrt(
total_player_count * self.beta**2
2 * self.beta**2
+ team_i.sigma_squared
+ team_j.sigma_squared
)
Expand Down
17 changes: 5 additions & 12 deletions openskill/models/weng_lin/thurstone_mosteller_part.py
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,6 @@ def predict_win(
self._check_teams(teams)

n = len(teams)
total_player_count = sum(len(team) for team in teams)

# 2 Player Case
if n == 2:
Expand All @@ -887,11 +886,7 @@ def predict_win(
b = teams_ratings[1]
result = phi_major(
(a.mu - b.mu)
/ math.sqrt(
total_player_count * self.beta**2
+ a.sigma_squared
+ b.sigma_squared
)
/ math.sqrt(2 * self.beta**2 + a.sigma_squared + b.sigma_squared)
)
return [result, 1 - result]

Expand All @@ -905,8 +900,7 @@ def predict_win(
sigma_b = pair_b_subset[0].sigma_squared
pairwise_probabilities.append(
phi_major(
(mu_a - mu_b)
/ math.sqrt(total_player_count * self.beta**2 + sigma_a + sigma_b)
(mu_a - mu_b) / math.sqrt(2 * self.beta**2 + sigma_a + sigma_b)
)
)

Expand Down Expand Up @@ -951,11 +945,11 @@ def predict_draw(self, teams: List[List[ThurstoneMostellerPartRating]]) -> float
pairwise_probabilities.append(
phi_major(
(draw_margin - mu_a + mu_b)
/ math.sqrt(total_player_count * self.beta**2 + sigma_a + sigma_b)
/ math.sqrt(2 * self.beta**2 + sigma_a + sigma_b)
)
- phi_major(
(mu_b - mu_a - draw_margin)
/ math.sqrt(total_player_count * self.beta**2 + sigma_a + sigma_b)
/ math.sqrt(2 * self.beta**2 + sigma_a + sigma_b)
)
)

Expand All @@ -975,7 +969,6 @@ def predict_rank(
self._check_teams(teams)

n = len(teams)
total_player_count = sum(len(team) for team in teams)
team_ratings = self._calculate_team_ratings(teams)

win_probabilities = []
Expand All @@ -986,7 +979,7 @@ def predict_rank(
team_win_probability += phi_major(
(team_i.mu - team_j.mu)
/ math.sqrt(
total_player_count * self.beta**2
2 * self.beta**2
+ team_i.sigma_squared
+ team_j.sigma_squared
)
Expand Down
4 changes: 2 additions & 2 deletions tests/models/weng_lin/test_bradley_terry_full.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,10 +531,10 @@ def test_predict_draw():
team_2 = [b1, b2]

probability = model.predict_draw(teams=[team_1, team_2])
assert probability == pytest.approx(0.1694772, 0.0001)
assert probability == pytest.approx(0.1919967, 0.0001)

probability = model.predict_draw(teams=[team_1, team_2, [a1], [a2], [b1]])
assert probability == pytest.approx(0.0518253, 0.0001)
assert probability == pytest.approx(0.0603735, 0.0001)

probability = model.predict_draw(teams=[[b1], [b1]])
assert probability == pytest.approx(0.5)
Expand Down
4 changes: 2 additions & 2 deletions tests/models/weng_lin/test_bradley_terry_part.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,10 +534,10 @@ def test_predict_draw():
team_2 = [b1, b2]

probability = model.predict_draw(teams=[team_1, team_2])
assert probability == pytest.approx(0.1694772, 0.0001)
assert probability == pytest.approx(0.1919967, 0.0001)

probability = model.predict_draw(teams=[team_1, team_2, [a1], [a2], [b1]])
assert probability == pytest.approx(0.0518253, 0.0001)
assert probability == pytest.approx(0.0603735, 0.0001)

probability = model.predict_draw(teams=[[b1], [b1]])
assert probability == pytest.approx(0.5)
Expand Down
4 changes: 2 additions & 2 deletions tests/models/weng_lin/test_plackett_luce.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,10 +529,10 @@ def test_predict_draw():
team_2 = [b1, b2]

probability = model.predict_draw(teams=[team_1, team_2])
assert probability == pytest.approx(0.1694772, 0.0001)
assert probability == pytest.approx(0.1919967, 0.0001)

probability = model.predict_draw(teams=[team_1, team_2, [a1], [a2], [b1]])
assert probability == pytest.approx(0.0518253, 0.0001)
assert probability == pytest.approx(0.0603735, 0.0001)

probability = model.predict_draw(teams=[[b1], [b1]])
assert probability == pytest.approx(0.5)
Expand Down
4 changes: 2 additions & 2 deletions tests/models/weng_lin/test_thurstone_mosteller_full.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,10 +538,10 @@ def test_predict_draw():
team_2 = [b1, b2]

probability = model.predict_draw(teams=[team_1, team_2])
assert probability == pytest.approx(0.1694772, 0.0001)
assert probability == pytest.approx(0.1919967, 0.0001)

probability = model.predict_draw(teams=[team_1, team_2, [a1], [a2], [b1]])
assert probability == pytest.approx(0.0518253, 0.0001)
assert probability == pytest.approx(0.0603735, 0.0001)

probability = model.predict_draw(teams=[[b1], [b1]])
assert probability == pytest.approx(0.5)
Expand Down
4 changes: 2 additions & 2 deletions tests/models/weng_lin/test_thurstone_mosteller_part.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,10 +542,10 @@ def test_predict_draw():
team_2 = [b1, b2]

probability = model.predict_draw(teams=[team_1, team_2])
assert probability == pytest.approx(0.1694772, 0.0001)
assert probability == pytest.approx(0.1919967, 0.0001)

probability = model.predict_draw(teams=[team_1, team_2, [a1], [a2], [b1]])
assert probability == pytest.approx(0.0518253, 0.0001)
assert probability == pytest.approx(0.0603735, 0.0001)

probability = model.predict_draw(teams=[[b1], [b1]])
assert probability == pytest.approx(0.5)
Expand Down

0 comments on commit 1fbc1b1

Please sign in to comment.