To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / _FullBNT / BNT / graph / cliques_to_strong_jtree.m @ 8:b5b38998ef3b
History | View | Annotate | Download (3.61 KB)
| 1 |
function [jtree, root, cliques, B, w] = mk_strong_jtree(cliques, ns, elim_order, MTG) |
|---|---|
| 2 |
% MK_SRONG_JTREE Make a strong junction tree. |
| 3 |
% [jtree, root, cliques, B, w] = mk_strong_jtree(cliques, ns, elim_order, MTG) |
| 4 |
% |
| 5 |
% Here is a definition of a strong jtree from Jensen et al. 1994: |
| 6 |
% "A junction tree is said to be strong if it has at least one distinguished clique R, |
| 7 |
% called a strong root, s.t. for each pair (C1,C2) of adjacent cliques in the tree, |
| 8 |
% with C1 closer to R than C2, there exists and ordering of [the nodes below] C2 |
| 9 |
% that respects [the partial order] and with the vertices of the separator C1 intersect C2 |
| 10 |
% preceeding the vertices [below C2] of C2 \ C1." |
| 11 |
% |
| 12 |
% For details, see |
| 13 |
% - Jensen, Jensen and Dittmer, "From influence diagrams to junction trees", UAI 94. |
| 14 |
% |
| 15 |
% MTG is the moralized, triangulated graph. |
| 16 |
% elim_order is the elimination ordering used to compute MTG. |
| 17 |
|
| 18 |
|
| 19 |
% Warning: this is a very naive implementation of the algorithm in Jensen et al. |
| 20 |
|
| 21 |
n = length(elim_order); |
| 22 |
alpha(elim_order) = n:-1:1; |
| 23 |
% alpha(u) = i if we eliminate u at step n-i+1 |
| 24 |
% i.e., vertices with higher alpha numbers are eliminated before vertices with lower numbers. |
| 25 |
% e.g., from the Jensen et al paper |
| 26 |
% node a=1 eliminated at step 6, so alpha(a)=16-6+1=11. |
| 27 |
% alpha = [11 1 2 10 9 3 4 7 5 8 13 12 6 16 15 14] |
| 28 |
|
| 29 |
|
| 30 |
% We sort the cliques in order of increasing index. The index of a clique C is defined as follows. |
| 31 |
% Let lower = {u | alpha(u) < alpha(v)}, and
|
| 32 |
% let v in C be the highest-numbered vertex s.t. the vertices in W = lower intersect C |
| 33 |
% have a common neighbor u in U, where U = lower \ C. |
| 34 |
% If such a v exists, define index(C) = alpha(v), otherwise, index(C) = 1. |
| 35 |
% Intuitively, index(C) is the step in the elimination process at which C disappears. |
| 36 |
|
| 37 |
num_cliques = length(cliques); |
| 38 |
index = zeros(1, num_cliques); |
| 39 |
for c = 1:num_cliques |
| 40 |
C = cliques{c};
|
| 41 |
highest_num = -inf; |
| 42 |
for vi = 1:length(C) |
| 43 |
v = C(vi); |
| 44 |
lower = find(alpha < alpha(v)); |
| 45 |
W = myintersect(lower, C); |
| 46 |
U = mysetdiff(lower, C); |
| 47 |
found = 0; |
| 48 |
for ui=1:length(U) |
| 49 |
u = U(ui); |
| 50 |
if mysubset(W, neighbors(MTG, u)) |
| 51 |
found = 1; |
| 52 |
break; |
| 53 |
end |
| 54 |
end |
| 55 |
if found |
| 56 |
if alpha(v) > highest_num |
| 57 |
highest_num = alpha(v); |
| 58 |
end |
| 59 |
end |
| 60 |
end |
| 61 |
if highest_num == -inf |
| 62 |
index(c) = 1; |
| 63 |
else |
| 64 |
index(c) = highest_num; |
| 65 |
end |
| 66 |
end |
| 67 |
|
| 68 |
|
| 69 |
% Permute the cliques so that they are ordered according to index |
| 70 |
[dummy, clique_order] = sort(index); |
| 71 |
cliques = cliques(clique_order); |
| 72 |
|
| 73 |
w = zeros(num_cliques, 1); |
| 74 |
B = sparse(num_cliques, 1); |
| 75 |
for i=1:num_cliques |
| 76 |
B(i, cliques{i}) = 1;
|
| 77 |
w(i) = prod(ns(cliques{i}));
|
| 78 |
end |
| 79 |
|
| 80 |
% Pearl p113 suggests ordering the cliques by rank of the highest vertex in each clique. |
| 81 |
% However, this will only work if we use maximum cardinality search. |
| 82 |
|
| 83 |
|
| 84 |
% Join up the cliques so that they satisfy the Running Intersection Property. |
| 85 |
% This states that, for all k > 1, S(k) subseteq C(j) for some j < k, where |
| 86 |
% S(k) = C(k) intersect (union_{i=1}^{k-1} C(i))
|
| 87 |
jtree = sparse(num_cliques, num_cliques); |
| 88 |
for k=2:num_cliques |
| 89 |
S = []; |
| 90 |
for i=1:k-1 |
| 91 |
S = myunion(S, cliques{i});
|
| 92 |
end |
| 93 |
S = myintersect(S, cliques{k});
|
| 94 |
found = 0; |
| 95 |
for j=1:k-1 |
| 96 |
if mysubset(S, cliques{j})
|
| 97 |
found = 1; |
| 98 |
break; |
| 99 |
end |
| 100 |
end |
| 101 |
if ~found |
| 102 |
disp(['RIP is violated for clique ' num2str(k)]); |
| 103 |
end |
| 104 |
jtree(k,j)=1; |
| 105 |
jtree(j,k)=1; |
| 106 |
end |
| 107 |
|
| 108 |
% Pearl p113 suggests connecting Ci to a predecessor Cj (j < i) sharing |
| 109 |
% the highest number of vertices with Ci (i.e., the heaviest i-j edge |
| 110 |
% in the jgraph). However, this will only work if we use maximum cardinality search. |
| 111 |
|
| 112 |
root = 1; |
| 113 |
|
| 114 |
|