about summary refs log tree commit diff
path: root/sourcecodes/bnt-master/BNT/examples/dynamic/kjaerulff1.m
blob: 28b315fc95a87835c36fef5d3ae86ee5821de387 (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
45
46
47
48
49
50
51
52
53
54
55
% Compare the speeds of various inference engines on the DBN in Kjaerulff
% "dHugin: A computational system for dynamic time-sliced {B}ayesian networks",
% Intl. J. Forecasting 11:89-111, 1995.
%
% The intra structure is (all arcs point downwards)
%
%  1 -> 2
%   \  /
%     3
%     |
%     4
%    / \
%   5   6
%   \  /
%     7
%     |
%     8
%
% The inter structure is 1->1, 4->4, 8->8

seed = 0;
rand('state', seed);
randn('state', seed);

ss = 8;
intra = zeros(ss);
intra(1,[2 3])=1;
intra(2,3)=1;
intra(3,4)=1;
intra(4,[5 6])=1;
intra([5 6], 7)=1;
intra(7,8)=1;

inter = zeros(ss);
inter(1,1)=1;
inter(4,4)=1;
inter(8,8)=1;

ns = 2*ones(1,ss);
onodes = 2;
bnet = mk_dbn(intra, inter, ns, 'observed', onodes, 'eclass2', (1:ss)+ss);
for i=1:2*ss
  bnet.CPD{i} = tabular_CPD(bnet, i);
end

T = 4;

engine = {};
engine{end+1} = jtree_unrolled_dbn_inf_engine(bnet, T);
engine{end+1} = jtree_dbn_inf_engine(bnet);
engine{end+1} = smoother_engine(jtree_2TBN_inf_engine(bnet));
%engine{end+1} = smoother_engine(hmm_2TBN_inf_engine(bnet)); % observed nodes have children

inf_time = cmp_inference_dbn(bnet, engine, T)
learning_time = cmp_learning_dbn(bnet, engine, T)