eigenvalue_ratio_constraint.hpp
Go to the documentation of this file.00001
00022 #ifndef __MLPACK_METHODS_GMM_EIGENVALUE_RATIO_CONSTRAINT_HPP
00023 #define __MLPACK_METHODS_GMM_EIGENVALUE_RATIO_CONSTRAINT_HPP
00024
00025 #include <mlpack/core.hpp>
00026
00027 namespace mlpack {
00028 namespace gmm {
00029
00036 class EigenvalueRatioConstraint
00037 {
00038 public:
00045 EigenvalueRatioConstraint(const arma::vec& ratios) :
00046 ratios(ratios)
00047 {
00048
00049 if (std::abs(ratios[0] - 1.0) > 1e-20)
00050 Log::Fatal << "EigenvalueRatioConstraint::EigenvalueRatioConstraint(): "
00051 << "first element of ratio vector is not 1.0!" << std::endl;
00052
00053 for (size_t i = 1; i < ratios.n_elem; ++i)
00054 {
00055 if (ratios[i] > 1.0)
00056 Log::Fatal << "EigenvalueRatioConstraint::EigenvalueRatioConstraint(): "
00057 << "element " << i << " of ratio vector is greater than 1.0!"
00058 << std::endl;
00059 if (ratios[i] < 0.0)
00060 Log::Warn << "EigenvalueRatioConstraint::EigenvalueRatioConstraint(): "
00061 << "element " << i << " of ratio vectors is negative and will "
00062 << "probably cause the covariance to be non-invertible..."
00063 << std::endl;
00064 }
00065 }
00066
00070 void ApplyConstraint(arma::mat& covariance) const
00071 {
00072
00073 arma::vec eigenvalues;
00074 arma::mat eigenvectors;
00075 arma::eig_sym(eigenvalues, eigenvectors, covariance);
00076
00077
00078
00079
00080
00081 eigenvalues = (eigenvalues[0] * ratios);
00082
00083
00084 covariance = eigenvectors * arma::diagmat(eigenvalues) * eigenvectors.t();
00085 }
00086
00087 private:
00089 const arma::vec& ratios;
00090 };
00091
00092 };
00093 };
00094
00095 #endif