annotate toolboxes/FullBNT-1.0.7/bnt/examples/static/SCG/scg_3node.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 % This example is from Page.143 of "Probabilistic Networks and Expert Systems",
wolffd@0 2 % Cowell, Dawid, Lauritzen and Spiegelhalter, 1999, Springer.
wolffd@0 3
wolffd@0 4 X = 1; Y = 2; Z = 3;
wolffd@0 5 n = 3;
wolffd@0 6
wolffd@0 7 dag = zeros(n);
wolffd@0 8 dag(X, Y)=1;
wolffd@0 9 dag(Y, Z)=1;
wolffd@0 10
wolffd@0 11 ns = ones(1, n);
wolffd@0 12 dnodes = [];
wolffd@0 13
wolffd@0 14 bnet = mk_bnet(dag, ns, dnodes);
wolffd@0 15 bnet.CPD{X} = gaussian_CPD(bnet, X, 'mean', 0, 'cov', 1);
wolffd@0 16 bnet.CPD{Y} = gaussian_CPD(bnet, Y, 'mean', 0, 'cov', 1, 'weights', 1);
wolffd@0 17 bnet.CPD{Z} = gaussian_CPD(bnet, Z, 'mean', 0, 'cov', 1, 'weights', 1);
wolffd@0 18
wolffd@0 19 engines = {};
wolffd@0 20 engines{end+1} = jtree_inf_engine(bnet);
wolffd@0 21 engines{end+1} = stab_cond_gauss_inf_engine(bnet);
wolffd@0 22 nengines = length(engines);
wolffd@0 23
wolffd@0 24 evidence = cell(1,n);
wolffd@0 25 evidence{Y} = 1.5;
wolffd@0 26
wolffd@0 27 for e=1:nengines
wolffd@0 28 engines{e} = enter_evidence(engines{e}, evidence);
wolffd@0 29 margX = marginal_nodes(engines{e}, X);
wolffd@0 30 assert(approxeq(margX.mu, 0.75))
wolffd@0 31 assert(approxeq(margX.Sigma, 0.5))
wolffd@0 32
wolffd@0 33 margZ = marginal_nodes(engines{e}, Z);
wolffd@0 34 assert(approxeq(margZ.mu, 1.5))
wolffd@0 35 assert(approxeq(margZ.Sigma, 1))
wolffd@0 36 end
wolffd@0 37
wolffd@0 38
wolffd@0 39 evidence = cell(1,n);
wolffd@0 40 evidence{Z} = 1.5;
wolffd@0 41
wolffd@0 42 for e=1:nengines
wolffd@0 43 engines{e} = enter_evidence(engines{e}, evidence);
wolffd@0 44 margX = marginal_nodes(engines{e}, X);
wolffd@0 45 assert(approxeq(margX.mu, 1/2))
wolffd@0 46 assert(approxeq(margX.Sigma, 2/3))
wolffd@0 47
wolffd@0 48 margY = marginal_nodes(engines{e}, Y);
wolffd@0 49 assert(approxeq(margY.mu, 1))
wolffd@0 50 assert(approxeq(margY.Sigma, 2/3))
wolffd@0 51 end
wolffd@0 52