openskill.models.weng_lin.thurstone_mosteller_part

Thurstone-Mosteller Partial Pairing Model

Specific classes and functions for the Thurstone-Mosteller Partial Pairing model.

Module Contents

Classes

ThurstoneMostellerPart

Based on Algorithm 3 by Weng and Lin [2011]

ThurstoneMostellerPartRating

Thurstone-Mosteller Partial Pairing player rating data.

class openskill.models.weng_lin.thurstone_mosteller_part.ThurstoneMostellerPart(mu=25.0, sigma=25.0 / 3.0, beta=25.0 / 6.0, kappa=0.0001, gamma=_gamma, tau=25.0 / 300.0, limit_sigma=False, balance=False)[source]

Based on Algorithm 3 by Weng and Lin [2011]

The Thurstone-Mosteller with Partial Pairing model extends the full pairing model to handle scenarios where not all players compete against each other. It retains the assumptions of the full pairing model—utilizing a single scalar value to represent player performance, enabling rating updates through match outcomes, and employing maximum likelihood estimation for rating estimation. This model relaxes the requirement for complete pairing and is ideal for situations where only specific players directly compete with each other.

Parameters:
  • mu (float) –

    Represents the initial belief about the skill of a player before any matches have been played. Known mostly as the mean of the Guassian prior distribution.

    Represented by: \(\mu\)

  • sigma (float) –

    Standard deviation of the prior distribution of player.

    Represented by: \(\sigma = \frac{\mu}{z}\) where \(z\) is an integer that represents the variance of the skill of a player.

  • beta (float) –

    Hyperparameter that determines the level of uncertainty or variability present in the prior distribution of ratings.

    Represented by: \(\beta = \frac{\sigma}{2}\)

  • kappa (float) –

    Arbitrary small positive real number that is used to prevent the variance of the posterior distribution from becoming too small or negative. It can also be thought of as a regularization parameter.

    Represented by: \(\kappa\)

  • gamma (Callable[[float, int, float, float, Sequence[ThurstoneMostellerPartRating], int, Optional[List[float]]], float]) –

    Custom function you can pass that must contain 5 parameters. The function must return a float or int.

    Represented by: \(\gamma\)

  • tau (float) –

    Additive dynamics parameter that prevents sigma from getting too small to increase rating change volatility.

    Represented by: \(\tau\)

  • limit_sigma (bool) – Boolean that determines whether to restrict the value of sigma from increasing.

  • balance (bool) – Boolean that determines whether to emphasize rating outliers.

static _a(team_ratings)[source]

Count the number of times a rank appears in the list of team ratings.

Represented by:

\[A_q = |\{s: r(s) = r(q)\}|, q = 1,...,k\]
Parameters:

team_ratings (List[ThurstoneMostellerPartTeamRating]) – The whole rating of a list of teams in a game.

Returns:

A list of ints.

Return type:

List[int]

_c(team_ratings)[source]

Calculate the square root of the collective team sigma.

Represented by:

\[c = \Biggl(\sum_{i=1}^k (\sigma_i^2 + \beta^2) \Biggr)\]

Algorithm 4: Procedure 3 in [Weng and Lin, 2011]

Parameters:

team_ratings (List[ThurstoneMostellerPartTeamRating]) – The whole rating of a list of teams in a game.

Returns:

A number.

Return type:

float

_calculate_rankings(game, ranks=None)[source]

Calculates the rankings based on the scores or ranks of the teams.

It assigns a rank to each team based on their score, with the team with the highest score being ranked first.

Parameters:
Returns:

A list of ranks for each team in the game.

Return type:

List[int]

_calculate_team_ratings(game, ranks=None, weights=None)[source]

Get the team ratings of a game.

Parameters:
  • game (Sequence[Sequence[ThurstoneMostellerPartRating]]) – A list of teams, where teams are lists of ThurstoneMostellerPartRating objects.

  • ranks (Optional[List[float]]) – A list of ranks for each team in the game.

  • weights (Optional[List[List[float]]]) – A list of lists of floats, where each inner list represents the contribution of each player to the team’s performance. The values should be normalized from 0 to 1.

Returns:

A list of ThurstoneMostellerPartTeamRating objects.

Return type:

List[ThurstoneMostellerPartTeamRating]

static _check_teams(teams)[source]

Ensure teams argument is valid.

Parameters:

teams (List[List[ThurstoneMostellerPartRating]]) – List of lists of ThurstoneMostellerPartRating objects.

Return type:

None

static _sum_q(team_ratings, c)[source]

Sum up all the values of mu / c raised to \(e\).

Represented by:

\[\sum_{s \in C_q} e^{\theta_s / c}, q=1, ...,k, \text{where } C_q = \{i: r(i) \geq r(q)\}\]

Algorithm 4: Procedure 3 in [Weng and Lin, 2011]

Parameters:
  • team_ratings (List[ThurstoneMostellerPartTeamRating]) – The whole rating of a list of teams in a game.

  • c (float) – The square root of the collective team sigma.

Returns:

A list of floats.

Return type:

List[float]

static create_rating(rating, name=None)[source]

Create a ThurstoneMostellerPartRating object from a list of mu and sigma values.

Parameters:
  • rating (List[float]) – A list of two values where the first value is the mu and the second value is the sigma.

  • name (Optional[str]) – An optional name for the player.

Returns:

A ThurstoneMostellerPartRating object created from the list passed in.

Return type:

ThurstoneMostellerPartRating

predict_draw(teams)[source]

Predict how likely a match up against teams of one or more players will draw. This algorithm has a time complexity of \(\mathcal{0}(n^2)\) where ‘n’ is the number of teams.

Parameters:

teams (List[List[ThurstoneMostellerPartRating]]) – A list of two or more teams.

Returns:

The odds of a draw.

Return type:

float

predict_rank(teams)[source]

Predict the shape of a match outcome. This algorithm has a time complexity of \(\mathcal{0}(n^2)\) where ‘n’ is the number of teams.

Parameters:

teams (List[List[ThurstoneMostellerPartRating]]) – A list of two or more teams.

Returns:

A list of team ranks with their probabilities.

Return type:

List[Tuple[int, float]]

predict_win(teams)[source]

Predict how likely a match up against teams of one or more players will go. This algorithm has a time complexity of \(\mathcal{0}(n^2)\) where ‘n’ is the number of teams.

This is a generalization of the algorithm in [Ibstedt et al., 2019] to asymmetric n-player n-teams.

Parameters:

teams (List[List[ThurstoneMostellerPartRating]]) – A list of two or more teams.

Returns:

A list of odds of each team winning.

Return type:

List[float]

rate(teams, ranks=None, scores=None, weights=None, tau=None, limit_sigma=None)[source]

Calculate the new ratings based on the given teams and parameters.

Parameters:
  • teams (List[List[ThurstoneMostellerPartRating]]) – A list of teams where each team is a list of ThurstoneMostellerPartRating objects.

  • ranks (Optional[List[float]]) – A list of floats where the lower values represent winners.

  • scores (Optional[List[float]]) – A list of floats where higher values represent winners.

  • weights (Optional[List[List[float]]]) – A list of lists of floats, where each inner list represents the contribution of each player to the team’s performance.

  • tau (Optional[float]) – Additive dynamics parameter that prevents sigma from getting too small to increase rating change volatility.

  • limit_sigma (Optional[bool]) – Boolean that determines whether to restrict the value of sigma from increasing.

Returns:

A list of teams where each team is a list of updated ThurstoneMostellerPartRating objects.

Return type:

List[List[ThurstoneMostellerPartRating]]

rating(mu=None, sigma=None, name=None)[source]

Returns a new rating object with your default parameters. The given parameters can be overridden from the defaults provided by the main model, but is not recommended unless you know what you are doing.

Parameters:
  • mu (Optional[float]) –

    Represents the initial belief about the skill of a player before any matches have been played. Known mostly as the mean of the Gaussian prior distribution.

    Represented by: \(\mu\)

  • sigma (Optional[float]) –

    Standard deviation of the prior distribution of player.

    Represented by: \(\sigma = \frac{\mu}{z}\) where \(z\) is an integer that represents the variance of the skill of a player.

  • name (Optional[str]) – Optional name for the player.

Returns:

ThurstoneMostellerPartRating object

Return type:

ThurstoneMostellerPartRating

class openskill.models.weng_lin.thurstone_mosteller_part.ThurstoneMostellerPartRating(mu, sigma, name=None)[source]

Thurstone-Mosteller Partial Pairing player rating data.

This object is returned by the ThurstoneMostellerPart.rating method.

Parameters:
  • mu (float) –

    Represents the initial belief about the skill of a player before any matches have been played. Known mostly as the mean of the Guassian prior distribution.

    Represented by: \(\mu\)

  • sigma (float) –

    Standard deviation of the prior distribution of player.

    Represented by: \(\sigma = \frac{\mu}{z}\) where \(z\) is an integer that represents the variance of the skill of a player.

  • name (Optional[str]) – Optional name for the player.

ordinal(z=3.0, alpha=1, target=0)[source]

A single scalar value that represents the player’s skill where their true skill is 99.7% likely to be higher.

Parameters:
  • z (float) – Float that represents the number of standard deviations to subtract from the mean. By default, set to 3.0, which corresponds to a 99.7% confidence interval in a normal distribution.

  • alpha (float) – Float scaling factor applied to the entire calculation. Adjusts the overall scale of the ordinal value. Defaults to 1.

  • target (float) – Optional float value used to shift the ordinal value towards a specific target. The shift is adjusted by the alpha scaling factor. Defaults to 0.

Returns:

\(\alpha \cdot ((\mu - z * \sigma) + \frac{\text{target}}{\alpha})\)

Return type:

float