rating

package module
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2020 License: MIT Imports: 7 Imported by: 1

README

rating

GoDoc Go Report Card Test

Usage: basic

This is the Go implementation of Gliko2 Rating In a simple use case we use as follows

Import the package
import "github.com/mashiike/rating"
Batch by Rating Period.

At the end of each rating period, it reflects the results of the game played in that period.

player := rating.New(1500.0, 200.0, 0.06)
opponents := []rating.Rating{
	rating.New(1400.0, 30.0, 0.06),
	rating.New(1550.0, 100.0, 0.06),
	rating.New(1700.0, 300.0, 0.06),
}
scores := []float64{
	rating.ScoreWin,
	rating.ScoreLose,
	rating.ScoreLose,
}
updated, _ := player.Update(opponents, scores, 0.5)
Sequentially for each game

Use Esteminated struct as follows. Then save the information in a database or file system etc.

player := rating.New(1500.0, 200.0, 0.06)
e := rating.NewEstimated(r)
opponent := rating.New(1400.0, 30.0, 0.06)
err := e.ApplyMatch(opponent, rating.ScoreWin)
//when the rating period is over
err = e.Fix(0.5)
updated := e.Fixed

Usage: use rating util GoDoc

svc := ratingutil.New(ratingutil.NewConfig())
team1 := svc.NewTeam(
	"bovidae",
	ratingutil.Players{
		svc.NewPlayer(
			"sheep",
			rating.New(1700.0, 50.0, svc.Config.InitialVolatility()),
			svc.Config.Now(),
		),
		svc.NewDefaultPlayer("goat"),
	},
)
team2 := svc.NewTeam(
	"equidae",
	ratingutil.Players{
		svc.NewPlayer(
			"donkey",
			rating.New(1400.0, 50.0, svc.Config.InitialVolatility()),
			svc.Config.Now(),
		),
		svc.NewDefaultPlayer("zebra"),
	},
)
match, _ := svc.NewMatch(team1, team2)
match.Add(team1, 1.0)
match.Add(team2, 0.0)
err := svc.Apply(match)

Documentation

Overview

Package rating implements the simple glicko-2 Rating. Glicko-2 Rating: see as following. (within this package, denoted as ref[1] below)

Professor Mark E. Glickman. "Example of the Glicko-2 system" http://www.glicko.net/glicko/glicko2.pdf

Note : The variable names in this package match the mathematical Greek letter variables of the dissertation. Note2: This English is written by the power of Google Translate.

Index

Examples

Constants

View Source
const (
	StrengthOnlyFormat = "1500.0"
	WithRangeFormat    = "1500.0 (800.0-2200.0)"
	CSVFormat          = "1500.0,350.0,0.06"
	DetailFormat       = "1500.0 (800.0-2200.0 v=0.06)"
	PlusMinusFormat    = "1500.0p-700.0"
	DefaultFormat      = "1500.0p-700.0v=0.06"
)

Rating Format examples I was impressed by the Format and Parse of time.Time, and added Rating.Parse and Rating.Format to Rating. The notation of Rating has various forms. Rating.Format and Rating.Parse can handle the notation in a format like Const below. elements is

Strength         1500.0
Deviation        350.0
Volatility       0.06
LowerStrength    800.0
UpperStrength    2200.0
95%PlusMinusDiff 700.0
View Source
const (
	InitialStrength  = 1500.0
	InitialDeviation = 350.0
)

Public Constant for rating value

View Source
const (

	//ScoreWin is Score when winning an opponent.
	ScoreWin = float64(1.0)
	//ScoreLose is Score when losing to an opponent.
	ScoreLose = float64(0.0)
	//ScoreDraw is Score when tied to an opponent.
	ScoreDraw = float64(0.5)
)

Variables

This section is empty.

Functions

func NewVolatility added in v0.5.0

func NewVolatility(start, count float64) float64

NewVolatility is a helper for determining Volatility. Calculate the appropriate value by entering the number of rating periods required to get back to the start deviation and the initial deviation

Types

type Estimated

type Estimated struct {
	sync.Mutex
	// in ref[1], this value is v^-1
	Accuracy float64 `json:"accuracy" db:"accuracy"`
	// in ref[1], this value is delta
	Improvement float64 `json:"improvement" db:"improvement"`
	// base fixed rating
	Fixed Rating `json:"fixed" db:"fixed"`
}

Estimated is a collection of Quantity related estimates that are being corrected. If you update the rating sequentially, use this struct to save the learning process during the current rating period.

func NewEstimated

func NewEstimated(rating Rating) *Estimated

NewEstimated is initial estimated value constractor

func (*Estimated) ApplyMatch

func (e *Estimated) ApplyMatch(opponent Rating, score float64) error

ApplyMatch reflects match results in the training estimates.

func (*Estimated) Fix

func (e *Estimated) Fix(tau float64) error

Fix ends the rating period and determines the new rating. system parameter tau. this value for determine next volatility. in ref[1] p.1: "Reasonable choices are between 0.3 and 1.2, though the system should be tested to decide which value results in greatest predictive accuracy. "

func (*Estimated) Rating

func (e *Estimated) Rating() Rating

Rating returns the current estimate

Example
package main

import (
	"fmt"

	"github.com/mashiike/rating"
)

func main() {
	player := rating.New(1500.0, 200.0, 0.06)
	opponents := []rating.Rating{
		rating.New(1400.0, 30.0, 0.06),
		rating.New(1550.0, 100.0, 0.06),
		rating.New(1700.0, 300.0, 0.06),
	}
	scores := []float64{
		rating.ScoreWin,
		rating.ScoreLose,
		rating.ScoreLose,
	}
	prev := player
	e := rating.NewEstimated(prev)
	for i := 0; i < len(opponents); i++ {
		e.ApplyMatch(opponents[i], scores[i])
		updated := e.Rating()
		fmt.Println(updated)
		fmt.Printf("strength  diff : %f\n", updated.Strength()-prev.Strength())
		fmt.Printf("deviation diff : %f\n", updated.Deviation()-prev.Deviation())
		fmt.Println("---")
		prev = updated
	}
	e.Fix(0.5)
	fmt.Println(e.Fixed)
}
Output:

1563.6 (1212.8-1914.4 v=0.06)
strength  diff : 63.560000
deviation diff : -24.600000
---
1492.4 (1175.7-1809.1 v=0.06)
strength  diff : -71.170000
deviation diff : -17.070000
---
1464.0 (1161.0-1767.1 v=0.06)
strength  diff : -28.340000
deviation diff : -6.820000
---
1464.0 (1161.0-1767.1 v=0.059996)

type ParseError

type ParseError struct {
	Layout     string
	Value      string
	LayoutElem string
	ValueElem  string
	Message    string
}

ParseError describes a problem parsing a rating string.

func (*ParseError) Error

func (e *ParseError) Error() string

Error returns the string representation of a ParseError.

type Rating

type Rating struct {
	// contains filtered or unexported fields
}

Rating is a structure to evaluate the strength of a player / team.

Example
package main

import (
	"fmt"

	"github.com/mashiike/rating"
)

func main() {
	player := rating.New(1500.0, 200.0, 0.06)
	opponents := []rating.Rating{
		rating.New(1400.0, 30.0, 0.06),
		rating.New(1550.0, 100.0, 0.06),
		rating.New(1700.0, 300.0, 0.06),
	}
	scores := []float64{
		rating.ScoreWin,
		rating.ScoreLose,
		rating.ScoreLose,
	}
	updated, _ := player.Update(opponents, scores, 0.5)
	fmt.Println(updated)
	fmt.Printf("strength  : %f\n", updated.Strength())
	fmt.Printf("deviation : %f\n", updated.Deviation())
	fmt.Printf("volatility: %f\n", updated.Volatility())
}
Output:

1464.0 (1161.0-1767.1 v=0.059996)
strength  : 1464.050000
deviation : 151.510000
volatility: 0.059996

func Average added in v0.5.0

func Average(ratings []Rating) Rating

Average returns the average strength of multiple Ratings

func Default

func Default(volatility float64) Rating

Default is return default rating for starting Player/Team.

func New

func New(strength, deviation, volatility float64) Rating

New is a constractor for Rating

func Parse

func Parse(layout, value string) (Rating, error)

Parse parses a formatted string and returns the rating value it represents. if not include volatility in layout, volatility set 0.06

func ParseWithVolatility

func ParseWithVolatility(layout, value string, volatility float64) (Rating, error)

ParseWithVolatility is parse a formatted string with default volatility.

func (Rating) AppendFormat

func (r Rating) AppendFormat(b []byte, layout string) []byte

AppendFormat is like Format but appends the textual as same as time.Time

func (Rating) Deviation

func (r Rating) Deviation() float64

Deviation is return RD(Rating Deviation) as general value.

func (Rating) Format

func (r Rating) Format(layout string) string

Format returns a textual representation of the rating value formatted as same as time.Time

func (Rating) Interval

func (r Rating) Interval() (float64, float64)

Interval is return value of strength 95% confidence interval.

func (Rating) IsDifferent

func (r Rating) IsDifferent(o Rating) bool

IsDifferent is a function to check the significance of Rating

func (Rating) IsStronger

func (r Rating) IsStronger(o Rating) bool

IsStronger is checker function. this rating r is storonger than rating o.

func (Rating) IsWeeker

func (r Rating) IsWeeker(o Rating) bool

IsWeeker is checker function. this rating r is weeker than rating o.

func (Rating) MarshalBinary

func (r Rating) MarshalBinary() ([]byte, error)

MarshalBinary implements the encoding.BinaryMarshaler interface.

func (Rating) MarshalJSON

func (r Rating) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface. The rating is a quoted string in Default format

func (Rating) MarshalText

func (r Rating) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface. The rating is formatted in Default Format.

func (Rating) Strength

func (r Rating) Strength() float64

Strength is return value of strength, as rating general value.

func (Rating) String

func (r Rating) String() string

String is for dump. fmt.Stringer interface implements format is DetailFormat as 1500.0 (800.0-2200.0 v=0.06)

func (*Rating) UnmarshalBinary

func (r *Rating) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.

func (*Rating) UnmarshalJSON

func (r *Rating) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface. The rating is expected to be a quoted string in Default format.

func (*Rating) UnmarshalText

func (r *Rating) UnmarshalText(data []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface. The rating is expected to be in Default Format.

func (Rating) Update

func (r Rating) Update(opponents []Rating, scores []float64, tau float64) (Rating, error)

Update is utils function for rating update. case non sequentially update, use this function.

func (Rating) Volatility

func (r Rating) Volatility() float64

Volatility is return Rating volatility.

func (Rating) WinProb

func (r Rating) WinProb(o Rating) float64

WinProb is estimate winning probability, this value 1500 and 1700, both RD is 0 => P(1700 is win) = 0.76

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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