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 arma::eig_sym(eigenvalues, eigenvectors, covariance);
73 eigenvalues = (eigenvalues[0] * ratios);
76 covariance = eigenvectors * arma::diagmat(eigenvalues) * eigenvectors.t();
80 template<
typename Archive>
90 const arma::vec ratios;
EigenvalueRatioConstraint(const arma::vec &ratios)
Create the EigenvalueRatioConstraint object with the given vector of eigenvalue ratios.
FirstShim< T > CreateNVP(T &t, const std::string &name, typename boost::enable_if< HasSerialize< T >>::type *=0)
Call this function to produce a name-value pair; this is similar to BOOST_SERIALIZATION_NVP(), but should be used for types that have a Serialize() function (or contain a type that has a Serialize() function) instead of a serialize() function.
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 Serialize(Archive &ar, const unsigned int)
Serialize the constraint.
void ApplyConstraint(arma::mat &covariance) const
Apply the eigenvalue ratio constraint to the given covariance matrix.
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...