Mercurial > hg > camir-aes2014
comparison toolboxes/FullBNT-1.0.7/graph/cliques_to_jtree.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 [jtree, root, B, w] = cliques_to_jtree(cliques, ns) | |
2 % MK_JTREE Make an optimal junction tree. | |
3 % [jtree, root, B, w] = mk_jtree(cliques, ns) | |
4 % | |
5 % A junction tree is a tree that satisfies the jtree property, which says: | |
6 % for each pair of cliques U,V with intersection S, all cliques on the path between U and V | |
7 % contain S. (This ensures that local propagation leads to global consistency.) | |
8 % | |
9 % We can create a junction tree by computing the maximal spanning tree of the junction graph. | |
10 % (The junction graph connects all cliques, and the weight of an edge (i,j) is | |
11 % |C(i) intersect C(j)|, where C(i) is the i'th clique.) | |
12 % | |
13 % The best jtree is the maximal spanning tree which minimizes the sum of the costs on each edge, | |
14 % where cost(i,j) = w(C(i)) + w(C(j)), and w(C) is the weight of clique C, | |
15 % which is the total number of values C can take on. | |
16 % | |
17 % For details, see | |
18 % - Jensen and Jensen, "Optimal Junction Trees", UAI 94. | |
19 % | |
20 % Input: | |
21 % cliques{i} = nodes in clique i | |
22 % ns(i) = number of values node i can take on | |
23 % Output: | |
24 % jtree(i,j) = 1 iff cliques i and j aer connected | |
25 % root = the clique that should be used as root | |
26 % B(i,j) = 1 iff node j occurs in clique i | |
27 % w(i) = weight of clique i | |
28 | |
29 | |
30 | |
31 num_cliques = length(cliques); | |
32 w = zeros(num_cliques, 1); | |
33 B = sparse(num_cliques, 1); | |
34 for i=1:num_cliques | |
35 B(i, cliques{i}) = 1; | |
36 w(i) = prod(ns(cliques{i})); | |
37 end | |
38 | |
39 | |
40 % C1(i,j) = length(intersect(cliques{i}, cliques{j})); | |
41 % The length of the intersection of two sets is the dot product of their bit vector representation. | |
42 C1 = B*B'; | |
43 C1 = setdiag(C1, 0); | |
44 | |
45 % C2(i,j) = w(i) + w(j) | |
46 num_cliques = length(w); | |
47 W = repmat(w, 1, num_cliques); | |
48 C2 = W + W'; | |
49 C2 = setdiag(C2, 0); | |
50 | |
51 jtree = sparse(minimum_spanning_tree(-C1, C2)); % Using -C1 gives *maximum* spanning tree | |
52 | |
53 % The root is arbitrary, but since the first pass is towards the root, | |
54 % we would like this to correspond to going forward in time in a DBN. | |
55 root = num_cliques; | |
56 | |
57 |