annotate _FullBNT/BNT/inference/dynamic/@bk_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 = marginal_nodes(engine, nodes, t, fam)
matthiasm@8 2 % MARGINAL_NODES Compute the marginal on the specified query nodes (bk)
matthiasm@8 3 %
matthiasm@8 4 % marginal = marginal_nodes(engine, i, t)
matthiasm@8 5 % returns Pr(X(i,t) | Y(1:T)), where X(i,t) is the i'th node in the t'th slice.
matthiasm@8 6 % If enter_evidence used filtering instead of smoothing, this will return Pr(X(i,t) | Y(1:t)).
matthiasm@8 7 %
matthiasm@8 8 % marginal = marginal_nodes(engine, query, t)
matthiasm@8 9 % returns Pr(X(query(1),t), ... X(query(end),t) | Y(1:T)),
matthiasm@8 10 % where X(q,t) is the q'th node in the t'th slice. If q > ss (slice size), this is equal
matthiasm@8 11 % to X(q mod ss, t+1). That is, 't' specifies the time slice of the earliest node.
matthiasm@8 12 % 'query' cannot span more than 2 time slices.
matthiasm@8 13 % Example:
matthiasm@8 14 % Consider a DBN with 2 nodes per slice.
matthiasm@8 15 % Then t=2, nodes=[1 3] refers to node 1 in slice 2 and node 1 in slice 3.
matthiasm@8 16
matthiasm@8 17 if nargin < 3, t = 1; end
matthiasm@8 18 if nargin < 4, fam = 0; else fam = 1; end
matthiasm@8 19
matthiasm@8 20
matthiasm@8 21 % clpot{t} contains slice t-1 and t
matthiasm@8 22 % Example
matthiasm@8 23 % clpot #: 1 2 3
matthiasm@8 24 % slices: 1 1,2 2,3
matthiasm@8 25 % For filtering, we must take care not to take future evidence into account.
matthiasm@8 26 % For smoothing, clpot{1} does not exist.
matthiasm@8 27
matthiasm@8 28 bnet = bnet_from_engine(engine);
matthiasm@8 29 ss = length(bnet.intra);
matthiasm@8 30
matthiasm@8 31 nodes2 = nodes;
matthiasm@8 32 if ~engine.filter
matthiasm@8 33 if t < engine.T
matthiasm@8 34 slice = t+1;
matthiasm@8 35 else % earliest t is T, so all nodes fit in one slice
matthiasm@8 36 slice = engine.T;
matthiasm@8 37 nodes2 = nodes + ss;
matthiasm@8 38 end
matthiasm@8 39 else
matthiasm@8 40 if t == 1
matthiasm@8 41 slice = 1;
matthiasm@8 42 else
matthiasm@8 43 if all(nodes<=ss)
matthiasm@8 44 slice = t;
matthiasm@8 45 nodes2 = nodes + ss;
matthiasm@8 46 elseif t == engine.T
matthiasm@8 47 slice = t;
matthiasm@8 48 else
matthiasm@8 49 slice = t + 1;
matthiasm@8 50 end
matthiasm@8 51 end
matthiasm@8 52 end
matthiasm@8 53
matthiasm@8 54 if engine.filter & t==1
matthiasm@8 55 c = clq_containing_nodes(engine.sub_engine1, nodes2, fam);
matthiasm@8 56 else
matthiasm@8 57 c = clq_containing_nodes(engine.sub_engine, nodes2, fam);
matthiasm@8 58 end
matthiasm@8 59 assert(c >= 1);
matthiasm@8 60 bigpot = engine.clpot{c, slice};
matthiasm@8 61
matthiasm@8 62 pot = marginalize_pot(bigpot, nodes2);
matthiasm@8 63 marginal = pot_to_marginal(pot);
matthiasm@8 64
matthiasm@8 65 % we convert the domain to the unrolled numbering system
matthiasm@8 66 % so that update_ess extracts the right evidence.
matthiasm@8 67 marginal.domain = nodes+(t-1)*ss;