Daniel@0: function order = strong_elim_order(G, node_sizes, partial_order) Daniel@0: % STRONG_ELIM_ORDER Find an elimination order to produce a strongly triangulated graph. Daniel@0: % order = strong_elim_order(moral_graph, node_sizes, partial_order) Daniel@0: % Daniel@0: % partial_order(i,j)=1 if we must marginalize i *after* j Daniel@0: % (so i will be nearer the strong root). Daniel@0: % e.g., if j is a decision node and i is its information set: Daniel@0: % we cannot maximize j if we have marginalized out some of i Daniel@0: % e.g., if j is a continuous child and i is its discrete parent: Daniel@0: % we want to integrate out the cts nodes before the discrete ones, Daniel@0: % so that the marginal is strong. Daniel@0: % Daniel@0: % For details, see Daniel@0: % - Jensen, Jensen and Dittmer, "From influence diagrams to junction trees", UAI 94. Daniel@0: % - Lauritzen, "Propgation of probabilities, means, and variances in mixed graphical Daniel@0: % association models", JASA 87(420):1098--1108, 1992. Daniel@0: % Daniel@0: % On p369 of the Jensen paper, they state "the reverse of the elimination order must be some Daniel@0: % extension of [the partial order] to a total order". Daniel@0: % We make no attempt to find the best such total ordering, in the sense of minimizing the weight Daniel@0: % of the resulting cliques. Daniel@0: Daniel@0: % Example from the Jensen paper: Daniel@0: % Let us number the nodes in Fig 1 from top to bottom, left to right, Daniel@0: % so a=1,b=2,D1=3,c=4,...,l=14,j=15,k=16. Daniel@0: % 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: Daniel@0: if 0 Daniel@0: total_order = topological_sort(partial_order); Daniel@0: order = total_order(end:-1:1); % no attempt to find an optimal constrained ordering! Daniel@0: return; Daniel@0: end Daniel@0: Daniel@0: % The following implementation is due to Ilya Shpitser and seems to give wrong Daniel@0: % results on cg1 Daniel@0: Daniel@0: n = length(G); Daniel@0: MG = G; % copy the original graph Daniel@0: uneliminated = ones(1,n); Daniel@0: order = zeros(1,n); Daniel@0: Daniel@0: for i=1:n Daniel@0: roots = []; Daniel@0: k = 1; Daniel@0: for j=1:n Daniel@0: if sum(partial_order(j,:)) == 0 Daniel@0: roots(k) = j; Daniel@0: k = k + 1; Daniel@0: end Daniel@0: end Daniel@0: U = find(uneliminated); Daniel@0: valid = myintersect(U, roots); Daniel@0: % Choose the best node from the set of valid candidates Daniel@0: score1 = zeros(1,length(valid)); Daniel@0: score2 = zeros(1,length(valid)); Daniel@0: for j=1:length(valid) Daniel@0: k = valid(j); Daniel@0: ns = myintersect(neighbors(G, k), U); Daniel@0: l = length(ns); Daniel@0: M = MG(ns,ns); Daniel@0: score1(j) = l^2 - sum(M(:)); % num. added edges Daniel@0: score2(j) = prod(node_sizes([k ns])); % weight of clique Daniel@0: end Daniel@0: j1s = find(score1==min(score1)); Daniel@0: j = j1s(argmin(score2(j1s))); Daniel@0: k = valid(j); Daniel@0: uneliminated(k) = 0; Daniel@0: order(i) = k; Daniel@0: ns = myintersect(neighbors(G, k), U); Daniel@0: if ~isempty(ns) Daniel@0: G(ns,ns) = 1; Daniel@0: G = setdiag(G,0); Daniel@0: end Daniel@0: partial_order(:,k) = 0; Daniel@0: end