annotate toolboxes/FullBNT-1.0.7/bnt/examples/static/Brutti/Belief_IOhmm.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 % Sigmoid Belief IOHMM
wolffd@0 2 % Here is the model
wolffd@0 3 %
wolffd@0 4 % X \ X \
wolffd@0 5 % | | | |
wolffd@0 6 % Q-|->Q-|-> ...
wolffd@0 7 % | / | /
wolffd@0 8 % Y Y
wolffd@0 9 %
wolffd@0 10 clear all;
wolffd@0 11 clc;
wolffd@0 12 rand('state',0); randn('state',0);
wolffd@0 13 X = 1; Q = 2; Y = 3;
wolffd@0 14 % intra time-slice graph
wolffd@0 15 intra=zeros(3);
wolffd@0 16 intra(X,[Q Y])=1;
wolffd@0 17 intra(Q,Y)=1;
wolffd@0 18 % inter time-slice graph
wolffd@0 19 inter=zeros(3);
wolffd@0 20 inter(Q,Q)=1;
wolffd@0 21
wolffd@0 22 ns = [1 3 1];
wolffd@0 23 dnodes = [2];
wolffd@0 24 eclass1 = [1 2 3];
wolffd@0 25 eclass2 = [1 4 3];
wolffd@0 26 bnet = mk_dbn(intra, inter, ns, dnodes, eclass1, eclass2);
wolffd@0 27 bnet.CPD{1} = root_CPD(bnet, 1);
wolffd@0 28 % ==========================================================
wolffd@0 29 bnet.CPD{2} = softmax_CPD(bnet, 2);
wolffd@0 30 bnet.CPD{4} = softmax_CPD(bnet, 5, 'discrete', [2]);
wolffd@0 31 % ==========================================================
wolffd@0 32 bnet.CPD{3} = gaussian_CPD(bnet, 3);
wolffd@0 33
wolffd@0 34 % make some data
wolffd@0 35 T=20;
wolffd@0 36 cases = cell(3, T);
wolffd@0 37 cases(1,:)=num2cell(round(rand(1,T)*2)+1);
wolffd@0 38 %cases(2,:)=num2cell(round(rand(1,T))+1);
wolffd@0 39 cases(3,:)=num2cell(rand(1,T));
wolffd@0 40
wolffd@0 41 engine = bk_inf_engine(bnet, 'exact', [1 2 3]);
wolffd@0 42
wolffd@0 43 % log lik before learning
wolffd@0 44 [engine, loglik] = enter_evidence(engine, cases);
wolffd@0 45
wolffd@0 46 % do learning
wolffd@0 47 ev=cell(1,1);
wolffd@0 48 ev{1}=cases;
wolffd@0 49 [bnet2, LL2] = learn_params_dbn_em(engine, ev, 3);