comparison toolboxes/FullBNT-1.0.7/bnt/general/fgraph_to_bnet.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 bnet = fgraph_to_bnet(fg)
2 % FGRAPH_TO_BNET Convert a factor graph to a Bayes net
3 % bnet = fgraph_to_bnet(fg)
4 %
5 % We assume all factors are tabular_CPD.
6 % We create 1 dummy observed node for every factor.
7
8 N = fg.nvars + fg.nfactors;
9 vnodes = 1:fg.nvars;
10 fnodes = fg.nvars+1:N;
11 dag = zeros(N);
12 for x=1:fg.nvars
13 dag(x, fnodes(fg.dep{x})) = 1;
14 end
15 ns = [fg.node_sizes ones(1, fg.nfactors)];
16 discrete = [fg.dnodes fnodes];
17 bnet = mk_bnet(dag, ns, 'discrete', discrete);
18 for x=1:fg.nvars
19 bnet.CPD{x} = tabular_CPD(bnet, x, 'CPT', 'unif');
20 end
21 ev = cell(1, fg.nvars); % no evidence
22 for i=1:fg.nfactors
23 f = fnodes(i);
24 e = fg.equiv_class(i);
25 pot = convert_to_pot(fg.factors{e}, 'd', fg.dom{i}, ev);
26 m = pot_to_marginal(pot);
27 bnet.CPD{f} = tabular_CPD(bnet, f, 'CPT', m.T);
28 end
29
30