ts-trueskill
Version:
Port of python trueskill package in TypeScript
124 lines (123 loc) • 4.56 kB
TypeScript
import { Gaussian } from 'ts-gaussian';
import { Rating } from './rating.js';
/**
* Calculates a draw-margin from the given drawProbability
*/
export declare function calcDrawMargin(drawProbability: number, size: number, env?: TrueSkill): number;
/**
* Implements a TrueSkill environment. An environment could have
* customized constants. Every games have not same design and may need to
* customize TrueSkill constants.
*
* For example, 60% of matches in your game have finished as draw then you
* should set ``draw_probability`` to 0.60
*
* const env = new TrueSkill(undefined, undefined, undefined, undefined, 0.6);
*
* For more details of the constants, see [The Math Behind TrueSkill by
* Jeff Moser](http://www.moserware.com/assets/computing-your-skill/The%20Math%20Behind%20TrueSkill.pdf).
*/
export declare class TrueSkill {
drawProbability: number;
guassian: Gaussian;
mu: number;
sigma: number;
beta: number;
tau: number;
/**
* @param mu initial mean of ratings
* @param sigma initial standard deviation of ratings
* @param beta distance that guarantees about 76% chance of winning
* @param tau dynamic factor
* @param drawProbability draw probability of the game
* @param guassian reuseable gaussian
*/
constructor(mu?: number, sigma?: number, beta?: number, tau?: number, drawProbability?: number, guassian?: Gaussian);
/**
* Recalculates ratings by the ranking table
*/
rate(ratingGroups: Rating[][] | any[], ranks?: number[] | null, weights?: number[][] | null, minDelta?: number): Rating[][] | any[];
/**
* Calculates the match quality of the given rating groups. Result
* is the draw probability in the association::
*
* ```ts
* env = TrueSkill()
* if (env.quality([team1, team2, team3]) < 0.50) {
* console.log('This match seems to be not so fair')
* }
* ```
*/
quality(ratingGroups: Rating[][], weights?: number[][]): number;
/**
* Initializes new `Rating` object, but it fixes default mu and
* sigma to the environment's.
* var env = TrueSkill(mu=0, sigma=1)
* var env.createRating()
* trueskill.Rating(mu=0.000, sigma=1.000)
*/
createRating(mu?: number, sigma?: number): Rating;
/**
* Returns the value of the rating exposure. It starts from 0 and
* converges to the mean. Use this as a sort key in a leaderboard
*/
expose(rating: Rating): number;
/**
* Taken from https://github.com/sublee/trueskill/issues/1
*/
winProbability(a: Rating[], b: Rating[]): number;
/**
* The non-draw version of "V" function.
* "V" calculates a variation of a mean.
*/
private _vWin;
private _vDraw;
/**
* The non-draw version of "W" function.
* "W" calculates a variation of a standard deviation.
*/
private _wWin;
/**
* The draw version of "W" function.
*/
private _wDraw;
/**
* Validates a ratingGroups argument. It should contain more than
* 2 groups and all groups must not be empty.
*/
private _validateRatingGroups;
private _validateWeights;
private _buildRatingLayer;
private _buildPerfLayer;
private _buildTeamPerfLayer;
private _buildTeamDiffLayer;
private _buildTruncLayer;
/**
* Sends messages within every nodes of the factor graph
* until the result is reliable.
*/
private _runSchedule;
}
/**
* A shortcut to rate just 2 players in a head-to-head match
*/
export declare function rate_1vs1(rating1: Rating, rating2: Rating, drawn?: boolean, minDelta?: number, env?: TrueSkill): [Rating, Rating];
/**
* A shortcut to calculate the match quality between 2 players in
* a head-to-head match
*/
export declare function quality_1vs1(rating1: Rating, rating2: Rating, env?: TrueSkill): number;
/**
* A proxy function for `TrueSkill.rate` of the global environment.
*/
export declare function rate(ratingGroups: Rating[][] | any[], ranks?: any[] | null, weights?: any[] | null, minDelta?: number, env?: TrueSkill): Rating[][];
export declare function winProbability(a: Rating[], b: Rating[], env?: TrueSkill): number;
/**
* A proxy function for `TrueSkill.quality` of the global
* environment.
*/
export declare function quality(ratingGroups: Rating[][] | any[], weights?: number[][], env?: TrueSkill): number;
/**
* A proxy function for TrueSkill.expose of the global environment.
*/
export declare function expose(rating: Rating, env?: TrueSkill): number;