26#include <Eigen/Sparse>
33using Sparse = Eigen::SparseMatrix<double>;
57template <
class Operator>
79 const std::optional<Vector> initial = {})
80 :
A_(A), dim_(A.rows()), nrIterations_(0) {
82 x0 = initial ? *initial : Vector::Random(dim_);
114 const Vector x = ritzVector_;
116 const double ritzValue = x.dot(
A_ * x);
117 const double error = (
A_ * x - ritzValue * x).norm();
130 bool compute(
size_t maxIterations,
double tol) {
132 bool isConverged =
false;
133 if (maxIterations == 0)
return isConverged;
135 Vector product =
A_ * ritzVector_;
137 for (
size_t i = 0; i < maxIterations && !isConverged; i++) {
140 ritzVector_ = product;
141 ritzVector_.normalize();
144 product =
A_ * ritzVector_;
145 ritzValue_ = ritzVector_.dot(product);
146 const double error = (product - ritzValue_ * ritzVector_).norm();
147 isConverged = error < tol;
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
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:96
Vector eigenvector() const
Return the eigenvector.
Definition PowerMethod.h:157
const Operator & A_
Const reference to an externally-held matrix whose minimum-eigenvalue we want to compute.
Definition PowerMethod.h:64
double eigenvalue() const
Return the eigenvalue.
Definition PowerMethod.h:154
Vector powerIteration() const
Run power iteration to get ritzVector with previous ritzVector x, and return A * x / || A * x ||.
Definition PowerMethod.h:106
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:113
PowerMethod(const Operator &A, const std::optional< Vector > initial={})
Construct from the aim matrix and intial ritz vector.
Definition PowerMethod.h:78
bool compute(size_t maxIterations, double tol)
Start the power/accelerated iteration, after performing the power/accelerated iteration,...
Definition PowerMethod.h:130
size_t nrIterations() const
Return the number of iterations.
Definition PowerMethod.h:122