scttcper/ts-trueskill

Need win probability

gamesguru opened this issue · 0 comments

According to sublee, quality() provides draw probability. To calculate win probability he provides an auxiliary code snippet to get things working. But this is Python code. I'm wondering if we can put together anything similar on the js side? Sublee quoted below:

TrueSkill provides a function (quality()) to calculate a draw probability between arbitrary ratings. But there’s no function for a win probability.

Anyway, if you need to calculate a win probability between only 2 teams, this code snippet will help you:

import itertools
import math

def win_probability(team1, team2):
    delta_mu = sum(r.mu for r in team1) - sum(r.mu for r in team2)
    sum_sigma = sum(r.sigma ** 2 for r in itertools.chain(team1, team2))
    size = len(team1) + len(team2)
    denom = math.sqrt(size * (BETA * BETA) + sum_sigma)
    ts = trueskill.global_env()
    return ts.cdf(delta_mu / denom)