comparison toolboxes/FullBNT-1.0.7/bnt/examples/dynamic/mk_chmm.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_chmm(N, Q, Y, discrete_obs, coupled, CPD)
2 % MK_CHMM Make a coupled Hidden Markov Model
3 %
4 % There are N hidden nodes, each connected to itself and its two nearest neighbors in the next
5 % slice (apart from the edges, where there is 1 nearest neighbor).
6 %
7 % Example: If N = 3, the hidden backbone is as follows, where all arrows point to the righ+t
8 %
9 % X1--X2
10 % \/
11 % /\
12 % X2--X2
13 % \/
14 % /\
15 % X3--X3
16 %
17 % Each hidden node has a "private" observed child (not shown).
18 %
19 % BNET = MK_CHMM(N, Q, Y)
20 % Each hidden node is discrete and has Q values.
21 % Each observed node is a Gaussian vector of length Y.
22 %
23 % BNET = MK_CHMM(N, Q, Y, DISCRETE_OBS)
24 % If discrete_obs = 1, the observations are discrete (values in {1, .., Y}).
25 %
26 % BNET = MK_CHMM(N, Q, Y, DISCRETE_OBS, COUPLED)
27 % If coupled = 0, the chains are not coupled, i.e., we make N parallel HMMs.
28 %
29 % BNET = MK_CHMM(N, Q, Y, DISCRETE_OBS, COUPLED, CPDs)
30 % means use the specified CPD structures instead of creating random params.
31 % CPD{i}.CPT, i=1:N specifies the prior
32 % CPD{i}.CPT, i=2N+1:3N specifies the transition model
33 % CPD{i}.mean, CPD{i}.cov, i=N+1:2N specifies the observation model if Gaussian
34 % CPD{i}.CPT, i=N+1:2N if discrete
35
36
37 if nargin < 2, Q = 2; end
38 if nargin < 3, Y = 1; end
39 if nargin < 4, discrete_obs = 0; end
40 if nargin < 5, coupled = 1; end
41 if nargin < 6, rnd = 1; else rnd = 0; end
42
43 ss = N*2;
44 hnodes = 1:N;
45 onodes = (1:N)+N;
46
47 intra = zeros(ss);
48 for i=1:N
49 intra(hnodes(i), onodes(i))=1;
50 end
51
52 inter = zeros(ss);
53 if coupled
54 for i=1:N
55 inter(i, max(i-1,1):min(i+1,N))=1;
56 end
57 else
58 inter(1:N, 1:N) = eye(N);
59 end
60
61 ns = [Q*ones(1,N) Y*ones(1,N)];
62
63 eclass1 = [hnodes onodes];
64 eclass2 = [hnodes+ss onodes];
65 if discrete_obs
66 dnodes = 1:ss;
67 else
68 dnodes = hnodes;
69 end
70 bnet = mk_dbn(intra, inter, ns, 'discrete', dnodes, 'eclass1', eclass1, 'eclass2', eclass2, ...
71 'observed', onodes);
72
73 if rnd
74 for i=hnodes(:)'
75 bnet.CPD{i} = tabular_CPD(bnet, i);
76 end
77 for i=onodes(:)'
78 if discrete_obs
79 bnet.CPD{i} = tabular_CPD(bnet, i);
80 else
81 bnet.CPD{i} = gaussian_CPD(bnet, i);
82 end
83 end
84 for i=hnodes(:)'+ss
85 bnet.CPD{i} = tabular_CPD(bnet, i);
86 end
87 else
88 for i=hnodes(:)'
89 bnet.CPD{i} = tabular_CPD(bnet, i, CPD{i}.CPT);
90 end
91 for i=onodes(:)'
92 if discrete_obs
93 bnet.CPD{i} = tabular_CPD(bnet, i, CPD{i}.CPT);
94 else
95 bnet.CPD{i} = gaussian_CPD(bnet, i, CPD{i}.mean, CPD{i}.cov);
96 end
97 end
98 for i=hnodes(:)'+ss
99 bnet.CPD{i} = tabular_CPD(bnet, i, CPD{i}.CPT);
100 end
101 end
102
103