annotate toolboxes/FullBNT-1.0.7/bnt/examples/static/gaussian2.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 % Make the following network (from Jensen (1996) p84 fig 4.17)
Daniel@0 2 % 1
Daniel@0 3 % / | \
Daniel@0 4 % 2 3 4
Daniel@0 5 % | | |
Daniel@0 6 % 5 6 7
Daniel@0 7 % \/ \/
Daniel@0 8 % 8 9
Daniel@0 9 % where all arcs point downwards
Daniel@0 10
Daniel@0 11
Daniel@0 12 N = 9;
Daniel@0 13 dag = zeros(N,N);
Daniel@0 14 dag(1,2)=1; dag(1,3)=1; dag(1,4)=1;
Daniel@0 15 dag(2,5)=1; dag(3,6)=1; dag(4,7)=1;
Daniel@0 16 dag(5,8)=1; dag(6,8)=1; dag(6,9)=1; dag(7,9) = 1;
Daniel@0 17
Daniel@0 18 ns = [5 4 3 2 2 1 2 2 2]; % vector-valued nodes
Daniel@0 19 %ns = ones(1,9); % scalar nodes
Daniel@0 20 dnodes = [];
Daniel@0 21
Daniel@0 22 bnet = mk_bnet(dag, ns, 'discrete', []);
Daniel@0 23 rand('state', 0);
Daniel@0 24 randn('state', 0);
Daniel@0 25 for i=1:N
Daniel@0 26 bnet.CPD{i} = gaussian_CPD(bnet, i);
Daniel@0 27 end
Daniel@0 28
Daniel@0 29 clear engine;
Daniel@0 30 engine{1} = gaussian_inf_engine(bnet);
Daniel@0 31 engine{2} = jtree_inf_engine(bnet);
Daniel@0 32
Daniel@0 33 [err, time] = cmp_inference_static(bnet, engine);
Daniel@0 34
Daniel@0 35 Nsamples = 100;
Daniel@0 36 samples = cell(N, Nsamples);
Daniel@0 37 for s=1:Nsamples
Daniel@0 38 samples(:,s) = sample_bnet(bnet);
Daniel@0 39 end
Daniel@0 40 bnet2 = learn_params(bnet, samples);