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