To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / _FullBNT / BNT / general / Old / calc_mpe_global.m @ 8:b5b38998ef3b
History | View | Annotate | Download (766 Bytes)
| 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); |