annotate toolboxes/FullBNT-1.0.7/bnt/examples/static/SCG/scg1.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 % Same as cg1, except we call stab_cond_gauss_inf_engine
wolffd@0 2
wolffd@0 3 bnet = mk_incinerator_bnet;
wolffd@0 4
wolffd@0 5 engines = {};
wolffd@0 6 engines{end+1} = stab_cond_gauss_inf_engine(bnet);
wolffd@0 7 engines{end+1} = jtree_inf_engine(bnet);
wolffd@0 8 engines{end+1} = cond_gauss_inf_engine(bnet);
wolffd@0 9 nengines = length(engines);
wolffd@0 10
wolffd@0 11 F = 1; W = 2; E = 3; B = 4; C = 5; D = 6; Min = 7; Mout = 8; L = 9;
wolffd@0 12 n = 9;
wolffd@0 13 dnodes = [B F W];
wolffd@0 14 cnodes = mysetdiff(1:n, dnodes);
wolffd@0 15
wolffd@0 16 evidence = cell(1,n); % no evidence
wolffd@0 17 ll = zeros(1, nengines);
wolffd@0 18 for e=1:nengines
wolffd@0 19 [engines{e}, ll(e)] = enter_evidence(engines{e}, evidence);
wolffd@0 20 end
wolffd@0 21 %assert(approxeq(ll(1), ll)))
wolffd@0 22 ll
wolffd@0 23
wolffd@0 24 % Compare to the results in table on p1107.
wolffd@0 25 % These results are printed to 3dp in Cowell p150
wolffd@0 26
wolffd@0 27 mu = zeros(1,n);
wolffd@0 28 sigma = zeros(1,n);
wolffd@0 29 dprob = zeros(1,n);
wolffd@0 30 addev = 1;
wolffd@0 31 tol = 1e-2;
wolffd@0 32 for e=1:nengines
wolffd@0 33 for i=cnodes(:)'
wolffd@0 34 m = marginal_nodes(engines{e}, i, addev);
wolffd@0 35 mu(i) = m.mu;
wolffd@0 36 sigma(i) = sqrt(m.Sigma);
wolffd@0 37 end
wolffd@0 38 for i=dnodes(:)'
wolffd@0 39 m = marginal_nodes(engines{e}, i, addev);
wolffd@0 40 dprob(i) = m.T(1);
wolffd@0 41 end
wolffd@0 42 assert(approxeq(mu([E D C L Min Mout]), [-3.25 3.04 -1.85 1.48 -0.214 2.83], tol))
wolffd@0 43 assert(approxeq(sigma([E D C L Min Mout]), [0.709 0.770 0.507 0.631 0.459 0.860], tol))
wolffd@0 44 assert(approxeq(dprob([B F W]), [0.85 0.95 0.29], tol))
wolffd@0 45 %m = marginal_nodes(engines{e}, bnet.names('E'), addev);
wolffd@0 46 %assert(approxeq(m.mu, -3.25, tol))
wolffd@0 47 %assert(approxeq(sqrt(m.Sigma), 0.709, tol))
wolffd@0 48 end
wolffd@0 49
wolffd@0 50 % Add evidence (p 1105, top right)
wolffd@0 51 evidence = cell(1,n);
wolffd@0 52 evidence{W} = 1; % industrial
wolffd@0 53 evidence{L} = 1.1;
wolffd@0 54 evidence{C} = -0.9;
wolffd@0 55
wolffd@0 56 ll = zeros(1, nengines);
wolffd@0 57 for e=1:nengines
wolffd@0 58 [engines{e}, ll(e)] = enter_evidence(engines{e}, evidence);
wolffd@0 59 end
wolffd@0 60 %assert(all(approxeq(ll(1), ll)))
wolffd@0 61 ll
wolffd@0 62
wolffd@0 63 for e=1:nengines
wolffd@0 64 for i=cnodes(:)'
wolffd@0 65 m = marginal_nodes(engines{e}, i, addev);
wolffd@0 66 mu(i) = m.mu;
wolffd@0 67 sigma(i) = sqrt(m.Sigma);
wolffd@0 68 end
wolffd@0 69 for i=dnodes(:)'
wolffd@0 70 m = marginal_nodes(engines{e}, i, addev);
wolffd@0 71 dprob(i) = m.T(1);
wolffd@0 72 end
wolffd@0 73 assert(approxeq(mu([E D C L Min Mout]), [-3.90 3.61 -0.9 1.1 0.5 4.11], tol))
wolffd@0 74 assert(approxeq(sigma([E D C L Min Mout]), [0.076 0.326 0 0 0.1 0.344], tol))
wolffd@0 75 assert(approxeq(dprob([B F W]), [0.0122 0.9995 1], tol))
wolffd@0 76 end
wolffd@0 77