Class: Fathom::BeliefNode
- Inherits:
-
DiscreteNode
- Object
- Node
- DiscreteNode
- Fathom::BeliefNode
- Defined in:
- lib/fathom/node/belief_node.rb
Instance Attribute Summary collapse
-
#likelihoods ⇒ Object
readonly
Returns the value of attribute likelihoods.
-
#precision_threshold ⇒ Object
readonly
Returns the value of attribute precision_threshold.
-
#probabilities ⇒ Object
readonly
Returns the value of attribute probabilities.
Attributes inherited from DiscreteNode
Attributes inherited from Node
#description, #distribution, #name, #values
Instance Method Summary collapse
- #add_accessor_for_cpm(cpm, node) ⇒ Object
- #add_child(child) ⇒ Object
- #add_parent(parent) ⇒ Object
-
#initialize(opts = {}) ⇒ BeliefNode
constructor
A new instance of BeliefNode.
- #inspect ⇒ Object
- #likelihood(label) ⇒ Object
Methods inherited from DiscreteNode
Methods inherited from Node
#children, #name_sym, #parents, #register_child, #register_parent, #simple_inspect
Constructor Details
#initialize(opts = {}) ⇒ BeliefNode
Returns a new instance of BeliefNode.
6 7 8 9 10 11 |
# File 'lib/fathom/node/belief_node.rb', line 6 def initialize(opts={}) super(opts) assert_probabilities(opts) assert_liklihoods(opts) @precision_threshold = opts.fetch(:precision_threshold, 0.00001) end |
Instance Attribute Details
#likelihoods ⇒ Object (readonly)
Returns the value of attribute likelihoods.
4 5 6 |
# File 'lib/fathom/node/belief_node.rb', line 4 def likelihoods @likelihoods end |
#precision_threshold ⇒ Object (readonly)
Returns the value of attribute precision_threshold.
4 5 6 |
# File 'lib/fathom/node/belief_node.rb', line 4 def precision_threshold @precision_threshold end |
#probabilities ⇒ Object (readonly)
Returns the value of attribute probabilities.
4 5 6 |
# File 'lib/fathom/node/belief_node.rb', line 4 def probabilities @probabilities end |
Instance Method Details
#add_accessor_for_cpm(cpm, node) ⇒ Object
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/fathom/node/belief_node.rb', line 54 def add_accessor_for_cpm(cpm, node) return false unless cpm.is_a?(CPMNode) and cpm.name_sym method_name = ("cpm_for_" + node.name_sym.to_s).to_sym return false if self.respond_to?(method_name) (class << self; self; end).module_eval do define_method method_name do cpm end end end |
#add_child(child) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/fathom/node/belief_node.rb', line 13 def add_child(child) if child.is_a?(BeliefNode) cpm = CPMNode.new(:parent => self, :child => child) # self.children << cpm self.add_accessor_for_cpm(cpm, child) self.add_accessor_for_node(child) # cpm.register_parent(self) self.children << child child.register_parent(self) child.add_accessor_for_cpm(cpm, self) else super(child) end end |
#add_parent(parent) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/fathom/node/belief_node.rb', line 28 def add_parent(parent) if parent.is_a?(BeliefNode) cpm = CPMNode.new(:parent => parent, :child => self) # self.parents << cpm self.add_accessor_for_cpm(cpm, parent) self.add_accessor_for_node(parent) # cpm.register_child(self) self.parents << parent parent.register_child(self) parent.add_accessor_for_cpm(cpm, self) else super(parent) end end |
#inspect ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/fathom/node/belief_node.rb', line 43 def inspect "#{self.class.to_s}: " + [ self.name, self.description, "children:", self.children.map {|e| e.is_a?(CPMNode) ? e.child.simple_inspect : e.simple_inspect }.inspect, "parents: ", self.parents.map {|e| e.is_a?(CPMNode) ? e.parent.simple_inspect : e.simple_inspect }.inspect, ].compact.join(", ") end |
#likelihood(label) ⇒ Object
65 66 67 |
# File 'lib/fathom/node/belief_node.rb', line 65 def likelihood(label) OpenStruct.new end |