Class: Variable

Inherits:
Gaussian show all
Defined in:
lib/TrueSkill/FactorGraph/Variable.rb

Instance Attribute Summary

Attributes inherited from Gaussian

#mu, #pi, #sigma, #tau

Instance Method Summary collapse

Methods inherited from Gaussian

#*, #/

Constructor Details

#initializeVariable

Returns a new instance of Variable



6
7
8
9
# File 'lib/TrueSkill/FactorGraph/Variable.rb', line 6

def initialize()
  super()
  @messages={}
end

Instance Method Details

#[](y) ⇒ Object



38
39
40
# File 'lib/TrueSkill/FactorGraph/Variable.rb', line 38

def [](y)
  @messages[y]
end

#[]=(y, value) ⇒ Object



42
43
44
# File 'lib/TrueSkill/FactorGraph/Variable.rb', line 42

def []=(y,value)
  @messages[y]=value
end

#delta(other) ⇒ Object



16
17
18
# File 'lib/TrueSkill/FactorGraph/Variable.rb', line 16

def delta(other)
  return [(@tau-other.tau).abs,Math.sqrt((@pi-other.pi).abs)].max
end

#set(val) ⇒ Object



11
12
13
14
15
# File 'lib/TrueSkill/FactorGraph/Variable.rb', line 11

def set(val)
  @delta=delta(val)
  @pi=val.pi
  @tau=val.tau
end

#to_sObject



45
46
47
# File 'lib/TrueSkill/FactorGraph/Variable.rb', line 45

def to_s
  return "<Variable "+self.object_id.to_s+" mu="+self.mu.to_s+" sigma= "+self.sigma.to_s+">"
end

#update_message(factor, pi = 0, tau = 0, message = nil) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/TrueSkill/FactorGraph/Variable.rb', line 20

def update_message(factor,pi=0,tau=0,message=nil)
  if  message.nil?
    message=Gaussian.new(nil,nil,pi,tau)
  end
  old_message=self[factor]
  self[factor]=message
  return set(self/old_message*message)
end

#update_value(factor, pi = 0, tau = 0, value = nil) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/TrueSkill/FactorGraph/Variable.rb', line 29

def update_value(factor,pi=0,tau=0,value=nil)
  if  value.nil?
    value=Gaussian.new(nil,nil,pi,tau)
  end
  old_message=self[factor]
  self[factor]=value*old_message/self
  return set(value)
end