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/learning/mcmc_sample_to_hist.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/learning/mcmc_sample_to_hist.m')
| -rw-r--r-- | sourcecodes/bnt-master/BNT/learning/mcmc_sample_to_hist.m | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/sourcecodes/bnt-master/BNT/learning/mcmc_sample_to_hist.m b/sourcecodes/bnt-master/BNT/learning/mcmc_sample_to_hist.m new file mode 100644 index 00000000..8b277c8a --- /dev/null +++ b/sourcecodes/bnt-master/BNT/learning/mcmc_sample_to_hist.m @@ -0,0 +1,36 @@ +function mcmc_post = mcmc_sample_to_hist(sampled_graphs, dags) +% MCMC_SAMPLE_TO_HIST Convert a set of sampled dags into a histogram over dags +% hist = mcmc_sample_to_hist(sampled_graphs, dags) +% +% sampled_graphs{m} is the m'th sampled dag +% dags{i} is the i'th dag in the hypothesis space +% hist(i) = Pr(model i | data) + +ndags = length(dags); +nsamples = length(sampled_graphs); +nnodes = length(dags{1}); +% sampled_bitv(m, :) is the m'th sampled graph represented as a vector of n^2 bits, computed +% by stacking the columns of the adjacency matrix vertically. +sampled_bitvs = zeros(nsamples, nnodes*nnodes); +for m=1:nsamples + sampled_bitvs(m, :) = sampled_graphs{m}(:)'; +end + +[ugraphs, I, J] = unique(sampled_bitvs, 'rows'); % each row of ugraphs is a unique bit vector +sampled_indices = subv2ind(2*ones(1,nnodes*nnodes), ugraphs+1); +counts = hist(J, 1:size(ugraphs,1)); % counts(i) = number of times graphs(i,:) occurs in the sample + +mcmc_post = zeros(1, ndags); +for i=1:ndags + bitv = dags{i}(:)'; + % Find the samples that corresponds to this graph by converting the graphs to bitvectors and + % then to integers. + ndx = subv2ind(2*ones(1,nnodes*nnodes), bitv+1); + locn = find(ndx == sampled_indices); + if ~isempty(locn) + mcmc_post(i) = counts(locn); + end +end +mcmc_post = normalise(mcmc_post); + + |
