12 #ifndef MLPACK_METHODS_GMM_POSITIVE_DEFINITE_CONSTRAINT_HPP 13 #define MLPACK_METHODS_GMM_POSITIVE_DEFINITE_CONSTRAINT_HPP 44 covariance = arma::symmatu(covariance);
45 if (!arma::eig_sym(eigval, eigvec, covariance))
47 Log::Fatal <<
"applying to constraint could not be accomplished." 55 if ((eigval[0] < 0.0) || ((eigval[eigval.n_elem - 1] / eigval[0]) > 1e5) ||
56 (eigval[eigval.n_elem - 1] < 1e-50))
61 const double minEigval = std::max(eigval[eigval.n_elem - 1] / 1e5, 1e-50);
62 for (
size_t i = 0; i < eigval.n_elem; ++i)
63 eigval[i] = std::max(eigval[i], minEigval);
66 covariance = eigvec * arma::diagmat(eigval) * eigvec.t();
81 double maxEigval = -DBL_MAX;
82 for (
size_t i = 0; i < diagCovariance.n_elem; ++i)
84 if (diagCovariance[i] > maxEigval)
85 maxEigval = diagCovariance[i];
88 for (
size_t i = 0; i < diagCovariance.n_elem; ++i)
90 if ((diagCovariance[i] < 0.0) || ((maxEigval / diagCovariance[i]) > 1e5)
91 || (maxEigval < 1e-50))
93 diagCovariance[i] = std::max(maxEigval / 1e5, 1e-50);
99 template<
typename Archive>
Linear algebra utility functions, generally performed on matrices or vectors.
static void ApplyConstraint(arma::mat &covariance)
Apply the positive definiteness constraint to the given covariance matrix, and ensure each value on t...
static void ApplyConstraint(arma::vec &diagCovariance)
Apply the positive definiteness constraint to the given diagonal covariance matrix (which is represen...
The core includes that mlpack expects; standard C++ includes and Armadillo.
static MLPACK_EXPORT util::PrefixedOutStream Fatal
Prints fatal messages prefixed with [FATAL], then terminates the program.
static void serialize(Archive &, const uint32_t)
Serialize the constraint (which stores nothing, so, nothing to do).
Given a covariance matrix, force the matrix to be positive definite.