comparison toolboxes/FullBNT-1.0.7/bnt/examples/static/StructLearn/mcmc1.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 % We compare MCMC structure learning with exhaustive enumeration of all dags.
2
3 N = 3;
4 %N = 4;
5 dag = mk_rnd_dag(N);
6 ns = 2*ones(1,N);
7 bnet = mk_bnet(dag, ns);
8 for i=1:N
9 bnet.CPD{i} = tabular_CPD(bnet, i);
10 end
11
12 ncases = 100;
13 data = zeros(N, ncases);
14 for m=1:ncases
15 data(:,m) = cell2num(sample_bnet(bnet));
16 end
17
18 dags = mk_all_dags(N);
19 score = score_dags(data, ns, dags);
20 post = normalise(exp(score));
21
22 [sampled_graphs, accept_ratio] = learn_struct_mcmc(data, ns, 'nsamples', 100, 'burnin', 10);
23 mcmc_post = mcmc_sample_to_hist(sampled_graphs, dags);
24
25 if 0
26 subplot(2,1,1)
27 bar(post)
28 subplot(2,1,2)
29 bar(mcmc_post)
30 print(gcf, '-djpeg', '/home/cs/murphyk/public_html/Bayes/Figures/mcmc_post.jpg')
31
32 clf
33 plot(accept_ratio)
34 print(gcf, '-djpeg', '/home/cs/murphyk/public_html/Bayes/Figures/mcmc_accept.jpg')
35 end