Daniel@0: % We compare MCMC structure learning with exhaustive enumeration of all dags. Daniel@0: Daniel@0: N = 3; Daniel@0: %N = 4; Daniel@0: dag = mk_rnd_dag(N); Daniel@0: ns = 2*ones(1,N); Daniel@0: bnet = mk_bnet(dag, ns); Daniel@0: for i=1:N Daniel@0: bnet.CPD{i} = tabular_CPD(bnet, i); Daniel@0: end Daniel@0: Daniel@0: ncases = 100; Daniel@0: data = zeros(N, ncases); Daniel@0: for m=1:ncases Daniel@0: data(:,m) = cell2num(sample_bnet(bnet)); Daniel@0: end Daniel@0: Daniel@0: dags = mk_all_dags(N); Daniel@0: score = score_dags(data, ns, dags); Daniel@0: post = normalise(exp(score)); Daniel@0: Daniel@0: [sampled_graphs, accept_ratio] = learn_struct_mcmc(data, ns, 'nsamples', 100, 'burnin', 10); Daniel@0: mcmc_post = mcmc_sample_to_hist(sampled_graphs, dags); Daniel@0: Daniel@0: if 0 Daniel@0: subplot(2,1,1) Daniel@0: bar(post) Daniel@0: subplot(2,1,2) Daniel@0: bar(mcmc_post) Daniel@0: print(gcf, '-djpeg', '/home/cs/murphyk/public_html/Bayes/Figures/mcmc_post.jpg') Daniel@0: Daniel@0: clf Daniel@0: plot(accept_ratio) Daniel@0: print(gcf, '-djpeg', '/home/cs/murphyk/public_html/Bayes/Figures/mcmc_accept.jpg') Daniel@0: end