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