annotate toolboxes/FullBNT-1.0.7/bnt/inference/static/@pearl_inf_engine/marginal_nodes.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 marginal = marginal_nodes(engine, query, add_ev)
wolffd@0 2 % MARGINAL_NODES Compute the marginal on the specified query nodes (loopy)
wolffd@0 3 % marginal = marginal_nodes(engine, query, add_ev)
wolffd@0 4 %
wolffd@0 5 % 'query' must be a single node.
wolffd@0 6 % add_ev is an optional argument; if 1, observed nodes will be set to their original size,
wolffd@0 7 % otherwise they will be treated like points.
wolffd@0 8
wolffd@0 9 if nargin < 3, add_ev = 0; end
wolffd@0 10
wolffd@0 11 if length(query) > 1
wolffd@0 12 error('can only compute marginal on single nodes or families')
wolffd@0 13 end
wolffd@0 14 bnet = bnet_from_engine(engine);
wolffd@0 15 ns = bnet.node_sizes(:);
wolffd@0 16
wolffd@0 17 switch engine.msg_type
wolffd@0 18 case 'd',
wolffd@0 19 T = engine.marginal{query};
wolffd@0 20 if ~add_ev
wolffd@0 21 marginal.T = shrink_obs_dims_in_table(T, query, engine.evidence);
wolffd@0 22 else
wolffd@0 23 marginal.T = T;
wolffd@0 24 end
wolffd@0 25 marginal.domain = query;
wolffd@0 26
wolffd@0 27 case 'g',
wolffd@0 28 if engine.disconnected_nodes_bitv(query)
wolffd@0 29 marginal.T = 1;
wolffd@0 30 marginal.domain = query;
wolffd@0 31 if add_ev
wolffd@0 32 marginal = add_ev_to_dmarginal(marginal, engine.evidence, ns)
wolffd@0 33 end
wolffd@0 34 return;
wolffd@0 35 end
wolffd@0 36
wolffd@0 37 marginal = engine.marginal{query};
wolffd@0 38 marginal.domain = query;
wolffd@0 39 if ~add_ev
wolffd@0 40 marginal = shrink_obs_dims_in_gaussian(marginal, query, engine.evidence, ns);
wolffd@0 41 end
wolffd@0 42 end
wolffd@0 43