comparison toolboxes/FullBNT-1.0.7/bnt/examples/static/mpe2.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 % Computing most probable explanation.
2
3 % If you don't break ties consistently, loopy can give wrong mpe
4 % even though the graph has no cycles, and even though the max-marginals are the same.
5 % This example was contributed by Wentau Yih <wtyih@yahoo.com> 29 Jan 02.
6
7 % define loop-free graph structure (all edges point down)
8 %
9 % Xe1 Xe2
10 % | |
11 % E1 E2
12 % \ /
13 % R1
14 % |
15 % Xr1
16
17 N = 6;
18 dag = zeros(N,N);
19 Xe1 = 1; Xe2 = 2; E1 = 3; E2 = 4; R1 = 5; Xr1 = 6;
20 dag(Xe1, E1) = 1;
21 dag(Xe2, E2) = 1;
22 dag([E1 E2], R1) = 1;
23 dag(R1, Xr1) = 1;
24
25 node_sizes = [ 1 1 2 2 2 1 ];
26
27 % create BN
28
29 bnet = mk_bnet(dag, node_sizes, 'observed', [Xe1 Xe2 Xr1]);
30
31 % fill in CPT
32
33 bnet.CPD{Xe1} = tabular_CPD(bnet, Xe1, [1]);
34 bnet.CPD{Xe2} = tabular_CPD(bnet, Xe2, [1]);
35 bnet.CPD{E1} = tabular_CPD(bnet, E1, [0.2 0.8]);
36 bnet.CPD{E2} = tabular_CPD(bnet, E2, [0.3 0.7]);
37 bnet.CPD{R1} = tabular_CPD(bnet, R1, [1 1 1 0.8 0 0 0 0.2]);
38 bnet.CPD{Xr1} = tabular_CPD(bnet, Xr1, [0.15 0.85]);
39
40 clear engine;
41 engine{1} = belprop_inf_engine(bnet);
42 engine{2} = jtree_inf_engine(bnet);
43 engine{3} = global_joint_inf_engine(bnet);
44 engine{4} = var_elim_inf_engine(bnet);
45
46 evidence = cell(1,N);
47 evidence{Xe1} = 1; evidence{Xe2} = 1; evidence{Xr1} = 1;
48
49 mpe = find_mpe(engine{1}, evidence, 'break_ties', 0) % gives wrong results
50 mpe = find_mpe(engine{1}, evidence)
51 for i=2:4
52 mpe = find_mpe(engine{i}, evidence)
53 end