Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

first working version

  • Loading branch information...
commit 8c4b7de17f8b039f0febfa8f605680a55facc7b7 1 parent 7c297e8
@larskuhnt larskuhnt authored
View
2  lib/saulabs/trueskill/factor_graph.rb
@@ -27,7 +27,7 @@ def initialize(teams, ranks, options = {})
end
def draw_margin
- Gauss::Distribution.inv_cdf((@draw_probability + 1) / 2.0) * Math.sqrt(1 + 1) * @beta
+ Gauss::Distribution.inv_cdf(0.5*(@draw_probability + 1)) * Math.sqrt(1 + 1) * @beta
end
def evaluate
View
3  lib/saulabs/trueskill/factors/greater_than.rb
@@ -19,7 +19,8 @@ def log_normalization
def update_message_at(index)
raise "illegal message index: #{index}" if index < 0 || index > 0
message = @messages[index]
- variable = @variables[index]
+ variable = @bindings[@messages[index]]
+
msg = variable / message
c = msg.precision
d = msg.precision_mean
View
6 lib/saulabs/trueskill/factors/likelihood.rb
@@ -14,13 +14,13 @@ def initialize(beta_squared, variable1, variable2)
def update_message_at(index)
raise "illegal message index: #{index}" if index < 0 || index > 1
case index
- when 0 then update_helper(@messages[0], @messages[1], @bindings[@messages[0]], @bindings[@messages[1]])
- when 1 then update_helper(@messages[1], @messages[0], @bindings[@messages[1]], @bindings[@messages[0]])
+ when 0 then update_helper(@messages[0], @messages[1], @variables[0], @variables[1])
+ when 1 then update_helper(@messages[1], @messages[0], @variables[1], @variables[0])
end
end
def log_normalization
- Gauss::Distribution.log_ratio_normalization(@bindings[@messages[0]], @messages[0])
+ Gauss::Distribution.log_ratio_normalization(@variables[0], @messages[0])
end
private
View
2  lib/saulabs/trueskill/layers/skills_to_performances.rb
@@ -9,7 +9,7 @@ def build
team_performances = []
team.each do |rating|
variable = TrueSkill::Rating.new(0.0, 0.0, rating.activity, rating.tau)
- @factors << Factors::Likelihood.new(@graph.beta_squared, rating, variable)
+ @factors << Factors::Likelihood.new(@graph.beta_squared, variable, rating)
team_performances << variable
end
@output << team_performances
View
2  lib/saulabs/trueskill/schedules/loop.rb
@@ -12,10 +12,8 @@ def initialize(schedule, max_delta)
def visit(depth = -1, max_depth = 0)
iterations = 1
delta = @schedule.visit(depth + 1, max_depth)
- puts "loop delta: #{delta}<br>"
while delta > @max_delta
delta = @schedule.visit(depth + 1, max_depth)
- puts "loop delta: #{delta}<br>"
iterations += 1
end
delta
View
1  lib/saulabs/trueskill/schedules/step.rb
@@ -10,7 +10,6 @@ def initialize(factor, index)
end
def visit(depth = -1, max_depth = 0)
- puts "#{@factor.class}: #{@index}<br>"
@factor.update_message_at(@index)
end
View
2  spec/saulabs/gauss/distribution_spec.rb
@@ -131,6 +131,7 @@
it "#cumulative_distribution_function should return 0.6064198" do
Gauss::Distribution.cumulative_distribution_function(0.27).should be_close(0.6064198, 0.00001)
+ Gauss::Distribution.cdf(2.0).should be_close(0.9772498, 0.00001)
end
it "#probability_density_function should return 0.384662" do
@@ -139,6 +140,7 @@
it "#quantile_function should return -0.62941" do
Gauss::Distribution.quantile_function(0.27).should be_close(-0.62941, 0.00001)
+ Gauss::Distribution.quantile_function(0.9).should be_close(1.281551, tolerance)
end
end
View
13 spec/saulabs/trueskill/factor_graph_spec.rb
@@ -12,9 +12,16 @@
it "should do something" do
result = @graph.evaluate
puts "[#{result.last.flatten.map(&:to_s).join(', ')}]<br>"
- # puts "[#{result.first}]<br>"
- result.last[0][0].mean.should be_close(37.17611, tolerance)
- result.last[0][0].deviation.should be_close(5.5262, tolerance)
+ result.last[0][0].mean.should be_close(29.61452, tolerance)
+ result.last[0][0].deviation.should be_close(3.5036, tolerance)
+ end
+
+ end
+
+ describe "#draw_margin" do
+
+ it "should be " do
+ @graph.draw_margin.should be_close(-0.998291, tolerance)
end
end
View
10 spec/saulabs/trueskill/factors/greater_than_spec.rb
@@ -3,22 +3,22 @@
describe TrueSkill::Factors::GreaterThan do
before :each do
- @variable = Gauss::Distribution.new(26.0, 1.1)
+ @variable = Gauss::Distribution.new(0.1, 1.1)
@factor = TrueSkill::Factors::GreaterThan.new(0.1, @variable)
end
describe "#update_message_at" do
- it "should return a difference of 0.0" do
- @factor.update_message_at(0).should be_close(0.0, tolerance)
+ it "should return a difference of 2.1409" do
+ @factor.update_message_at(0).should be_close(2.1409, tolerance)
end
end
describe "#log_normalization" do
- it "should be 0.0" do
- @factor.log_normalization.should == 0.0
+ it "should be -0.69314" do
+ @factor.log_normalization.should be_close(-0.69314, tolerance)
end
end
View
9 spec/saulabs/trueskill/factors/weighted_sum_spec.rb
@@ -51,11 +51,16 @@
end
- describe "#update_message_at 0" do
+ describe "#update_message_at" do
- it "should return a difference of 4.50116" do
+ it "should return a difference of 4.50116 for message 0" do
@factor.update_message_at(0).should be_close(4.50116, tolerance)
end
+
+ it "should return a difference of 4.50116 for message 1" do
+ @factor.update_message_at(0)
+ @factor.update_message_at(1).should be_close(4.0, tolerance)
+ end
end
View
2  spec/spec_helper.rb
@@ -16,7 +16,7 @@ def tolerance
def create_teams
[
[
- TrueSkill::Rating.new(25, 8.1)
+ TrueSkill::Rating.new(25, 4.1)
],
[
TrueSkill::Rating.new(27, 3.1),
Please sign in to comment.
Something went wrong with that request. Please try again.