comparison toolboxes/FullBNT-1.0.7/graph/Old/dag_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, cliques, B, w, elim_order, moral_edges, fill_in_edges, strong] = ...
2 dag_to_jtree(dag, node_sizes, partial_order, stages, clusters)
3 % DAG_TO_JTREE Moralize and triangulate a DAG, and make a junction tree from its cliques.
4 % [jtree, root, cliques, B, w, elim_order, moral_edges, fill_in_edges, strong] = ...
5 % dag_to_jtree(dag, node_sizes, partial_order, stages, clusters)
6 %
7 % Input:
8 % dag(i,j)
9 % jtree(i,j) = 1 iff there is an arc between clique i and clique j
10 % root = the root clique
11 % cliques{i} = the nodes in clique i
12 % B(i,j) = 1 iff node j occurs in clique i
13 % w(i) = weight of clique i
14
15 N = length(bnet.dag);
16 if nargin < 2, obs_nodes = []; end
17 if nargin < 3, stages = { 1:N }; end
18 if nargin < 4, clusters = {}; end
19
20 [MG, moral_edges] = moralize(bnet.dag);
21
22 % Add extra arcs between nodes in each cluster to ensure they occur in the same clique
23 for i=1:length(clusters)
24 c = clusters{i};
25 MG(c,c) = 1;
26 end
27 MG = setdiag(MG, 0);
28
29 % Find an optimal elimination ordering (NP-hard problem!)
30 ns = bnet.node_sizes(:);
31 ns(obs_nodes) = 1; % observed nodes have only 1 possible value
32 partial_order = determine_elim_constraints(bnet, obs_nodes);
33
34 if isempty(partial_order)
35 strong = 0;
36 elim_order = best_first_elim_order(MG, ns, stages);
37 else
38 strong = 1;
39 elim_order = strong_elim_order(MG, ns, partial_order);
40 end
41
42 [MTG, cliques, fill_in_edges] = triangulate(MG, elim_order);
43
44 % Connect the cliques up into a jtree,
45 [jtree, root, B, w] = cliques_to_jtree(cliques, ns);
46
47 if 0
48 disp('testing dag to jtree');
49 % Find the cliques containing each node, and check they form a connected subtree
50 clqs_con_node = cell(1,N);
51 for i=1:N
52 clqs_con_node{i} = find(B(:,i))';
53 end
54 check_jtree_property(clqs_con_node, jtree);
55 end