Browse files

added some more documentation

  • Loading branch information...
1 parent 7febe24 commit 4844140c50315c5b003a7a69987f4fd969237496 @larskuhnt larskuhnt committed Apr 27, 2010
View
58 lib/saulabs/trueskill/factor_graph.rb
@@ -3,9 +3,60 @@ module TrueSkill
class FactorGraph
- attr_reader :teams, :beta, :beta_squared, :draw_probability, :epsilon, :layers
+ # @return [Array<Array<TrueSkill::Rating>>]
+ attr_reader :teams
- # @param teams (Array) 2 dimensional array of ratings
+ # @return [Float]
+ attr_reader :beta
+
+ # @return [Float]
+ attr_reader :beta_squared
+
+ # @return [Float]
+ attr_reader:draw_probability
+
+ # @return [Float]
+ attr_reader:epsilon
+
+ # @private
+ attr_reader:layers
+
+
+ # Creates a new trueskill factor graph for calculating the new skills based on the given game parameters
+ #
+ # @param [Array<Array<TrueSkill::Rating>>] teams
+ # player-ratings grouped in Arrays by teams
+ # @param [Array<Integer>] ranks
+ # team rankings, example: [2,1,3] first team in teams finished 2nd, second team 1st and third team 3rd
+ # @param [Hash] options
+ # the options hash to configure the factor graph constants beta and draw_probability
+ #
+ # @option options [Float] :beta (4.166667)
+ # the length of the skill-chain. Use a low value for games with a small amount of chance (Go, Chess, etc.) and
+ # a high value for games with a high amount of chance (Uno, Bridge, etc.)
+ # @option options [Float] :draw_probability (0.1)
+ # how probable is a draw in the game outcome [0.0,1.0]
+ #
+ # @example Calculating new skills of a two team game, where one team has one player and the other two
+ #
+ # require 'rubygems'
+ # require 'saulabs/trueskill'
+ #
+ # include Saulabs::TrueSkill
+ #
+ # # team 1 has just one player with a mean skill of 27.1, a skill-deviation of 2.13
+ # # and an play activity of 100 %
+ # team1 = [Rating.new(27.1, 2.13, 1.0)]
+ #
+ # # team 2 has two players
+ # team2 = [Rating.new(22.0, 0.98, 0.8), Rating.new(31.1, 5.33, 0.9)]
+ #
+ # # team 1 finished first and team 2 second
+ # graph = FactorGraph.new([team1, team2], [1,2])
+ #
+ # # update the Ratings
+ # graph.update_skills
+ #
def initialize(teams, ranks, options = {})
@teams = teams
@ranks = ranks
@@ -30,6 +81,9 @@ def draw_margin
Gauss::Distribution.inv_cdf(0.5*(@draw_probability + 1)) * Math.sqrt(1 + 1) * @beta
end
+ # Updates the skills of the players inplace
+ #
+ # @return [Float] the probability of the games outcome
def update_skills
build_layers
run_schedule
View
3 lib/saulabs/trueskill/factors/base.rb
@@ -1,7 +1,10 @@
module Saulabs
module TrueSkill
+
+ # @private
module Factors
+ # @private
class Base
def initialize
View
2 lib/saulabs/trueskill/factors/greater_than.rb
@@ -1,7 +1,9 @@
module Saulabs
module TrueSkill
+ # @private
module Factors
+ # @private
class GreaterThan < Base
def initialize(epsilon, variable)
View
2 lib/saulabs/trueskill/factors/likelihood.rb
@@ -1,7 +1,9 @@
module Saulabs
module TrueSkill
+ # @private
module Factors
+ # @private
class Likelihood < Base
def initialize(beta_squared, variable1, variable2)
View
2 lib/saulabs/trueskill/factors/prior.rb
@@ -1,7 +1,9 @@
module Saulabs
module TrueSkill
+ # @private
module Factors
+ # @private
class Prior < Base
def initialize(mean, variance, variable)
View
4 lib/saulabs/trueskill/factors/weighted_sum.rb
@@ -1,9 +1,9 @@
-require 'pp'
-
module Saulabs
module TrueSkill
+ # @private
module Factors
+ # @private
class WeightedSum < Base
attr_reader :weights, :weights_squared, :index_order
View
2 lib/saulabs/trueskill/factors/within.rb
@@ -1,7 +1,9 @@
module Saulabs
module TrueSkill
+ # @private
module Factors
+ # @private
class Within < Base
def initialize(epsilon, variable)
View
2 lib/saulabs/trueskill/layers/base.rb
@@ -1,7 +1,9 @@
module Saulabs
module TrueSkill
+ # @private
module Layers
+ # @private
class Base
attr_accessor :graph, :factors, :output, :input
View
4 lib/saulabs/trueskill/layers/iterated_team_performances.rb
@@ -1,7 +1,9 @@
module Saulabs
module TrueSkill
+ # @private
module Layers
-
+
+ # @private
class IteratedTeamPerformances < Base
def initialize(graph, team_perf_diff, team_diff_comp)
View
4 lib/saulabs/trueskill/layers/performances_to_team_performances.rb
@@ -1,7 +1,9 @@
module Saulabs
module TrueSkill
+ # @private
module Layers
-
+
+ # @private
class PerformancesToTeamPerformances < Base
def build
View
4 lib/saulabs/trueskill/layers/prior_to_skills.rb
@@ -1,7 +1,9 @@
module Saulabs
module TrueSkill
+ # @private
module Layers
-
+
+ # @private
class PriorToSkills < Base
def initialize(graph, teams)
View
4 lib/saulabs/trueskill/layers/skills_to_performances.rb
@@ -1,7 +1,9 @@
module Saulabs
module TrueSkill
+ # @private
module Layers
-
+
+ # @private
class SkillsToPerformances < Base
def build
View
4 lib/saulabs/trueskill/layers/team_difference_comparision.rb
@@ -1,7 +1,9 @@
module Saulabs
module TrueSkill
+ # @private
module Layers
-
+
+ # @private
class TeamDifferenceComparision < Base
def initialize(graph, ranks)
View
4 lib/saulabs/trueskill/layers/team_performance_differences.rb
@@ -1,7 +1,9 @@
module Saulabs
module TrueSkill
+ # @private
module Layers
-
+
+ # @private
class TeamPerformanceDifferences < Base
def initialize(graph)
View
2 lib/saulabs/trueskill/schedules/base.rb
@@ -1,7 +1,9 @@
module Saulabs
module TrueSkill
+ # @private
module Schedules
+ # @private
class Base
def visit(depth = -1, max_depth = 0)
View
2 lib/saulabs/trueskill/schedules/loop.rb
@@ -1,7 +1,9 @@
module Saulabs
module TrueSkill
+ # @private
module Schedules
+ # @private
class Loop < Base
def initialize(schedule, max_delta)
View
2 lib/saulabs/trueskill/schedules/sequence.rb
@@ -1,7 +1,9 @@
module Saulabs
module TrueSkill
+ # @private
module Schedules
+ # @private
class Sequence < Base
def initialize(schedules)
View
2 lib/saulabs/trueskill/schedules/step.rb
@@ -1,7 +1,9 @@
module Saulabs
module TrueSkill
+ # @private
module Schedules
+ # @private
class Step < Base
def initialize(factor, index)
View
18 spec/saulabs/trueskill/factor_graph_spec.rb
@@ -4,23 +4,27 @@
before :each do
@teams = create_teams
+ @skill = @teams.first.first
@graph = TrueSkill::FactorGraph.new(@teams, [1,2,3])
end
- describe "#evaluate" do
+ describe "#update_skills" do
- it "should do something" do
- result = @graph.evaluate
- puts "[#{result.last.flatten.map(&:to_s).join(', ')}]<br>"
- result.last[0][0].mean.should be_close(29.61452, tolerance)
- result.last[0][0].deviation.should be_close(3.5036, tolerance)
+ it "should update the mean of the first player in team1 to 29.61452" do
+ @graph.update_skills
+ @skill.mean.should be_close(29.61452, tolerance)
+ end
+
+ it "should update the deviation of the first player in team1 to 3.5036" do
+ @graph.update_skills
+ @skill.deviation.should be_close(3.5036, tolerance)
end
end
describe "#draw_margin" do
- it "should be " do
+ it "should be -0.998291" do
@graph.draw_margin.should be_close(-0.998291, tolerance)
end
View
7 spec/saulabs/trueskill_spec.rb
@@ -1,7 +0,0 @@
-require File.dirname(__FILE__) + '/../../spec_helper'
-
-describe Saulabs::TrueSkill do
-
-
-
-end

0 comments on commit 4844140

Please sign in to comment.