Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fixed factor marginal reset

  • Loading branch information...
commit e8b928c1c676ace8a5eefca479489756a0e29658 1 parent 5d689c5
@larskuhnt larskuhnt authored
View
2  lib/saulabs/gauss/distribution.rb
@@ -55,7 +55,7 @@ def log_ratio_normalisation(x, y)
end
# copy values from other distribution
- def absorb!(other)
+ def replace(other)
@precision = other.precision
@precision_mean = other.precision_mean
@mean = other.mean
View
10 lib/saulabs/trueskill/factors/base.rb
@@ -9,6 +9,7 @@ class Base
def initialize
@messages = []
@bindings = {}
+ @priors = []
end
def update_message_at(idx)
@@ -29,22 +30,21 @@ def log_normalisation
end
def reset_marginals
- @bindings.values.each { |var| var.absorb!(Gauss::Distribution.with_deviation(0.0, 0.0)) }
+ @bindings.values.each { |var| var.replace(Gauss::Distribution.new) }
end
def send_message_at(idx)
self.send_message(@messages[idx], @bindings[@messages[idx]])
end
- # message: normal distribution
def send_message(message, variable)
- log_z = Saulabs::Gauss::Distribution.log_product_normalisation(message, variable)
- variable.absorb!(message * variable)
+ log_z = Gauss::Distribution.log_product_normalisation(message, variable)
+ variable.replace(message * variable)
return log_z
end
def bind(variable)
- message = Saulabs::Gauss::Distribution.new
+ message = Gauss::Distribution.new
@messages << message
@bindings[message] = variable
return message
View
4 lib/saulabs/trueskill/factors/prior.rb
@@ -17,8 +17,8 @@ def update_message(message, variable)
variable.precision + @message.precision - message.precision
)
diff = variable - message
- variable.absorb!(new_marginal)
- message.absorb!(@message)
+ variable.replace(new_marginal)
+ message.replace(@message)
return diff
end
View
5 lib/saulabs/trueskill/layers/prior_to_skills.rb
@@ -13,8 +13,9 @@ def build
@teams.each do |team|
team_skills = []
team.each do |skill|
- @factors << Factors::Prior.new(skill.mean, skill.variance + @graph.tau_squared, Gauss::Distribution.new)
- team_skills << skill
+ variable = Gauss::Distribution.new
+ @factors << Factors::Prior.new(skill.mean, skill.variance + @graph.tau_squared, variable)
+ team_skills << variable
end
@output << team_skills
end
View
6 spec/saulabs/gauss/distribution_spec.rb
@@ -72,15 +72,15 @@
end
-describe Gauss::Distribution, "#absorb!" do
+describe Gauss::Distribution, "#replace" do
before :each do
@dist1 = Gauss::Distribution.with_deviation(25.0, 8.333333)
@dist2 = Gauss::Distribution.with_deviation(9.0, 4)
end
- it "should be equal to the absorbed distribution" do
- @dist1.absorb!(@dist2)
+ it "should be equal to the replaced distribution" do
+ @dist1.replace(@dist2)
@dist1.should == @dist2
end
View
21 spec/saulabs/trueskill/factor_graph_spec.rb
@@ -3,15 +3,22 @@
describe Saulabs::TrueSkill::FactorGraph do
before :each do
- @teams = [
- [Saulabs::Gauss::Distribution.with_deviation(25, 25/3.0)],
- [Saulabs::Gauss::Distribution.with_deviation(25, 25/3.0)]
- ]
- @graph = Saulabs::TrueSkill::FactorGraph.new(@teams, :tau => 0.1, :beta => 20, :draw_probability => 0.0)
- @result = @graph.evaluate
+ @teams = create_teams
+ @graph = TrueSkill::FactorGraph.new(@teams, :tau => 0.1, :beta => 20, :draw_probability => 0.0)
end
- it "should do something" do
+ describe "#evaluate" do
+
+ it "should do something" do
+ result = @graph.evaluate
+ puts "[#{result.last.flatten.map(&:to_s).join(', ')}]<br>"
+ puts "[#{result.first}]<br>"
+ end
+
+ it "should do something" do
+ raise (Gauss::Distribution.with_deviation(25, 25/3.0) - Gauss::Distribution.with_deviation(25, 25/1.5)).inspect
+ end
+
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.