[mlpack] 10/40: Force a minimum value on the diagonal.

Barak A. Pearlmutter barak+git at pearlmutter.net
Mon Feb 15 19:34:23 UTC 2016


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

bap pushed a commit to branch master
in repository mlpack.

commit 97bcd6032b7a0743de7c3a18ffa0b22816449d67
Author: Ryan Curtin <ryan at ratml.org>
Date:   Wed Jan 13 14:45:42 2016 -0500

    Force a minimum value on the diagonal.
    
    This is necessary so that the inverse covariance doesn't explode.  If the
    covariance is sufficiently small, then the PDF of the Gaussian will condense
    towards a delta function, and you will end up with inf's in your probabilities,
    which turn into NaNs when normalized, and then your entire model turns into
    NaNs.
    
    Note that the PositiveDefinite constraint can be replaced with the NoConstraint
    class for speed if necessary.
---
 src/mlpack/methods/gmm/positive_definite_constraint.hpp | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/mlpack/methods/gmm/positive_definite_constraint.hpp b/src/mlpack/methods/gmm/positive_definite_constraint.hpp
index 9f4596f..d13566f 100644
--- a/src/mlpack/methods/gmm/positive_definite_constraint.hpp
+++ b/src/mlpack/methods/gmm/positive_definite_constraint.hpp
@@ -20,18 +20,26 @@ namespace mlpack {
 namespace gmm {
 
 /**
- * Given a covariance matrix, force the matrix to be positive definite.
+ * Given a covariance matrix, force the matrix to be positive definite.  Also
+ * force a minimum value on the diagonal, so that even if the matrix is
+ * invertible, it doesn't 
  */
 class PositiveDefiniteConstraint
 {
  public:
   /**
-   * Apply the positive definiteness constraint to the given covariance matrix.
+   * Apply the positive definiteness constraint to the given covariance matrix,
+   * and ensure each value on the diagonal is at least 1e-50.
    *
    * @param covariance Covariance matrix.
    */
   static void ApplyConstraint(arma::mat& covariance)
   {
+    // Make sure each diagonal element is at least 1e-50.
+    for (size_t i = 0; i < covariance.n_cols; ++i)
+      if (std::abs(covariance(i, i)) < 1e-50)
+        covariance(i, i) = 1e-50;
+
     // Realistically, all we care about is that we can perform a Cholesky
     // decomposition of the matrix, so that FactorCovariance() doesn't fail
     // later.  Therefore, that's what we'll do to check for positive

-- 
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