wolffd@0: function bnet = mk_chmm(N, Q, Y, discrete_obs, coupled, CPD) wolffd@0: % MK_CHMM Make a coupled Hidden Markov Model wolffd@0: % wolffd@0: % There are N hidden nodes, each connected to itself and its two nearest neighbors in the next wolffd@0: % slice (apart from the edges, where there is 1 nearest neighbor). wolffd@0: % wolffd@0: % Example: If N = 3, the hidden backbone is as follows, where all arrows point to the righ+t wolffd@0: % wolffd@0: % X1--X2 wolffd@0: % \/ wolffd@0: % /\ wolffd@0: % X2--X2 wolffd@0: % \/ wolffd@0: % /\ wolffd@0: % X3--X3 wolffd@0: % wolffd@0: % Each hidden node has a "private" observed child (not shown). wolffd@0: % wolffd@0: % BNET = MK_CHMM(N, Q, Y) wolffd@0: % Each hidden node is discrete and has Q values. wolffd@0: % Each observed node is a Gaussian vector of length Y. wolffd@0: % wolffd@0: % BNET = MK_CHMM(N, Q, Y, DISCRETE_OBS) wolffd@0: % If discrete_obs = 1, the observations are discrete (values in {1, .., Y}). wolffd@0: % wolffd@0: % BNET = MK_CHMM(N, Q, Y, DISCRETE_OBS, COUPLED) wolffd@0: % If coupled = 0, the chains are not coupled, i.e., we make N parallel HMMs. wolffd@0: % wolffd@0: % BNET = MK_CHMM(N, Q, Y, DISCRETE_OBS, COUPLED, CPDs) wolffd@0: % means use the specified CPD structures instead of creating random params. wolffd@0: % CPD{i}.CPT, i=1:N specifies the prior wolffd@0: % CPD{i}.CPT, i=2N+1:3N specifies the transition model wolffd@0: % CPD{i}.mean, CPD{i}.cov, i=N+1:2N specifies the observation model if Gaussian wolffd@0: % CPD{i}.CPT, i=N+1:2N if discrete wolffd@0: wolffd@0: wolffd@0: if nargin < 2, Q = 2; end wolffd@0: if nargin < 3, Y = 1; end wolffd@0: if nargin < 4, discrete_obs = 0; end wolffd@0: if nargin < 5, coupled = 1; end wolffd@0: if nargin < 6, rnd = 1; else rnd = 0; end wolffd@0: wolffd@0: ss = N*2; wolffd@0: hnodes = 1:N; wolffd@0: onodes = (1:N)+N; wolffd@0: wolffd@0: intra = zeros(ss); wolffd@0: for i=1:N wolffd@0: intra(hnodes(i), onodes(i))=1; wolffd@0: end wolffd@0: wolffd@0: inter = zeros(ss); wolffd@0: if coupled wolffd@0: for i=1:N wolffd@0: inter(i, max(i-1,1):min(i+1,N))=1; wolffd@0: end wolffd@0: else wolffd@0: inter(1:N, 1:N) = eye(N); wolffd@0: end wolffd@0: wolffd@0: ns = [Q*ones(1,N) Y*ones(1,N)]; wolffd@0: wolffd@0: eclass1 = [hnodes onodes]; wolffd@0: eclass2 = [hnodes+ss onodes]; wolffd@0: if discrete_obs wolffd@0: dnodes = 1:ss; wolffd@0: else wolffd@0: dnodes = hnodes; wolffd@0: end wolffd@0: bnet = mk_dbn(intra, inter, ns, 'discrete', dnodes, 'eclass1', eclass1, 'eclass2', eclass2, ... wolffd@0: 'observed', onodes); wolffd@0: wolffd@0: if rnd wolffd@0: for i=hnodes(:)' wolffd@0: bnet.CPD{i} = tabular_CPD(bnet, i); wolffd@0: end wolffd@0: for i=onodes(:)' wolffd@0: if discrete_obs wolffd@0: bnet.CPD{i} = tabular_CPD(bnet, i); wolffd@0: else wolffd@0: bnet.CPD{i} = gaussian_CPD(bnet, i); wolffd@0: end wolffd@0: end wolffd@0: for i=hnodes(:)'+ss wolffd@0: bnet.CPD{i} = tabular_CPD(bnet, i); wolffd@0: end wolffd@0: else wolffd@0: for i=hnodes(:)' wolffd@0: bnet.CPD{i} = tabular_CPD(bnet, i, CPD{i}.CPT); wolffd@0: end wolffd@0: for i=onodes(:)' wolffd@0: if discrete_obs wolffd@0: bnet.CPD{i} = tabular_CPD(bnet, i, CPD{i}.CPT); wolffd@0: else wolffd@0: bnet.CPD{i} = gaussian_CPD(bnet, i, CPD{i}.mean, CPD{i}.cov); wolffd@0: end wolffd@0: end wolffd@0: for i=hnodes(:)'+ss wolffd@0: bnet.CPD{i} = tabular_CPD(bnet, i, CPD{i}.CPT); wolffd@0: end wolffd@0: end wolffd@0: wolffd@0: