14 #ifndef __MLPACK_METHODS_GMM_EIGENVALUE_RATIO_CONSTRAINT_HPP
15 #define __MLPACK_METHODS_GMM_EIGENVALUE_RATIO_CONSTRAINT_HPP
40 ratios(const_cast<double*>(ratios.memptr()), ratios.n_elem, false)
43 if (std::abs(ratios[0] - 1.0) > 1e-20)
44 Log::Fatal <<
"EigenvalueRatioConstraint::EigenvalueRatioConstraint(): "
45 <<
"first element of ratio vector is not 1.0!" << std::endl;
47 for (
size_t i = 1; i < ratios.n_elem; ++i)
50 Log::Fatal <<
"EigenvalueRatioConstraint::EigenvalueRatioConstraint(): "
51 <<
"element " << i <<
" of ratio vector is greater than 1.0!"
54 Log::Warn <<
"EigenvalueRatioConstraint::EigenvalueRatioConstraint(): "
55 <<
"element " << i <<
" of ratio vectors is negative and will "
56 <<
"probably cause the covariance to be non-invertible..."
67 arma::vec eigenvalues;
68 arma::mat eigenvectors;
69 arma::eig_sym(eigenvalues, eigenvectors, covariance);
75 eigenvalues = (eigenvalues[0] *
ratios);
78 covariance = eigenvectors * arma::diagmat(eigenvalues) * eigenvectors.t();
82 template<
typename Archive>
void ApplyConstraint(arma::mat &covariance) const
Apply the eigenvalue ratio constraint to the given covariance matrix.
Linear algebra utility functions, generally performed on matrices or vectors.
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.
const arma::vec ratios
Ratios for eigenvalues.
static util::PrefixedOutStream Fatal
Prints fatal messages prefixed with [FATAL], then terminates the program.
EigenvalueRatioConstraint(const arma::vec &ratios)
Create the EigenvalueRatioConstraint object with the given vector of eigenvalue ratios.
Include all of the base components required to write MLPACK methods, and the main MLPACK Doxygen docu...
void Serialize(Archive &ar, const unsigned int)
Serialize the constraint.
static 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...