doc/classes/BayesNet.src/M000021.html in bn4r-0.1.2 vs doc/classes/BayesNet.src/M000021.html in bn4r-0.9.0
- old
+ new
@@ -1,53 +1,23 @@
-<?xml version="1.0" encoding="iso-8859-1"?>
-<!DOCTYPE html
- PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-
-<html>
-<head>
- <title>create_from_xmlbif (BayesNet)</title>
- <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
- <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
-</head>
-<body class="standalone-code">
- <pre><span class="ruby-comment cmt"># File lib/bn4r/bn_import.rb, line 26</span>
-<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">create_from_xmlbif</span>(<span class="ruby-identifier">file</span>, <span class="ruby-identifier">bn</span>=<span class="ruby-keyword kw">self</span>)
- <span class="ruby-identifier">doc</span> = <span class="ruby-constant">Document</span>.<span class="ruby-identifier">new</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-identifier">file</span>, <span class="ruby-value str">"r"</span>)
-
- <span class="ruby-comment cmt"># first go through and add the variables</span>
- <span class="ruby-identifier">doc</span>.<span class="ruby-identifier">elements</span>.<span class="ruby-identifier">each</span>(<span class="ruby-value str">"BIF/NETWORK/VARIABLE"</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">variable</span><span class="ruby-operator">|</span>
-
- <span class="ruby-identifier">name</span> = <span class="ruby-identifier">variable</span>.<span class="ruby-identifier">elements</span>[<span class="ruby-value str">"NAME"</span>]
-
- <span class="ruby-identifier">outcomes</span> = []
- <span class="ruby-identifier">variable</span>.<span class="ruby-identifier">elements</span>.<span class="ruby-identifier">each</span>(<span class="ruby-value str">"OUTCOME"</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">outcome</span><span class="ruby-operator">|</span>
- <span class="ruby-identifier">outcomes</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">outcome</span>.<span class="ruby-identifier">text</span>
- }
- <span class="ruby-comment cmt"># transform from text to boolean</span>
- <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">outcomes</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">==</span> <span class="ruby-value">2</span> <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">outcomes</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-value str">"true"</span>) <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">outcomes</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-value str">"false"</span>)
- <span class="ruby-identifier">outcomes</span> = <span class="ruby-identifier">outcomes</span>.<span class="ruby-identifier">collect</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">o</span><span class="ruby-operator">|</span> <span class="ruby-identifier">o</span> <span class="ruby-operator">==</span> <span class="ruby-value str">"true"</span>}
- <span class="ruby-keyword kw">end</span>
- <span class="ruby-identifier">node</span> = <span class="ruby-constant">BayesNetNode</span>.<span class="ruby-identifier">new</span>( <span class="ruby-identifier">name</span>.<span class="ruby-identifier">text</span>, <span class="ruby-identifier">outcomes</span> )
- <span class="ruby-identifier">bn</span>.<span class="ruby-identifier">add_vertex</span>(<span class="ruby-identifier">node</span>)
- }
-
- <span class="ruby-comment cmt"># for each variable we list, we will look up </span>
- <span class="ruby-comment cmt"># the conditional probability table for it.</span>
-
- <span class="ruby-identifier">doc</span>.<span class="ruby-identifier">elements</span>.<span class="ruby-identifier">each</span>(<span class="ruby-value str">"BIF/NETWORK/DEFINITION/"</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">definition</span><span class="ruby-operator">|</span>
- <span class="ruby-identifier">node</span> = <span class="ruby-identifier">get_variable</span>( <span class="ruby-identifier">definition</span>.<span class="ruby-identifier">elements</span>[<span class="ruby-value str">"FOR"</span>].<span class="ruby-identifier">text</span> )
- <span class="ruby-identifier">givens_array</span> = []
- <span class="ruby-identifier">definition</span>.<span class="ruby-identifier">elements</span>.<span class="ruby-identifier">each</span>(<span class="ruby-value str">"GIVEN"</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">given</span><span class="ruby-operator">|</span>
- <span class="ruby-identifier">givens_array</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">get_variable</span>( <span class="ruby-identifier">given</span>.<span class="ruby-identifier">text</span> )
- }
-
- <span class="ruby-identifier">table</span> = <span class="ruby-identifier">definition</span>.<span class="ruby-identifier">elements</span>[<span class="ruby-value str">"TABLE"</span>].<span class="ruby-identifier">text</span>.<span class="ruby-identifier">split</span>
-
- <span class="ruby-identifier">givens_array</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">g</span><span class="ruby-operator">|</span> <span class="ruby-identifier">bn</span>.<span class="ruby-identifier">add_edge</span>(<span class="ruby-identifier">g</span>, <span class="ruby-identifier">node</span>) }
-
- <span class="ruby-identifier">node</span>.<span class="ruby-identifier">set_probability_table</span>(<span class="ruby-identifier">givens_array</span>, <span class="ruby-identifier">table</span>)
- }
- <span class="ruby-identifier">bn</span>
-<span class="ruby-keyword kw">end</span></pre>
-</body>
+<?xml version="1.0" encoding="iso-8859-1"?>
+<!DOCTYPE html
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html>
+<head>
+ <title>nodes_ordered_by_dependencies (BayesNet)</title>
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
+ <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
+</head>
+<body class="standalone-code">
+ <pre><span class="ruby-comment cmt"># File lib/bn4r/bn.rb, line 142</span>
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">nodes_ordered_by_dependencies</span>(<span class="ruby-identifier">nodes</span> = <span class="ruby-identifier">vertices</span>, <span class="ruby-identifier">bn_ordered</span> = <span class="ruby-constant">Array</span>.<span class="ruby-identifier">new</span>)
+ <span class="ruby-identifier">nodes</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">v</span><span class="ruby-operator">|</span>
+ <span class="ruby-keyword kw">next</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">bn_ordered</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">v</span>)
+ <span class="ruby-identifier">nodes_ordered_by_dependencies</span>(<span class="ruby-identifier">v</span>.<span class="ruby-identifier">parents</span>, <span class="ruby-identifier">bn_ordered</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-operator">!</span><span class="ruby-identifier">v</span>.<span class="ruby-identifier">root?</span>
+ <span class="ruby-identifier">bn_ordered</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">v</span>
+ }
+ <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">bn_ordered</span>.<span class="ruby-identifier">flatten</span>
+ <span class="ruby-keyword kw">end</span></pre>
+</body>
</html>
\ No newline at end of file