Mercurial > hg > camir-aes2014
comparison toolboxes/FullBNT-1.0.7/bnt/general/Old/calc_mpe_dbn.m @ 0:e9a9cd732c1e tip
first hg version after svn
author | wolffd |
---|---|
date | Tue, 10 Feb 2015 15:05:51 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:e9a9cd732c1e |
---|---|
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 |