MLPACK  1.0.7
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 namespace mlpack {
26 namespace gmm {
27 
32 {
33  public:
39  static void ApplyConstraint(arma::mat& covariance)
40  {
41  // TODO: make this more efficient.
42  if (det(covariance) <= 1e-50)
43  {
44  Log::Debug << "Covariance matrix is not positive definite. Adding "
45  << "perturbation." << std::endl;
46 
47  double perturbation = 1e-30;
48  while (det(covariance) <= 1e-50)
49  {
50  covariance.diag() += perturbation;
51  perturbation *= 10;
52  }
53  }
54  }
55 };
56 
57 }; // namespace gmm
58 }; // namespace mlpack
59 
60 #endif