26#include <Eigen/Sparse>
32using Sparse = Eigen::SparseMatrix<double>;
56template <
class Operator>
78 const boost::optional<Vector> initial = boost::none)
79 :
A_(A), dim_(A.rows()), nrIterations_(0) {
81 x0 = initial ? initial.get() : Vector::Random(dim_);
113 const Vector x = ritzVector_;
115 const double ritzValue = x.dot(
A_ * x);
116 const double error = (
A_ * x - ritzValue * x).norm();
129 bool compute(
size_t maxIterations,
double tol) {
131 bool isConverged =
false;
133 for (
size_t i = 0; i < maxIterations && !isConverged; i++) {
138 ritzValue_ = ritzVector_.dot(
A_ * ritzVector_);
typedef and functions to augment Eigen's MatrixXd
typedef and functions to augment Eigen's VectorXd
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
Compute maximum Eigenpair with power method.
Definition: PowerMethod.h:57
Vector powerIteration(const Vector &x) const
Run power iteration to get ritzVector with previous ritzVector x, and return A * x / || A * x ||.
Definition: PowerMethod.h:95
Vector eigenvector() const
Return the eigenvector.
Definition: PowerMethod.h:149
const Operator & A_
Const reference to an externally-held matrix whose minimum-eigenvalue we want to compute.
Definition: PowerMethod.h:63
double eigenvalue() const
Return the eigenvalue.
Definition: PowerMethod.h:146
PowerMethod(const Operator &A, const boost::optional< Vector > initial=boost::none)
Construct from the aim matrix and intial ritz vector.
Definition: PowerMethod.h:77
Vector powerIteration() const
Run power iteration to get ritzVector with previous ritzVector x, and return A * x / || A * x ||.
Definition: PowerMethod.h:105
bool converged(double tol) const
After Perform power iteration on a single Ritz value, check if the Ritz residual for the current Ritz...
Definition: PowerMethod.h:112
bool compute(size_t maxIterations, double tol)
Start the power/accelerated iteration, after performing the power/accelerated iteration,...
Definition: PowerMethod.h:129
size_t nrIterations() const
Return the number of iterations.
Definition: PowerMethod.h:121