Mercurial > hg > camir-aes2014
comparison toolboxes/FullBNT-1.0.7/bnt/examples/static/cg1.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 % Conditional Gaussian network | |
2 % The waste incinerator emissions example from Lauritzen (1992), | |
3 % "Propogation of Probabilities, Means and Variances in Mixed Graphical Association Models", | |
4 % JASA 87(420): 1098--1108 | |
5 % | |
6 % This example is reprinted on p145 of "Probabilistic Networks and Expert Systems", | |
7 % Cowell, Dawid, Lauritzen and Spiegelhalter, 1999, Springer. | |
8 % | |
9 % For a picture, see http://www.cs.berkeley.edu/~murphyk/Bayes/usage.html#cg_model | |
10 | |
11 ns = 2*ones(1,9); | |
12 %bnet = mk_incinerator_bnet(ns); | |
13 bnet = mk_incinerator_bnet; | |
14 | |
15 engines = {}; | |
16 %engines{end+1} = stab_cond_gauss_inf_engine(bnet); | |
17 engines{end+1} = jtree_inf_engine(bnet); | |
18 engines{end+1} = cond_gauss_inf_engine(bnet); | |
19 nengines = length(engines); | |
20 | |
21 F = 1; W = 2; E = 3; B = 4; C = 5; D = 6; Min = 7; Mout = 8; L = 9; | |
22 n = 9; | |
23 dnodes = [B F W]; | |
24 cnodes = mysetdiff(1:n, dnodes); | |
25 | |
26 evidence = cell(1,n); % no evidence | |
27 ll = zeros(1, nengines); | |
28 for e=1:nengines | |
29 [engines{e}, ll(e)] = enter_evidence(engines{e}, evidence); | |
30 end | |
31 %assert(approxeq(ll(1), ll))) | |
32 ll | |
33 | |
34 % Compare to the results in table on p1107. | |
35 % These results are printed to 3dp in Cowell p150 | |
36 | |
37 mu = zeros(1,n); | |
38 sigma = zeros(1,n); | |
39 dprob = zeros(1,n); | |
40 addev = 1; | |
41 tol = 1e-2; | |
42 for e=1:nengines | |
43 for i=cnodes(:)' | |
44 m = marginal_nodes(engines{e}, i, addev); | |
45 mu(i) = m.mu; | |
46 sigma(i) = sqrt(m.Sigma); | |
47 end | |
48 for i=dnodes(:)' | |
49 m = marginal_nodes(engines{e}, i, addev); | |
50 dprob(i) = m.T(1); | |
51 end | |
52 assert(approxeq(mu([E D C L Min Mout]), [-3.25 3.04 -1.85 1.48 -0.214 2.83], tol)) | |
53 assert(approxeq(sigma([E D C L Min Mout]), [0.709 0.770 0.507 0.631 0.459 0.860], tol)) | |
54 assert(approxeq(dprob([B F W]), [0.85 0.95 0.29], tol)) | |
55 %m = marginal_nodes(engines{e}, bnet.names('E'), addev); | |
56 %assert(approxeq(m.mu, -3.25, tol)) | |
57 %assert(approxeq(sqrt(m.Sigma), 0.709, tol)) | |
58 end | |
59 | |
60 % Add evidence (p 1105, top right) | |
61 evidence = cell(1,n); | |
62 evidence{W} = 1; % industrial | |
63 evidence{L} = 1.1; | |
64 evidence{C} = -0.9; | |
65 | |
66 ll = zeros(1, nengines); | |
67 for e=1:nengines | |
68 [engines{e}, ll(e)] = enter_evidence(engines{e}, evidence); | |
69 end | |
70 assert(all(approxeq(ll(1), ll))) | |
71 | |
72 for e=1:nengines | |
73 for i=cnodes(:)' | |
74 m = marginal_nodes(engines{e}, i, addev); | |
75 mu(i) = m.mu; | |
76 sigma(i) = sqrt(m.Sigma); | |
77 end | |
78 for i=dnodes(:)' | |
79 m = marginal_nodes(engines{e}, i, addev); | |
80 dprob(i) = m.T(1); | |
81 end | |
82 assert(approxeq(mu([E D C L Min Mout]), [-3.90 3.61 -0.9 1.1 0.5 4.11], tol)) | |
83 assert(approxeq(sigma([E D C L Min Mout]), [0.076 0.326 0 0 0.1 0.344], tol)) | |
84 assert(approxeq(dprob([B F W]), [0.0122 0.9995 1], tol)) | |
85 end | |
86 |