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