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-master/BNT/potentials/@cpot/CVS/Entries | 14 ++++++++++ .../BNT/potentials/@cpot/CVS/Entries.Log | 1 + .../bnt-master/BNT/potentials/@cpot/CVS/Repository | 1 + .../bnt-master/BNT/potentials/@cpot/CVS/Root | 1 + .../BNT/potentials/@cpot/Old/CVS/Entries | 3 +++ .../BNT/potentials/@cpot/Old/CVS/Repository | 1 + .../bnt-master/BNT/potentials/@cpot/Old/CVS/Root | 1 + .../BNT/potentials/@cpot/Old/cpot_to_mpot.m | 25 +++++++++++++++++ .../potentials/@cpot/Old/normalize_pot.convert.m | 9 +++++++ sourcecodes/bnt-master/BNT/potentials/@cpot/cpot.m | 17 ++++++++++++ .../bnt-master/BNT/potentials/@cpot/cpot_to_mpot.m | 29 ++++++++++++++++++++ .../bnt-master/BNT/potentials/@cpot/display.m | 4 +++ .../BNT/potentials/@cpot/divide_by_pot.m | 13 +++++++++ .../bnt-master/BNT/potentials/@cpot/domain_pot.m | 5 ++++ .../BNT/potentials/@cpot/enter_cts_evidence_pot.m | 15 +++++++++++ .../BNT/potentials/@cpot/marginalize_pot.m | 31 ++++++++++++++++++++++ .../BNT/potentials/@cpot/multiply_by_pot.m | 13 +++++++++ .../BNT/potentials/@cpot/multiply_pots.m | 11 ++++++++ .../BNT/potentials/@cpot/normalize_pot.m | 10 +++++++ .../BNT/potentials/@cpot/pot_to_marginal.m | 6 +++++ .../bnt-master/BNT/potentials/@cpot/rescale_pot.m | 5 ++++ .../BNT/potentials/@cpot/set_domain_pot.m | 5 ++++ 22 files changed, 220 insertions(+) create mode 100644 sourcecodes/bnt-master/BNT/potentials/@cpot/CVS/Entries create mode 100644 sourcecodes/bnt-master/BNT/potentials/@cpot/CVS/Entries.Log create mode 100644 sourcecodes/bnt-master/BNT/potentials/@cpot/CVS/Repository create mode 100644 sourcecodes/bnt-master/BNT/potentials/@cpot/CVS/Root create mode 100644 sourcecodes/bnt-master/BNT/potentials/@cpot/Old/CVS/Entries create mode 100644 sourcecodes/bnt-master/BNT/potentials/@cpot/Old/CVS/Repository create mode 100644 sourcecodes/bnt-master/BNT/potentials/@cpot/Old/CVS/Root create mode 100644 sourcecodes/bnt-master/BNT/potentials/@cpot/Old/cpot_to_mpot.m create mode 100644 sourcecodes/bnt-master/BNT/potentials/@cpot/Old/normalize_pot.convert.m create mode 100644 sourcecodes/bnt-master/BNT/potentials/@cpot/cpot.m create mode 100644 sourcecodes/bnt-master/BNT/potentials/@cpot/cpot_to_mpot.m create mode 100644 sourcecodes/bnt-master/BNT/potentials/@cpot/display.m create mode 100644 sourcecodes/bnt-master/BNT/potentials/@cpot/divide_by_pot.m create mode 100644 sourcecodes/bnt-master/BNT/potentials/@cpot/domain_pot.m create mode 100644 sourcecodes/bnt-master/BNT/potentials/@cpot/enter_cts_evidence_pot.m create mode 100644 sourcecodes/bnt-master/BNT/potentials/@cpot/marginalize_pot.m create mode 100644 sourcecodes/bnt-master/BNT/potentials/@cpot/multiply_by_pot.m create mode 100644 sourcecodes/bnt-master/BNT/potentials/@cpot/multiply_pots.m create mode 100644 sourcecodes/bnt-master/BNT/potentials/@cpot/normalize_pot.m create mode 100644 sourcecodes/bnt-master/BNT/potentials/@cpot/pot_to_marginal.m create mode 100644 sourcecodes/bnt-master/BNT/potentials/@cpot/rescale_pot.m create mode 100644 sourcecodes/bnt-master/BNT/potentials/@cpot/set_domain_pot.m (limited to 'sourcecodes/bnt-master/BNT/potentials/@cpot') diff --git a/sourcecodes/bnt-master/BNT/potentials/@cpot/CVS/Entries b/sourcecodes/bnt-master/BNT/potentials/@cpot/CVS/Entries new file mode 100644 index 00000000..7f4397ef --- /dev/null +++ b/sourcecodes/bnt-master/BNT/potentials/@cpot/CVS/Entries @@ -0,0 +1,14 @@ +/cpot.m/1.1.1.1/Wed May 29 15:59:58 2002// +/cpot_to_mpot.m/1.1.1.1/Wed May 29 15:59:58 2002// +/display.m/1.1.1.1/Wed May 29 15:59:58 2002// +/divide_by_pot.m/1.1.1.1/Wed May 29 15:59:58 2002// +/domain_pot.m/1.1.1.1/Wed May 29 15:59:58 2002// +/enter_cts_evidence_pot.m/1.1.1.1/Wed May 29 15:59:58 2002// +/marginalize_pot.m/1.1.1.1/Wed May 29 15:59:58 2002// +/multiply_by_pot.m/1.1.1.1/Wed May 29 15:59:58 2002// +/multiply_pots.m/1.1.1.1/Wed May 29 15:59:58 2002// +/normalize_pot.m/1.1.1.1/Wed May 29 15:59:58 2002// +/pot_to_marginal.m/1.1.1.1/Wed May 29 15:59:58 2002// +/rescale_pot.m/1.1.1.1/Wed May 29 15:59:58 2002// +/set_domain_pot.m/1.1.1.1/Wed May 29 15:59:58 2002// +D diff --git a/sourcecodes/bnt-master/BNT/potentials/@cpot/CVS/Entries.Log b/sourcecodes/bnt-master/BNT/potentials/@cpot/CVS/Entries.Log new file mode 100644 index 00000000..24f16336 --- /dev/null +++ b/sourcecodes/bnt-master/BNT/potentials/@cpot/CVS/Entries.Log @@ -0,0 +1 @@ +A D/Old//// diff --git a/sourcecodes/bnt-master/BNT/potentials/@cpot/CVS/Repository b/sourcecodes/bnt-master/BNT/potentials/@cpot/CVS/Repository new file mode 100644 index 00000000..12ecad25 --- /dev/null +++ b/sourcecodes/bnt-master/BNT/potentials/@cpot/CVS/Repository @@ -0,0 +1 @@ +FullBNT/BNT/potentials/@cpot diff --git a/sourcecodes/bnt-master/BNT/potentials/@cpot/CVS/Root b/sourcecodes/bnt-master/BNT/potentials/@cpot/CVS/Root new file mode 100644 index 00000000..f3bd14a6 --- /dev/null +++ b/sourcecodes/bnt-master/BNT/potentials/@cpot/CVS/Root @@ -0,0 +1 @@ +:ext:nsaunier@bnt.cvs.sourceforge.net:/cvsroot/bnt diff --git a/sourcecodes/bnt-master/BNT/potentials/@cpot/Old/CVS/Entries b/sourcecodes/bnt-master/BNT/potentials/@cpot/Old/CVS/Entries new file mode 100644 index 00000000..3345f808 --- /dev/null +++ b/sourcecodes/bnt-master/BNT/potentials/@cpot/Old/CVS/Entries @@ -0,0 +1,3 @@ +/cpot_to_mpot.m/1.1.1.1/Wed May 29 15:59:58 2002// +/normalize_pot.convert.m/1.1.1.1/Wed May 29 15:59:58 2002// +D diff --git a/sourcecodes/bnt-master/BNT/potentials/@cpot/Old/CVS/Repository b/sourcecodes/bnt-master/BNT/potentials/@cpot/Old/CVS/Repository new file mode 100644 index 00000000..bdb2b68d --- /dev/null +++ b/sourcecodes/bnt-master/BNT/potentials/@cpot/Old/CVS/Repository @@ -0,0 +1 @@ +FullBNT/BNT/potentials/@cpot/Old diff --git a/sourcecodes/bnt-master/BNT/potentials/@cpot/Old/CVS/Root b/sourcecodes/bnt-master/BNT/potentials/@cpot/Old/CVS/Root new file mode 100644 index 00000000..f3bd14a6 --- /dev/null +++ b/sourcecodes/bnt-master/BNT/potentials/@cpot/Old/CVS/Root @@ -0,0 +1 @@ +:ext:nsaunier@bnt.cvs.sourceforge.net:/cvsroot/bnt diff --git a/sourcecodes/bnt-master/BNT/potentials/@cpot/Old/cpot_to_mpot.m b/sourcecodes/bnt-master/BNT/potentials/@cpot/Old/cpot_to_mpot.m new file mode 100644 index 00000000..05899b99 --- /dev/null +++ b/sourcecodes/bnt-master/BNT/potentials/@cpot/Old/cpot_to_mpot.m @@ -0,0 +1,25 @@ +function mom = cpot_to_mpot(can) +% CPOT_TO_MPOT Convert a canonical potential to moment form. +% mom = cpot_to_mpot(can) + +[logp, mu, Sigma] = canonical_to_moment(can.g, can.h, can.K); +mom = mpot(can.domain, can.sizes, logp, mu, Sigma); + +%%%%%%% + +function [logp, mu, Sigma] = canonical_to_moment(g, h, K) +% CANONICAL_TO_MOMENT Convert canonical characteristics to moment form. +% [logp, mu, Sigma] = canonical_to_moment(g, h, K) + +if det(K)==0 + Sigma = inf*size(K); +else + Sigma = inv(K); +end +mu = Sigma*h; +n = length(mu); +if isempty(mu) + logp = g - 0.5*(log(det(K)) - n*log(2*pi)); +else + logp = g - 0.5*(log(det(K)) - n*log(2*pi) - mu'*K*mu); +end diff --git a/sourcecodes/bnt-master/BNT/potentials/@cpot/Old/normalize_pot.convert.m b/sourcecodes/bnt-master/BNT/potentials/@cpot/Old/normalize_pot.convert.m new file mode 100644 index 00000000..59c473cc --- /dev/null +++ b/sourcecodes/bnt-master/BNT/potentials/@cpot/Old/normalize_pot.convert.m @@ -0,0 +1,9 @@ +function [mom2, loglik] = normalize_pot(can) +% NORMALIZE_POT Convert the canonical potential Pr(X,E) into moment potential Pr(X|E) and return log Pr(E). +% [mom, loglik] = normalize_pot(can) + +mom = cpot_to_mpot(can); +mom = struct(mom); % violate privacy of object +loglik = mom.logp; +%mom.logp = 0; % now represents Pr(X | E) instead of Pr(X, E). +mom2 = mpot(mom.domain, mom.sizes, 0, mom.mu, mom.Sigma); diff --git a/sourcecodes/bnt-master/BNT/potentials/@cpot/cpot.m b/sourcecodes/bnt-master/BNT/potentials/@cpot/cpot.m new file mode 100644 index 00000000..b8dfbf03 --- /dev/null +++ b/sourcecodes/bnt-master/BNT/potentials/@cpot/cpot.m @@ -0,0 +1,17 @@ +function pot = cpot(members, sizes, g, h, K) +% CPOT Make a canonical Gaussian potential. +% pot = cpot(members, sizes, g, h, K) +% +% All params default to 0 if omitted. + +n = sum(sizes); +if nargin < 3, g = 0; end +if nargin < 4, h = zeros(n,1); end +if nargin < 5, K = zeros(n,n); end + +pot.domain = members; +pot.sizes = sizes(:)'; +pot.g = g; +pot.h = h; +pot.K = K; +pot = class(pot, 'cpot'); diff --git a/sourcecodes/bnt-master/BNT/potentials/@cpot/cpot_to_mpot.m b/sourcecodes/bnt-master/BNT/potentials/@cpot/cpot_to_mpot.m new file mode 100644 index 00000000..73739d7e --- /dev/null +++ b/sourcecodes/bnt-master/BNT/potentials/@cpot/cpot_to_mpot.m @@ -0,0 +1,29 @@ +function mom = cpot_to_mpot(can) +% CPOT_TO_MPOT Convert a canonical potential to moment form. +% mom = cpot_to_mpot(can) + +[logp, mu, Sigma] = canonical_to_moment(can.g, can.h, can.K); +mom = mpot(can.domain, can.sizes, logp, mu, Sigma); + +%%%%%%% + +function [logp, mu, Sigma] = canonical_to_moment(g, h, K) +% CANONICAL_TO_MOMENT Convert canonical characteristics to moment form. +% [logp, mu, Sigma] = canonical_to_moment(g, h, K) + +n = length(K); +if isempty(K) + logp = g - 0.5*(log(det(K)) - n*log(2*pi)); + Sigma = []; + mu = []; +else + if det(K)==0 + Sigma = inf*ones(n,n); + mu = zeros(n,1); % if the precision is zero, the mean is arbitrary + logp = g; % the scaling factor for the uniform distribution is 1 + else + Sigma = inv(K); + mu = Sigma*h; + logp = g - 0.5*(log(det(K)) - n*log(2*pi) - mu'*K*mu); + end +end diff --git a/sourcecodes/bnt-master/BNT/potentials/@cpot/display.m b/sourcecodes/bnt-master/BNT/potentials/@cpot/display.m new file mode 100644 index 00000000..35a4f0b3 --- /dev/null +++ b/sourcecodes/bnt-master/BNT/potentials/@cpot/display.m @@ -0,0 +1,4 @@ +function display(pot) + +disp('canonical potential object'); +disp(struct(pot)); diff --git a/sourcecodes/bnt-master/BNT/potentials/@cpot/divide_by_pot.m b/sourcecodes/bnt-master/BNT/potentials/@cpot/divide_by_pot.m new file mode 100644 index 00000000..1e2bb2b9 --- /dev/null +++ b/sourcecodes/bnt-master/BNT/potentials/@cpot/divide_by_pot.m @@ -0,0 +1,13 @@ +function bigpot = divide_by_pot(bigpot, smallpot) +% DIVIDE_BY_POT bigpot /= smallpot for cpot +% bigpot = divide_by_pot(bigpot, smallpot) +% +% smallpot's domain must be a subset of bigpot's domain. + +bigpot.g = bigpot.g - smallpot.g; +if sum(smallpot.sizes) > 0 + mask = find_equiv_posns(smallpot.domain, bigpot.domain); + u = block(mask, bigpot.sizes); + bigpot.h(u) = bigpot.h(u) - smallpot.h; + bigpot.K(u, u) = bigpot.K(u, u) - smallpot.K; +end diff --git a/sourcecodes/bnt-master/BNT/potentials/@cpot/domain_pot.m b/sourcecodes/bnt-master/BNT/potentials/@cpot/domain_pot.m new file mode 100644 index 00000000..aa5ce392 --- /dev/null +++ b/sourcecodes/bnt-master/BNT/potentials/@cpot/domain_pot.m @@ -0,0 +1,5 @@ +function dom = domain_pot(pot) +% DOMAIN_POT Return the domain of this cpot. +% dom = domain_pot(pot) + +dom = pot.domain; diff --git a/sourcecodes/bnt-master/BNT/potentials/@cpot/enter_cts_evidence_pot.m b/sourcecodes/bnt-master/BNT/potentials/@cpot/enter_cts_evidence_pot.m new file mode 100644 index 00000000..246729ae --- /dev/null +++ b/sourcecodes/bnt-master/BNT/potentials/@cpot/enter_cts_evidence_pot.m @@ -0,0 +1,15 @@ +function pot = enter_cts_evidence_pot(pot, Y, y) +% function pot = enter_cts_evidence_pot(pot, Y, y) (cpot) + +ns = sparse(1, max(pot.domain)); +ns(pot.domain) = pot.sizes; + +X = mysetdiff(pot.domain, Y); +[hx, hy, KXX, KXY, KYX, KYY] = partition_matrix_vec(pot.h, pot.K, X, Y, ns); +pot.g = pot.g + hy'*y - 0.5*y'*KYY*y; +if ~isempty(X) + pot.h = hx - KXY*y; + pot.K = KXX; +end + +pot.sizes(find_equiv_posns(Y,pot.domain)) = 0; diff --git a/sourcecodes/bnt-master/BNT/potentials/@cpot/marginalize_pot.m b/sourcecodes/bnt-master/BNT/potentials/@cpot/marginalize_pot.m new file mode 100644 index 00000000..ae9ee839 --- /dev/null +++ b/sourcecodes/bnt-master/BNT/potentials/@cpot/marginalize_pot.m @@ -0,0 +1,31 @@ +function smallpot = marginalize_pot(bigpot, keep, maximize, useC) +% MARGINALIZE_POT Marginalize a cpot onto a smaller domain. +% smallpot = marginalize_pot(bigpot, keep, maximize, useC) +% +% The maximize argument is ignored - maxing out a Gaussian is the same as summing it out, +% since the mode and mean are equal. +% The useC argument is ignored. + +node_sizes = sparse(1, max(bigpot.domain)); +node_sizes(bigpot.domain) = bigpot.sizes; +sum_over = mysetdiff(bigpot.domain, keep); + +if sum(node_sizes(sum_over))==0 % isempty(sum_over) + %smallpot = bigpot; + smallpot = cpot(keep, node_sizes(keep), bigpot.g, bigpot.h, bigpot.K); +else + [h1, h2, K11, K12, K21, K22] = partition_matrix_vec(bigpot.h, bigpot.K, sum_over, keep, node_sizes); + n = length(h1); + K11inv = inv(K11); + g = bigpot.g + 0.5*(n*log(2*pi) - log(det(K11)) + h1'*K11inv*h1); + if length(h2) > 0 % ~isempty(keep) % we are are actually keeping something + A = K21*K11inv; + h = h2 - A*h1; + K = K22 - A*K12; + else + h = []; + K = []; + end + smallpot = cpot(keep, node_sizes(keep), g, h, K); +end + diff --git a/sourcecodes/bnt-master/BNT/potentials/@cpot/multiply_by_pot.m b/sourcecodes/bnt-master/BNT/potentials/@cpot/multiply_by_pot.m new file mode 100644 index 00000000..1ab24f55 --- /dev/null +++ b/sourcecodes/bnt-master/BNT/potentials/@cpot/multiply_by_pot.m @@ -0,0 +1,13 @@ +function bigpot = multiply_by_pot(bigpot, smallpot, varargin) +% MULTIPLY_BY_POT bigpot *= smallpot for cpot +% bigpot = multiply_by_pot(bigpot, smallpot) +% +% smallpot's domain must be a subset of bigpot's domain. + +bigpot.g = bigpot.g + smallpot.g; +if sum(smallpot.sizes) > 0 + mask = find_equiv_posns(smallpot.domain, bigpot.domain); + u = block(mask, bigpot.sizes); + bigpot.h(u) = bigpot.h(u) + smallpot.h; + bigpot.K(u, u) = bigpot.K(u, u) + smallpot.K; +end diff --git a/sourcecodes/bnt-master/BNT/potentials/@cpot/multiply_pots.m b/sourcecodes/bnt-master/BNT/potentials/@cpot/multiply_pots.m new file mode 100644 index 00000000..3506e36e --- /dev/null +++ b/sourcecodes/bnt-master/BNT/potentials/@cpot/multiply_pots.m @@ -0,0 +1,11 @@ +function T = multiply_pots(T1, T2) +% MULTIPLY_POTS Multiply a pair of dpots together pointwise (cpot) +% T = multiply_pots(pots) + +dom = myunion(T1.domain, T2.domain); +ns = sparse(1, max(dom)); +ns(T1.domain) = T1.sizes; +ns(T2.domain) = T2.sizes; +T = cpot(dom, ns(dom)); +T = multiply_by_pot(T, T1); +T = multiply_by_pot(T, T2); diff --git a/sourcecodes/bnt-master/BNT/potentials/@cpot/normalize_pot.m b/sourcecodes/bnt-master/BNT/potentials/@cpot/normalize_pot.m new file mode 100644 index 00000000..c6f89dc3 --- /dev/null +++ b/sourcecodes/bnt-master/BNT/potentials/@cpot/normalize_pot.m @@ -0,0 +1,10 @@ +function [pot, loglik] = normalize_pot(pot) +% NORMALIZE_POT Convert the canonical potential Pr(X,E) into Pr(X|E) and return log Pr(E). +% [pot, loglik] = normalize_pot(pot) + +mom = cpot_to_mpot(pot); % move the normalizing constant out of g, to reveal the coefficient +%loglik = scaling_factor_pot(mom); +%loglik = mom.logp; +[temp, loglik] = normalize_pot(mom); +pot.g = pot.g - loglik; + diff --git a/sourcecodes/bnt-master/BNT/potentials/@cpot/pot_to_marginal.m b/sourcecodes/bnt-master/BNT/potentials/@cpot/pot_to_marginal.m new file mode 100644 index 00000000..4c3fb79f --- /dev/null +++ b/sourcecodes/bnt-master/BNT/potentials/@cpot/pot_to_marginal.m @@ -0,0 +1,6 @@ +function m = pot_to_marginal(pot) +% POT_TO_MARGINAL Convert a cpot to a marginal structure. +% m = pot_to_marginal(pot) + +mom = cpot_to_mpot(pot); +m = pot_to_marginal(mom); diff --git a/sourcecodes/bnt-master/BNT/potentials/@cpot/rescale_pot.m b/sourcecodes/bnt-master/BNT/potentials/@cpot/rescale_pot.m new file mode 100644 index 00000000..ad962455 --- /dev/null +++ b/sourcecodes/bnt-master/BNT/potentials/@cpot/rescale_pot.m @@ -0,0 +1,5 @@ +function pot = rescale_pot(pot, s) +% RESCALE_POT Add a constant to the cpot scale factor. +% pot = rescale_pot(pot, s) + +pot.g = pot.g + s; diff --git a/sourcecodes/bnt-master/BNT/potentials/@cpot/set_domain_pot.m b/sourcecodes/bnt-master/BNT/potentials/@cpot/set_domain_pot.m new file mode 100644 index 00000000..2178c51d --- /dev/null +++ b/sourcecodes/bnt-master/BNT/potentials/@cpot/set_domain_pot.m @@ -0,0 +1,5 @@ +function pot = set_domain_pot(pot, domain) +% SET_DOMAIN_POT Change the domain of a potential (dpot) +% pot = set_domain_pot(pot, domain) + +pot.domain = domain; -- cgit 1.4.1