Daniel@0: function [bnet, onodes] = mk_hmm_bnet(T, Q, O, cts_obs, param_tying) Daniel@0: % MK_HMM_BNET Make a (static( bnet to represent a hidden Markov model Daniel@0: % [bnet, onodes] = mk_hmm_bnet(T, Q, O, cts_obs, param_tying) Daniel@0: % Daniel@0: % T = num time slices Daniel@0: % Q = num hidden states Daniel@0: % O = size of the observed node (num discrete values or length of vector) Daniel@0: % cts_obs - 1 means the observed node is a continuous-valued vector, 0 means it's discrete Daniel@0: % param_tying - 1 means we create 3 CPDs, 0 means we create 1 CPD per node Daniel@0: Daniel@0: N = 2*T; Daniel@0: dag = zeros(N); Daniel@0: for i=1:T-1 Daniel@0: dag(i,i+1)=1; Daniel@0: end Daniel@0: onodes = T+1:N; Daniel@0: for i=1:T Daniel@0: dag(i, onodes(i)) = 1; Daniel@0: end Daniel@0: Daniel@0: if cts_obs Daniel@0: dnodes = 1:T; Daniel@0: else Daniel@0: dnodes = 1:N; Daniel@0: end Daniel@0: ns = [Q*ones(1,T) O*ones(1,T)]; Daniel@0: Daniel@0: if param_tying Daniel@0: eclass = [1 2*ones(1,T-1) 3*ones(1,T)]; Daniel@0: else Daniel@0: eclass = 1:N; Daniel@0: end Daniel@0: Daniel@0: bnet = mk_bnet(dag, ns, dnodes, eclass); Daniel@0: Daniel@0: hnodes = mysetdiff(1:N, onodes); Daniel@0: if ~param_tying Daniel@0: for i=hnodes(:)' Daniel@0: bnet.CPD{i} = tabular_CPD(bnet, i); Daniel@0: end Daniel@0: if cts_obs Daniel@0: for i=onodes(:)' Daniel@0: bnet.CPD{i} = gaussian_CPD(bnet, i); Daniel@0: end Daniel@0: else Daniel@0: for i=onodes(:)' Daniel@0: bnet.CPD{i} = tabular_CPD(bnet, i); Daniel@0: end Daniel@0: end Daniel@0: else Daniel@0: bnet.CPD{1} = tabular_CPD(bnet, 1); Daniel@0: bnet.CPD{2} = tabular_CPD(bnet, 2); Daniel@0: if cts_obs Daniel@0: bnet.CPD{3} = gaussian_CPD(bnet, 3); Daniel@0: else Daniel@0: bnet.CPD{3} = tabular_CPD(bnet, 3); Daniel@0: end Daniel@0: end