To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Revision:

root / _FullBNT / BNT / general / Old / calc_mpe_dbn.m @ 8:b5b38998ef3b

History | View | Annotate | Download (1.1 KB)

1
function [mpe, ll] = calc_mpe_dbn(engine, evidence, break_ties)
2
% CALC_MPE Computes the most probable explanation of the evidence
3
% [mpe, ll] = calc_mpe_dbn(engine, evidence, break_ties)
4
%
5
% INPUT
6
% engine must support max-propagation
7
% evidence{i,t} is the observed value of node i in slice t, or [] if hidden
8
%
9
% OUTPUT
10
% mpe{i,t} is the most likely value of node i (cell array!)
11
% ll is the log-likelihood of the globally best assignment
12
%
13
% This currently only works when all hidden nodes are discrete
14

    
15
if nargin < 3, break_ties = 0; end
16

    
17
if break_ties
18
  disp('warning: break ties is ignored')
19
end
20

    
21
[engine, ll] = enter_evidence(engine, evidence, 'maximize', 1);
22

    
23
observed = ~isemptycell(evidence);
24
[ss T] = size(evidence);
25
scalar = 1;
26
N = length(evidence);
27
mpe = cell(ss,T);
28
bnet = bnet_from_engine(engine);
29
ns = bnet.node_sizes;
30
for t=1:T
31
  for i=1:ss
32
    m = marginal_nodes(engine, i, t);
33
    % observed nodes are all set to 1 inside the inference engine, so we must undo this
34
    if observed(i,t)
35
      mpe{i,t} = evidence{i,t};
36
    else
37
      assert(length(m.T) == ns(i));
38
      mpe{i,t} = argmax(m.T);
39
    end
40
  end
41
end