view toolboxes/FullBNT-1.0.7/bnt/general/Old/calc_mpe_global.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
line wrap: on
line source
function [mpe, ll] = calc_mpe_global(bnet, evidence)
% CALC_MPE_GLOBAL Compute the most probable explanation(s) from the global joint
% [mpe, ll] = calc_mpe_global(bnet, evidence)
%
% mpe(k,i) is the most probable value of node i in the k'th global mode 
% ll is the log likelihood
%
% We assume all nodes are discrete

engine = global_joint_inf_engine(bnet);
engine = enter_evidence(engine, evidence);
S1 = struct(engine); % violate object privacy
S2 = struct(S1.jpot); % joint potential
prob = max(S2.T(:));
modes = find(S2.T(:) == prob);

ens = bnet.node_sizes;
onodes = find(~isemptycell(evidence));
ens(onodes) = 1;
mpe = ind2subv(ens, modes);
for k=1:length(modes)
  for i=onodes(:)'
    mpe(k,i) = evidence{i};
  end
end
ll = log(prob);

mpe = num2cell(mpe);