Class: Fathom::DiscreteNode

Inherits:
Node
  • Object
show all
Defined in:
lib/fathom/node/discrete_node.rb

Direct Known Subclasses

BeliefNode, DataCollection

Instance Attribute Summary collapse

Attributes inherited from Node

#description, #distribution, #name, #values

Instance Method Summary collapse

Methods inherited from Node

#add_child, #add_parent, #children, #inspect, #name_sym, #parents, #register_child, #register_parent, #simple_inspect

Constructor Details

#initialize(opts = {}) ⇒ DiscreteNode

Returns a new instance of DiscreteNode.



5
6
7
8
9
# File 'lib/fathom/node/discrete_node.rb', line 5

def initialize(opts={})
  opts[:distribution] ||= :discrete_uniform
  super(opts)
  assert_labels(opts)
end

Instance Attribute Details

#labelsObject (readonly)

Returns the value of attribute labels.



3
4
5
# File 'lib/fathom/node/discrete_node.rb', line 3

def labels
  @labels
end

Instance Method Details

#likelihood(ignored_value) ⇒ Object Also known as: l

This makes it easier to interface to a belief node



21
22
23
# File 'lib/fathom/node/discrete_node.rb', line 21

def likelihood(ignored_value)
  GSL::Vector.ary_to_gv(Array.new(self.size, 1))
end

#randObject



16
17
18
# File 'lib/fathom/node/discrete_node.rb', line 16

def rand
  self.labels[self.distribution.rand(self.size)]
end

#sizeObject Also known as: length



11
12
13
# File 'lib/fathom/node/discrete_node.rb', line 11

def size
  @size ||= self.labels.length
end