26using Sparse = Eigen::SparseMatrix<double>;
50template <
class Operator>
55 Vector previousVector_;
63 const Operator &A,
const boost::optional<Vector> initial = boost::none,
64 double initialBeta = 0.0)
67 this->ritzVector_ = initial ? initial.get() : Vector::Random(this->dim_);
68 this->ritzVector_.normalize();
69 previousVector_ = Vector::Zero(this->dim_);
81 const double beta)
const {
82 Vector y = this->
A_ * x1 - beta * x0;
103 Vector initVector = this->ritzVector_;
104 const double up = initVector.dot( this->
A_ * initVector );
105 const double down = initVector.dot(initVector);
106 const double mu = up / down;
107 double maxBeta = mu * mu / 4;
109 std::vector<double> betas;
111 Matrix R = Matrix::Zero(this->dim_, 10);
113 for (
size_t t = 0; t < T; t++) {
115 betas = {2 / 3 * maxBeta, 0.99 * maxBeta, maxBeta, 1.01 * maxBeta,
118 for (
size_t k = 0; k < betas.size(); ++k) {
120 Vector x0 = initVector;
121 Vector x00 = Vector::Zero(this->dim_);
123 for (
size_t j = 1; j < 10; j++) {
134 const Vector x = R.col(9);
135 const double up = x.dot(this->
A_ * x);
136 const double down = x.dot(x);
137 const double mu = up / down;
139 if (mu * mu / 4 > maxBeta) {
142 maxBeta = mu * mu / 4;
147 return betas[maxIndex];
156 bool compute(
size_t maxIterations,
double tol) {
158 bool isConverged =
false;
160 for (
size_t i = 0; i < maxIterations && !isConverged; i++) {
161 ++(this->nrIterations_);
162 Vector tmp = this->ritzVector_;
166 previousVector_ = tmp;
168 this->ritzValue_ = this->ritzVector_.dot(this->
A_ * this->ritzVector_);
Power method for fast eigenvalue and eigenvector computation.
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
Compute maximum Eigenpair with accelerated power method.
Definition: AcceleratedPowerMethod.h:51
Vector acceleratedPowerIteration(const Vector &x1, const Vector &x0, const double beta) const
Run accelerated power iteration to get ritzVector with beta and previous two ritzVector x0 and x00,...
Definition: AcceleratedPowerMethod.h:80
AcceleratedPowerMethod(const Operator &A, const boost::optional< Vector > initial=boost::none, double initialBeta=0.0)
Constructor from aim matrix A (given as Matrix or Sparse), optional intial vector as ritzVector.
Definition: AcceleratedPowerMethod.h:62
double estimateBeta(const size_t T=10) const
Tuning the momentum beta using the Best Heavy Ball algorithm in Ref(3), T is the iteration time to fi...
Definition: AcceleratedPowerMethod.h:101
Vector acceleratedPowerIteration() const
Run accelerated power iteration to get ritzVector with beta and previous two ritzVector x0 and x00,...
Definition: AcceleratedPowerMethod.h:92
bool compute(size_t maxIterations, double tol)
Start the accelerated iteration, after performing the accelerated iteration, calculate the ritz error...
Definition: AcceleratedPowerMethod.h:156
Compute maximum Eigenpair with power method.
Definition: PowerMethod.h:57
const Operator & A_
Const reference to an externally-held matrix whose minimum-eigenvalue we want to compute.
Definition: PowerMethod.h:63
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