12 #ifndef MLPACK_METHODS_GMM_EIGENVALUE_RATIO_CONSTRAINT_HPP 13 #define MLPACK_METHODS_GMM_EIGENVALUE_RATIO_CONSTRAINT_HPP 38 ratios(const_cast<double*>(ratios.memptr()), ratios.n_elem, false)
41 if (std::abs(ratios[0] - 1.0) > 1e-20)
42 Log::Fatal <<
"EigenvalueRatioConstraint::EigenvalueRatioConstraint(): " 43 <<
"first element of ratio vector is not 1.0!" << std::endl;
45 for (
size_t i = 1; i < ratios.n_elem; ++i)
48 Log::Fatal <<
"EigenvalueRatioConstraint::EigenvalueRatioConstraint(): " 49 <<
"element " << i <<
" of ratio vector is greater than 1.0!" 52 Log::Warn <<
"EigenvalueRatioConstraint::EigenvalueRatioConstraint(): " 53 <<
"element " << i <<
" of ratio vectors is negative and will " 54 <<
"probably cause the covariance to be non-invertible..." 65 arma::vec eigenvalues;
66 arma::mat eigenvectors;
67 covariance = arma::symmatu(covariance);
68 if (!arma::eig_sym(eigenvalues, eigenvectors, covariance))
70 Log::Fatal <<
"applying to constraint could not be accomplished." 78 eigenvalues = (eigenvalues[0] * ratios);
81 covariance = eigenvectors * arma::diagmat(eigenvalues) * eigenvectors.t();
91 arma::uvec eigvalOrder = arma::sort_index(diagCovariance);
92 arma::vec eigvals = diagCovariance(eigvalOrder);
98 eigvals = eigvals[0] * ratios;
101 for (
size_t i = 0; i < eigvalOrder.n_elem; ++i)
102 diagCovariance[eigvalOrder[i]] = eigvals[i];
106 template<
typename Archive>
111 ar(CEREAL_NVP(const_cast<arma::vec&>(ratios)));
116 const arma::vec ratios;
EigenvalueRatioConstraint(const arma::vec &ratios)
Create the EigenvalueRatioConstraint object with the given vector of eigenvalue ratios.
Linear algebra utility functions, generally performed on matrices or vectors.
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.
void ApplyConstraint(arma::vec &diagCovariance) const
Apply the eigenvalue ratio constraint to the given diagonal covariance matrix (represented as a vecto...
static MLPACK_EXPORT util::PrefixedOutStream Warn
Prints warning messages prefixed with [WARN ].
Given a vector of eigenvalue ratios, ensure that the covariance matrix always has those eigenvalue ra...
void serialize(Archive &ar, const uint32_t)
Serialize the constraint.
void ApplyConstraint(arma::mat &covariance) const
Apply the eigenvalue ratio constraint to the given covariance matrix.