https://github.com/cheeze2000/rank3
A library for online ranking
https://github.com/cheeze2000/rank3
Last synced: about 1 month ago
JSON representation
A library for online ranking
- Host: GitHub
- URL: https://github.com/cheeze2000/rank3
- Owner: cheeze2000
- Created: 2026-01-15T13:36:55.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2026-01-15T13:37:58.000Z (6 months ago)
- Last Synced: 2026-05-19T15:57:36.056Z (2 months ago)
- Language: TypeScript
- Size: 3.91 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# rank3
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.
# Usage
Players have mu = 25 and sigma = 25/3 by default.
Players have their perceived skill, which is (mu - sigma * 3).
```ts
// 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.5
```
Group players in teams.
```ts
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.
```ts
// 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.
```ts
const bt = new BradleyTerry({
scoreFunction: (score0, score1) => {
return 1 / (1 + Math.exp(-0.1 * (score0 - score1)))
}
});
const updatedPlayers: Record = bt.apply(game);
```
Applying the model to a game immutably returns an updated set of players indexed by their names.
```ts
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 ]
```