Compute an approximate SVD with IRLBA.
More...
#include <cmath>
#include <cstdint>
#include <random>
#include <stdexcept>
#include <type_traits>
#include "utils.hpp"
#include "lanczos.hpp"
#include "Matrix/simple.hpp"
#include "sanisizer/sanisizer.hpp"
#include "Eigen/Dense"
Go to the source code of this file.
|
| template<class Matrix_ , class EigenMatrix_ , class EigenVector_ > |
| std::pair< bool, int > | irlba::compute (const Matrix_ &matrix, const Eigen::Index number, EigenMatrix_ &outU, EigenMatrix_ &outV, EigenVector_ &outD, const Options< EigenVector_ > &options) |
| |
| template<class InputEigenMatrix_ , class OutputEigenMatrix_ , class EigenVector_ > |
| std::pair< bool, int > | irlba::compute_simple (const InputEigenMatrix_ &matrix, Eigen::Index number, OutputEigenMatrix_ &outU, OutputEigenMatrix_ &outV, EigenVector_ &outD, const Options< EigenVector_ > &options) |
| |
| template<class EigenMatrix_ = Eigen::MatrixXd, class EigenVector_ = Eigen::VectorXd, class Matrix_ > |
| Results< EigenMatrix_, EigenVector_ > | irlba::compute (const Matrix_ &matrix, Eigen::Index number, const Options< EigenVector_ > &options) |
| |
| template<class OutputEigenMatrix_ = Eigen::MatrixXd, class EigenVector_ = Eigen::VectorXd, class InputEigenMatrix_ > |
| Results< OutputEigenMatrix_, EigenVector_ > | irlba::compute_simple (const InputEigenMatrix_ &matrix, Eigen::Index number, const Options< EigenVector_ > &options) |
| |
Compute an approximate SVD with IRLBA.
◆ compute() [1/2]
template<class Matrix_ , class EigenMatrix_ , class EigenVector_ >
| std::pair< bool, int > irlba::compute |
( |
const Matrix_ & | matrix, |
|
|
const Eigen::Index | number, |
|
|
EigenMatrix_ & | outU, |
|
|
EigenMatrix_ & | outV, |
|
|
EigenVector_ & | outD, |
|
|
const Options< EigenVector_ > & | options ) |
Implements the Implicitly Restarted Lanczos Bidiagonalization Algorithm (IRLBA) for fast truncated singular value decomposition. This is heavily derived from the C code in the irlba package, with refactoring into C++ to use Eigen instead of LAPACK for much of the matrix algebra.
- Template Parameters
-
| Matrix_ | Class satisfying the Matrix<EigenVector_, EigenMatrix_> interface. |
| EigenMatrix_ | A dense floating-point Eigen::Matrix class to store the output. |
| EigenVector_ | A floating-point Eigen::Vector class to store the output, typically of the same scalar type as EigenMatrix_. |
- Parameters
-
| [in] | matrix | Input matrix. |
| number | Number of singular triplets to obtain. The returned number of triplets may be lower, see Options::cap_number for details. |
| [out] | outU | Output matrix containing the left singular vectors corresponding to the largest singular values. Each column corresponds to a left singular vector, of which there are number (or less, depending on Options::cap_number). The number of rows is equal to the number of rows in mat. |
| [out] | outV | Output matrix containing the right singular vectors corresponding to the largest singular values. Each column corresponds to a right singular vector, of which there are number (or less, depending on Options::cap_number). The number of rows is equal to the number of columns in mat. |
| [out] | outD | Output vector containing the largest singular values, ordered by decreasing size. This has length equal to number (or lower, depending on Options::cap_number). |
| options | Further options. |
- Returns
- A pair where the first entry indicates whether the algorithm converged, and the second entry indicates the number of restart iterations performed.
◆ compute() [2/2]
template<class EigenMatrix_ = Eigen::MatrixXd, class EigenVector_ = Eigen::VectorXd, class Matrix_ >
| Results< EigenMatrix_, EigenVector_ > irlba::compute |
( |
const Matrix_ & | matrix, |
|
|
Eigen::Index | number, |
|
|
const Options< EigenVector_ > & | options ) |
Convenient overload of compute() that allocates memory for the output matrices of the SVD.
- Template Parameters
-
| EigenMatrix_ | A dense floating-point Eigen::Matrix class to store the output. |
| EigenVector_ | A floating-point Eigen::Vector class for the output, typically of the same scalar type as EigenMatrix_. |
| Matrix_ | Class satisfying the Matrix<EigenVector_, EigenMatrix_> interface. |
- Parameters
-
| [in] | matrix | Input matrix. |
| number | Number of singular triplets to obtain. |
| options | Further options. |
- Returns
- A
Results object containing the singular vectors and values, as well as some statistics on convergence.
◆ compute_simple() [1/2]
template<class OutputEigenMatrix_ = Eigen::MatrixXd, class EigenVector_ = Eigen::VectorXd, class InputEigenMatrix_ >
| Results< OutputEigenMatrix_, EigenVector_ > irlba::compute_simple |
( |
const InputEigenMatrix_ & | matrix, |
|
|
Eigen::Index | number, |
|
|
const Options< EigenVector_ > & | options ) |
Convenient overload of compute() that accepts an Eigen matrix directly.
- Template Parameters
-
| InputEigenMatrix_ | An Eigen matrix class containing the input data. |
| OutputEigenMatrix_ | A dense floating-point Eigen::Matrix class for the output. |
| EigenVector_ | A floating-point Eigen::Vector class for the output, typically of the same scalar type as OutputEigenMatrix_. |
| Matrix_ | Class satisfying the Matrix<EigenVector_, EigenMatrix_> interface. |
- Parameters
-
| [in] | matrix | Input matrix. |
| number | Number of singular triplets to obtain. |
| options | Further options. |
- Returns
- A
Results object containing the singular vectors and values, as well as some statistics on convergence.
◆ compute_simple() [2/2]
template<class InputEigenMatrix_ , class OutputEigenMatrix_ , class EigenVector_ >
| std::pair< bool, int > irlba::compute_simple |
( |
const InputEigenMatrix_ & | matrix, |
|
|
Eigen::Index | number, |
|
|
OutputEigenMatrix_ & | outU, |
|
|
OutputEigenMatrix_ & | outV, |
|
|
EigenVector_ & | outD, |
|
|
const Options< EigenVector_ > & | options ) |
Convenient overload of compute() that accepts an Eigen matrix directly.
- Template Parameters
-
| InputEigenMatrix_ | An Eigen matrix class containing the input data. |
| OutputEigenMatrix_ | A dense floating-point Eigen::Matrix class to store the output. |
| EigenVector_ | A floating-point Eigen::Vector class to store the output, typically of the same scalar type as EigenMatrix_. |
- Parameters
-
| [in] | matrix | Input matrix. |
| number | Number of singular triplets to obtain. The returned number of triplets may be lower, see Options::cap_number for details. |
| [out] | outU | Output matrix containing the left singular vectors corresponding to the largest singular values. Each column corresponds to a left singular vector, of which there are number (or less, depending on Options::cap_number). The number of rows is equal to the number of rows in mat. |
| [out] | outV | Output matrix containing the right singular vectors corresponding to the largest singular values. Each column corresponds to a right singular vector, of which there are number (or less, depending on Options::cap_number). The number of rows is equal to the number of columns in mat. |
| [out] | outD | Output vector containing the largest singular values, ordered by decreasing size. This has length equal to number (or lower, depending on Options::cap_number). |
| options | Further options. |
- Returns
- A pair where the first entry indicates whether the algorithm converged, and the second entry indicates the number of restart iterations performed.