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