annotate toolboxes/FullBNT-1.0.7/bnt/examples/dynamic/mk_fhmm.m @ 0:cc4b1211e677 tip

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