12 #ifndef TAPKEE_EIGENDECOMPOSITION_H_ 13 #define TAPKEE_EIGENDECOMPOSITION_H_ 16 #ifdef TAPKEE_WITH_ARPACK 25 namespace tapkee_internal
28 #ifdef TAPKEE_WITH_ARPACK 29 template <
class MatrixType,
class MatrixOperationType>
36 arpack(wm,target_dimension+skip,MatrixOperationType::ARPACK_CODE);
38 if (arpack.
info() == Eigen::Success)
54 template <
class MatrixType,
class MatrixOperationType>
57 timed_context context(
"Eigen library dense eigendecomposition");
62 if (solver.info() == Eigen::Success)
64 if (MatrixOperationType::largest)
67 DenseMatrix selected_eigenvectors = solver.eigenvectors().rightCols(target_dimension);
72 DenseMatrix selected_eigenvectors = solver.eigenvectors().leftCols(target_dimension+skip).rightCols(target_dimension);
84 template <
class MatrixType,
class MatrixOperationType>
97 MatrixOperationType operation(wm);
105 Y.col(i) -= r*Y.col(j);
110 for (
int k = i; k<Y.cols(); k++)
113 Y.col(i) *= (1.f / norm);
120 if (eigenOfB.info() == Eigen::Success)
122 if (MatrixOperationType::largest)
125 DenseMatrix selected_eigenvectors = (Y*eigenOfB.eigenvectors()).rightCols(target_dimension);
130 DenseMatrix selected_eigenvectors = (Y*eigenOfB.eigenvectors()).leftCols(target_dimension+skip).rightCols(target_dimension);
141 template <
typename MatrixType>
144 #ifdef TAPKEE_WITH_ARPACK 160 #ifdef TAPKEE_WITH_ARPACK 168 return eigendecomposition_impl_arpack<DenseMatrix,DenseMatrixOperation>
169 (m,target_dimension,eigen_strategy.
skip());
171 return eigendecomposition_impl_arpack<DenseMatrix,DenseImplicitSquareMatrixOperation>
172 (m,target_dimension,eigen_strategy.
skip());
174 return eigendecomposition_impl_arpack<DenseMatrix,DenseInverseMatrixOperation>
175 (m,target_dimension,eigen_strategy.
skip());
178 #ifdef TAPKEE_WITH_VIENNACL 179 if (strategy.
is(HeterogeneousOpenCLStrategy))
182 return eigendecomposition_impl_arpack<DenseMatrix,GPUDenseMatrixOperation>
183 (m,target_dimension,eigen_strategy.
skip());
185 return eigendecomposition_impl_arpack<DenseMatrix,GPUDenseImplicitSquareMatrixOperation>
186 (m,target_dimension,eigen_strategy.
skip());
201 return eigendecomposition_impl_dense<DenseMatrix,DenseMatrixOperation>
202 (m,target_dimension,eigen_strategy.
skip());
204 return eigendecomposition_impl_dense<DenseMatrix,DenseMatrixOperation>
205 (m,target_dimension,eigen_strategy.
skip());
207 return eigendecomposition_impl_dense<DenseMatrix,DenseInverseMatrixOperation>
208 (m,target_dimension,eigen_strategy.
skip());
221 return eigendecomposition_impl_randomized<DenseMatrix,DenseMatrixOperation>
222 (m,target_dimension,eigen_strategy.
skip());
224 return eigendecomposition_impl_randomized<DenseMatrix,DenseImplicitSquareMatrixOperation>
225 (m,target_dimension,eigen_strategy.
skip());
227 return eigendecomposition_impl_randomized<DenseMatrix,DenseInverseMatrixOperation>
228 (m,target_dimension,eigen_strategy.
skip());
231 #ifdef TAPKEE_WITH_VIENNACL 232 if (strategy.
is(HeterogeneousOpenCLStrategy))
235 return eigendecomposition_impl_randomized<DenseMatrix,GPUDenseMatrixOperation>
236 (m,target_dimension,eigen_strategy.
skip());
238 return eigendecomposition_impl_randomized<DenseMatrix,GPUDenseImplicitSquareMatrixOperation>
239 (m,target_dimension,eigen_strategy.
skip());
255 #ifdef TAPKEE_WITH_ARPACK 263 return eigendecomposition_impl_arpack<SparseWeightMatrix,SparseInverseMatrixOperation>
264 (m,target_dimension,eigen_strategy.
skip());
278 return eigendecomposition_impl_dense<SparseWeightMatrix,SparseInverseMatrixOperation>
279 (m,target_dimension,eigen_strategy.
skip());
292 return eigendecomposition_impl_randomized<SparseWeightMatrix,SparseInverseMatrixOperation>
293 (m,target_dimension,eigen_strategy.
skip());
333 template <
class MatrixType>
336 const MatrixType& m,
IndexType target_dimension)
340 #ifdef TAPKEE_WITH_ARPACK EigendecompositionResult eigendecomposition_impl_randomized(const MatrixType &wm, IndexType target_dimension, unsigned int skip)
Randomized redsvd-like implementation of eigendecomposition-based embedding.
static const EigenMethod Dense("Dense")
Eigen library dense method (could be useful for debugging). Computes all eigenvectors thus can be ver...
static const EigendecompositionStrategy SmallestEigenvalues("Smallest eigenvalues", 1)
static const EigenMethod Randomized("Randomized")
Randomized method (implementation taken from the redsvd lib). Supports only standard but not generali...
EigendecompositionResult randomized(const SparseWeightMatrix &m, const ComputationStrategy &strategy, const EigendecompositionStrategy &eigen_strategy, IndexType target_dimension)
static const EigendecompositionStrategy SquaredLargestEigenvalues("Largest eigenvalues of squared matrix", 0)
const Matrix< Scalar, Dynamic, Dynamic > & eigenvectors() const
Returns the eigenvectors of given matrix.
Eigen::Matrix< tapkee::ScalarType, Eigen::Dynamic, Eigen::Dynamic > DenseMatrix
dense matrix type (non-overridable)
EigendecompositionResult eigendecomposition(const EigenMethod &method, const ComputationStrategy &strategy, const EigendecompositionStrategy &eigen_strategy, const MatrixType &m, IndexType target_dimension)
Multiple implementation handler method for various eigendecomposition methods.
EigendecompositionResult dense(const DenseMatrix &m, const ComputationStrategy &strategy, const EigendecompositionStrategy &eigen_strategy, IndexType target_dimension)
EigendecompositionResult randomized(const DenseMatrix &m, const ComputationStrategy &strategy, const EigendecompositionStrategy &eigen_strategy, IndexType target_dimension)
double ScalarType
default scalar value (can be overrided with TAPKEE_CUSTOM_INTERNAL_NUMTYPE define) ...
ComputationInfo info() const
Reports whether previous computation was successful.
EigendecompositionResult dense(const MatrixType &m, const ComputationStrategy &strategy, const EigendecompositionStrategy &eigen_strategy, IndexType target_dimension)
An exception type that is thrown when eigendecomposition is failed.
EigendecompositionResult randomized(const MatrixType &m, const ComputationStrategy &strategy, const EigendecompositionStrategy &eigen_strategy, IndexType target_dimension)
Eigen::SparseMatrix< tapkee::ScalarType > SparseWeightMatrix
sparse weight matrix type (non-overridable)
EigendecompositionResult arpack(const MatrixType &m, const ComputationStrategy &strategy, const EigendecompositionStrategy &eigen_strategy, IndexType target_dimension)
EigendecompositionResult arpack(const SparseWeightMatrix &m, const ComputationStrategy &strategy, const EigendecompositionStrategy &eigen_strategy, IndexType target_dimension)
static const EigenMethod Arpack("Arpack")
ARPACK-based method (requires the ARPACK library binaries to be available around). Recommended to be used as a default method. Supports both generalized and standard eigenproblems.
EigendecompositionResult dense(const SparseWeightMatrix &m, const ComputationStrategy &strategy, const EigendecompositionStrategy &eigen_strategy, IndexType target_dimension)
int IndexType
indexing type (non-overridable) set to int for compatibility with OpenMP 2.0
EigendecompositionResult eigendecomposition_impl_dense(const MatrixType &wm, IndexType target_dimension, unsigned int skip)
Eigen library dense implementation of eigendecomposition-based embedding.
static const ComputationStrategy HomogeneousCPUStrategy("CPU")
Eigen::SelfAdjointEigenSolver< tapkee::DenseMatrix > DenseSelfAdjointEigenSolver
selfadjoint solver (non-overridable)
static const EigendecompositionStrategy LargestEigenvalues("Largest eigenvalues", 0)
void message_info(const std::string &msg)
std::string get_eigen_method_name(const EigenMethod &m)
EigendecompositionResult arpack(const DenseMatrix &m, const ComputationStrategy &strategy, const EigendecompositionStrategy &eigen_strategy, IndexType target_dimension)
const Matrix< Scalar, Dynamic, 1 > & eigenvalues() const
Returns the eigenvalues of given matrix.
static LoggingSingleton & instance()
EigendecompositionResult eigendecomposition_impl_arpack(const MatrixType &wm, IndexType target_dimension, unsigned int skip)
ARPACK implementation of eigendecomposition-based embedding.
ScalarType gaussian_random()
An exception type that is thrown when unsupported method is called.
TAPKEE_INTERNAL_PAIR< tapkee::DenseMatrix, tapkee::DenseVector > EigendecompositionResult
size_t getNbrIterations() const
tapkee::DenseMatrix DenseSymmetricMatrix
dense symmetric matrix (non-overridable, currently just dense matrix, can be improved later) ...
bool is(const M &m) const