From 8070dc963753142bb86c4ed698d91fd623ed28e7 Mon Sep 17 00:00:00 2001 From: ziejd2 Date: Thu, 28 Sep 2017 15:04:40 -0500 Subject: 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 --- .../BNT/CPDs/@tabular_CPD/maximize_params.m | 52 ++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 sourcecodes/bnt-master/BNT/CPDs/@tabular_CPD/maximize_params.m (limited to 'sourcecodes/bnt-master/BNT/CPDs/@tabular_CPD/maximize_params.m') diff --git a/sourcecodes/bnt-master/BNT/CPDs/@tabular_CPD/maximize_params.m b/sourcecodes/bnt-master/BNT/CPDs/@tabular_CPD/maximize_params.m new file mode 100644 index 00000000..c4317a78 --- /dev/null +++ b/sourcecodes/bnt-master/BNT/CPDs/@tabular_CPD/maximize_params.m @@ -0,0 +1,52 @@ +function CPD = maximize_params(CPD, temp) +% MAXIMIZE_PARAMS Set the params of a tabular node to their ML/MAP values. +% CPD = maximize_params(CPD, temp) + +if ~adjustable_CPD(CPD), return; end + +%assert(approxeq(sum(CPD.counts(:)), CPD.nsamples)); % false! +switch CPD.prior_type + case 'none', + counts = reshape(CPD.counts, size(CPD.CPT)); + CPD.CPT = mk_stochastic(counts); + case 'dirichlet', + counts = reshape(CPD.counts, size(CPD.CPT)); + CPD.CPT = mk_stochastic(counts + CPD.dirichlet); + + % case 'entropic', +% % For an HMM, +% % CPT(i,j) = pr(X(t)=j | X(t-1)=i) = transprob(i,j) +% % counts(i,j) = E #(X(t-1)=i, X(t)=j) = exp_num_trans(i,j) +% Z = 1-temp; +% fam_sz = CPD.sizes; +% psz = prod(fam_sz(1:end-1)); +% ssz = fam_sz(end); +% counts = reshape(CPD.counts, psz, ssz); +% CPT = zeros(psz, ssz); +% for i=CPD.entropic_pcases(:)' +% [CPT(i,:), logpost] = entropic_map_estimate(counts(i,:), Z); +% end +% non_entropic_pcases = mysetdiff(1:psz, CPD.entropic_pcases); +% for i=non_entropic_pcases(:)' +% CPT(i,:) = mk_stochastic(counts(i,:)); +% end +% %for i=1:psz +% % [CPT(i,:), logpost] = entropic_map(counts(i,:), Z); +% %end +% if CPD.trim & (temp < 2) % at high temps, we would trim everything! +% % grad(j) = d log lik / d theta(i ->j) +% % CPT(i,j) = 0 => counts(i,j) = 0 +% % so we can safely replace 0s by 1s in the denominator +% denom = CPT(i,:) + (CPT(i,:)==0); +% grad = counts(i,:) ./ denom; +% trim = find(CPT(i,:) <= exp(-(1/Z)*grad)); % eqn 32 +% if ~isempty(trim) +% CPT(i,trim) = 0; +% if all(CPD.trimmed_trans(i,trim)==0) % trimming for 1st time +% disp(['trimming CPT(' num2str(i) ',' num2str(trim) ')']) +% end +% CPD.trimmed_trans(i,trim) = 1; +% end +% end +% CPD.CPT = myreshape(CPT, CPD.sizes); +end -- cgit 1.4.1