Javascript implementation of Weng-Lin Rating, using Bradley Terry model as described at https://jmlr.csail.mit.edu/papers/volume12/weng11a/weng11a.pdf
Installation
Add wenglin
to your list of dependencies in package.json
:
npm install --save wenglin
Importing wenglin module
Use CommonJS's require
const Rater Team Player } = ;
Quick example
const rater = ;const WINNER = 1; const LOSER = 0; const team_1 = players: score: WINNER;const team_2 = players: score: LOSER; const result =
Modules
Player skill is represented by two parameters: mu and sigma
Mu is the actual skill of the player and sigma is its standard deviation.
Default values for mu and sigma are 25. and 25 / 3.
Rater is the main rating processor. It is initialized with BETA (sigma / 2) parameter by default so it can me omitted.
const rater = ;const rater = BETA;
Once rater is initialized, it can be invoked with all teams as separated arguments:
;
Team: Team represents a set of players, each with its skill data and a score. Score scale does not matter. It is compared between teams pairs and considered win, draw or loss.
const team_1 = players: player_1 player_2 ... score: 0;const team_1 = players: player_x player_y ... score: 1;
Player: This class stores a player's skill, mu and sigma. Player class is initialized with default mu and sigma but can also be overwritten.
> const player = ;> const player = mu: 25 sigma: 25 / 3;
Player skill can be obtained calling its skill method
> const player = mu: 25 sigma: 25 / 3 ref: my_db_player;> player mu: 25 sigma_sq: 6944444444444446 sigma: 8333333333333334
Player can also store a reference to an object of your choice to keep track of players in your implementation and ease its usage after Rater results are returned.
> const my_db_player = id: 'Player id';> const player = mu: 25 sigma: 25 / 3 ref: my_db_player;> player; id: 'Player id'
Full usage example
Following example represents a match between tree teams of two players each. Team 1 loses the match and teams 2 and 3 win with a draw.
> const Rater Team Player} = ; > const team_1 = players: score: 60; > const team_2 = players: score: 80; > const team_3 = players: score: 80; > const BETA = 416;> team_1 team_2 team_3; Player _mu: 21071628993408070 _sigma: 8018753738744802 _sigma_sq: 6430041152263375 _ref: undefined Player _mu: 21071628993408070 _sigma: 8018753738744802 _sigma_sq: 6430041152263375 _ref: undefined Player _mu: 26964185503295965 _sigma: 8018753738744802 _sigma_sq: 6430041152263375 _ref: undefined Player _mu: 26964185503295965 _sigma: 8018753738744802 _sigma_sq: 6430041152263375 _ref: undefined Player _mu: 26964185503295965 _sigma: 8018753738744802 _sigma_sq: 6430041152263375 _ref: undefined Player _mu: 26964185503295965 _sigma: 8018753738744802 _sigma_sq: 6430041152263375 _ref: undefined
Results
Rater output is an array of Player objects with the new rating and in the same input order. Original players are kept intact. After results are returned by rater, you can iterate over result items to obtain each reference and data at your side.
> const BETA = 4;> const result = team_1 team_2 ...; > player_1_skill = result mu: 23035814496704035 sigma: 817755635771097 sigma_sq: 668724279835391 mu: 23035814496704035 sigma: 817755635771097 sigma_sq: 668724279835391 mu: 26964185503295965 sigma: 817755635771097 sigma_sq: 668724279835391 mu: 26964185503295965 sigma: 817755635771097 sigma_sq: 668724279835391