Loading...
Searching...
No Matches
IterGP.h
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// Copyright (c) gpridge developers
3//
4// IterGP: posterior and computational uncertainty in Gaussian processes.
5// Wenger, Pleiss, Hennig, Cunningham, Weinberger, NeurIPS 2022,
6// DOI 10.48550/arxiv.2205.15449.
7//
8// A GP whose linear solve has not converged is not a GP with a slightly wrong
9// posterior -- it is a GP whose posterior is unknown in the directions the
10// solver never explored. IterGP makes that explicit. After i actions
11// S = [s_1 ... s_i] the solver has learned K^{-1} only on span(S), and the
12// representer weights and posterior covariance are
13//
14// C_i = S (S^T K_hat S)^{-1} S^T, v_i = C_i y
15// Sigma_i(x,x') = k(x,x') - k(x)^T C_i k(x')
16//
17// with K_hat = K + sigma^2 I. Because C_i <= K_hat^{-1} in the Loewner order,
18// Sigma_i is an UPPER bound on the exact posterior covariance: the belief is
19// never tighter than the computation justifies. That is the property this
20// codebase wants, where an ill-conditioned kernel plus a truncated CG solve
21// otherwise yields confident extrapolation.
22//
23// The split is additive and exact:
24//
25// Sigma_i = Sigma_exact + (k(x)^T (K_hat^{-1} - C_i) k(x'))
26// \________/ \____________________________/
27// mathematical computational
28//
29// so a caller can report which part of its uncertainty comes from having
30// finite data and which from having stopped solving early.
31
32#ifndef GPR_ML_GP_ITERGP_H_
33#define GPR_ML_GP_ITERGP_H_
34
35#include <Eigen/Cholesky>
36#include <Eigen/Core>
37
38namespace gpr {
39namespace itergp {
40
48
54class IterGP {
55public:
59 void run(const Eigen::MatrixXd& K_hat, const Eigen::VectorXd& y,
61
62 [[nodiscard]] int iterations() const noexcept
63 {
64 return static_cast<int>(S_.cols());
65 }
66
68 [[nodiscard]] const Eigen::MatrixXd& actions() const noexcept
69 {
70 return S_;
71 }
72
74 [[nodiscard]] const Eigen::VectorXd& representerWeights() const noexcept
75 {
76 return v_;
77 }
78
81 [[nodiscard]] Eigen::MatrixXd inverseApproximation() const;
82
84 [[nodiscard]] double posteriorMean(const Eigen::VectorXd& kx) const;
85
88 [[nodiscard]] double combinedVariance(double kxx,
89 const Eigen::VectorXd& kx) const;
90
94 [[nodiscard]] double computationalVariance(
95 const Eigen::LDLT<Eigen::MatrixXd>& exact,
96 const Eigen::VectorXd& kx) const;
97
99 [[nodiscard]] double relativeResidual(const Eigen::MatrixXd& K_hat,
100 const Eigen::VectorXd& y) const;
101
102private:
103 Eigen::MatrixXd S_;
104 Eigen::MatrixXd KS_;
105 Eigen::MatrixXd Sinv_;
106 Eigen::VectorXd v_;
107};
108
109} // namespace itergp
110} // namespace gpr
111
112#endif // GPR_ML_GP_ITERGP_H_
@ y
Definition Enums.h:28
double posteriorMean(const Eigen::VectorXd &kx) const
Posterior mean at a test point with cross-covariance k(x) = K_xn.
Definition IterGP.cpp:102
const Eigen::MatrixXd & actions() const noexcept
The actions taken, n x i.
Definition IterGP.h:68
double relativeResidual(const Eigen::MatrixXd &K_hat, const Eigen::VectorXd &y) const
Relative residual ||K_hat v_i - y|| / ||y||, the usual convergence view.
Definition IterGP.cpp:135
const Eigen::VectorXd & representerWeights() const noexcept
v_i = C_i y, the representer weights the run justifies.
Definition IterGP.h:74
Eigen::MatrixXd inverseApproximation() const
Definition IterGP.cpp:94
double computationalVariance(const Eigen::LDLT< Eigen::MatrixXd > &exact, const Eigen::VectorXd &kx) const
Definition IterGP.cpp:123
int iterations() const noexcept
Definition IterGP.h:62
double combinedVariance(double kxx, const Eigen::VectorXd &kx) const
Definition IterGP.cpp:110
void run(const Eigen::MatrixXd &K_hat, const Eigen::VectorXd &y, int iterations, Policy policy=Policy::ConjugateGradient)
Definition IterGP.cpp:15
@ Unit
s_i = e_i, the i-th coordinate direction
Definition IterGP.h:46
@ ConjugateGradient
s_i = residual of the current iterate
Definition IterGP.h:45
Gaussian-process regression, kernels, priors, and the searches that run on the surrogate.
Definition Macros.h:16