about summary refs log tree commit diff
path: root/sourcecodes/bnt-master/BNT/examples/static/nodeorderExample.m
diff options
context:
space:
mode:
authorziejd22018-03-14 23:23:33 -0500
committerGitHub2018-03-14 23:23:33 -0500
commit1ff6baa44e22b91eefb48aea6f3befa078c0489b (patch)
treee0fd79d2e32fd2aedda2eadaed0f19af3514c520 /sourcecodes/bnt-master/BNT/examples/static/nodeorderExample.m
parent6882395afdadf4e982b25b5215071a0932730950 (diff)
parentc80226899f5cdd9f11c163817d59445213f5bef0 (diff)
downloadBNW-1ff6baa44e22b91eefb48aea6f3befa078c0489b.tar.gz
Merge pull request #1 from ziejd2/octave_php_separate
Octave php separate
Diffstat (limited to 'sourcecodes/bnt-master/BNT/examples/static/nodeorderExample.m')
-rw-r--r--sourcecodes/bnt-master/BNT/examples/static/nodeorderExample.m68
1 files changed, 68 insertions, 0 deletions
diff --git a/sourcecodes/bnt-master/BNT/examples/static/nodeorderExample.m b/sourcecodes/bnt-master/BNT/examples/static/nodeorderExample.m
new file mode 100644
index 00000000..165f3210
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/static/nodeorderExample.m
@@ -0,0 +1,68 @@
+% example to illustrate why nodes must be numbered topologically.
+% Due to Shinya OHTANI <ohtani@pdp.crl.sony.co.jp>
+% 9 June 2004
+
+%%%%%%%%% WRONG RESULTS because 2 -> 1 
+% should have P(parent|no evidence) = prior = [03. 0.7]
+
+node = struct('ChildNode', 1, ...
+               'ParentNode', 2);
+
+adjacency = zeros(2);
+adjacency([node.ParentNode], node.ChildNode) = 1;
+
+value = {{'TRUE'; 'FALSE'}, ...
+          {'TRUE'; 'FALSE'}};
+
+bnet = mk_bnet(adjacency, [2 2]);
+bnet.CPD{node.ChildNode} = tabular_CPD(bnet, node.ChildNode, [0.2 0.4 0.8 0.6]);
+bnet.CPD{node.ParentNode} = tabular_CPD(bnet, node.ParentNode, [0.3 0.7]);
+
+evidence = cell(1,2);
+% evidence{node.ChildNode} = 1;
+% evidence{node.ParentNode} = 1;
+
+engine = jtree_inf_engine(bnet);
+[engine, loglik] = enter_evidence(engine, evidence);
+
+
+marg = marginal_nodes(engine, node.ChildNode);
+disp(sprintf('    ChildNode     : %8.6f   %8.6f',marg.T(1),marg.T(2)) );
+marg = marginal_nodes(engine, node.ParentNode);
+disp(sprintf('    ParentNode    : %8.6f   %8.6f',marg.T(1),marg.T(2)) );
+
+% 
+%     ChildNode   : 0.534483   0.465517
+%     ParentNode  : 0.155172   0.844828
+% loglik = 0.15
+
+
+
+%%%%%%%%% RIGHT RESULTS because 1 -> 2
+
+node = struct('ChildNode', 2, ...
+               'ParentNode', 1);
+
+
+adjacency = zeros(2);
+adjacency([node.ParentNode], node.ChildNode) = 1;
+
+value = {{'TRUE'; 'FALSE'}, ...
+          {'TRUE'; 'FALSE'}};
+
+bnet = mk_bnet(adjacency, [2 2]);
+bnet.CPD{node.ChildNode} = tabular_CPD(bnet, node.ChildNode, [0.2 0.4 0.8 0.6]);
+bnet.CPD{node.ParentNode} = tabular_CPD(bnet, node.ParentNode, [0.3 0.7]);
+
+evidence = cell(1,2);
+% evidence{node.ChildNode} = 1;
+% evidence{node.ParentNode} = 1;
+
+engine = jtree_inf_engine(bnet);
+[engine, loglik] = enter_evidence(engine, evidence);
+
+
+marg = marginal_nodes(engine, node.ChildNode);
+disp(sprintf('    ChildNode     : %8.6f   %8.6f',marg.T(1),marg.T(2)) );
+marg = marginal_nodes(engine, node.ParentNode);
+disp(sprintf('    ParentNode    : %8.6f   %8.6f',marg.T(1),marg.T(2)) );