Class: Node
- Inherits:
-
Object
- Object
- Node
- Defined in:
- lib/fathom/archive/n2.rb,
lib/fathom/archive/n3.rb,
lib/fathom/archive/node.rb
Overview
Some noodling about what a node might contain in order to describe the joint probabilities.
Instance Attribute Summary collapse
-
#labels ⇒ Object
readonly
Returns the value of attribute labels.
-
#likelihood ⇒ Object
(also: #l)
readonly
Returns the value of attribute likelihood.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#parents ⇒ Object
readonly
Returns the value of attribute parents.
-
#probabilities ⇒ Object
(also: #p)
readonly
Returns the value of attribute probabilities.
-
#variable ⇒ Object
readonly
Returns the value of attribute variable.
Class Method Summary collapse
Instance Method Summary collapse
- #belief ⇒ Object (also: #b)
-
#initialize(*args) ⇒ Node
constructor
A new instance of Node.
- #inspect ⇒ Object
- #inverse_probability(label) ⇒ Object
-
#observe(values) ⇒ Object
Take an array, array of arrays, dictionary, hash, or OpenStruct.
- #odds(label) ⇒ Object
- #probability(label) ⇒ Object
- #to_a ⇒ Object
Constructor Details
#initialize(*args) ⇒ Node
Returns a new instance of Node.
9 10 11 12 13 |
# File 'lib/fathom/archive/n2.rb', line 9 def initialize(variable, *parents) @variable = Variable.infer(variable) raise ArgumentError, "A valid variable cannot be implied from #{variable}" unless @variable @parents = parents end |
Instance Attribute Details
#labels ⇒ Object (readonly)
Returns the value of attribute labels.
8 9 10 |
# File 'lib/fathom/archive/node.rb', line 8 def labels @labels end |
#likelihood ⇒ Object (readonly) Also known as: l
Returns the value of attribute likelihood.
8 9 10 |
# File 'lib/fathom/archive/node.rb', line 8 def likelihood @likelihood end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
15 16 17 |
# File 'lib/fathom/archive/n2.rb', line 15 def name self.variable.name end |
#parents ⇒ Object (readonly)
Returns the value of attribute parents.
8 9 10 |
# File 'lib/fathom/archive/n2.rb', line 8 def parents @parents end |
#probabilities ⇒ Object (readonly) Also known as: p
Returns the value of attribute probabilities.
8 9 10 |
# File 'lib/fathom/archive/node.rb', line 8 def probabilities @probabilities end |
#variable ⇒ Object (readonly)
Returns the value of attribute variable.
8 9 10 |
# File 'lib/fathom/archive/n2.rb', line 8 def variable @variable end |
Class Method Details
.infer(obj, *parents) ⇒ Object
24 25 26 27 |
# File 'lib/fathom/archive/n2.rb', line 24 def infer(obj, *parents) return obj if obj.is_a?(Node) end |
Instance Method Details
#belief ⇒ Object Also known as: b
32 33 34 |
# File 'lib/fathom/archive/node.rb', line 32 def belief probabilities * likelihood end |
#inspect ⇒ Object
19 20 21 |
# File 'lib/fathom/archive/n2.rb', line 19 def inspect "Node: #{self.name} #{ self.parents.map{|p| p.name}.inspect }" end |
#inverse_probability(label) ⇒ Object
44 45 46 |
# File 'lib/fathom/archive/node.rb', line 44 def inverse_probability(label) 1 - probability(label) end |
#observe(values) ⇒ Object
Take an array, array of arrays, dictionary, hash, or OpenStruct. Anything but an array can add a new parent to observe.
87 88 |
# File 'lib/fathom/archive/n3.rb', line 87 def observe(values) end |
#odds(label) ⇒ Object
48 49 50 |
# File 'lib/fathom/archive/node.rb', line 48 def odds(label) probability(label) / inverse_probability(label) end |
#probability(label) ⇒ Object
40 41 42 |
# File 'lib/fathom/archive/node.rb', line 40 def probability(label) probabilities[index_for(label)] end |
#to_a ⇒ Object
52 53 54 |
# File 'lib/fathom/archive/node.rb', line 52 def to_a self.probabilities.to_a end |