Mercurial > hg > camir-aes2014
comparison toolboxes/FullBNT-1.0.7/bnt/examples/static/discrete3.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 % Compare various inference engines on the following network (from Jensen (1996) p84 fig 4.17) | |
2 % 1 | |
3 % / | \ | |
4 % 2 3 4 | |
5 % | | | | |
6 % 5 6 7 | |
7 % \/ \/ | |
8 % 8 9 | |
9 % where all arcs point downwards | |
10 | |
11 N = 9; | |
12 dag = zeros(N,N); | |
13 dag(1,2)=1; dag(1,3)=1; dag(1,4)=1; | |
14 dag(2,5)=1; dag(3,6)=1; dag(4,7)=1; | |
15 dag(5,8)=1; dag(6,8)=1; dag(6,9)=1; dag(7,9) = 1; | |
16 | |
17 dnodes = 1:N; | |
18 false = 1; true = 2; | |
19 ns = 2*ones(1,N); % binary nodes | |
20 | |
21 onodes = [1]; | |
22 evidence = cell(1,N); | |
23 evidence(onodes) = num2cell(1); | |
24 bnet = mk_bnet(dag, ns, 'observed', onodes); | |
25 % use random params | |
26 %for i=1:N | |
27 % bnet.CPD{i} = tabular_CPD(bnet, i); | |
28 %end | |
29 bnet.CPD{1} = tabular_CPD(bnet, 1, 'sparse', 1, 'CPT', [0.8, 0.2]); | |
30 bnet.CPD{2} = tabular_CPD(bnet, 2, 'sparse', 1, 'CPT', [1 0 0 1]); | |
31 bnet.CPD{3} = tabular_CPD(bnet, 3, 'sparse', 1, 'CPT', [0 1 1 0]); | |
32 bnet.CPD{4} = tabular_CPD(bnet, 4, 'sparse', 1, 'CPT', [1 1 0 0]); | |
33 bnet.CPD{5} = tabular_CPD(bnet, 5, 'sparse', 1, 'CPT', [0 0 1 1]); | |
34 bnet.CPD{6} = tabular_CPD(bnet, 6, 'sparse', 1, 'CPT', [1 0 0 1]); | |
35 bnet.CPD{7} = tabular_CPD(bnet, 7, 'sparse', 1, 'CPT', [0 1 1 0]); | |
36 bnet.CPD{8} = tabular_CPD(bnet, 8, 'sparse', 1, 'CPT', [1 1 0 0 0 0 1 1]); | |
37 bnet.CPD{9} = tabular_CPD(bnet, 9, 'sparse', 1, 'CPT', [0 1 0 1 1 0 1 0]); | |
38 | |
39 engine = jtree_sparse_inf_engine(bnet); | |
40 tic | |
41 [engine, ll] = enter_evidence(engine, evidence); | |
42 toc | |
43 |