comparison toolboxes/FullBNT-1.0.7/bnt/examples/static/burglary.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 % Burglar alarm example
2
3 N = 5;
4 dag = zeros(N,N);
5 E = 1; B = 2; R = 3; A = 4; C = 5;
6 dag(E,[R A]) = 1;
7 dag(B,A) = 1;
8 dag(A,C)=1;
9
10 % true = state 1, false = state 2
11 ns = 2*ones(1,N); % binary nodes
12 bnet = mk_bnet(dag, ns);
13
14 bnet.CPD{E} = tabular_CPD(bnet, E, [0.1 0.9]);
15 bnet.CPD{B} = tabular_CPD(bnet, B, [0.01 0.99]);
16 %bnet.CPD{R} = tabular_CPD(bnet, R, [0.65 0.00001 0.35 0.99999]);
17 bnet.CPD{R} = tabular_CPD(bnet, R, [0.65 0.01 0.35 0.99]);
18 bnet.CPD{A} = tabular_CPD(bnet, A, [0.95 0.8 0.3 0.001 0.05 0.2 0.7 0.999]);
19 bnet.CPD{C} = tabular_CPD(bnet, C, [0.7 0.05 0.3 0.95]);
20
21
22 engine = jtree_inf_engine(bnet);
23 ev = cell(1,N);
24 ev{C} = 1;
25 engine = enter_evidence(engine, ev);
26 mE = marginal_nodes(engine, E);
27 mB = marginal_nodes(engine, B);
28 fprintf('P(E|c)=%5.3f, P(B|c)=%5.3f\n', mE.T(1), mB.T(1))
29
30 ev{C} = 1;
31 ev{R} = 1;
32 engine = enter_evidence(engine, ev);
33 mE = marginal_nodes(engine, E);
34 mB = marginal_nodes(engine, B);
35 fprintf('P(E|c,r)=%5.3f, P(B|c,r)=%5.3f\n', mE.T(1), mB.T(1))
36
37
38 if 0
39 nsamples = 100;
40 samples = zeros(nsamples, 5);
41 for i=1:nsamples
42 samples(i,:) = cell2num(sample_bnet(bnet))';
43 end
44 end