comparison toolboxes/FullBNT-1.0.7/bnt/inference/static/@belprop_fg_inf_engine/find_mpe.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 function mpe = find_mpe(engine, evidence, varargin)
2 % FIND_MPE Find the most probable explanation of the data (belprop_fg)
3 % function mpe = find_mpe(engine, evidence,...)
4 %
5 % evidence{i} = [] if X(i) is hidden, and otherwise contains its observed value (scalar or column vector).
6 %
7 % This finds the marginally most likely value for each hidden node,
8 % and may give the wrong results even if the graph is acyclic,
9 % unless you set break_ties = 1.
10 %
11 % The following optional arguments can be specified in the form of name/value pairs:
12 % [default value in brackets]
13 %
14 % break_ties is optional. If 1, we will force ties to be broken consistently
15 % by calling enter_evidence N times. (see Jensen96, p106) Default = 1.
16
17 break_ties = 1;
18
19 % parse optional params
20 args = varargin;
21 nargs = length(args);
22 for i=1:2:nargs
23 switch args{i},
24 case 'break_ties', break_ties = args{i+1};
25 otherwise,
26 error(['invalid argument name ' args{i}]);
27 end
28 end
29
30 engine = enter_evidence(engine, evidence, 'maximize', 1);
31
32 observed = ~isemptycell(evidence);
33 evidence = evidence(:); % hack to handle unrolled DBNs
34 N = length(evidence);
35 mpe = cell(1,N);
36 for i=1:N
37 m = marginal_nodes(engine, i);
38 % observed nodes are all set to 1 inside the inference engine, so we must undo this
39 if observed(i)
40 mpe{i} = evidence{i};
41 else
42 mpe{i} = argmax(m.T);
43 if break_ties
44 evidence{i} = mpe{i};
45 [engine, ll] = enter_evidence(engine, evidence, 'maximize', 1);
46 end
47 end
48 end
49