Loading...
Searching...
No Matches
LowRankSolve.h
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// Copyright (c) gpridge developers
3//
4// Low-rank solver for the gradient-enhanced GP: pivoted partial Cholesky of the
5// (PSD, numerically low-rank) training kernel K + a Woodbury noisy solve. This
6// is the fast np=1 GP core (#88): O(nobs^2 r) instead of
7// the HS-SVD eigen-form's O(nobs * N_modes * r) (N_modes = 2925 Mercer
8// functions at degree 24), since it works on the nobs x nobs kernel directly --
9// no Mercer modes. It never factors the full ill-conditioned K to completion:
10// the pivoted factorization stops at the numerical rank, dropping the tiny tail
11// eigenvalues that carry the conditioning, and the Woodbury inner system is
12// sigma^2-regularized. Math: scripts/derive_rank_reduction.py (Woodbury
13// identity verified in SymPy); Fine-Scheinberg 2001; Harbrecht-Peters-Schneider
14// 2012 (||K - L L^T||_tr = sum of dropped pivots); Williams-Seeger 2001.
15
16#ifndef GPR_ML_GP_LOW_RANK_SOLVE_H_
17#define GPR_ML_GP_LOW_RANK_SOLVE_H_
18
19#include <Eigen/Core>
20
21namespace gpr {
22
23// Pivoted partial Cholesky of a symmetric PSD matrix K (nobs x nobs):
24// K ~ L L^T, L in R^{nobs x r}, with greedy diagonal-residual pivoting.
25// Stops when the largest residual diagonal <= rtol * trace0 (relative tail
26// energy) or r == max_rank. The factor L holds the kept Cholesky columns in the
27// PIVOTED order mapped back to original rows (L is lower-trapezoidal up to the
28// pivot permutation, but stored in original-row layout so L L^T ~ K directly).
29// Returns the achieved rank r. K is read-only; an O(nobs^2) scratch copy of the
30// residual is used internally.
32public:
33 // Factorize K -> L (nobs x rank). rtol is the relative trace-residual stop;
34 // max_rank caps the rank (<=0 means nobs).
35 void factorize(const Eigen::MatrixXd& K, double rtol = 1e-12,
36 int max_rank = 0);
37
38 int rank() const
39 {
40 return static_cast<int>(L_.cols());
41 }
42 Eigen::Index numObs() const
43 {
44 return L_.rows();
45 }
46 const Eigen::MatrixXd& factor() const
47 {
48 return L_;
49 } // nobs x rank
50
51 // alpha = (K + sigma2 I)^{-1} y via Woodbury with K ~ L L^T:
52 // (L L^T + sigma2 I)^{-1} y
53 // = (1/sigma2) [ y - L (sigma2 I_r + L^T L)^{-1} (L^T y) ].
54 // The inner r x r system M = sigma2 I_r + L^T L is SPD and well-conditioned
55 // (sigma2 floor); it is Cholesky-factored once in factorizeInner().
56 Eigen::VectorXd solveNoisy(const Eigen::VectorXd& y, double sigma2) const;
57
58 // log det(K + sigma2 I) for the marginal likelihood, via the matrix
59 // determinant lemma:
60 // log det(L L^T + sigma2 I)
61 // = (nobs - r) log sigma2 + log det(sigma2 I_r + L^T L).
62 double logDetNoisy(double sigma2) const;
63
64private:
65 Eigen::MatrixXd L_; // nobs x rank low-rank Cholesky factor (K ~ L L^T)
66};
67
68} // namespace gpr
69
70#endif // GPR_ML_GP_LOW_RANK_SOLVE_H_
@ y
Definition Enums.h:28
void factorize(const Eigen::MatrixXd &K, double rtol=1e-12, int max_rank=0)
Eigen::Index numObs() const
Eigen::VectorXd solveNoisy(const Eigen::VectorXd &y, double sigma2) const
double logDetNoisy(double sigma2) const
const Eigen::MatrixXd & factor() const
Gaussian-process regression, kernels, priors, and the searches that run on the surrogate.
Definition Macros.h:16