about summary refs log tree commit diff
path: root/sourcecodes/bnt-master/BNT/inference/static/@jtree_limid_inf_engine/Old
diff options
context:
space:
mode:
Diffstat (limited to 'sourcecodes/bnt-master/BNT/inference/static/@jtree_limid_inf_engine/Old')
-rw-r--r--sourcecodes/bnt-master/BNT/inference/static/@jtree_limid_inf_engine/Old/CVS/Entries3
-rw-r--r--sourcecodes/bnt-master/BNT/inference/static/@jtree_limid_inf_engine/Old/CVS/Repository1
-rw-r--r--sourcecodes/bnt-master/BNT/inference/static/@jtree_limid_inf_engine/Old/CVS/Root1
-rw-r--r--sourcecodes/bnt-master/BNT/inference/static/@jtree_limid_inf_engine/Old/marginal_family.m59
-rw-r--r--sourcecodes/bnt-master/BNT/inference/static/@jtree_limid_inf_engine/Old/marginal_nodes_SS.m52
5 files changed, 116 insertions, 0 deletions
diff --git a/sourcecodes/bnt-master/BNT/inference/static/@jtree_limid_inf_engine/Old/CVS/Entries b/sourcecodes/bnt-master/BNT/inference/static/@jtree_limid_inf_engine/Old/CVS/Entries
new file mode 100644
index 00000000..0b350b99
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/inference/static/@jtree_limid_inf_engine/Old/CVS/Entries
@@ -0,0 +1,3 @@
+/marginal_family.m/1.1.1.1/Wed May 29 15:59:56 2002//
+/marginal_nodes_SS.m/1.1.1.1/Wed May 29 15:59:56 2002//
+D
diff --git a/sourcecodes/bnt-master/BNT/inference/static/@jtree_limid_inf_engine/Old/CVS/Repository b/sourcecodes/bnt-master/BNT/inference/static/@jtree_limid_inf_engine/Old/CVS/Repository
new file mode 100644
index 00000000..59988183
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/inference/static/@jtree_limid_inf_engine/Old/CVS/Repository
@@ -0,0 +1 @@
+FullBNT/BNT/inference/static/@jtree_limid_inf_engine/Old
diff --git a/sourcecodes/bnt-master/BNT/inference/static/@jtree_limid_inf_engine/Old/CVS/Root b/sourcecodes/bnt-master/BNT/inference/static/@jtree_limid_inf_engine/Old/CVS/Root
new file mode 100644
index 00000000..f3bd14a6
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/inference/static/@jtree_limid_inf_engine/Old/CVS/Root
@@ -0,0 +1 @@
+:ext:nsaunier@bnt.cvs.sourceforge.net:/cvsroot/bnt
diff --git a/sourcecodes/bnt-master/BNT/inference/static/@jtree_limid_inf_engine/Old/marginal_family.m b/sourcecodes/bnt-master/BNT/inference/static/@jtree_limid_inf_engine/Old/marginal_family.m
new file mode 100644
index 00000000..cd660ae4
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/inference/static/@jtree_limid_inf_engine/Old/marginal_family.m
@@ -0,0 +1,59 @@
+function [m, pot] = marginal_family(engine, query)
+% MARGINAL_NODES Compute the marginal on the family of the specified node (jtree_limid)
+% [m, pot] = marginal_family(engine, query)
+%
+% query should be a single decision node, or [] (to compute global max expected utility)
+
+bnet = bnet_from_engine(engine);
+if isempty(query)
+  compute_meu = 1;
+  d = bnet.decision_nodes(1); % pick an arbitrary root to collect to
+  fam = []; % marginalize root pot down to a point
+else
+  compute_meu = 0;
+  d = query;
+  assert(myismember(d, bnet.decision_nodes));
+  fam = family(bnet.dag, d);
+end
+
+clpot = init_clpot(bnet, engine.cliques, engine.clq_ass_to_node, engine.evidence, engine.exclude);
+
+% collect to root (clique containing d) 
+C = length(engine.cliques);
+seppot = cell(C, C);    % separators are implicitely initialized to 1s
+for n=engine.postorder{d}(1:end-1)
+  for p=parents(engine.rooted_jtree{d}, n)
+    %clpot{p} = divide_by_pot(clpot{n}, seppot{p,n}); % dividing by 1 is redundant
+    seppot{p,n} = marginalize_pot(clpot{n}, engine.separator{p,n});
+    clpot{p} = multiply_by_pot(clpot{p}, seppot{p,n});
+  end
+end
+
+root = engine.clq_ass_to_node(d);
+assert(root == engine.postorder{d}(end));
+pot = marginalize_pot(clpot{root}, fam);
+m = pot_to_marginal(pot);
+
+%%%%%%%%%%%
+
+
+function clpot = init_clpot(bnet, cliques, clq_ass_to_node, evidence, exclude)
+
+% Set the clique potentials to all 1s
+C = length(cliques);
+clpot = cell(1, C);
+ns = bnet.node_sizes;
+for i=1:C
+  clpot{i} = upot(cliques{i}, ns(cliques{i}));
+end
+
+N = length(bnet.dag);
+nodes = mysetdiff(1:N, exclude);
+
+for n=nodes(:)'
+  fam = family(bnet.dag, n);
+  e = bnet.equiv_class(n);
+  c = clq_ass_to_node(n);
+  pot = convert_to_pot(bnet.CPD{e}, 'u', ns, fam, evidence);
+  clpot{c} = multiply_by_pot(clpot{c}, pot);
+end
diff --git a/sourcecodes/bnt-master/BNT/inference/static/@jtree_limid_inf_engine/Old/marginal_nodes_SS.m b/sourcecodes/bnt-master/BNT/inference/static/@jtree_limid_inf_engine/Old/marginal_nodes_SS.m
new file mode 100644
index 00000000..2b6ff642
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/inference/static/@jtree_limid_inf_engine/Old/marginal_nodes_SS.m
@@ -0,0 +1,52 @@
+function [pot, MEU] = marginal_nodes(engine, d)
+
+C = length(cliques);
+%clpot = init_clpot(limid, cliques, d, clq_ass_to_node);
+clpot = init_clpot(limid, cliques, [], clq_ass_to_node);
+
+% collect to root
+if 1
+  % HUGIN
+  seppot = cell(C, C);    % separators are implicitely initialized to 1s
+  for n=postorder{di}(1:end-1)
+    for p=parents(rooted_jtree{di}, n)
+      %clpot{p} = divide_by_pot(clpot{n}, seppot{p,n}); % dividing by 1 is redundant
+      seppot{p,n} = marginalize_pot(clpot{n}, separator{p,n});
+      clpot{p} = multiply_by_pot(clpot{p}, seppot{p,n});
+    end
+  end
+else
+  % Shafer-Shenoy
+  msg = cell(C,C);
+  for n=postorder{di}(1:end-1)
+    for c=children(rooted_jtree{di}, n)
+      clpot{n} = multiply_by_pot(clpot{n}, msg{c,n});
+    end
+    p = parents(rooted_jtree{di}, n);
+    %msg{n,p} = marginalize_pot(clpot{n}, cliques{p});
+    msg{n,p} = marginalize_pot(clpot{n}, separator{n,p});
+  end
+  root = clq_ass_to_node(d);
+  n=postorder{di}(end);
+  assert(n == root);
+  for c=children(rooted_jtree{di}, n)
+    clpot{n} = multiply_by_pot(clpot{n}, msg{c,n});
+  end
+end	
+
+fam = family(limid.dag, d);
+pot = marginalize_pot(clpot{root}, fam);
+
+%%%%%%%
+jpot = compute_joint_pot_limid(limid);
+pot2 = marginalize_pot(jpot, fam);
+assert(approxeq_pot(pot, pot2))
+%%%%%%
+
+[policy, score] = extract_policy(pot);
+
+e = limid.equiv_class(d);
+limid.CPD{e} = set_params(limid.CPD{e}, 'policy', policy);
+
+  
+