mlpack  1.0.12
positive_definite_constraint.hpp
Go to the documentation of this file.
1 
14 #ifndef __MLPACK_METHODS_GMM_POSITIVE_DEFINITE_CONSTRAINT_HPP
15 #define __MLPACK_METHODS_GMM_POSITIVE_DEFINITE_CONSTRAINT_HPP
16 
17 #include <mlpack/core.hpp>
18 
19 namespace mlpack {
20 namespace gmm {
21 
26 {
27  public:
33  static void ApplyConstraint(arma::mat& covariance)
34  {
35  // TODO: make this more efficient.
36  if (arma::det(covariance) <= 1e-50)
37  {
38  Log::Debug << "Covariance matrix is not positive definite. Adding "
39  << "perturbation." << std::endl;
40 
41  double perturbation = 1e-30;
42  while (arma::det(covariance) <= 1e-50)
43  {
44  covariance.diag() += perturbation;
45  perturbation *= 10;
46  }
47  }
48  }
49 };
50 
51 }; // namespace gmm
52 }; // namespace mlpack
53 
54 #endif
55 
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: load.hpp:23
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:76
Given a covariance matrix, force the matrix to be positive definite.