positive_definite_constraint.hpp
Go to the documentation of this file.00001
00022 #ifndef __MLPACK_METHODS_GMM_POSITIVE_DEFINITE_CONSTRAINT_HPP
00023 #define __MLPACK_METHODS_GMM_POSITIVE_DEFINITE_CONSTRAINT_HPP
00024
00025 namespace mlpack {
00026 namespace gmm {
00027
00031 class PositiveDefiniteConstraint
00032 {
00033 public:
00039 static void ApplyConstraint(arma::mat& covariance)
00040 {
00041
00042 if (det(covariance) <= 1e-50)
00043 {
00044 Log::Debug << "Covariance matrix is not positive definite. Adding "
00045 << "perturbation." << std::endl;
00046
00047 double perturbation = 1e-30;
00048 while (det(covariance) <= 1e-50)
00049 {
00050 covariance.diag() += perturbation;
00051 perturbation *= 10;
00052 }
00053 }
00054 }
00055 };
00056
00057 };
00058 };
00059
00060 #endif