annotate toolboxes/FullBNT-1.0.7/bnt/inference/static/@global_joint_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
rev   line source
wolffd@0 1 function [mpe, ll] = find_mpe(engine, evidence)
wolffd@0 2 % FIND_MPE_GLOBAL Compute the most probable explanation(s) from the global joint
wolffd@0 3 % [mpe, ll] = find_mpe(engine, evidence)
wolffd@0 4 %
wolffd@0 5 % mpe(k,i) is the most probable value of node i in the k'th global mode (cell array)
wolffd@0 6 %
wolffd@0 7 % We assume all nodes are discrete
wolffd@0 8
wolffd@0 9 %engine = global_joint_inf_engine(bnet);
wolffd@0 10 bnet = bnet_from_engine(engine);
wolffd@0 11 engine = enter_evidence(engine, evidence);
wolffd@0 12 S1 = struct(engine); % violate object privacy
wolffd@0 13 S2 = struct(S1.jpot); % joint potential
wolffd@0 14 prob = max(S2.T(:));
wolffd@0 15 modes = find(S2.T(:) == prob);
wolffd@0 16
wolffd@0 17 ens = bnet.node_sizes;
wolffd@0 18 onodes = find(~isemptycell(evidence));
wolffd@0 19 ens(onodes) = 1;
wolffd@0 20 mpe = ind2subv(ens, modes);
wolffd@0 21 for k=1:length(modes)
wolffd@0 22 for i=onodes(:)'
wolffd@0 23 mpe(k,i) = evidence{i};
wolffd@0 24 end
wolffd@0 25 end
wolffd@0 26 ll = log(prob);
wolffd@0 27
wolffd@0 28 mpe = num2cell(mpe);