comparison toolboxes/FullBNT-1.0.7/graph/strong_elim_order.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:e9a9cd732c1e
1 function order = strong_elim_order(G, node_sizes, partial_order)
2 % STRONG_ELIM_ORDER Find an elimination order to produce a strongly triangulated graph.
3 % order = strong_elim_order(moral_graph, node_sizes, partial_order)
4 %
5 % partial_order(i,j)=1 if we must marginalize i *after* j
6 % (so i will be nearer the strong root).
7 % e.g., if j is a decision node and i is its information set:
8 % we cannot maximize j if we have marginalized out some of i
9 % e.g., if j is a continuous child and i is its discrete parent:
10 % we want to integrate out the cts nodes before the discrete ones,
11 % so that the marginal is strong.
12 %
13 % For details, see
14 % - Jensen, Jensen and Dittmer, "From influence diagrams to junction trees", UAI 94.
15 % - Lauritzen, "Propgation of probabilities, means, and variances in mixed graphical
16 % association models", JASA 87(420):1098--1108, 1992.
17 %
18 % On p369 of the Jensen paper, they state "the reverse of the elimination order must be some
19 % extension of [the partial order] to a total order".
20 % We make no attempt to find the best such total ordering, in the sense of minimizing the weight
21 % of the resulting cliques.
22
23 % Example from the Jensen paper:
24 % Let us number the nodes in Fig 1 from top to bottom, left to right,
25 % so a=1,b=2,D1=3,c=4,...,l=14,j=15,k=16.
26 % The elimination ordering they propose on p370 is [14 15 16 11 12 1 4 5 10 8 13 9 7 6 3 2];
27
28 if 0
29 total_order = topological_sort(partial_order);
30 order = total_order(end:-1:1); % no attempt to find an optimal constrained ordering!
31 return;
32 end
33
34 % The following implementation is due to Ilya Shpitser and seems to give wrong
35 % results on cg1
36
37 n = length(G);
38 MG = G; % copy the original graph
39 uneliminated = ones(1,n);
40 order = zeros(1,n);
41
42 for i=1:n
43 roots = [];
44 k = 1;
45 for j=1:n
46 if sum(partial_order(j,:)) == 0
47 roots(k) = j;
48 k = k + 1;
49 end
50 end
51 U = find(uneliminated);
52 valid = myintersect(U, roots);
53 % Choose the best node from the set of valid candidates
54 score1 = zeros(1,length(valid));
55 score2 = zeros(1,length(valid));
56 for j=1:length(valid)
57 k = valid(j);
58 ns = myintersect(neighbors(G, k), U);
59 l = length(ns);
60 M = MG(ns,ns);
61 score1(j) = l^2 - sum(M(:)); % num. added edges
62 score2(j) = prod(node_sizes([k ns])); % weight of clique
63 end
64 j1s = find(score1==min(score1));
65 j = j1s(argmin(score2(j1s)));
66 k = valid(j);
67 uneliminated(k) = 0;
68 order(i) = k;
69 ns = myintersect(neighbors(G, k), U);
70 if ~isempty(ns)
71 G(ns,ns) = 1;
72 G = setdiag(G,0);
73 end
74 partial_order(:,k) = 0;
75 end