MLPACK  1.0.11
positive_definite_constraint.hpp
Go to the documentation of this file.
1 
22 #ifndef __MLPACK_METHODS_GMM_POSITIVE_DEFINITE_CONSTRAINT_HPP
23 #define __MLPACK_METHODS_GMM_POSITIVE_DEFINITE_CONSTRAINT_HPP
24 
25 #include <mlpack/core.hpp>
26 
27 namespace mlpack {
28 namespace gmm {
29 
34 {
35  public:
41  static void ApplyConstraint(arma::mat& covariance)
42  {
43  // TODO: make this more efficient.
44  if (arma::det(covariance) <= 1e-50)
45  {
46  Log::Debug << "Covariance matrix is not positive definite. Adding "
47  << "perturbation." << std::endl;
48 
49  double perturbation = 1e-30;
50  while (arma::det(covariance) <= 1e-50)
51  {
52  covariance.diag() += perturbation;
53  perturbation *= 10;
54  }
55  }
56  }
57 };
58 
59 }; // namespace gmm
60 }; // namespace mlpack
61 
62 #endif
63 
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: load.hpp:31
static void ApplyConstraint(arma::mat &covariance)
Apply the positive definiteness constraint to the given covariance matrix.
static util::NullOutStream Debug
Dumps debug output into the bit nether regions.
Definition: log.hpp:84
Given a covariance matrix, force the matrix to be positive definite.