comparison toolboxes/FullBNT-1.0.7/bnt/inference/dynamic/@bk_ff_hmm_inf_engine/private/dbn_to_hmm.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 [prior, transmat] = dbn_to_hmm(bnet)
2 % DBN_TO_HMM Compute the discrete HMM matrices from a simple DBN
3 % [prior, transmat] = dbn_to_hmm(bnet)
4
5 onodes = bnet.observed;
6 ss = length(bnet.intra);
7 evidence = cell(1,2*ss);
8 hnodes = mysetdiff(1:ss, onodes);
9 prior = multiply_CPTs(bnet, [], hnodes, evidence);
10 transmat = multiply_CPTs(bnet, hnodes, hnodes+ss, evidence);
11 %obsmat1 = multiply_CPTs(bnet, hnodes, onodes, evidence);
12 %obsmat = multiply_CPTs(bnet, hnodes+ss, onodes+ss, evidence);
13 %obsmat1 = obsmat if the observation matrices are tied across slices
14
15
16
17 %%%%%%%%%%%%
18
19 function mat = multiply_CPTs(bnet, pdom, cdom, evidence)
20
21 % MULTIPLY_CPTS Make a matrix Pr(Y|X), where X represents all the parents, and Y all the children
22 % We assume the children have no intra-connections.
23 %
24 % e.g., Consider the DBN with interconnectivity i->i', j->j',k', k->i',k'
25 % Then transition matrix = Pr(i,j,k -> i',j',k') = Pr(i,k->i') Pr(j->j') Pr(j,k->k')
26
27 dom = [pdom cdom];
28 ns = bnet.node_sizes;
29 bigpot = dpot(dom, ns(dom));
30 for j=cdom(:)'
31 e = bnet.equiv_class(j);
32 fam = family(bnet.dag, j);
33 pot = convert_to_pot(bnet.CPD{e}, 'd', fam(:), evidence);
34 bigpot = multiply_by_pot(bigpot, pot);
35 end
36 psize = prod(ns(pdom));
37 csize = prod(ns(cdom));
38 T = pot_to_marginal(bigpot);
39 mat = reshape(T.T, [psize csize]);
40
41