Sha256: 058dcfffcbc087cc3818678aa4d5cc60773e24df878244c09539b749bbf62fcb
Contents?: true
Size: 931 Bytes
Versions: 2
Compression:
Stored size: 931 Bytes
Contents
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'fathom')) class Fathom::DiscreteNode < 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
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
fathom-0.3.2 | lib/fathom/node/discrete_node.rb |
fathom-0.3.1 | lib/fathom/node/discrete_node.rb |