openskill

package module
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 18, 2023 License: MIT Imports: 6 Imported by: 5

README

openskill.go

A Go implementation of the Weng-Lin Rating, as described here

Based on the Javascript implementation found here

This package requires the version of the Go language to be 1.20 or higher.

TODO

[ ] Improve README

[ ] Add unit testing

[ ] Add links to other implementations

[ ] write more BETTER code

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Ordinal

func Ordinal(rating Rating, options *Options) float64

Ordinal takes a Rating and returns a value that has 99.7% of representing the player true skill rating

func PredictDraw added in v0.4.0

func PredictDraw(teams []Team, options *Options) float64

PredictDraw returns the probability that a set of teams will tie based on their rating. If there is only one team, the function will return 1, and if there is no teams, it will return -1

func PredictRank added in v0.5.0

func PredictRank(teams []Team, options *Options) (predictions [][]float64)

PredictRank calculates and predicts the ranks of teams based on pairwise probabilities.

Parameters:

teams: A slice of Team structs representing the teams.
options: A pointer to an Options struct that holds the configuration options.

Returns:

predictions: A 2D slice of float64 containing the predicted ranks and corresponding probabilities.
             Each inner slice has two elements: rank and probability.
             The outer slice represents the predictions for each team.
             The length of predictions slice is equal to the number of teams.

func PredictWin added in v0.4.0

func PredictWin(teams []Team, options *Options) []float64

PredictWin returns the probability of each team has to win ordered by the order of the teams. If there is only one team, the function will return nil.

func RankDataMin added in v0.5.0

func RankDataMin(data []float64) []float64

RankDataMin calculates the ranks for a given slice of float64 values. It assigns ranks based on the values in ascending order, where the lowest value gets rank 1. If there are ties (equal values), the tied elements receive the same rank, with the next rank skipped.

Parameters:

data: A slice of float64 values for which ranks need to be calculated.

Returns:

A new slice of float64 values representing the ranks corresponding to the input data.

Types

type Gamma

type Gamma func(adjustedTeamUncertainty float64, amountOfTeams int64, averageTeamSkill float64, teamUncertaintySquared float64, team *Team, teamRanking int64) float64

Gamma represents a function to help to reduce the variance of how much the skill uncertainty degree can change. It is defined by user and helps to correct cases in which the player skill can assume huge negative or positive values with an uncertainty value near zero. Said function returns a number to adjust the skill uncertainty.

type Model

type Model func(teams []Team, options *Options) []Team

Model represents the kind of ranking model is chosen to be used

type NewRatingParams

type NewRatingParams struct {
	AveragePlayerSkill     float64
	SkillUncertaintyDegree float64
}

NewRatingParams represents the values that help initilize a rating.

type Options

type Options struct {
	// StandardizedPlayerSkill is a constant that is set in way that, the following assertion
	// is always true:
	//
	// StandardizedPlayerSkill == (Ordinal(Rating) - Rating.AveragePlayerSkill) / Rating.SkillUncertaintyDegree
	//
	// The bigger this constant is, the smaller the degree of uncertainty relative to average skill.
	// When not set,it defaults to 3.
	StandardizedPlayerSkill *float64

	// AveragePlayerSkill represents the default value of a player average skill level.
	// When not set, it defaults to 25.
	AveragePlayerSkill *float64

	// SkillUncertaintyDegree represents the default value of uncertainty for a player skill.
	// When not set, it defaults to Options.AveragePlayerSkill / Options.NormalizedPlayerSkill
	SkillUncertaintyDegree *float64

	// SmallPositive is a value to use when a ranking model tries to update a player uncertainty
	// with a negative value. It is rarely needed to do such substitutions.
	// When not set, it defaults to 0.001
	SmallPositive *float64

	// GammaFunction is a pointer to a function that is used to adjust
	// how much SkillUncertaintyDegree can vary. When not set, it defaults
	// to an internal implementation that mirrors the one found on item 6.1 of the
	// Weng-Lin paper for the Packett-Luce model.
	GammaFunction *Gamma

	// VarianceForTeamPerformance represents a constant to adjust the value of a team
	// performance. When not set, it defaults to (Options.SkillUncertaintyDegree / 2) ^ 2.
	// The default value for this constant takes into consideration if Options.SkillUncertaintyDegree is set or if
	// either Options.AveragePlayerSkill or Options.NormalizedPlayerSkill are set.
	VarianceForTeamPerformance *float64

	// Model represents the current model of ranking used. When not set, it defaults to Plackett-Luce.
	Model *Model

	// Rankings is a optional slice of rankings that is used when provided order of the teams for the
	// Rate function differs from the actual order of rankings. Other use for this field is to indicate
	// when ties happened after a competition.
	Rankings []int64

	// Scores is slice of the scores of the teams after competing. In this implementation
	// is a slice of integer values because otherwise, a lot of the internal operations
	// would use maps. This field doesn't need to be initialized with values.
	Scores []int64

	// Tau is a value that prevents the uncertainty to drop to a value that is too low.
	// Setting this constant, allows the rating to stay pliable even after many games.
	// A suggested value for this constant is Options.AveragePlayerSkill / 300.
	Tau *float64

	// PreventUncertaintyIncrease is an optional boolean value that, if it is set, and if Options.Tau is set,
	// prevents the uncertainty value to increase, thus stopping the fringe case when the Ordinal of player
	// rating decrease after a victory, which can feel unfair.
	PreventUncertaintyIncrease *bool
	// contains filtered or unexported fields
}

Options contains the values provided of the constants used by the rating system, plus optional rankings and scores of the teams to be rated, plus a optional paramenter that stops a player true skill rating from going after a victory, which can feel unfair.

type Rating

type Rating struct {
	// AveragePlayerSkill represents the average
	// value for a player skill. It normally is
	// the value in the middle of normal or
	// logistic distribution.
	AveragePlayerSkill float64

	// SkillUncertaintyDegree represents the amount
	// of uncertainty of the skill of a player.
	// This value is used to set the bounds of the
	// probalistic distribution.
	SkillUncertaintyDegree float64
}

Rating represents a player's skill in the particular set rankings

func NewRating

func NewRating(init *NewRatingParams, options *Options) *Rating

NewRating creates a new Rating, with optional initializing rating values and a optional set of default constants. Useful when not creating ratings in a vacuum.

type Team

type Team []*Rating

Team is nothing more than a collection of Ratings

func BradleyTerryFull

func BradleyTerryFull(game []Team, options *Options) []Team

BradleyTerryFull is a implementation of the Bradley-Terry ranking model that uses full pairing. The Bradley-Terry model uses logistic distribution to properly rank the teams. It accepts the a slice with the team that are competing, plus an options parameter, with things such as scores and previous rankings. The function return a slice of teams that are properly ranked.

func BradleyTerryPart added in v0.2.0

func BradleyTerryPart(game []Team, options *Options) []Team

BradleyTerryPart is a implementation of the Bradley-Terry ranking model that uses partial pairing. The Bradley-Terry model uses logistic distribution to properly rank the teams. Partial pairing is less accurate than a full pairing, but works better in situations with a high number of teams. This function accepts the a slice with the team that are competing, plus an options parameter, with things such as scores and previous rankings. The function return a slice of teams that are properly ranked.

func NewTeam added in v0.2.0

func NewTeam(teams ...*Rating) Team

NewTeam is a small utility function to create a Team from many players.

func PlackettLuce

func PlackettLuce(game []Team, options *Options) []Team

PlackettLuce represents the Plackett-Luce ranking model, which is the generalized version of the Bradley-Terry model

func Rate

func Rate(teams []Team, options Options) []Team

Rate rates a group of teams with the provided optional parameters for classification

func ThurstoneMostellerFull added in v0.3.0

func ThurstoneMostellerFull(game []Team, options *Options) []Team

ThurstoneMostellerFull is a implementation of the Thurstone-Mosteller ranking model that uses full pairing. The Thurstone-Mosteller model uses gaussian distribution to properly rank the teams. It accepts the a slice with the team that are competing, plus an options parameter, with things such as scores and previous rankings. The function return a slice of teams that are properly ranked.

func ThurstoneMostellerPart added in v0.3.0

func ThurstoneMostellerPart(game []Team, options *Options) []Team

ThurstoneMostellerPart is a implementation of the Thurstone-Mosteller ranking model that uses partial pairing. The Thurstone-Mosteller model uses gaussian distribution to properly rank the teams. Partial pairing is less accurate than a full pairing, but works better in situations with a high number of teams. This function accepts the a slice with the team that are competing, plus an options parameter, with things such as scores and previous rankings. The function return a slice of teams that are properly ranked.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL