[mlpack-git] master: phi.hpp no longer used, see GaussianDistribution::Probability() (8b9294b)

gitdub at big.cc.gt.atl.ga.us gitdub at big.cc.gt.atl.ga.us
Thu Mar 5 21:57:06 EST 2015


Repository : https://github.com/mlpack/mlpack

On branch  : master
Link       : https://github.com/mlpack/mlpack/compare/904762495c039e345beba14c1142fd719b3bd50e...f94823c800ad6f7266995c700b1b630d5ffdcf40

>---------------------------------------------------------------

commit 8b9294b75e2c00694a94ff383b8b1f407854dce9
Author: michaelfox99 <michaelfox99 at gmail.com>
Date:   Thu Aug 7 03:44:51 2014 +0000

    phi.hpp no longer used, see GaussianDistribution::Probability()


>---------------------------------------------------------------

8b9294b75e2c00694a94ff383b8b1f407854dce9
 src/mlpack/methods/gmm/phi.hpp | 147 -----------------------------------------
 1 file changed, 147 deletions(-)

diff --git a/src/mlpack/methods/gmm/phi.hpp b/src/mlpack/methods/gmm/phi.hpp
deleted file mode 100644
index c2f58b8..0000000
--- a/src/mlpack/methods/gmm/phi.hpp
+++ /dev/null
@@ -1,147 +0,0 @@
-/**
- * @author Parikshit Ram (pram at cc.gatech.edu)
- * @file phi.hpp
- *
- * This file computes the Gaussian probability
- * density function
- */
-#ifndef __MLPACK_METHODS_MOG_PHI_HPP
-#define __MLPACK_METHODS_MOG_PHI_HPP
-
-#include <mlpack/core.hpp>
-
-namespace mlpack {
-namespace gmm {
-
-/**
- * Calculates the univariate Gaussian probability density function.
- *
- * Example use:
- * @code
- * double x, mean, var;
- * ....
- * double f = phi(x, mean, var);
- * @endcode
- *
- * @param x Observation.
- * @param mean Mean of univariate Gaussian.
- * @param var Variance of univariate Gaussian.
- * @return Probability of x being observed from the given univariate Gaussian.
- */
-inline double phi(const double x, const double mean, const double var)
-{
-  return exp(-1.0 * ((x - mean) * (x - mean) / (2 * var)))
-      / sqrt(2 * M_PI * var);
-}
-
-/**
- * Calculates the multivariate Gaussian probability density function.
- *
- * Example use:
- * @code
- * extern arma::vec x, mean;
- * extern arma::mat cov;
- * ....
- * double f = phi(x, mean, cov);
- * @endcode
- *
- * @param x Observation.
- * @param mean Mean of multivariate Gaussian.
- * @param cov Covariance of multivariate Gaussian.
- * @return Probability of x being observed from the given multivariate Gaussian.
- */
-inline double phi(const arma::vec& x,
-                  const arma::vec& mean,
-                  const arma::mat& cov)
-{
-  arma::vec diff = mean - x;
-
-  // Parentheses required for Armadillo 3.0.0 bug.
-  arma::vec exponent = -0.5 * (trans(diff) * inv(cov) * diff);
-
-  // TODO: What if det(cov) < 0?
-  return pow(2 * M_PI, (double) x.n_elem / -2.0) * pow(det(cov), -0.5) *
-      exp(exponent[0]);
-}
-
-/**
- * Calculates the multivariate Gaussian probability density function and also
- * the gradients with respect to the mean and the variance.
- *
- * Example use:
- * @code
- * extern arma::vec x, mean, g_mean, g_cov;
- * std::vector<arma::mat> d_cov; // the dSigma
- * ....
- * double f = phi(x, mean, cov, d_cov, &g_mean, &g_cov);
- * @endcode
- */
-inline double phi(const arma::vec& x,
-                  const arma::vec& mean,
-                  const arma::mat& cov,
-                  const std::vector<arma::mat>& d_cov,
-                  arma::vec& g_mean,
-                  arma::vec& g_cov)
-{
-  // We don't call out to another version of the function to avoid inverting the
-  // covariance matrix more than once.
-  arma::mat cinv = inv(cov);
-
-  arma::vec diff = mean - x;
-  // Parentheses required for Armadillo 3.0.0 bug.
-  arma::vec exponent = -0.5 * (trans(diff) * inv(cov) * diff);
-
-  long double f = pow(2 * M_PI, (double) x.n_elem / 2) * pow(det(cov), -0.5)
-      * exp(exponent[0]);
-
-  // Calculate the g_mean values; this is a (1 x dim) vector.
-  arma::vec invDiff = cinv * diff;
-  g_mean = f * invDiff;
-
-  // Calculate the g_cov values; this is a (1 x (dim * (dim + 1) / 2)) vector.
-  for (size_t i = 0; i < d_cov.size(); i++)
-  {
-    arma::mat inv_d = cinv * d_cov[i];
-
-    g_cov[i] = f * dot(d_cov[i] * invDiff, invDiff) +
-        accu(inv_d.diag()) / 2;
-  }
-
-  return f;
-}
-
-/**
- * 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.
- */
-inline void phi(const arma::mat& x,
-                const arma::vec& mean,
-                const arma::mat& cov,
-                arma::vec& probabilities)
-{
-  // Column i of 'diffs' is the difference between x.col(i) and the mean.
-  arma::mat diffs = x - (mean * arma::ones<arma::rowvec>(x.n_cols));
-
-  // Now, we only want to calculate the diagonal elements of (diffs' * cov^-1 *
-  // diffs).  We just don't need any of the other elements.  We can calculate
-  // the right hand part of the equation (instead of the left side) so that
-  // later we are referencing columns, not rows -- that is faster.
-  arma::mat rhs = -0.5 * inv(cov) * diffs;
-  arma::vec exponents(diffs.n_cols); // We will now fill this.
-  for (size_t i = 0; i < diffs.n_cols; i++)
-    exponents(i) = exp(accu(diffs.unsafe_col(i) % rhs.unsafe_col(i)));
-
-  probabilities = pow(2 * M_PI, (double) mean.n_elem / -2.0) *
-      pow(det(cov), -0.5) * exponents;
-}
-
-}; // namespace gmm
-}; // namespace mlpack
-
-#endif



More information about the mlpack-git mailing list