annotate toolboxes/FullBNT-1.0.7/bnt/examples/static/Models/Old/mk_hmm_bnet.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, onodes] = mk_hmm_bnet(T, Q, O, cts_obs, param_tying)
Daniel@0 2 % MK_HMM_BNET Make a (static( bnet to represent a hidden Markov model
Daniel@0 3 % [bnet, onodes] = mk_hmm_bnet(T, Q, O, cts_obs, param_tying)
Daniel@0 4 %
Daniel@0 5 % T = num time slices
Daniel@0 6 % Q = num hidden states
Daniel@0 7 % O = size of the observed node (num discrete values or length of vector)
Daniel@0 8 % cts_obs - 1 means the observed node is a continuous-valued vector, 0 means it's discrete
Daniel@0 9 % param_tying - 1 means we create 3 CPDs, 0 means we create 1 CPD per node
Daniel@0 10
Daniel@0 11 N = 2*T;
Daniel@0 12 dag = zeros(N);
Daniel@0 13 for i=1:T-1
Daniel@0 14 dag(i,i+1)=1;
Daniel@0 15 end
Daniel@0 16 onodes = T+1:N;
Daniel@0 17 for i=1:T
Daniel@0 18 dag(i, onodes(i)) = 1;
Daniel@0 19 end
Daniel@0 20
Daniel@0 21 if cts_obs
Daniel@0 22 dnodes = 1:T;
Daniel@0 23 else
Daniel@0 24 dnodes = 1:N;
Daniel@0 25 end
Daniel@0 26 ns = [Q*ones(1,T) O*ones(1,T)];
Daniel@0 27
Daniel@0 28 if param_tying
Daniel@0 29 eclass = [1 2*ones(1,T-1) 3*ones(1,T)];
Daniel@0 30 else
Daniel@0 31 eclass = 1:N;
Daniel@0 32 end
Daniel@0 33
Daniel@0 34 bnet = mk_bnet(dag, ns, dnodes, eclass);
Daniel@0 35
Daniel@0 36 hnodes = mysetdiff(1:N, onodes);
Daniel@0 37 if ~param_tying
Daniel@0 38 for i=hnodes(:)'
Daniel@0 39 bnet.CPD{i} = tabular_CPD(bnet, i);
Daniel@0 40 end
Daniel@0 41 if cts_obs
Daniel@0 42 for i=onodes(:)'
Daniel@0 43 bnet.CPD{i} = gaussian_CPD(bnet, i);
Daniel@0 44 end
Daniel@0 45 else
Daniel@0 46 for i=onodes(:)'
Daniel@0 47 bnet.CPD{i} = tabular_CPD(bnet, i);
Daniel@0 48 end
Daniel@0 49 end
Daniel@0 50 else
Daniel@0 51 bnet.CPD{1} = tabular_CPD(bnet, 1);
Daniel@0 52 bnet.CPD{2} = tabular_CPD(bnet, 2);
Daniel@0 53 if cts_obs
Daniel@0 54 bnet.CPD{3} = gaussian_CPD(bnet, 3);
Daniel@0 55 else
Daniel@0 56 bnet.CPD{3} = tabular_CPD(bnet, 3);
Daniel@0 57 end
Daniel@0 58 end