about summary refs log tree commit diff
path: root/sourcecodes/bnt-master/BNT/inference/dynamic/@ff_inf_engine/ff_inf_engine.m
blob: ade261068bc8e808bc8b15112e7940e11a092272 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
function engine = ff_inf_engine(bnet)
% FF_INF_ENGINE Factored frontier inference engine for DBNs
% engine = ff_inf_engine(bnet)
%
% The model must be topologically isomorphic to an HMM.
% In addition, each hidden node is assumed to have at most one observed child,
% and each observed child is assumed to have exactly one hidden parent.
%
% For details of this algorithm, see
%  "The Factored Frontier Algorithm for Approximate Inference in DBNs",
%   Kevin Murphy and Yair Weiss, UAI 2001.
%
% THIS IS HIGHLY EXPERIMENTAL CODE!

ss = length(bnet.intra);
onodes = bnet.observed;
hnodes = mysetdiff(1:ss, onodes);

[persistent_nodes, transient_nodes] = partition_dbn_nodes(bnet.intra, bnet.inter);
assert(isequal(onodes, transient_nodes));
assert(isequal(hnodes, persistent_nodes));

engine.onodes = onodes;
engine.hnodes = hnodes;
engine.marginals = [];
engine.fwd = [];
engine.back = [];
engine.CPDpot = [];
engine.filter = [];

obschild = zeros(1,ss);
for i=engine.hnodes(:)'
  %ocs = myintersect(children(bnet.dag, i), onodes);
  ocs = children(bnet.intra, i);
  assert(length(ocs) <= 1);
  if length(ocs)==1
    obschild(i) = ocs(1);
  end
end  
engine.obschild = obschild;


engine = class(engine, 'ff_inf_engine', inf_engine(bnet));