Class: Netica::BayesNetwork

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dne_file_path = nil) ⇒ BayesNetwork

Returns a new instance of BayesNetwork.



7
8
9
10
11
12
# File 'lib/netica/bayes_network.rb', line 7

def initialize(dne_file_path = nil)
  if dne_file_path
    self.dne_file_path = dne_file_path
    load_dne_file
  end
end

Instance Attribute Details

#current_networkObject

Returns the value of attribute current_network.



5
6
7
# File 'lib/netica/bayes_network.rb', line 5

def current_network
  @current_network
end

#dne_file_pathObject

Returns the value of attribute dne_file_path.



5
6
7
# File 'lib/netica/bayes_network.rb', line 5

def dne_file_path
  @dne_file_path
end

Instance Method Details

#decision_nodesObject



27
28
29
# File 'lib/netica/bayes_network.rb', line 27

def decision_nodes
  nodes.collect{ |n| n if n.decision_node? }.compact
end

#load_from_state(network_hash) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/netica/bayes_network.rb', line 43

def load_from_state(network_hash)
  NeticaLogger.info "Loading state from network_hash => #{network_hash}"
  network_hash["decision_nodes"].each do |node_name, node_value|
    NeticaLogger.info "Setting #{node_name} => #{node_value}"
    node(node_name).value = node_value
  end
end

#nature_nodesObject



31
32
33
# File 'lib/netica/bayes_network.rb', line 31

def nature_nodes
  nodes.collect{ |n| n if n.nature_node? }.compact
end

#node(nodeName) ⇒ Node

retrieve the node from the associated network whose name matches the “nodeName” supplied.

Parameters:

  • nodeName (String)

    Name of the node to find

Returns:

  • (Node)


19
20
21
# File 'lib/netica/bayes_network.rb', line 19

def node(nodeName)
  nodes.select{ |n| n if n.name == nodeName }[0]
end

#node_hash(nodes) ⇒ Object



55
56
57
58
59
# File 'lib/netica/bayes_network.rb', line 55

def node_hash(nodes)
  node_hash = {}
  nodes.collect{|dn| node_hash.store(dn.name, dn.value) }
  node_hash
end

#node_set(name) ⇒ Object



39
40
41
# File 'lib/netica/bayes_network.rb', line 39

def node_set(name)
  nodes.collect{ |n| n if n.isInNodeset(name) }.compact.sort{|a,b| b.beliefs <=> a.beliefs }
end

#node_setsObject



35
36
37
# File 'lib/netica/bayes_network.rb', line 35

def node_sets
  current_network.getAllNodesets(false).split(",").collect{|ns_name| node_set(ns_name)}
end

#nodesObject



23
24
25
# File 'lib/netica/bayes_network.rb', line 23

def nodes
  current_network.nodes
end

#stateObject



51
52
53
# File 'lib/netica/bayes_network.rb', line 51

def state
  { :dne_file_path => dne_file_path, :decision_nodes => node_hash(decision_nodes), :nature_nodes => node_hash(nature_nodes) }
end