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