Sha256: 5fb436e23586d5908efbacd726a86b20cca78e4a7c78f41d1ce0ef0a177aa982
Contents?: true
Size: 939 Bytes
Versions: 4
Compression:
Stored size: 939 Bytes
Contents
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'fathom')) class Fathom::DiscreteNode < Fathom::Node attr_reader :labels def initialize(opts={}) opts[:distribution] ||= :discrete_uniform super(opts) assert_labels(opts) end def size @size ||= self.labels.length end alias :length :size def rand self.labels[self.distribution.rand(self.size)] end # This makes it easier to interface to a belief node def likelihood(ignored_value) GSL::Vector.ary_to_gv(Array.new(self.size, 1)) end alias :l :likelihood protected def assert_labels(opts) @labels = opts[:labels] @labels ||= self.values @labels ||= [:true, :false] @labels = Array[@labels] unless @labels.is_a?(Array) @labels.uniq! end end if __FILE__ == $0 include Fathom # TODO: Is there anything you want to do to run this file on its own? # DiscreteNode.new end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
fathom-0.3.7 | lib/fathom/node/discrete_node.rb |
fathom-0.3.6 | lib/fathom/node/discrete_node.rb |
fathom-0.3.4 | lib/fathom/node/discrete_node.rb |
fathom-0.3.3 | lib/fathom/node/discrete_node.rb |