Class: Fathom::DiscreteNode
- Defined in:
- lib/fathom/node/discrete_node.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#labels ⇒ Object
readonly
Returns the value of attribute labels.
Attributes inherited from Node
#description, #distribution, #name, #values
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ DiscreteNode
constructor
A new instance of DiscreteNode.
-
#likelihood(ignored_value) ⇒ Object
(also: #l)
This makes it easier to interface to a belief node.
- #rand ⇒ Object
- #size ⇒ Object (also: #length)
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
#labels ⇒ Object (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 |
#rand ⇒ Object
16 17 18 |
# File 'lib/fathom/node/discrete_node.rb', line 16 def rand self.labels[self.distribution.rand(self.size)] end |
#size ⇒ Object Also known as: length
11 12 13 |
# File 'lib/fathom/node/discrete_node.rb', line 11 def size @size ||= self.labels.length end |