Class: Node

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Node

Returns a new instance of Node.

Raises:

  • (ArgumentError)


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

#labelsObject (readonly)

Returns the value of attribute labels.



8
9
10
# File 'lib/fathom/archive/node.rb', line 8

def labels
  @labels
end

#likelihoodObject (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

#nameObject (readonly)

Returns the value of attribute name.



15
16
17
# File 'lib/fathom/archive/n2.rb', line 15

def name
  self.variable.name
end

#parentsObject (readonly)

Returns the value of attribute parents.



8
9
10
# File 'lib/fathom/archive/n2.rb', line 8

def parents
  @parents
end

#probabilitiesObject (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

#variableObject (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

#beliefObject Also known as: b



32
33
34
# File 'lib/fathom/archive/node.rb', line 32

def belief
  probabilities * likelihood
end

#inspectObject



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_aObject



52
53
54
# File 'lib/fathom/archive/node.rb', line 52

def to_a
  self.probabilities.to_a
end