wolffd@0: function mpe = find_mpe(engine, evidence, varargin) wolffd@0: % FIND_MPE Find the most probable explanation of the data (belprop) wolffd@0: % function mpe = find_mpe(engine, evidence,...) wolffd@0: % wolffd@0: % evidence{i} = [] if X(i) is hidden, and otherwise contains its observed value (scalar or column vector). wolffd@0: % wolffd@0: % This finds the marginally most likely value for each hidden node, wolffd@0: % and may give the wrong results even if the graph is acyclic, wolffd@0: % unless you set break_ties = 1. wolffd@0: % wolffd@0: % The following optional arguments can be specified in the form of name/value pairs: wolffd@0: % [default value in brackets] wolffd@0: % wolffd@0: % break_ties is optional. If 1, we will force ties to be broken consistently wolffd@0: % by calling enter_evidence N times. (see Jensen96, p106) Default = 1. wolffd@0: wolffd@0: break_ties = 1; wolffd@0: wolffd@0: % parse optional params wolffd@0: args = varargin; wolffd@0: nargs = length(args); wolffd@0: for i=1:2:nargs wolffd@0: switch args{i}, wolffd@0: case 'break_ties', break_ties = args{i+1}; wolffd@0: otherwise, wolffd@0: error(['invalid argument name ' args{i}]); wolffd@0: end wolffd@0: end wolffd@0: wolffd@0: engine = enter_evidence(engine, evidence, 'maximize', 1); wolffd@0: wolffd@0: observed = ~isemptycell(evidence); wolffd@0: evidence = evidence(:); % hack to handle unrolled DBNs wolffd@0: N = length(evidence); wolffd@0: mpe = cell(1,N); wolffd@0: for i=1:N wolffd@0: m = marginal_nodes(engine, i); wolffd@0: % observed nodes are all set to 1 inside the inference engine, so we must undo this wolffd@0: if observed(i) wolffd@0: mpe{i} = evidence{i}; wolffd@0: else wolffd@0: mpe{i} = argmax(m.T); wolffd@0: if break_ties wolffd@0: evidence{i} = mpe{i}; wolffd@0: [engine, ll] = enter_evidence(engine, evidence, 'maximize', 1); wolffd@0: end wolffd@0: end wolffd@0: end wolffd@0: