comparison toolboxes/FullBNT-1.0.7/bnt/examples/dynamic/mk_fhmm.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 = mk_fhmm(N, Q, Y, discrete_obs)
2 % MK_FHMM Make a factorial Hidden Markov Model
3 %
4 % There are N independent parallel hidden chains, each connected to the output
5 %
6 % e.g., N = 2 (vertical/diagonal edges point down)
7 %
8 % A1--->A2
9 % | B1--|->B2
10 % | / |/
11 % Y1 Y2
12 %
13 % [bnet, onode] = mk_chmm(n, q, y, discrete_obs)
14 %
15 % Each hidden node is discrete and has Q values.
16 % If discrete_obs = 1, each observed node is discrete and has values 1..Y.
17 % If discrete_obs = 0, each observed node is a Gaussian vector of length Y.
18
19 if nargin < 2, Q = 2; end
20 if nargin < 3, Y = 2; end
21 if nargin < 4, discrete_obs = 1; end
22
23 ss = N+1;
24 hnodes = 1:N;
25 onode = N+1;
26
27 intra = zeros(ss);
28 intra(hnodes, onode) = 1;
29
30 inter = eye(ss);
31 inter(onode,onode) = 0;
32
33 ns = [Q*ones(1,N) Y];
34
35 eclass1 = [hnodes onode];
36 eclass2 = [hnodes+ss onode];
37 if discrete_obs
38 dnodes = 1:ss;
39 else
40 dnodes = hnodes;
41 end
42 bnet = mk_dbn(intra, inter, ns, 'discrete', dnodes, 'eclass1', eclass1, 'eclass2', eclass2, ...
43 'observed', onode);
44
45 for i=hnodes(:)'
46 bnet.CPD{i} = tabular_CPD(bnet, i);
47 end
48 i = onode;
49 if discrete_obs
50 bnet.CPD{i} = tabular_CPD(bnet, i);
51 else
52 bnet.CPD{i} = gaussian_CPD(bnet, i);
53 end
54 for i=hnodes(:)'+ss
55 bnet.CPD{i} = tabular_CPD(bnet, i);
56 end
57
58