Getting Started
Installation
npm install --save openskill
openskill ships both ESM and CommonJS builds plus TypeScript definitions, so
it works out of the box in modern Node.js, Bun, Deno, and bundlers.
// ESM
import { rating, rate, ordinal } from 'openskill'
// CommonJS
const { rating, rate, ordinal } = require('openskill')
Hello, rating
Every player has a rating represented as a Gaussian distribution: mu is the
believed skill, sigma is the uncertainty.
import { rating } from 'openskill'
const a1 = rating()
// { mu: 25, sigma: 8.333333333333334 }
const a2 = rating({ mu: 32.444, sigma: 5.123 })
// { mu: 32.444, sigma: 5.123 }
Rating a match
Pass an array of teams (where each team is an array of ratings) to rate. The
first team in the array is the winner by default.
import { rating, rate } from 'openskill'
const a1 = rating()
const a2 = rating()
const b1 = rating()
const b2 = rating()
// Team A beats Team B
const [[newA1, newA2], [newB1, newB2]] = rate([
[a1, a2],
[b1, b2],
])
Teams can be asymmetric — a 3v2, 1v4, or 8-way free-for-all all work the same way.
Comparing players
Use ordinal to get a single number you can sort by.
import { ordinal } from 'openskill'
ordinal({ mu: 27.6, sigma: 8.07 }) // ≈ 3.39
By default this returns mu - 3 * sigma, the lower bound of a 99.7%
confidence interval — newer players ramp up as their sigma shrinks.
Breaking changes in v5.0.0
Outputs now match the Python reference bit-for-bit. To get there, a few defaults changed:
- Hyperparameter defaults (
sigma,beta,tau,epsilon) are now constants instead of being derived frommu. If you used to pass onlymuand rely on derived defaults, pass the others explicitly. tauis applied unconditionally. Passtau: 0to keep the old behaviour.epsilon(the Thurstone-Mosteller draw margin) defaults to0.1. The former0.0001value was both the draw margin and the per-stepsigmafloor; the floor now lives behindkappa(default0.0001).- The standard-normal CDF/PDF in
src/statistics.tsare now computed viaerfusing Python'sNormalDistformulas. This only affects the Thurstone-Mosteller models.
Beyond the basics
rate also supports:
- Ranks and scores —
rank: [4, 1, 3, 2]orscore: [37, 19, 37, 42]for arbitrary orderings and ties (Ranking →) - Victory margins —
marginamplifies updates for lopsided scores (Ranking →) - Partial play —
weightscales each player's update by their contribution (Ranking →) - Alternate models — Bradley-Terry and Thurstone-Mosteller variants (Models →)
- Tuning —
tau,limitSigma,balance, and the underlying hyperparameters (API Reference →)