Mercurial > hg > camir-ismir2012
view toolboxes/FullBNT-1.0.7/bnt/examples/static/StructLearn/mcmc1.m @ 0:cc4b1211e677 tip
initial commit to HG from
Changeset:
646 (e263d8a21543) added further path and more save "camirversion.m"
author | Daniel Wolff |
---|---|
date | Fri, 19 Aug 2016 13:07:06 +0200 |
parents | |
children |
line wrap: on
line source
% We compare MCMC structure learning with exhaustive enumeration of all dags. N = 3; %N = 4; dag = mk_rnd_dag(N); ns = 2*ones(1,N); bnet = mk_bnet(dag, ns); for i=1:N bnet.CPD{i} = tabular_CPD(bnet, i); end ncases = 100; data = zeros(N, ncases); for m=1:ncases data(:,m) = cell2num(sample_bnet(bnet)); end dags = mk_all_dags(N); score = score_dags(data, ns, dags); post = normalise(exp(score)); [sampled_graphs, accept_ratio] = learn_struct_mcmc(data, ns, 'nsamples', 100, 'burnin', 10); mcmc_post = mcmc_sample_to_hist(sampled_graphs, dags); if 0 subplot(2,1,1) bar(post) subplot(2,1,2) bar(mcmc_post) print(gcf, '-djpeg', '/home/cs/murphyk/public_html/Bayes/Figures/mcmc_post.jpg') clf plot(accept_ratio) print(gcf, '-djpeg', '/home/cs/murphyk/public_html/Bayes/Figures/mcmc_accept.jpg') end