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