rstt.ranking.inferer package

Submodules

rstt.ranking.inferer.elo module

class rstt.ranking.inferer.elo.Elo(k: float = 20.0, lc: float = 400.0, base: float = 10.0)[source]

Bases: object

Eo Inferer

Simple implementation based on wikipedia

Parameters

kfloat, optional

The K-factor, by default 20.0

lcfloat, optional

The constant dividing the ratings difference in the expected score formula, by default 400.0.

expectedScore(rating1: float, rating2: float) float[source]

Compute the expected score

Parameters

rating1float

a rating

rating2float

another rating

Returns

float

expected result of the player with rating1 against the player with rating2

post_rating(prior_rating: float, ratings_opponents: list[float], scores: list[float])[source]

Update the rating of a player given a list of opponent’s ratings and corresponding scores against.

Parameters

prior_ratingfloat

a rating to update

ratings_opponentslist[float]

opponent’s ratings

scoreslist[float]

scores associated to the prior_rating

Returns

float

post rating

rate(rating_groups: list[list[float]], scores: list[float], *args, **kwars) list[list[float]][source]

Rate method for elo

Parameters

rating_groupsList[List[float]]

Elo ratings formated by teams, for example [[elo_player1], [elo_player2]].

scoresList[float]

corresponding scores of the ratings, for example [[1.0],[0.0]] assuming player1 won the duel.

Returns

List[List[float]]

updated ratings in the formats [[new_elo1][new_elo2]]

rstt.ranking.inferer.elo.expectedScore(self, rating1: float, rating2: float) float

Compute the expected score

Parameters

rating1float

a rating

rating2float

another rating

Returns

float

expected result of the player with rating1 against the player with rating2

rstt.ranking.inferer.elo.rate(self, rating_groups: list[list[float]], scores: list[float], *args, **kwars) list[list[float]]

Rate method for elo

Parameters

rating_groupsList[List[float]]

Elo ratings formated by teams, for example [[elo_player1], [elo_player2]].

scoresList[float]

corresponding scores of the ratings, for example [[1.0],[0.0]] assuming player1 won the duel.

Returns

List[List[float]]

updated ratings in the formats [[new_elo1][new_elo2]]

rstt.ranking.inferer.glicko module

class rstt.ranking.inferer.glicko.Glicko(minRD: float = 30.0, maxRD: float = 350.0, c: float = 63.2, q: float = 0.005756462732485115, lc: int = 400)[source]

Bases: object

Glicko Inferer

The Glicko rating system is often described as an improvement of rstt.ranking.inferer.Elo. here, the implementation is based on Dr. Mark E. Glickman description.

Note

The source paper gives more instruction (notion of rating period) than what an Inferer class should do in RSTT. Step1, for example is implemented by the rstt.ranking.standard.BasicGlicko because it is related to the usage of the system, rather than what the Inferer does.

Warning

There is no type-checker support for ‘Glicko ratings’. In the documentation we use the typehint ‘GlickoRating’. Anything with a public mu and sigma attribute fits the bill.

Parameters

minRDfloat, optional

minimal value of RD, by default 30.0

maxRDfloat, optional

maximal value of RD, by default 350.0

cfloat, optional

constant used for ‘inactivity decay’, by default 63.2

qfloat, optional

No idea what it represent, feel free to play arround, by default math.log(10, math.e)/400

lcint, optional

Logistic constant similar to the one in rstt.rnaking.inferer.Elo, by default 400

G(rd: float) float[source]

_summary_

Implements: page 3, step2, g(RD) formula.

Parameters

rdfloat

the RD of a rating

Returns

float

g(RD)

d2(rating1, games: list[tuple[Any, float]]) float[source]

Implements: page 4, d^2 formula.

Parameters

rating1GlickoRating

the main rating

gamesList[Tuple[GlickoRating, float]]

A list of [opponent_rating, score_of_rating1]

Returns

float

the d2 value

Warns

Rarely a ZeroDivisionError occurs. In this case, the warning contains all the computational information. Execution continues using a very small value instead.

expectedScore(rating1, rating2, update: bool = True) float[source]

Compute the expected score

Implements: page 4, E(s|r,rj,RDj) when update=True or page 5, E otherwise.

Parameters

rating1GlickoRating

‘main’ rating

rating2GlickoRating

opponents rating

updatebool, optional

Wheter to use the formula for update or not, by default True.

Returns

float

The expected score of the player with rating1 against player with rating2

newRating(rating1, games: list[tuple[Any, float]])[source]

Rating Update method

Implements: page 3, step2.

Parameters

rating1GlickoRating

a rating to update.

gamesList[Tuple[GlickoRating, float]]

A list of results formated under as [opponent_rating, score_of rating1]

Returns

GlickoRating

the new updated rating

prePeriod_RD(rating: Any) float[source]

pre update RD value

Implements: page 3, step1, formula (b).

Parameters

ratingGlickoRating

A rating to ‘pre-update’

Returns

float

the new RD value of the rating.

rate(rating, ratings_opponents: list[Any], scores: list[float], *args, **kwars)[source]

Glicko rate method

End to end method to compute a new glicko rating based on a collection of results

Parameters

ratingGlickoRating

the rating to update

ratingsList[GlickoRating]

list of opponent ratings

scoresList[float]

list of score achieved by rating1 against the ‘ratings’ opponents, in the same order

Returns

GlickoRating

The new rating.

rstt.ranking.inferer.playerlevel module

class rstt.ranking.inferer.playerlevel.PlayerLevel[source]

Bases: object

rate(player: SPlayer) float[source]

rstt.ranking.inferer.playerwinprc module

class rstt.ranking.inferer.playerwinprc.PlayerWinPRC(default: float = -1.0, scope: int = 2147483647)[source]

Bases: object

Inferer based on Player win rate

Parameters

defaultfloat, optional

A rating for when no game was yet played, by default -1.0

scopeint, optional

The number of game to consider, starting from the most recent one, by default np.iinfo(np.int32).max.

rate(player: SPlayer, *args, **kwargs) float[source]

Win rate inference

Parameters

playerPlayer

a player to rate

Returns

Dict[Player, float]

the player and its associated rating

rstt.ranking.inferer.playerwinprc.rate(self, player: SPlayer, *args, **kwargs) float

Win rate inference

Parameters

playerPlayer

a player to rate

Returns

Dict[Player, float]

the player and its associated rating

rstt.ranking.inferer.eventscoring module

class rstt.ranking.inferer.eventscoring.EventDataSet(window_range: int = 1)[source]

Bases: object

add(event: Event)[source]
window(window: int | None = None)[source]
class rstt.ranking.inferer.eventscoring.EventScoring(window_range: int = 1, tops: int = 1, default: dict[int, float] = {})[source]

Bases: object

add_event(event: Event, relevance: dict[int, float] | None = None)[source]
rate(player: SPlayer) float[source]

Module contents

Modules for Inferer It include impleentation of the Elo and Glicko rating system

class rstt.ranking.inferer.Elo(k: float = 20.0, lc: float = 400.0, base: float = 10.0)[source]

Bases: object

Eo Inferer

Simple implementation based on wikipedia

Parameters

kfloat, optional

The K-factor, by default 20.0

lcfloat, optional

The constant dividing the ratings difference in the expected score formula, by default 400.0.

expectedScore(rating1: float, rating2: float) float[source]

Compute the expected score

Parameters

rating1float

a rating

rating2float

another rating

Returns

float

expected result of the player with rating1 against the player with rating2

post_rating(prior_rating: float, ratings_opponents: list[float], scores: list[float])[source]

Update the rating of a player given a list of opponent’s ratings and corresponding scores against.

Parameters

prior_ratingfloat

a rating to update

ratings_opponentslist[float]

opponent’s ratings

scoreslist[float]

scores associated to the prior_rating

Returns

float

post rating

rate(rating_groups: list[list[float]], scores: list[float], *args, **kwars) list[list[float]][source]

Rate method for elo

Parameters

rating_groupsList[List[float]]

Elo ratings formated by teams, for example [[elo_player1], [elo_player2]].

scoresList[float]

corresponding scores of the ratings, for example [[1.0],[0.0]] assuming player1 won the duel.

Returns

List[List[float]]

updated ratings in the formats [[new_elo1][new_elo2]]

class rstt.ranking.inferer.EventScoring(window_range: int = 1, tops: int = 1, default: dict[int, float] = {})[source]

Bases: object

add_event(event: Event, relevance: dict[int, float] | None = None)[source]
rate(player: SPlayer) float[source]
class rstt.ranking.inferer.Glicko(minRD: float = 30.0, maxRD: float = 350.0, c: float = 63.2, q: float = 0.005756462732485115, lc: int = 400)[source]

Bases: object

Glicko Inferer

The Glicko rating system is often described as an improvement of rstt.ranking.inferer.Elo. here, the implementation is based on Dr. Mark E. Glickman description.

Note

The source paper gives more instruction (notion of rating period) than what an Inferer class should do in RSTT. Step1, for example is implemented by the rstt.ranking.standard.BasicGlicko because it is related to the usage of the system, rather than what the Inferer does.

Warning

There is no type-checker support for ‘Glicko ratings’. In the documentation we use the typehint ‘GlickoRating’. Anything with a public mu and sigma attribute fits the bill.

Parameters

minRDfloat, optional

minimal value of RD, by default 30.0

maxRDfloat, optional

maximal value of RD, by default 350.0

cfloat, optional

constant used for ‘inactivity decay’, by default 63.2

qfloat, optional

No idea what it represent, feel free to play arround, by default math.log(10, math.e)/400

lcint, optional

Logistic constant similar to the one in rstt.rnaking.inferer.Elo, by default 400

G(rd: float) float[source]

_summary_

Implements: page 3, step2, g(RD) formula.

Parameters

rdfloat

the RD of a rating

Returns

float

g(RD)

d2(rating1, games: list[tuple[Any, float]]) float[source]

Implements: page 4, d^2 formula.

Parameters

rating1GlickoRating

the main rating

gamesList[Tuple[GlickoRating, float]]

A list of [opponent_rating, score_of_rating1]

Returns

float

the d2 value

Warns

Rarely a ZeroDivisionError occurs. In this case, the warning contains all the computational information. Execution continues using a very small value instead.

expectedScore(rating1, rating2, update: bool = True) float[source]

Compute the expected score

Implements: page 4, E(s|r,rj,RDj) when update=True or page 5, E otherwise.

Parameters

rating1GlickoRating

‘main’ rating

rating2GlickoRating

opponents rating

updatebool, optional

Wheter to use the formula for update or not, by default True.

Returns

float

The expected score of the player with rating1 against player with rating2

newRating(rating1, games: list[tuple[Any, float]])[source]

Rating Update method

Implements: page 3, step2.

Parameters

rating1GlickoRating

a rating to update.

gamesList[Tuple[GlickoRating, float]]

A list of results formated under as [opponent_rating, score_of rating1]

Returns

GlickoRating

the new updated rating

prePeriod_RD(rating: Any) float[source]

pre update RD value

Implements: page 3, step1, formula (b).

Parameters

ratingGlickoRating

A rating to ‘pre-update’

Returns

float

the new RD value of the rating.

rate(rating, ratings_opponents: list[Any], scores: list[float], *args, **kwars)[source]

Glicko rate method

End to end method to compute a new glicko rating based on a collection of results

Parameters

ratingGlickoRating

the rating to update

ratingsList[GlickoRating]

list of opponent ratings

scoresList[float]

list of score achieved by rating1 against the ‘ratings’ opponents, in the same order

Returns

GlickoRating

The new rating.

class rstt.ranking.inferer.Glicko2(mu: float = 1500, tau: float = 0.3, epsilon: float = 5e-09, *args, **kwargs)[source]

Bases: Glicko

Glicko2 Inference

Implement the glicko-2 rating system as descried by Prof. Mark E. Glickman.

Parameters

mufloat, optional

The default mu of the rating, used to scaled down the GlickoRating, by default 1500.0

tau: float, optional

Glicko2 Inference parameter. Tau constrains the change in volatility over time. Reasonable choices are between 0.3 and 1.2, by default 0.3

epsilon: float, optional

Glicko2 Inference parameter. Convergence tolerance of the Illinois algorithm used in step 5 of rating update, by default 0.000000005

Note

Glicko2 is implemented using Glicko Inference with q := 1.0

epsilon

NOTE on epsilon for _step5

The value does not match ‘The value e = 0.000001 is a sufficiently small choice’ Does not reproduce the iteration of the calculation example e = 0.000000005 does produce very similar numerical values, and number of steps!

Value of A,B fA, fB in step5 iteration

epsilon = 0.00000001 -5.626821433520073 -6.126821433520073 -0.0005355033552526004 1.999675064776017 -5.626821433520073 -5.626955295265377 -0.0002677516776263002 1.5228332788134666e-08

epsilong = 0.000000001 -5.626821433520073 -6.126821433520073 -0.0005355033552526004 1.999675064776017 -5.626821433520073 -5.626955295265377 -0.0002677516776263002 1.5228332788134666e-08 -5.626955295265377 -5.626955287652446 1.5228332788134666e-08 -1.5227465554983055e-08 -5.626955295265377 -5.626955291458803 7.614166394067333e-09 -0.0005354469812191957

self.epsilon = 0.000000005 -5.626821433520073 -6.126821433520073 -0.0005355033552526004 1.999675064776017 -5.626821433520073 -5.626955295265377 -0.0002677516776263002 1.5228332788134666e-08 -5.626955295265377 -5.626955287652446 1.5228332788134666e-08 -1.5227465554983055e-08

.

expectedScore(rating1: GlickoRating, rating2: GlickoRating, *args, **kwargs)[source]

Compute the expected score

Implements: page 4, E(s|r,rj,RDj) when update=True or page 5, E otherwise.

Parameters

rating1GlickoRating

‘main’ rating

rating2GlickoRating

opponents rating

updatebool, optional

Wheter to use the formula for update or not, by default True.

Returns

float

The expected score of the player with rating1 against player with rating2

f(x: float, phi2: float, delta2: float, v: float, a: float, tau: float)[source]
rate(rating: Glicko2Rating, ratings_opponents: list[Glicko2Rating], scores: list[float])[source]
NOTE: scaling up and down rating
  • within the rate method increase number of operation.

  • within the forward method makes it harder to read and maintain.

class rstt.ranking.inferer.PlayerLevel[source]

Bases: object

rate(player: SPlayer) float[source]
class rstt.ranking.inferer.PlayerWinPRC(default: float = -1.0, scope: int = 2147483647)[source]

Bases: object

Inferer based on Player win rate

Parameters

defaultfloat, optional

A rating for when no game was yet played, by default -1.0

scopeint, optional

The number of game to consider, starting from the most recent one, by default np.iinfo(np.int32).max.

rate(player: SPlayer, *args, **kwargs) float[source]

Win rate inference

Parameters

playerPlayer

a player to rate

Returns

Dict[Player, float]

the player and its associated rating