Class: Java::NorsysNetica::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/netica/node.rb

Constant Summary collapse

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
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#value(state_name = nil) ⇒ Object

Returns the value of attribute value.



2
3
4
# File 'lib/netica/node.rb', line 2

def value
  @value
end

Instance Method Details

#beliefsObject



38
39
40
# File 'lib/netica/node.rb', line 38

def beliefs
  states.collect{ |st| getBelief(st.to_s) }
end

#decision_node?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/netica/node.rb', line 30

def decision_node?
  type == :decision
end

#freeObject



98
99
100
101
102
103
104
105
106
# File 'lib/netica/node.rb', line 98

def free
  begin
    Netica::NeticaLogger.info "Deleting #{self.to_s}"
    finalize()
    delete()
    states.each{|s| s==nil or s.free() }
  rescue Java::NorsysNetica::NeticaException
  end
end

#hintObject



42
43
44
# File 'lib/netica/node.rb', line 42

def hint
  user().getString("Hint")
end

#incrObject



74
75
76
77
78
# File 'lib/netica/node.rb', line 74

def incr
  if decision_node?
    self.value = value + 1
  end
end

#inspectObject



90
91
92
# File 'lib/netica/node.rb', line 90

def inspect
  "#<Java::NorsysNetica::#{self.to_s} value:#{value}>"
end

#kindObject



22
23
24
# File 'lib/netica/node.rb', line 22

def kind
  NODE_KINDS[getKind]
end

#nameObject



18
19
20
# File 'lib/netica/node.rb', line 18

def name
  getName
end

#nature_node?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/netica/node.rb', line 34

def nature_node?
  type == :nature
end

#statesObject



94
95
96
# File 'lib/netica/node.rb', line 94

def states
  (0...getNumStates()).map{|i| state(i) }
end

#to_sObject



80
81
82
83
84
85
86
87
88
# File 'lib/netica/node.rb', line 80

def to_s
  if type == kind
    prefix = type.capitalize
  else
    prefix = "#{type.capitalize}#{kind.capitalize}"
  end

  "#{prefix}Node:#{name}"
end

#top_parent_nodeObject



46
47
48
# File 'lib/netica/node.rb', line 46

def top_parent_node
  getParents().sort_by_belief()[0]
end

#typeObject



26
27
28
# File 'lib/netica/node.rb', line 26

def type
  NODE_TYPES[getType]
end