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