The Game
class
We use the Game
class to model events and perform inference.
TrueSkillThroughTime.Game
— TypeThe Game
class
Game(teams::Vector{Vector{Player}}, result::Vector{Float64}, p_draw::Float64, weights::Vector{Vector{Float64}})
Properties:
teams::Vector{Vector{Player}}
result::Vector{Float64}
p_draw::Float64
weights::Vector{Vector{Float64}}
likelihoods::Vector{Vector{Gaussian}}
evidence::Float64
Let us return to the example seen on the first page of this manual.
a1 = ttt.Player(); a2 = ttt.Player(); a3 = ttt.Player(); a4 = ttt.Player()
team_a = [ a1, a2 ]
team_b = [ a3, a4 ]
g = ttt.Game([team_a, team_b])
g.teams
2-element Vector{Vector{Player}}:
[Player(Gaussian(mu=0.0, sigma=6.0), beta=1.0, gamma=0.03), Player(Gaussian(mu=0.0, sigma=6.0), beta=1.0, gamma=0.03)]
[Player(Gaussian(mu=0.0, sigma=6.0), beta=1.0, gamma=0.03), Player(Gaussian(mu=0.0, sigma=6.0), beta=1.0, gamma=0.03)]
where the teams' order in the list implicitly defines the game's result: the teams appearing first in the list (lower index) beat those appearing later (higher index).
Evidence and likelihood
During the initialization, the Game
class computes the prior prediction of the observed result (the evidence
property) and the approximate likelihood of each player (the likelihoods
property).
lhs = g.likelihoods
round(g.evidence, digits=3)
0.5
In this case, the evidence is $0.5$ because both teams had the same prior skill estimates.
Posterior
The method posteriors()
of class Game
to compute the posteriors.
TrueSkillThroughTime.posteriors
— Functionposteriors(g::Game)
pos = ttt.posteriors(g)
pos[1][1]
Gaussian(mu=2.361085, sigma=5.515911)
Posteriors can also be found by manually multiplying the likelihoods and priors.
lhs[1][1] * a1.prior
Gaussian(mu=2.361085, sigma=5.515911)
Team performance
TrueSkillThroughTime.performance
— Methodperformance(G::Game,i::Int64)
We can obtain the expected performance of the first team.
ttt.performance(g,1)
Gaussian(mu=0.0, sigma=8.602325)
Full example
We now analyze a more complex example in which the same four players participate in a multi-team game. The players are organized into three teams of different sizes: two teams with only one player and the other with two players. The result has a single winning team and a tie between the other two losing teams. Unlike the previous example, we need to use a draw probability greater than zero.
ta = [a1]
tb = [a2, a3]
tc = [a4]
teams_3 = [ta, tb, tc]
result = [1., 0., 0.]
g = ttt.Game(teams_3, result, p_draw=0.25)
g.result
3-element Vector{Float64}:
1.0
0.0
0.0
The team with the highest score is the winner, and the teams with the same score are tied. In this way, we can specify any outcome including global draws. The evidence and posteriors can be queried in the same way as before.
ttt.posteriors(g)
3-element Vector{Vector{Gaussian}}:
[Gaussian(mu=3.863839, sigma=4.723847)]
[Gaussian(mu=-1.290302, sigma=4.775861), Gaussian(mu=-1.290302, sigma=4.775861)]
[Gaussian(mu=-2.573537, sigma=4.273613)]