annotate toolboxes/FullBNT-1.0.7/graph/Old/best_first_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 = best_first_elim_order(G, node_sizes, stage)
Daniel@0 2 % BEST_FIRST_ELIM_ORDER Greedily search for an optimal elimination order.
Daniel@0 3 % order = best_first_elim_order(moral_graph, node_sizes)
Daniel@0 4 %
Daniel@0 5 % Find an order in which to eliminate nodes from the graph in such a way as to try and minimize the
Daniel@0 6 % weight of the resulting triangulated graph. The weight of a graph is the sum of the weights of each
Daniel@0 7 % of its cliques; the weight of a clique is the product of the weights of each of its members; the
Daniel@0 8 % weight of a node is the number of values it can take on.
Daniel@0 9 %
Daniel@0 10 % Since this is an NP-hard problem, we use the following greedy heuristic:
Daniel@0 11 % at each step, eliminate that node which will result in the addition of the least
Daniel@0 12 % number of fill-in edges, breaking ties by choosing the node that induces the lighest clique.
Daniel@0 13 % For details, see
Daniel@0 14 % - Kjaerulff, "Triangulation of graphs -- algorithms giving small total state space",
Daniel@0 15 % Univ. Aalborg tech report, 1990 (www.cs.auc.dk/~uk)
Daniel@0 16 % - C. Huang and A. Darwiche, "Inference in Belief Networks: A procedural guide",
Daniel@0 17 % Intl. J. Approx. Reasoning, 11, 1994
Daniel@0 18 %
Daniel@0 19
Daniel@0 20 % Warning: This code is pretty old and could probably be made faster.
Daniel@0 21
Daniel@0 22 n = length(G);
Daniel@0 23 if nargin < 3, stage = { 1:n }; end % no constraints
Daniel@0 24
Daniel@0 25 % For long DBNs, it may be useful to eliminate all the nodes in slice t before slice t+1.
Daniel@0 26 % This will ensure that the jtree has a repeating structure (at least away from both edges).
Daniel@0 27 % This is why we have stages.
Daniel@0 28 % See the discussion of splicing jtrees on p68 of
Daniel@0 29 % Geoff Zweig's PhD thesis, Dept. Comp. Sci., UC Berkeley, 1998.
Daniel@0 30 % This constraint can increase the clique size significantly.
Daniel@0 31
Daniel@0 32 MG = G; % copy the original graph
Daniel@0 33 uneliminated = ones(1,n);
Daniel@0 34 order = zeros(1,n);
Daniel@0 35 t = 1; % Counts which time slice we are on
Daniel@0 36 for i=1:n
Daniel@0 37 U = find(uneliminated);
Daniel@0 38 valid = myintersect(U, stage{t});
Daniel@0 39 % Choose the best node from the set of valid candidates
Daniel@0 40 score1 = zeros(1,length(valid));
Daniel@0 41 score2 = zeros(1,length(valid));
Daniel@0 42 for j=1:length(valid)
Daniel@0 43 k = valid(j);
Daniel@0 44 ns = myintersect(neighbors(G, k), U);
Daniel@0 45 l = length(ns);
Daniel@0 46 M = MG(ns,ns);
Daniel@0 47 score1(j) = l^2 - sum(M(:)); % num. added edges
Daniel@0 48 score2(j) = prod(node_sizes([k ns])); % weight of clique
Daniel@0 49 end
Daniel@0 50 j1s = find(score1==min(score1));
Daniel@0 51 j = j1s(argmin(score2(j1s)));
Daniel@0 52 k = valid(j);
Daniel@0 53 uneliminated(k) = 0;
Daniel@0 54 order(i) = k;
Daniel@0 55 ns = myintersect(neighbors(G, k), U);
Daniel@0 56 if ~isempty(ns)
Daniel@0 57 G(ns,ns) = 1;
Daniel@0 58 G = setdiag(G,0);
Daniel@0 59 end
Daniel@0 60 if ~any(logical(uneliminated(stage{t}))) % are we allowed to the next slice?
Daniel@0 61 t = t + 1;
Daniel@0 62 end
Daniel@0 63 end
Daniel@0 64