Mercurial > hg > camir-aes2014
comparison toolboxes/FullBNT-1.0.7/bnt/general/Old/calc_mpe_given_inf_engine.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, prob] = calc_mpe_given_inf_engine(engine, evidence) | |
2 % CALC_MPE_GIVEN_ENGINE Computes the most probable explanation of the evidence | |
3 % [mpe, prob] = calc_mpe_given_inf_engine(engine, evidence) | |
4 % | |
5 % INPUT | |
6 % engine must support max-propagation | |
7 % evidence{i} is the obsevred value of node i, or [] if hidden | |
8 % | |
9 % OUTPUT | |
10 % mpe(i) is the most likely value of node i | |
11 % prob is the likelihood of the globally best assignment | |
12 % | |
13 % This currently only works when all nodes are discrete | |
14 | |
15 [engine, ll] = enter_evidence(engine, evidence); | |
16 | |
17 observed = ~isemptycell(evidence); | |
18 N = length(evidence); | |
19 mpe = zeros(1,N); | |
20 for i=1:N | |
21 m = marginal_nodes(engine, i); | |
22 % discrete observed nodes are all set to 1 inside the inference engine, so we must undo this | |
23 if observed(i) | |
24 mpe(i) = evidence{i}; | |
25 else | |
26 mpe(i) = argmax(m.T); | |
27 end | |
28 end | |
29 | |
30 bnet = bnet_from_engine(engine); | |
31 ll = log_lik_complete(bnet, num2cell(mpe(:))); | |
32 prob = exp(ll); |