Skip to content

Commit

Permalink
Modify default tau value to 25/300 (#61)
Browse files Browse the repository at this point in the history
* Modify default tau value to 25/300

* Remove note about default tau value

* Add changelog fragment
  • Loading branch information
vivekjoshy committed Nov 29, 2022
1 parent e6b194b commit 40b2989
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 32 deletions.
8 changes: 5 additions & 3 deletions benchmark/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@

import jsonlines
import trueskill
from prompt_toolkit import print_formatted_text as print, HTML, prompt
from prompt_toolkit import HTML
from prompt_toolkit import print_formatted_text as print
from prompt_toolkit import prompt
from prompt_toolkit.completion import WordCompleter
from prompt_toolkit.shortcuts import ProgressBar

import openskill
from openskill.models import (
ThurstoneMostellerPart,
ThurstoneMostellerFull,
BradleyTerryFull,
BradleyTerryPart,
PlackettLuce,
ThurstoneMostellerFull,
ThurstoneMostellerPart,
)

# Stores
Expand Down
8 changes: 5 additions & 3 deletions benchmark/draw_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,20 @@
import numpy as np
import pandas
import trueskill
from prompt_toolkit import print_formatted_text as print, HTML, prompt
from prompt_toolkit import HTML
from prompt_toolkit import print_formatted_text as print
from prompt_toolkit import prompt
from prompt_toolkit.completion import WordCompleter
from prompt_toolkit.shortcuts import ProgressBar
from sklearn.model_selection import train_test_split

import openskill
from openskill.models import (
ThurstoneMostellerPart,
ThurstoneMostellerFull,
BradleyTerryFull,
BradleyTerryPart,
PlackettLuce,
ThurstoneMostellerFull,
ThurstoneMostellerPart,
)

# Stores
Expand Down
8 changes: 5 additions & 3 deletions benchmark/split_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,20 @@
import jsonlines
import numpy as np
import trueskill
from prompt_toolkit import print_formatted_text as print, HTML, prompt
from prompt_toolkit import HTML
from prompt_toolkit import print_formatted_text as print
from prompt_toolkit import prompt
from prompt_toolkit.completion import WordCompleter
from prompt_toolkit.shortcuts import ProgressBar
from sklearn.model_selection import train_test_split

import openskill
from openskill.models import (
ThurstoneMostellerPart,
ThurstoneMostellerFull,
BradleyTerryFull,
BradleyTerryPart,
PlackettLuce,
ThurstoneMostellerFull,
ThurstoneMostellerPart,
)

# Stores
Expand Down
1 change: 1 addition & 0 deletions changes/61.breaking.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Modify default ``tau`` value to ``25/300`` #61
3 changes: 2 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@
pass

try:
import sphinx
from distutils.version import LooseVersion

import sphinx

cmd_line_template = (
"sphinx-apidoc --implicit-namespaces -f -o {outputdir} {moduledir}"
)
Expand Down
2 changes: 1 addition & 1 deletion docs/time_decay.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from openskill import Rating, rate, predict_win
from openskill import Rating, predict_win, rate

x, y = Rating(), Rating()

Expand Down
9 changes: 4 additions & 5 deletions openskill/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
from openskill.rate import ordinal
from openskill.rate import (
rate,
Rating,
create_rating,
team_rating,
predict_win,
ordinal,
predict_draw,
predict_win,
rate,
team_rating,
)


__version__ = "2.5.1"
8 changes: 8 additions & 0 deletions openskill/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,17 @@ def beta_squared(**options) -> float:
return beta(**options) ** 2


def tau(**options) -> float:
if "tau" in options:
return options["tau"]
else:
return mu(**options) / 300


class Constants:
def __init__(self, **options):
self.EPSILON: float = epsilon(**options)
self.TWO_BETA_SQUARED: float = 2 * beta_squared(**options)
self.BETA_SQUARED: float = beta_squared(**options)
self.Z: float = z(**options)
self.TAU: float = tau(**options)
14 changes: 7 additions & 7 deletions openskill/rate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
import itertools
import math
from functools import reduce
from typing import Optional, Union, List
from typing import List, Optional, Union

from openskill.constants import mu as default_mu, beta, Constants
from openskill.constants import Constants, beta
from openskill.constants import mu as default_mu
from openskill.constants import sigma as default_sigma
from openskill.models.plackett_luce import PlackettLuce
from openskill.statistics import phi_major, phi_major_inverse
from openskill.util import unwind, rankings
from openskill.util import rankings, unwind


class Rating:
Expand Down Expand Up @@ -262,13 +263,12 @@ def rate(teams: List[List[Rating]], **options) -> List[List[Rating]]:
:param prevent_sigma_increase: A :class:`~bool` that prevents sigma from ever increasing.
:param options: Pass in a set of custom values for constants defined in the Weng-Lin paper.
:return: Returns a list of :class:`~openskill.rate.Rating` objects.
.. note::
``tau`` will default to ``25/300`` in the next major version update.
"""
constants = Constants(**options)
tau = constants.TAU
original_teams = copy.deepcopy(teams)
if "tau" in options:
tau_squared = options["tau"] * options["tau"]
tau_squared = tau * tau
for team_index, team in enumerate(teams):
for player_index, player in enumerate(team):
teams[team_index][player_index].sigma = math.sqrt(
Expand Down
6 changes: 1 addition & 5 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import math
from abc import ABC, abstractmethod
from collections import UserString
from collections.abc import (
Mapping,
Set,
Sequence,
)
from collections.abc import Mapping, Sequence, Set
from decimal import Decimal
from numbers import Real
from typing import List
Expand Down
5 changes: 4 additions & 1 deletion tests/test_constants.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from openskill.constants import z, mu, sigma, epsilon, beta, beta_squared
from openskill.constants import beta, beta_squared, epsilon, mu, sigma, tau, z


def test_constants():
Expand All @@ -21,3 +21,6 @@ def test_constants():

assert beta_squared(beta_squared=16.2) == 16.2
assert beta_squared() == pytest.approx(17.361111111111114)

assert tau(tau=0.3) == 0.3
assert tau() == pytest.approx(0.08333333)
2 changes: 1 addition & 1 deletion tests/test_ordinal.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from openskill import ordinal, Rating
from openskill import Rating, ordinal


def test_ordinal():
Expand Down
3 changes: 1 addition & 2 deletions tests/test_team_rating.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import pytest

from openskill import Rating
from openskill import team_rating
from openskill import Rating, team_rating

r = Rating()
team_1 = [r]
Expand Down

0 comments on commit 40b2989

Please sign in to comment.