Mercurial > hg > mauch-mirex-2010
annotate _FullBNT/BNT/inference/static/@enumerative_inf_engine/marginal_nodes.m @ 9:4ea6619cb3f5 tip
removed log files
author | matthiasm |
---|---|
date | Fri, 11 Apr 2014 15:55:11 +0100 |
parents | b5b38998ef3b |
children |
rev | line source |
---|---|
matthiasm@8 | 1 function [marginal, loglik] = marginal_nodes(engine, query) |
matthiasm@8 | 2 % MARGINAL_NODES Compute the marginal on the specified query nodes (enumerative_inf) |
matthiasm@8 | 3 % [marginal, loglik] = marginal_nodes(engine, query) |
matthiasm@8 | 4 |
matthiasm@8 | 5 |
matthiasm@8 | 6 if isempty(query) & nargout < 2 |
matthiasm@8 | 7 marginal.T = 1; |
matthiasm@8 | 8 marginal.domain = []; |
matthiasm@8 | 9 return; |
matthiasm@8 | 10 end |
matthiasm@8 | 11 |
matthiasm@8 | 12 evidence = engine.evidence; |
matthiasm@8 | 13 bnet = bnet_from_engine(engine); |
matthiasm@8 | 14 assert(isempty(bnet.cnodes)); |
matthiasm@8 | 15 n = length(bnet.dag); |
matthiasm@8 | 16 observed = ~isemptycell(evidence); |
matthiasm@8 | 17 vals = cat(1,evidence{observed}); |
matthiasm@8 | 18 vals = vals(:)'; |
matthiasm@8 | 19 ns = bnet.node_sizes; |
matthiasm@8 | 20 |
matthiasm@8 | 21 sz = ns(query); |
matthiasm@8 | 22 T = 0*myones(sz); |
matthiasm@8 | 23 p = 0; |
matthiasm@8 | 24 for i=1:prod(ns) |
matthiasm@8 | 25 inst = ind2subv(ns, i); % i'th instantiation |
matthiasm@8 | 26 if isempty(vals) | inst(observed) == vals % agrees with evidence |
matthiasm@8 | 27 prob = exp(log_lik_complete(bnet, num2cell(inst(:)))); |
matthiasm@8 | 28 p = p + prob; |
matthiasm@8 | 29 v = inst(query); |
matthiasm@8 | 30 j = subv2ind(sz, v); |
matthiasm@8 | 31 T(j) = T(j) + prob; |
matthiasm@8 | 32 end |
matthiasm@8 | 33 end |
matthiasm@8 | 34 |
matthiasm@8 | 35 [T, lik] = normalise(T); |
matthiasm@8 | 36 lik = p; |
matthiasm@8 | 37 loglik = log(lik); |
matthiasm@8 | 38 |
matthiasm@8 | 39 Tsmall = shrink_obs_dims_in_table(T, query, evidence); |
matthiasm@8 | 40 marginal.domain = query; |
matthiasm@8 | 41 marginal.T = Tsmall; |