diff options
| author | ziejd2 | 2017-09-28 15:04:40 -0500 |
|---|---|---|
| committer | ziejd2 | 2017-09-28 15:04:40 -0500 |
| commit | 8070dc963753142bb86c4ed698d91fd623ed28e7 (patch) | |
| tree | d0f6dd8fc46a49b819aa55c1a90faa14d8448883 /sourcecodes/bnt-master/BNT/examples/static/StructLearn/cooper_yoo.m | |
| parent | 7cc31810d53176e805532b2789955f4eedbce6bb (diff) | |
| download | BNW-8070dc963753142bb86c4ed698d91fd623ed28e7.tar.gz | |
BNW using Octave instead of Matlab.
This version of BNW should perform the same as the original version. The only difference is that it uses Octave instead of Matlab when running BayesNet Toolbox during parameter learning. I am calling this BNW_1.02. It can be accessed at: compbio.uthsc.edu/BNW_1.02
Diffstat (limited to 'sourcecodes/bnt-master/BNT/examples/static/StructLearn/cooper_yoo.m')
| -rw-r--r-- | sourcecodes/bnt-master/BNT/examples/static/StructLearn/cooper_yoo.m | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/sourcecodes/bnt-master/BNT/examples/static/StructLearn/cooper_yoo.m b/sourcecodes/bnt-master/BNT/examples/static/StructLearn/cooper_yoo.m new file mode 100644 index 00000000..97ceb44a --- /dev/null +++ b/sourcecodes/bnt-master/BNT/examples/static/StructLearn/cooper_yoo.m @@ -0,0 +1,65 @@ +% Do the example in Cooper and Yoo, "Causal discovery from a mixture of experimental and +% observational data", UAI 99, p120 + +N = 2; +dag = zeros(N); +A = 1; B = 2; +dag(A,B) = 1; +ns = 2*ones(1,N); + +bnet0 = mk_bnet(dag, ns); +%bnet0.CPD{A} = tabular_CPD(bnet0, A, 'unif', 1); +bnet0.CPD{A} = tabular_CPD(bnet0, A, 'CPT', 'unif', 'prior_type', 'dirichlet'); +bnet0.CPD{B} = tabular_CPD(bnet0, B, 'CPT', 'unif', 'prior_type', 'dirichlet'); + +samples = [2 2; + 2 1; + 2 2; + 1 1; + 1 2; + 2 2; + 1 1; + 2 2; + 1 2; + 2 1; + 1 1]; + +clamped = [0 0; + 0 0; + 0 0; + 0 0; + 0 0; + 1 0; + 1 0; + 0 1; + 0 1; + 0 1; + 0 1]; + +nsamples = size(samples, 1); + +% sequential version +LL = 0; +bnet = bnet0; +for l=1:nsamples + ev = num2cell(samples(l,:)'); + manip = find(clamped(l,:)'); + LL = LL + log_marg_lik_complete(bnet, ev, manip); + bnet = bayes_update_params(bnet, ev, manip); +end +assert(approxeq(exp(LL), 5.97e-7)) % compare with result from UAI paper + + +% batch version +cases = num2cell(samples'); +LL2 = log_marg_lik_complete(bnet0, cases, clamped'); +bnet2 = bayes_update_params(bnet0, cases, clamped'); + +assert(approxeq(LL, LL2)) + +for j=1:N + s1 = struct(bnet.CPD{j}); % violate object privacy + s2 = struct(bnet2.CPD{j}); + assert(approxeq(s1.CPT, s2.CPT)) +end + |
