[mlpack] 274/324: Implemented Save, Load

Barak A. Pearlmutter barak+git at cs.nuim.ie
Sun Aug 17 08:22:18 UTC 2014


This is an automated email from the git hooks/post-receive script.

bap pushed a commit to branch svn-trunk
in repository mlpack.

commit b355d89156b162ff92dd745f5708e921cbf60083
Author: michaelfox99 <michaelfox99 at 9d5b8971-822b-0410-80eb-d18c1038ef23>
Date:   Tue Aug 5 13:29:06 2014 +0000

    Implemented Save, Load
    
    
    git-svn-id: http://svn.cc.gatech.edu/fastlab/mlpack/trunk@16958 9d5b8971-822b-0410-80eb-d18c1038ef23
---
 src/mlpack/core/dists/gaussian_distribution.cpp | 40 +++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/src/mlpack/core/dists/gaussian_distribution.cpp b/src/mlpack/core/dists/gaussian_distribution.cpp
index 7c8f14e..595613e 100644
--- a/src/mlpack/core/dists/gaussian_distribution.cpp
+++ b/src/mlpack/core/dists/gaussian_distribution.cpp
@@ -1,6 +1,7 @@
 /**
  * @file gaussian_distribution.cpp
  * @author Ryan Curtin
+ * @author Michael Fox
  *
  * Implementation of Gaussian distribution class.
  */
@@ -9,6 +10,31 @@
 using namespace mlpack;
 using namespace mlpack::distribution;
 
+/**
+ * Calculates the multivariate Gaussian probability density function for each
+ * data point (column) in the given matrix, with respect to the given mean and
+ * variance.
+ *
+ * @param x List of observations.
+ * @param mean Mean of multivariate Gaussian.
+ * @param cov Covariance of multivariate Gaussian.
+ * @param probabilities Output probabilities for each input observation.
+ */
+
+double GaussianDistribution::Probability(const arma::vec& observation) const
+{
+  arma::vec diff = mean - observation;
+  
+  // Parentheses required for Armadillo 3.0.0 bug.
+  arma::vec exponent = -0.5 * (trans(diff) * inv(covariance) * diff);
+  
+  // TODO: What if det(cov) < 0?
+  return pow(2 * M_PI, (double) observation.n_elem / -2.0) *
+      pow(det(covariance), -0.5) * exp(exponent[0]);
+}
+
+
+
 arma::vec GaussianDistribution::Random() const
 {
   // Should we store chol(covariance) for easier calculation later?
@@ -149,3 +175,17 @@ std::string GaussianDistribution::ToString() const
   convert << util::Indent(data.str());
   return convert.str();
 }
+
+
+/*
+ * Save to or Load from SaveRestoreUtility
+ */
+void GaussianDistribution::Save(util::SaveRestoreUtility& sr) const {
+  sr.SaveParameter(Type(), "type");
+  sr.SaveParameter(mean, "mean");
+  sr.SaveParameter(covariance, "covariance");
+}
+void GaussianDistribution::Load(const util::SaveRestoreUtility& sr) {
+  sr.LoadParameter(mean, "mean");
+  sr.LoadParameter(covariance, "covariance");
+}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/mlpack.git



More information about the debian-science-commits mailing list