comparison toolboxes/FullBNT-1.0.7/bnt/general/Old/calc_mpe_global.m @ 0:cc4b1211e677 tip

initial commit to HG from Changeset: 646 (e263d8a21543) added further path and more save "camirversion.m"
author Daniel Wolff
date Fri, 19 Aug 2016 13:07:06 +0200
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:cc4b1211e677
1 function [mpe, ll] = calc_mpe_global(bnet, evidence)
2 % CALC_MPE_GLOBAL Compute the most probable explanation(s) from the global joint
3 % [mpe, ll] = calc_mpe_global(bnet, evidence)
4 %
5 % mpe(k,i) is the most probable value of node i in the k'th global mode
6 % ll is the log likelihood
7 %
8 % We assume all nodes are discrete
9
10 engine = global_joint_inf_engine(bnet);
11 engine = enter_evidence(engine, evidence);
12 S1 = struct(engine); % violate object privacy
13 S2 = struct(S1.jpot); % joint potential
14 prob = max(S2.T(:));
15 modes = find(S2.T(:) == prob);
16
17 ens = bnet.node_sizes;
18 onodes = find(~isemptycell(evidence));
19 ens(onodes) = 1;
20 mpe = ind2subv(ens, modes);
21 for k=1:length(modes)
22 for i=onodes(:)'
23 mpe(k,i) = evidence{i};
24 end
25 end
26 ll = log(prob);
27
28 mpe = num2cell(mpe);