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.
Index ¶
- Constants
- func ComputeInitialVolatility(start, end, count float64) float64
- type Estimated
- type ParseError
- type Rating
- func (r Rating) AppendFormat(b []byte, layout string) []byte
- func (r Rating) Deviation() float64
- func (r Rating) Format(layout string) string
- func (r Rating) Interval() (float64, float64)
- func (r Rating) IsDifferent(o Rating) bool
- func (r Rating) IsStronger(o Rating) bool
- func (r Rating) IsWeeker(o Rating) bool
- func (r Rating) MarshalBinary() ([]byte, error)
- func (r Rating) MarshalJSON() ([]byte, error)
- func (r Rating) MarshalText() ([]byte, error)
- func (r Rating) Strength() float64
- func (r Rating) String() string
- func (r *Rating) UnmarshalBinary(data []byte) error
- func (r *Rating) UnmarshalJSON(data []byte) error
- func (r *Rating) UnmarshalText(data []byte) error
- func (r Rating) Update(opponents []Rating, scores []float64, tau float64) (Rating, error)
- func (r Rating) Volatility() float64
- func (r Rating) WinProb(o Rating) float64
Examples ¶
Constants ¶
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
const ( InitialStrength = 1500.0 InitialDeviation = 350.0 )
Public Constant for rating value
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 ComputeInitialVolatility ¶
ComputeInitialVolatility is utils function for detamine volatility start and end is deviation. count is rating period count.
Types ¶
type Estimated ¶
type Estimated struct { sync.Mutex // in ref[1], this value is v^-1 Accuracy float64 `json:"accuracy"` // in ref[1], this value is delta Improvement float64 `json:"improvement"` // base fixed rating Fixed Rating `json:"fixed"` // system paramter 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. " Tau float64 `json:"tau"` // contains filtered or unexported fields }
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 ¶
NewEstimated is initial estimated value constractor
func (*Estimated) ApplyMatch ¶
ApplyMatch reflects match results in the training estimates.
func (*Estimated) 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, 0.5) 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() 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 time 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 Parse ¶
Parse parses a formatted string and returns the rating value it represents. if not include volatility in layout, volatility set 0.06
func ParseWithVolatility ¶
ParseWithVolatility is parse a formatted string with default volatility.
func (Rating) AppendFormat ¶
AppendFormat is like Format but appends the textual as same as time.Time
func (Rating) Format ¶
Format returns a textual representation of the time value formatted as same as time.Time
func (Rating) IsDifferent ¶
IsDifferent is a function to check the significance of Rating
func (Rating) IsStronger ¶
IsStronger is checker function. this rating r is storonger than rating o.
func (Rating) MarshalBinary ¶
MarshalBinary implements the encoding.BinaryMarshaler interface.
func (Rating) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface. The rating is a quoted string in Default format
func (Rating) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface. The rating is formatted in Default Format.
func (Rating) 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 ¶
UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.
func (*Rating) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface. The rating is expected to be a quoted string in Default format.
func (*Rating) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface. The rating is expected to be in Default Format.
func (Rating) Update ¶
Update is utils function for rating update. case non sequentially update, use this function.
func (Rating) Volatility ¶
Volatility is return Rating volatility.