Class: Saulabs::TrueSkill::FactorGraph

Inherits:
Object
  • Object
show all
Defined in:
lib/saulabs/trueskill/factor_graph.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(teams, ranks, options = {}) ⇒ FactorGraph

teams: 2 dimensional array of ratings



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/saulabs/trueskill/factor_graph.rb', line 9

def initialize(teams, ranks, options = {})
  @teams = teams
  @ranks = ranks
  @beta = options[:beta] || 25/6.0
  @draw_probability = options[:draw_probability] || 0.1
  @beta_squared = @beta**2
  @epsilon = -Math.sqrt(2.0 * @beta_squared) * Gauss::Distribution.inv_cdf((1.0 - @draw_probability) / 2.0)
  
  @prior_layer = Layers::PriorToSkills.new(self, @teams)
  @layers = [
    @prior_layer,
    Layers::SkillsToPerformances.new(self),
    Layers::PerformancesToTeamPerformances.new(self),
    Layers::IteratedTeamPerformances.new(self,
      Layers::TeamPerformanceDifferences.new(self),
      Layers::TeamDifferenceComparision.new(self, ranks)
    )
  ]
end

Instance Attribute Details

#betaObject (readonly)

Returns the value of attribute beta.



6
7
8
# File 'lib/saulabs/trueskill/factor_graph.rb', line 6

def beta
  @beta
end

#beta_squaredObject (readonly)

Returns the value of attribute beta_squared.



6
7
8
# File 'lib/saulabs/trueskill/factor_graph.rb', line 6

def beta_squared
  @beta_squared
end

#draw_probabilityObject (readonly)

Returns the value of attribute draw_probability.



6
7
8
# File 'lib/saulabs/trueskill/factor_graph.rb', line 6

def draw_probability
  @draw_probability
end

#epsilonObject (readonly)

Returns the value of attribute epsilon.



6
7
8
# File 'lib/saulabs/trueskill/factor_graph.rb', line 6

def epsilon
  @epsilon
end

#layersObject (readonly)

Returns the value of attribute layers.



6
7
8
# File 'lib/saulabs/trueskill/factor_graph.rb', line 6

def layers
  @layers
end

#teamsObject (readonly)

Returns the value of attribute teams.



6
7
8
# File 'lib/saulabs/trueskill/factor_graph.rb', line 6

def teams
  @teams
end

Instance Method Details

#draw_marginObject



29
30
31
# File 'lib/saulabs/trueskill/factor_graph.rb', line 29

def draw_margin
  Gauss::Distribution.inv_cdf(0.5*(@draw_probability + 1)) * Math.sqrt(1 + 1) * @beta
end

#evaluateObject



33
34
35
36
37
# File 'lib/saulabs/trueskill/factor_graph.rb', line 33

def evaluate
  build_layers
  run_schedule
  [ranking_probability, updated_skills]
end