about summary refs log tree commit diff
path: root/sourcecodes/bnt-master/BNT/examples/static/gaussian2.m
blob: 157a86cb6839cd1c53f7387bbd0e931c62212f31 (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
% Make the following network (from Jensen (1996) p84 fig 4.17)
%    1
%  / | \
% 2  3  4
% |  |  |
% 5  6  7
%  \/ \/
%  8   9
% where all arcs point downwards


N = 9;
dag = zeros(N,N);
dag(1,2)=1; dag(1,3)=1; dag(1,4)=1;
dag(2,5)=1; dag(3,6)=1; dag(4,7)=1;
dag(5,8)=1; dag(6,8)=1; dag(6,9)=1; dag(7,9) = 1;

ns = [5 4 3 2 2 1 2 2 2]; % vector-valued nodes
%ns = ones(1,9); % scalar nodes
dnodes = [];

bnet = mk_bnet(dag, ns, 'discrete', []);
rand('state', 0);
randn('state', 0);
for i=1:N
  bnet.CPD{i} = gaussian_CPD(bnet, i);
end

clear engine;
engine{1} = gaussian_inf_engine(bnet);
engine{2} = jtree_inf_engine(bnet);

[err, time] = cmp_inference_static(bnet, engine);

Nsamples = 100;
samples = cell(N, Nsamples);
for s=1:Nsamples
  samples(:,s) = sample_bnet(bnet);
end
bnet2 = learn_params(bnet, samples);