wolffd@0: function [mpe, prob] = calc_mpe_given_inf_engine(engine, evidence) wolffd@0: % CALC_MPE_GIVEN_ENGINE Computes the most probable explanation of the evidence wolffd@0: % [mpe, prob] = calc_mpe_given_inf_engine(engine, evidence) wolffd@0: % wolffd@0: % INPUT wolffd@0: % engine must support max-propagation wolffd@0: % evidence{i} is the obsevred value of node i, or [] if hidden wolffd@0: % wolffd@0: % OUTPUT wolffd@0: % mpe(i) is the most likely value of node i wolffd@0: % prob is the likelihood of the globally best assignment wolffd@0: % wolffd@0: % This currently only works when all nodes are discrete wolffd@0: wolffd@0: [engine, ll] = enter_evidence(engine, evidence); wolffd@0: wolffd@0: observed = ~isemptycell(evidence); wolffd@0: N = length(evidence); wolffd@0: mpe = zeros(1,N); wolffd@0: for i=1:N wolffd@0: m = marginal_nodes(engine, i); wolffd@0: % discrete observed nodes are all set to 1 inside the inference engine, so we must undo this wolffd@0: if observed(i) wolffd@0: mpe(i) = evidence{i}; wolffd@0: else wolffd@0: mpe(i) = argmax(m.T); wolffd@0: end wolffd@0: end wolffd@0: wolffd@0: bnet = bnet_from_engine(engine); wolffd@0: ll = log_lik_complete(bnet, num2cell(mpe(:))); wolffd@0: prob = exp(ll);