comparison toolboxes/FullBNT-1.0.7/bnt/examples/static/StructLearn/cooper_yoo.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 % Do the example in Cooper and Yoo, "Causal discovery from a mixture of experimental and
2 % observational data", UAI 99, p120
3
4 N = 2;
5 dag = zeros(N);
6 A = 1; B = 2;
7 dag(A,B) = 1;
8 ns = 2*ones(1,N);
9
10 bnet0 = mk_bnet(dag, ns);
11 %bnet0.CPD{A} = tabular_CPD(bnet0, A, 'unif', 1);
12 bnet0.CPD{A} = tabular_CPD(bnet0, A, 'CPT', 'unif', 'prior_type', 'dirichlet');
13 bnet0.CPD{B} = tabular_CPD(bnet0, B, 'CPT', 'unif', 'prior_type', 'dirichlet');
14
15 samples = [2 2;
16 2 1;
17 2 2;
18 1 1;
19 1 2;
20 2 2;
21 1 1;
22 2 2;
23 1 2;
24 2 1;
25 1 1];
26
27 clamped = [0 0;
28 0 0;
29 0 0;
30 0 0;
31 0 0;
32 1 0;
33 1 0;
34 0 1;
35 0 1;
36 0 1;
37 0 1];
38
39 nsamples = size(samples, 1);
40
41 % sequential version
42 LL = 0;
43 bnet = bnet0;
44 for l=1:nsamples
45 ev = num2cell(samples(l,:)');
46 manip = find(clamped(l,:)');
47 LL = LL + log_marg_lik_complete(bnet, ev, manip);
48 bnet = bayes_update_params(bnet, ev, manip);
49 end
50 assert(approxeq(exp(LL), 5.97e-7)) % compare with result from UAI paper
51
52
53 % batch version
54 cases = num2cell(samples');
55 LL2 = log_marg_lik_complete(bnet0, cases, clamped');
56 bnet2 = bayes_update_params(bnet0, cases, clamped');
57
58 assert(approxeq(LL, LL2))
59
60 for j=1:N
61 s1 = struct(bnet.CPD{j}); % violate object privacy
62 s2 = struct(bnet2.CPD{j});
63 assert(approxeq(s1.CPT, s2.CPT))
64 end
65