annotate toolboxes/FullBNT-1.0.7/graph/strong_elim_order.m @ 0:cc4b1211e677 tip

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