Mercurial > hg > camir-aes2014
annotate 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 |
rev | line source |
---|---|
wolffd@0 | 1 function [mpe, ll] = calc_mpe_dbn(engine, evidence, break_ties) |
wolffd@0 | 2 % CALC_MPE Computes the most probable explanation of the evidence |
wolffd@0 | 3 % [mpe, ll] = calc_mpe_dbn(engine, evidence, break_ties) |
wolffd@0 | 4 % |
wolffd@0 | 5 % INPUT |
wolffd@0 | 6 % engine must support max-propagation |
wolffd@0 | 7 % evidence{i,t} is the observed value of node i in slice t, or [] if hidden |
wolffd@0 | 8 % |
wolffd@0 | 9 % OUTPUT |
wolffd@0 | 10 % mpe{i,t} is the most likely value of node i (cell array!) |
wolffd@0 | 11 % ll is the log-likelihood of the globally best assignment |
wolffd@0 | 12 % |
wolffd@0 | 13 % This currently only works when all hidden nodes are discrete |
wolffd@0 | 14 |
wolffd@0 | 15 if nargin < 3, break_ties = 0; end |
wolffd@0 | 16 |
wolffd@0 | 17 if break_ties |
wolffd@0 | 18 disp('warning: break ties is ignored') |
wolffd@0 | 19 end |
wolffd@0 | 20 |
wolffd@0 | 21 [engine, ll] = enter_evidence(engine, evidence, 'maximize', 1); |
wolffd@0 | 22 |
wolffd@0 | 23 observed = ~isemptycell(evidence); |
wolffd@0 | 24 [ss T] = size(evidence); |
wolffd@0 | 25 scalar = 1; |
wolffd@0 | 26 N = length(evidence); |
wolffd@0 | 27 mpe = cell(ss,T); |
wolffd@0 | 28 bnet = bnet_from_engine(engine); |
wolffd@0 | 29 ns = bnet.node_sizes; |
wolffd@0 | 30 for t=1:T |
wolffd@0 | 31 for i=1:ss |
wolffd@0 | 32 m = marginal_nodes(engine, i, t); |
wolffd@0 | 33 % observed nodes are all set to 1 inside the inference engine, so we must undo this |
wolffd@0 | 34 if observed(i,t) |
wolffd@0 | 35 mpe{i,t} = evidence{i,t}; |
wolffd@0 | 36 else |
wolffd@0 | 37 assert(length(m.T) == ns(i)); |
wolffd@0 | 38 mpe{i,t} = argmax(m.T); |
wolffd@0 | 39 end |
wolffd@0 | 40 end |
wolffd@0 | 41 end |