wolffd@0
|
1 function marginal = marginal_family(engine, i, t)
|
wolffd@0
|
2 % MARGINAL_FAMILY Compute the marginal on the specified family (ff)
|
wolffd@0
|
3 % marginal = marginal_family(engine, i, t)
|
wolffd@0
|
4
|
wolffd@0
|
5
|
wolffd@0
|
6 if engine.filter
|
wolffd@0
|
7 error('can''t currently use marginal_family when filtering with ff');
|
wolffd@0
|
8 end
|
wolffd@0
|
9
|
wolffd@0
|
10 if nargin < 3, t = 1; end
|
wolffd@0
|
11
|
wolffd@0
|
12 % The method is similar to the following HMM equation:
|
wolffd@0
|
13 % xi(i,j,t) = normalise( alpha(i,t) * transmat(i,j) * obsmat(j,t+1) * beta(j,t+1) )
|
wolffd@0
|
14 % where xi(i,j,t) = Pr(Q(t)=i, Q(t+1)=j | y(1:T))
|
wolffd@0
|
15
|
wolffd@0
|
16 bnet = bnet_from_engine(engine);
|
wolffd@0
|
17 ss = length(bnet.intra);
|
wolffd@0
|
18
|
wolffd@0
|
19 if myismember(i, engine.onodes)
|
wolffd@0
|
20 ps = parents(bnet.dag, i);
|
wolffd@0
|
21 p = ps(1);
|
wolffd@0
|
22 marginal = pot_to_marginal(engine.marginals{ps(1),t});
|
wolffd@0
|
23 fam = ([ps i]) + (t-1)*ss;
|
wolffd@0
|
24 elseif t==1
|
wolffd@0
|
25 marginal = pot_to_marginal(engine.marginals{i,t});
|
wolffd@0
|
26 fam = i + (t-1)*ss;
|
wolffd@0
|
27 else
|
wolffd@0
|
28 pot = engine.CPDpot{i,t};
|
wolffd@0
|
29 c = engine.obschild(i);
|
wolffd@0
|
30 if c>0
|
wolffd@0
|
31 pot = multiply_by_pot(pot, engine.CPDpot{c,t});
|
wolffd@0
|
32 end
|
wolffd@0
|
33 pot = multiply_by_pot(pot, engine.back{i,t});
|
wolffd@0
|
34 ps = parents(bnet.dag, i+ss);
|
wolffd@0
|
35 for p=ps(:)'
|
wolffd@0
|
36 pot = multiply_by_pot(pot, engine.fwd{p,t-1});
|
wolffd@0
|
37 end
|
wolffd@0
|
38 marginal = pot_to_marginal(normalize_pot(pot));
|
wolffd@0
|
39 fam = ([ps i+ss]) + (t-2)*ss;
|
wolffd@0
|
40 end
|
wolffd@0
|
41
|
wolffd@0
|
42 % we convert the domain to the unrolled numbering system
|
wolffd@0
|
43 % so that update_ess extracts the right evidence.
|
wolffd@0
|
44 marginal.domain = fam;
|