about summary refs log tree commit diff
path: root/sourcecodes/bnt-master/BNT/potentials/@mpot
diff options
context:
space:
mode:
authorziejd22017-09-28 15:04:40 -0500
committerziejd22017-09-28 15:04:40 -0500
commit8070dc963753142bb86c4ed698d91fd623ed28e7 (patch)
treed0f6dd8fc46a49b819aa55c1a90faa14d8448883 /sourcecodes/bnt-master/BNT/potentials/@mpot
parent7cc31810d53176e805532b2789955f4eedbce6bb (diff)
downloadBNW-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/potentials/@mpot')
-rw-r--r--sourcecodes/bnt-master/BNT/potentials/@mpot/CVS/Entries9
-rw-r--r--sourcecodes/bnt-master/BNT/potentials/@mpot/CVS/Repository1
-rw-r--r--sourcecodes/bnt-master/BNT/potentials/@mpot/CVS/Root1
-rw-r--r--sourcecodes/bnt-master/BNT/potentials/@mpot/display.m4
-rw-r--r--sourcecodes/bnt-master/BNT/potentials/@mpot/marginalize_pot.m27
-rw-r--r--sourcecodes/bnt-master/BNT/potentials/@mpot/mpot.m17
-rw-r--r--sourcecodes/bnt-master/BNT/potentials/@mpot/mpot_to_cpot.m21
-rw-r--r--sourcecodes/bnt-master/BNT/potentials/@mpot/normalize_pot.m6
-rw-r--r--sourcecodes/bnt-master/BNT/potentials/@mpot/pot_to_marginal.m13
-rw-r--r--sourcecodes/bnt-master/BNT/potentials/@mpot/rescale_pot.m5
-rw-r--r--sourcecodes/bnt-master/BNT/potentials/@mpot/set_domain_pot.m5
11 files changed, 109 insertions, 0 deletions
diff --git a/sourcecodes/bnt-master/BNT/potentials/@mpot/CVS/Entries b/sourcecodes/bnt-master/BNT/potentials/@mpot/CVS/Entries
new file mode 100644
index 00000000..c542af05
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/potentials/@mpot/CVS/Entries
@@ -0,0 +1,9 @@
+/display.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//
+/mpot.m/1.1.1.1/Wed May 29 15:59:58 2002//
+/mpot_to_cpot.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 Jul 30 13:37:52 2003//
+D
diff --git a/sourcecodes/bnt-master/BNT/potentials/@mpot/CVS/Repository b/sourcecodes/bnt-master/BNT/potentials/@mpot/CVS/Repository
new file mode 100644
index 00000000..1d9311e4
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/potentials/@mpot/CVS/Repository
@@ -0,0 +1 @@
+FullBNT/BNT/potentials/@mpot
diff --git a/sourcecodes/bnt-master/BNT/potentials/@mpot/CVS/Root b/sourcecodes/bnt-master/BNT/potentials/@mpot/CVS/Root
new file mode 100644
index 00000000..f3bd14a6
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/potentials/@mpot/CVS/Root
@@ -0,0 +1 @@
+:ext:nsaunier@bnt.cvs.sourceforge.net:/cvsroot/bnt
diff --git a/sourcecodes/bnt-master/BNT/potentials/@mpot/display.m b/sourcecodes/bnt-master/BNT/potentials/@mpot/display.m
new file mode 100644
index 00000000..90f0e2fc
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/potentials/@mpot/display.m
@@ -0,0 +1,4 @@
+function display(pot)
+
+disp('moment Gaussian potential object');
+disp(struct(pot));
diff --git a/sourcecodes/bnt-master/BNT/potentials/@mpot/marginalize_pot.m b/sourcecodes/bnt-master/BNT/potentials/@mpot/marginalize_pot.m
new file mode 100644
index 00000000..88751c62
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/potentials/@mpot/marginalize_pot.m
@@ -0,0 +1,27 @@
+function smallpot = marginalize_pot(bigpot, keep, maximize, useC)
+% MARGINALIZE_POT Marginalize a mpot 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);
+
+[logp, mu, Sigma] = marginalize_gaussian(bigpot.logp, bigpot.mu, bigpot.Sigma, ...
+					 keep, sum_over, node_sizes);
+smallpot = mpot(keep, node_sizes(keep), logp, mu, Sigma);
+
+%%%%%%
+
+function [logpX, muX, SXX] = marginalize_gaussian(logp, mu, Sigma, X, Y, ns)
+% MARGINALIZE_GAUSSIAN Compute Pr(X) from Pr(X,Y) where X and Y are jointly Gaussian.
+% [logpX, muX, SXX] = marginalize_gaussian(logp, mu, Sigma, X, Y, ns)
+%
+% sizes(i) is the size of the i'th block in domain.
+ 
+[muX, muY, SXX, SXY, SYX, SYY] = partition_matrix_vec(mu, Sigma, X, Y, ns);
+logpX = logp; % Lauritzen (1996) p161          
diff --git a/sourcecodes/bnt-master/BNT/potentials/@mpot/mpot.m b/sourcecodes/bnt-master/BNT/potentials/@mpot/mpot.m
new file mode 100644
index 00000000..1c790f8a
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/potentials/@mpot/mpot.m
@@ -0,0 +1,17 @@
+function pot = mpot(members, sizes, logp, mu, Sigma)
+% MPOT Make a moment Gaussian potential.
+% pot = mpot(members, sizes, logp, mu, Sigma)
+%
+% All params default to 0 if omitted.
+
+n = sum(sizes);
+if nargin < 3, logp = 0; end
+if nargin < 4, mu = zeros(n,1); end
+if nargin < 5, Sigma = zeros(n,n); end
+  
+pot.domain = members;
+pot.sizes = sizes;
+pot.logp = logp;
+pot.mu = mu;
+pot.Sigma = Sigma;zeros(n,n);      
+pot = class(pot, 'mpot');
diff --git a/sourcecodes/bnt-master/BNT/potentials/@mpot/mpot_to_cpot.m b/sourcecodes/bnt-master/BNT/potentials/@mpot/mpot_to_cpot.m
new file mode 100644
index 00000000..ffb3192b
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/potentials/@mpot/mpot_to_cpot.m
@@ -0,0 +1,21 @@
+function can = mpot_to_cpot(mom)
+% MPOT_TO_CPOT Convert a moment potential to canonical form.
+% mom = mpot_to_cpot(can)
+
+[g, h, K] = moment_to_canonical(mom.logp, mom.mu, mom.Sigma);
+can = cpot(mom.domain, mom.sizes, g, h, K);
+
+%%%%%%%%%%%
+
+function [g, h, K] = moment_to_canonical(logp, mu, Sigma)
+% MOMENT_TO_CANONICAL Convert moment characteristics to canonical form.
+% [g, h, K] = moment_to_canonical(logp, mu, Sigma)
+
+K = inv(Sigma);
+h = K*mu;
+n = length(K);
+if isempty(mu)
+  g = logp + 0.5*(log(det(K)) - n*log(2*pi));
+else
+  g = logp + 0.5*(log(det(K)) - n*log(2*pi) - mu'*K*mu);
+end        
diff --git a/sourcecodes/bnt-master/BNT/potentials/@mpot/normalize_pot.m b/sourcecodes/bnt-master/BNT/potentials/@mpot/normalize_pot.m
new file mode 100644
index 00000000..a9c2e935
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/potentials/@mpot/normalize_pot.m
@@ -0,0 +1,6 @@
+function [pot, loglik] = normalize_pot(pot)
+% NORMALIZE_POT Convert the moment potential Pr(X,E) into Pr(X|E) and return log Pr(E).
+% [pot, loglik] = normalize_pot(pot)
+
+loglik = pot.logp;
+pot.logp = 0;
diff --git a/sourcecodes/bnt-master/BNT/potentials/@mpot/pot_to_marginal.m b/sourcecodes/bnt-master/BNT/potentials/@mpot/pot_to_marginal.m
new file mode 100644
index 00000000..b5bd041e
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/potentials/@mpot/pot_to_marginal.m
@@ -0,0 +1,13 @@
+function m = pot_to_marginal(pot)
+% POT_TO_MARGINAL Convert a mpot to a marginal structure.
+% m = pot_to_marginal(pot)
+
+m.domain = pot.domain;
+m.T = exp(pot.logp);
+m.mu = pot.mu;
+m.Sigma = pot.Sigma;
+
+if isvectorBNT(m.T)
+  m.T = m.T(:)';
+end
+
diff --git a/sourcecodes/bnt-master/BNT/potentials/@mpot/rescale_pot.m b/sourcecodes/bnt-master/BNT/potentials/@mpot/rescale_pot.m
new file mode 100644
index 00000000..39d1809d
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/potentials/@mpot/rescale_pot.m
@@ -0,0 +1,5 @@
+function pot = rescale_pot(pot, s)
+% RESCALE_POT Add a constant to the mpot scale factor.
+% pot = rescale_pot(pot, s)
+
+pot.logp = pot.logp + s;
diff --git a/sourcecodes/bnt-master/BNT/potentials/@mpot/set_domain_pot.m b/sourcecodes/bnt-master/BNT/potentials/@mpot/set_domain_pot.m
new file mode 100644
index 00000000..91d5a7bb
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/potentials/@mpot/set_domain_pot.m
@@ -0,0 +1,5 @@
+function pot = set_domain_pot(pot, domain)
+% SET_DOMAIN_POT Change the domain of a potential (mpot)
+% pot = set_domain_pot(pot, domain)
+
+pot.domain = domain;