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