Class: Netica::BayesNetwork
- Inherits:
-
Object
- Object
- Netica::BayesNetwork
- Defined in:
- lib/netica/bayes_network.rb
Instance Attribute Summary collapse
-
#current_network ⇒ Object
Returns the value of attribute current_network.
-
#dne_file_path ⇒ Object
Returns the value of attribute dne_file_path.
Instance Method Summary collapse
- #decision_nodes ⇒ Object
-
#initialize(dne_file_path = nil) ⇒ BayesNetwork
constructor
A new instance of BayesNetwork.
- #load_from_state(network_hash) ⇒ Object
- #nature_nodes ⇒ Object
-
#node(nodeName) ⇒ Node
retrieve the node from the associated network whose name matches the “nodeName” supplied.
- #node_hash(nodes) ⇒ Object
- #node_set(name) ⇒ Object
- #node_sets ⇒ Object
- #nodes ⇒ Object
- #state ⇒ Object
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_network ⇒ Object
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_path ⇒ Object
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_nodes ⇒ Object
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_nodes ⇒ Object
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.
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_sets ⇒ Object
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 |
#nodes ⇒ Object
23 24 25 |
# File 'lib/netica/bayes_network.rb', line 23 def nodes current_network.nodes end |
#state ⇒ Object
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 |