Loading...
Searching...
No Matches
gpr::linalg::linop::LanczosVarianceCache Class Reference

#include <gpr/linalg/linop/Krylov.h>

Classes

struct  Quadratic

Public Member Functions

 LanczosVarianceCache (const SymmetricOperator &K, const Eigen::VectorXd &start)
Quadratic quadraticDiagonal (const Eigen::MatrixXd &C, double tolerance, double lambda_min, double flop_budget)
Eigen::Index steps () const noexcept

Detailed Description

Lanczos basis of K from one start vector, kept with full reorthogonalisation so that the cached quadratic forms c^T Q T^{-1} Q^T c are lower bounds on c^T K^{-1} c with a computable gap.

Definition at line 86 of file Krylov.h.

Constructor & Destructor Documentation

◆ LanczosVarianceCache()

gpr::linalg::linop::LanczosVarianceCache::LanczosVarianceCache ( const SymmetricOperator & K,
const Eigen::VectorXd & start )

Definition at line 199 of file Krylov.cpp.

201 : K_(K)
202{
203 if (start.size() != K.order())
204 throw std::invalid_argument("Lanczos start vector has the wrong order");
205 next_norm_ = start.norm();
206 if (!(next_norm_ > 0.0) || !std::isfinite(next_norm_))
207 throw std::invalid_argument("Lanczos start vector must be nonzero");
208 next_ = start / next_norm_;
209 Q_.resize(K.order(), 0);
210}

Member Function Documentation

◆ quadraticDiagonal()

LanczosVarianceCache::Quadratic gpr::linalg::linop::LanczosVarianceCache::quadraticDiagonal ( const Eigen::MatrixXd & C,
double tolerance,
double lambda_min,
double flop_budget )
nodiscard

Extend the basis until every column's bound is below tolerance or the next step would exceed flop_budget. lambda_min is a lower bound on the smallest eigenvalue of K (the noise floor).

Definition at line 268 of file Krylov.cpp.

271{
272 if (C.rows() != K_.order() || !(lambda_min > 0.0))
273 throw std::invalid_argument("invalid Lanczos variance query");
274 const double start_flops = flops_;
275 double spent_on_queries = 0.0;
276 Quadratic out = evaluate(C, lambda_min);
277 spent_on_queries += out.flops;
278 // Double the basis between checks so evaluation stays a fixed fraction
279 // of the Lanczos work.
280 Eigen::Index target = std::max<Eigen::Index>(1, steps());
281 while (!(out.error_bound.maxCoeff() <= tolerance)) {
282 target = std::min<Eigen::Index>(K_.order(), 2 * target);
283 const double step_flops =
284 K_.applyFlops(1) + 8.0 * static_cast<double>(K_.order() * target);
285 bool grew = false;
286 while (steps() < target) {
287 if (flops_ - start_flops + spent_on_queries + step_flops >
288 flop_budget)
289 break;
290 if (!extend()) break;
291 grew = true;
292 }
293 if (!grew) break;
294 out = evaluate(C, lambda_min);
295 spent_on_queries += out.flops;
296 if (exhausted_ || steps() >= K_.order()) break;
297 }
298 out.within_tolerance = out.error_bound.maxCoeff() <= tolerance;
299 out.flops = flops_ - start_flops + spent_on_queries;
300 return out;
301}
Eigen::Index steps() const noexcept
Definition Krylov.h:106
eon_relax_band_t eon_relax_surface_fn void eon_relax_outcome_t * out

◆ steps()

Eigen::Index gpr::linalg::linop::LanczosVarianceCache::steps ( ) const
inlinenodiscardnoexcept

Definition at line 106 of file Krylov.h.

107 {
108 return static_cast<Eigen::Index>(alpha_.size());
109 }

The documentation for this class was generated from the following files: