class Java::NorsysNetica::Node attr_accessor :value # from https://github.com/SixArm/sixarm_ruby_netica NODE_KINDS = { Java::NorsysNetica::Node::NATURE_NODE => :nature, Java::NorsysNetica::Node::DECISION_NODE => :decision, Java::NorsysNetica::Node::UTILITY_NODE => :utility, Java::NorsysNetica::Node::CONSTANT_NODE => :constant, Java::NorsysNetica::Node::DISCONNECTED_NODE => :disconnected, } NODE_TYPES = { Java::NorsysNetica::Node::DISCRETE_TYPE => :nature, Java::NorsysNetica::Node::CONTINUOUS_TYPE => :decision, } def name getName end def kind NODE_KINDS[getKind] end def type NODE_TYPES[getType] end def decision_node? type == :decision end def nature_node? type == :nature end def beliefs states.collect{ |st| getBelief(st.to_s) } end def hint user().getString("Hint") end def top_parent_node getParents().sort_by_belief()[0] end def value(state_name = nil) if decision_node? finding().getReal() elsif state_name states.collect{ |st| return getBelief(st.to_s) if state_name == st.to_s } else state_values = {} states.collect{ |st| state_values.store(st.to_s, getBelief(st.to_s)) } state_values end end def value=(new_value) Netica::NeticaLogger.info "Setting #{self.name} to #{new_value}" if decision_node? finding().setReal(new_value) elsif nature_node? finding.enterState(new_value) end end def incr if decision_node? self.value = value + 1 end end def to_s if type == kind prefix = type.capitalize else prefix = "#{type.capitalize}#{kind.capitalize}" end "#{prefix}Node:#{name}" end def inspect "#" end def states (0...getNumStates()).map{|i| state(i) } end def free begin NeticaLogger.info "Deleting #{self.to_s}" finalize() delete() states.each{|s| s==nil or s.free() } rescue Java::NorsysNetica::NeticaException end end end