comparison toolboxes/FullBNT-1.0.7/bnt/examples/static/mpe1.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 seed = 1;
2 rand('state', seed);
3 randn('state', seed);
4
5 N = 4;
6 dag = zeros(N,N);
7 C = 1; S = 2; R = 3; W = 4;
8 dag(C,[R S]) = 1;
9 dag(R,W) = 1;
10 dag(S,W)=1;
11
12 false = 1; true = 2;
13 ns = 2*ones(1,N); % binary nodes
14
15 bnet = mk_bnet(dag, ns);
16 if 0
17 bnet.CPD{C} = tabular_CPD(bnet, C, [0.5 0.5]);
18 bnet.CPD{R} = tabular_CPD(bnet, R, [0.8 0.2 0.2 0.8]);
19 bnet.CPD{S} = tabular_CPD(bnet, S, [0.5 0.9 0.5 0.1]);
20 bnet.CPD{W} = tabular_CPD(bnet, W, [1 0.1 0.1 0.01 0 0.9 0.9 0.99]);
21 else
22 for i=1:N, bnet.CPD{i} = tabular_CPD(bnet, i); end
23 end
24
25
26
27 evidence = cell(1,N);
28 onodes = [1 3];
29 data = sample_bnet(bnet);
30 evidence(onodes) = data(onodes);
31
32 clear engine;
33 engine{1} = belprop_inf_engine(bnet);
34 engine{2} = jtree_inf_engine(bnet);
35 engine{3} = global_joint_inf_engine(bnet);
36 engine{4} = var_elim_inf_engine(bnet);
37 E = length(engine);
38
39 clear mpe;
40 for e=1:E
41 mpe{e} = find_mpe(engine{e}, evidence);
42 end
43 for e=2:E
44 assert(isequal(mpe{1}, mpe{e}))
45 end