Loading...
Searching...
No Matches
Preconditioner.h
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// Copyright (c) gpridge developers
3// See LICENSE for details.
4
5// Partial pivoted Cholesky of the kernel part A0 of K = A0 + diag(s), and the
6// preconditioner P = F F^T + diag(s) it defines (Gardner et al., "GPyTorch",
7// NeurIPS 2018). K - P is the positive semi-definite pivot residual E, so the
8// eigenvalues of P^{-1} K lie in [1, 1 + lambda_max(E) / min(s)] and
9// 1 + tr(E) / min(s) bounds the condition number CG sees.
10
11#ifndef GPR_LINALG_LINOP_PRECONDITIONER_H_
12#define GPR_LINALG_LINOP_PRECONDITIONER_H_
13
14#include <Eigen/Cholesky>
15#include <Eigen/Core>
16#include <functional>
17#include <vector>
18
19#include "Operator.h"
20
21namespace gpr::linalg::linop {
22
24 Eigen::MatrixXd factor;
25 std::vector<Eigen::Index> pivots;
26 Eigen::VectorXd residual_diagonal;
28 std::vector<double> residual_trace;
30 double flops = 0.0;
31};
32
37 const SymmetricOperator& kernel,
38 const std::function<bool(Eigen::Index, double, double)>& keep_going);
39
41[[nodiscard]] double pivotFlops(double column_flops, Eigen::Index order,
42 Eigen::Index rank);
43
47[[nodiscard]] std::vector<double> schurResidualTraces(const Eigen::MatrixXd& L);
48
50public:
52 PivotedCholeskyPreconditioner(Eigen::MatrixXd factor,
53 Eigen::VectorXd shift);
54
55 [[nodiscard]] Eigen::Index order() const noexcept
56 {
57 return shift_.size();
58 }
59 [[nodiscard]] Eigen::Index rank() const noexcept
60 {
61 return factor_.cols();
62 }
63 [[nodiscard]] bool valid() const noexcept
64 {
65 return valid_;
66 }
67
69 [[nodiscard]] Eigen::MatrixXd solve(const Eigen::MatrixXd& X) const;
71 [[nodiscard]] Eigen::MatrixXd apply(const Eigen::MatrixXd& X) const;
72 [[nodiscard]] double logDeterminant() const;
75 [[nodiscard]] Eigen::MatrixXd sample(const Eigen::MatrixXd& G) const;
76 [[nodiscard]] double solveFlops(Eigen::Index rhs) const;
77
78private:
79 Eigen::MatrixXd factor_;
80 Eigen::VectorXd shift_;
81 Eigen::VectorXd inv_shift_;
82 Eigen::LLT<Eigen::MatrixXd> capacitance_;
83 bool valid_ = false;
84};
85
86} // namespace gpr::linalg::linop
87
88#endif // GPR_LINALG_LINOP_PRECONDITIONER_H_
Eigen::MatrixXd apply(const Eigen::MatrixXd &X) const
P X.
Eigen::MatrixXd solve(const Eigen::MatrixXd &X) const
P^{-1} X by Woodbury.
Eigen::MatrixXd sample(const Eigen::MatrixXd &G) const
std::vector< double > schurResidualTraces(const Eigen::MatrixXd &L)
double pivotFlops(double column_flops, Eigen::Index order, Eigen::Index rank)
Pivot cost: one column read and the update against the previous pivots.
PartialCholesky partialPivotedCholesky(const SymmetricOperator &kernel, const std::function< bool(Eigen::Index, double, double)> &keep_going)
Eigen::MatrixXd factor
order x rank
std::vector< Eigen::Index > pivots
double flops
Operations spent, counting column reads at the operator's cost.
std::vector< double > residual_trace
residual_trace[r] = tr(A0 - F_r F_r^T) after r pivots.