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