A library for online ranking from https://www.csie.ntu.edu.tw/~cjlin/papers/online_ranking/online_journal.pdf.
The library implements the Weng-Lin ranking algorithm based on the Bradley-Terry model.
Players have mu = 25 and sigma = 25/3 by default. Players have their perceived skill, which is (mu - sigma * 3).
// p1 has the default mu = 25, sigma = 25/3, pretty much still unrated.
const p1 = new Player("Player 1");
p1.skill
// 0
// p2 is a much stronger player, with mu = 30 and sigma = 0.5
const p2 = new Player("Player 2", 30, 0.5);
p2.skill
// 28.5Group players in teams.
const team1 = new Team([p1, p2]);
const team2 = new Team([p3, p4]);
const team3 = new Team([p5, p6]);Create a game where the teams are against one another. Game outcomes are either ranks or scores.
// a game where team 1 is in 3rd place, team 2 is in 1st place and team 3 is in 2nd place.
const game = new Game(
[team1, team2, team3],
[3, 1, 2],
"ranks",
);
// a game where teams have their respective scores
const game = new Game(
[team1, team2, team3],
[5, -3, 2],
"scores",
);Create a Bradley-Terry model. Optionally customise the rank function or score function. Rank and score functions take in 2 ranks or scores and return a real number between 0 and 1.
const bt = new BradleyTerry({
scoreFunction: (score0, score1) => {
return 1 / (1 + Math.exp(-0.1 * (score0 - score1)))
}
});
const updatedPlayers: Record<string, Player> = bt.apply(game);Applying the model to a game immutably returns an updated set of players indexed by their names.
const bt = new BradleyTerry();
const game = new Game(
[team2, team3],
[1, 2],
"ranks",
);
for (const player of Object.values(bt.apply(game))) {
console.log([player.name, player.mu, player.sigma]);
}
// [ "Player 3", 27.63523138347365, 8.065506316323548 ]
// [ "Player 4", 27.63523138347365, 8.065506316323548 ]
// [ "Player 5", 22.36476861652635, 8.065506316323548 ]
// [ "Player 6", 22.36476861652635, 8.065506316323548 ]