Skip to content

Commit

Permalink
Fix wrong example of TrueSkill.create_rating()
Browse files Browse the repository at this point in the history
  • Loading branch information
sublee committed Apr 27, 2015
1 parent f76086d commit 6cc463c
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 1 deletion.
20 changes: 19 additions & 1 deletion trueskill/__init__.py
Expand Up @@ -7,6 +7,7 @@
:copyright: (c) 2012-2015 by Heungsub Lee
:license: BSD, see LICENSE for more details.
"""
from __future__ import absolute_import
from itertools import chain, imap, izip
Expand Down Expand Up @@ -55,6 +56,7 @@ def calc_draw_probability(draw_margin, size, env=None):
:param size: the number of players in two comparing teams.
:param env: the :class:`TrueSkill` object. Defaults to the global
environment.
"""
if env is None:
env = global_env()
Expand All @@ -68,6 +70,7 @@ def calc_draw_margin(draw_probability, size, env=None):
:param size: the number of players in two comparing teams.
:param env: the :class:`TrueSkill` object. Defaults to the global
environment.
"""
if env is None:
env = global_env()
Expand Down Expand Up @@ -100,6 +103,7 @@ class Rating(Gaussian):
:param mu: the mean.
:param sigma: the standard deviation.
"""

def __init__(self, mu=None, sigma=None):
Expand Down Expand Up @@ -163,6 +167,7 @@ class TrueSkill(object):
:param backend: the name of a backend which implements cdf, pdf, ppf. See
:mod:`trueskill.backends` for more details. Defaults to
``None``.
"""

def __init__(self, mu=MU, sigma=SIGMA, beta=BETA, tau=TAU,
Expand All @@ -183,8 +188,9 @@ def create_rating(self, mu=None, sigma=None):
sigma to the environment's.
>>> env = TrueSkill(mu=0, sigma=1)
>>> env.Rating()
>>> env.create_rating()
trueskill.Rating(mu=0.000, sigma=1.000)
"""
if mu is None:
mu = self.mu
Expand Down Expand Up @@ -249,6 +255,7 @@ def validate_rating_groups(self, rating_groups):
>>> env.validate_rating_groups([(Rating(),), (Rating(),)])
... #doctest: +ELLIPSIS
[(truekill.Rating(...),), (trueskill.Rating(...),)]
"""
# check group sizes
if len(rating_groups) < 2:
Expand Down Expand Up @@ -310,6 +317,7 @@ def factor_graph_builders(self, rating_groups, ranks, weights):
| |
| |
trunc_layer: O O (TruncateFactor)
"""
flatten_ratings = sum(imap(tuple, rating_groups), ())
flatten_weights = sum(imap(tuple, weights), ())
Expand Down Expand Up @@ -460,6 +468,7 @@ def rate(self, rating_groups, ranks=None, weights=None, min_delta=DELTA):
solve this error. set the backend to "mpmath".
.. versionadded:: 0.2
"""
rating_groups, keys = self.validate_rating_groups(rating_groups)
weights = self.validate_weights(weights, rating_groups, keys)
Expand Down Expand Up @@ -512,6 +521,7 @@ def quality(self, rating_groups, weights=None):
:param weights: weights of each players for "partial play".
.. versionadded:: 0.2
"""
rating_groups, keys = self.validate_rating_groups(rating_groups)
weights = self.validate_weights(weights, rating_groups, keys)
Expand Down Expand Up @@ -560,6 +570,7 @@ def expose(self, rating):
leaderboard = sorted(ratings, key=env.expose, reverse=True)
.. versionadded:: 0.4
"""
k = self.mu / self.sigma
return rating.mu - k * rating.sigma
Expand All @@ -576,6 +587,7 @@ def make_as_global(self):
trueskill.Rating(mu=50.000, sigma=8.333)
But if you need just one environment, :func:`setup` is better to use.
"""
return setup(env=self)

Expand Down Expand Up @@ -615,6 +627,7 @@ def rate_1vs1(rating1, rating2, drawn=False, min_delta=DELTA, env=None):
:returns: a tuple containing recalculated 2 ratings.
.. versionadded:: 0.2
"""
if env is None:
env = global_env()
Expand All @@ -636,6 +649,7 @@ def quality_1vs1(rating1, rating2, env=None):
environment.
.. versionadded:: 0.2
"""
if env is None:
env = global_env()
Expand Down Expand Up @@ -665,6 +679,7 @@ def setup(mu=MU, sigma=SIGMA, beta=BETA, tau=TAU,
trueskill.TrueSkill(mu=50.000, ...)
>>> Rating()
trueskill.Rating(mu=50.000, sigma=8.333)
"""
if env is None:
env = TrueSkill(mu, sigma, beta, tau, draw_probability, backend)
Expand All @@ -676,6 +691,7 @@ def rate(rating_groups, ranks=None, weights=None, min_delta=DELTA):
"""A proxy function for :meth:`TrueSkill.rate` of the global environment.
.. versionadded:: 0.2
"""
return global_env().rate(rating_groups, ranks, weights, min_delta)

Expand All @@ -685,6 +701,7 @@ def quality(rating_groups, weights=None):
environment.
.. versionadded:: 0.2
"""
return global_env().quality(rating_groups, weights)

Expand All @@ -693,6 +710,7 @@ def expose(rating):
"""A proxy function for :meth:`TrueSkill.expose` of the global environment.
.. versionadded:: 0.4
"""
return global_env().expose(rating)

Expand Down
3 changes: 3 additions & 0 deletions trueskill/backends.py
Expand Up @@ -7,6 +7,7 @@
:copyright: (c) 2012-2015 by Heungsub Lee.
:license: BSD, see LICENSE for more details.
"""
from __future__ import absolute_import
import math
Expand Down Expand Up @@ -88,6 +89,7 @@ def choose_backend(backend):
mpf('7.6198530241605255e-24')
.. versionadded:: 0.3
"""
if backend is None: # fallback
return cdf, pdf, ppf
Expand Down Expand Up @@ -118,6 +120,7 @@ def available_backends():
setup(backend='mpmath')
.. versionadded:: 0.3
"""
backends = [None]
for backend in ['mpmath', 'scipy']:
Expand Down
8 changes: 8 additions & 0 deletions trueskill/deprecated.py
Expand Up @@ -7,6 +7,7 @@
:copyright: (c) 2012-2015 by Heungsub Lee
:license: BSD, see LICENSE for more details.
"""
from __future__ import absolute_import

Expand All @@ -33,6 +34,7 @@ def dynamic_draw_probability(rating1, rating2, env=None):
.. deprecated:: 0.4.1
Use :func:`quality_1vs1` instead.
"""
from warnings import warn
warn('Use quality_1vs1 instead', DeprecationWarning)
Expand Down Expand Up @@ -62,6 +64,7 @@ def TrueSkill_Rating(self, mu=None, sigma=None):
.. deprecated:: 0.2
Override :meth:`create_rating` instead.
"""
from warnings import warn
warn('TrueSkill.Rating is now called TrueSkill.create_rating',
Expand All @@ -75,6 +78,7 @@ def TrueSkill_transform_ratings(self, rating_groups, ranks=None,
.. deprecated:: 0.2
Override :meth:`rate` instead.
"""
from warnings import warn
warn('TrueSkill.transform_ratings is now called TrueSkill.rate',
Expand All @@ -89,6 +93,7 @@ def TrueSkill_match_quality(self, rating_groups):
.. deprecated:: 0.2
Override :meth:`quality` instead.
"""
from warnings import warn
warn('TrueSkill.match_quality is now called TrueSkill.quality',
Expand All @@ -103,6 +108,7 @@ def TrueSkill_rate_1vs1(self, rating1, rating2, drawn=False, min_delta=DELTA):
.. deprecated:: 0.4
Use :func:`rate_1vs1` instead.
"""
from warnings import warn
warn('Use rate_1vs1, a normal function instead', DeprecationWarning)
Expand All @@ -114,6 +120,7 @@ def TrueSkill_quality_1vs1(self, rating1, rating2):
.. deprecated:: 0.4
Use :func:`quality_1vs1` instead.
"""
from warnings import warn
warn('Use quality_1vs1, a normal function instead', DeprecationWarning)
Expand All @@ -126,6 +133,7 @@ def Rating_exposure(self):
.. deprecated:: 0.4
Use :meth:`TrueSkill.expose` instead.
"""
from warnings import warn
warn('Use TrueSkill.expose instead', DeprecationWarning)
Expand Down
1 change: 1 addition & 0 deletions trueskill/factorgraph.py
Expand Up @@ -7,6 +7,7 @@
:copyright: (c) 2012-2015 by Heungsub Lee.
:license: BSD, see LICENSE for more details.
"""
from __future__ import absolute_import
import itertools
Expand Down
1 change: 1 addition & 0 deletions trueskill/mathematics.py
Expand Up @@ -8,6 +8,7 @@
:copyright: (c) 2012-2015 by Heungsub Lee.
:license: BSD, see LICENSE for more details.
"""
from __future__ import absolute_import
import copy
Expand Down

0 comments on commit 6cc463c

Please sign in to comment.