Loading...
Searching...
No Matches
DerivativeSKI.h
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// Copyright (c) gpridge developers
3//
4// D-SKI and D-SKIP: structured kernel interpolation for a gradient-enhanced GP.
5// Eriksson, Dong, Lee, Bindel, Wilson, "Scaling Gaussian Process Regression
6// with Derivatives", NeurIPS 2018, DOI 10.48550/arxiv.1810.12283.
7//
8// SKI replaces the kernel by an interpolation through a regular grid,
9// k(x,x') ~ w(x)^T K_UU w(x'), with w the cubic-convolution weights (four
10// nonzeros per point). D-SKI differentiates the interpolation rather than the
11// kernel, so the joint energy/gradient matrix inherits the same factor:
12//
13// [ K dK ] [ W ] [ W ]^T
14// [ dK^T d2K ] ~ [ dW ] K_UU [ dW ]
15//
16// which costs one K_UU multiply instead of an (n(d+1))^2 assembly.
17//
18// The grid is m^d points, so D-SKI alone is confined to low dimension. D-SKIP
19// carries it to higher d by keeping the ARD product form
20// k(x,x') = prod_i k_i(x_i,x_i') and compressing each pairwise product of
21// one-dimensional factors back to low rank with Lanczos.
22//
23// Whether that helps *this* kernel is an empirical question, not an assumption:
24// interpolation error and rank growth are measured against the exact matrix by
25// DerivativeSKI::approximationError and the DSkipProduct rank report.
26
27#ifndef GPR_ML_GP_DERIVATIVE_SKI_H_
28#define GPR_ML_GP_DERIVATIVE_SKI_H_
29
30#include <Eigen/Core>
31#include <cstdint>
32#include <vector>
33
34namespace gpr {
35namespace ski {
36
39[[nodiscard]] double cubicConvolutionWeight(double s) noexcept;
40[[nodiscard]] double cubicConvolutionWeightDerivative(double s) noexcept;
41
47 Eigen::MatrixXd W;
48 Eigen::MatrixXd dW;
49 Eigen::Index out_of_grid;
50};
51
55public:
56 UniformGrid(double lo, double hi, Eigen::Index m);
57
58 [[nodiscard]] Eigen::Index size() const noexcept
59 {
60 return m_;
61 }
62 [[nodiscard]] double spacing() const noexcept
63 {
64 return h_;
65 }
66 [[nodiscard]] double at(Eigen::Index i) const noexcept
67 {
68 return origin_ + static_cast<double>(i) * h_;
69 }
70
71 [[nodiscard]] double indexOf(double x) const noexcept
72 {
73 return (x - origin_) / h_;
74 }
75
76private:
77 double origin_ = 0.0;
78 double h_ = 1.0;
79 Eigen::Index m_ = 0;
80};
81
82[[nodiscard]] InterpolationWeights interpolate(const UniformGrid& grid,
83 const Eigen::VectorXd& x);
84
93public:
97 DerivativeSKI(const Eigen::VectorXd& x, double lengthscale, Eigen::Index m);
98
99 [[nodiscard]] Eigen::Index numPoints() const noexcept
100 {
101 return n_;
102 }
103 [[nodiscard]] Eigen::Index gridSize() const noexcept
104 {
105 return grid_.size();
106 }
107 [[nodiscard]] Eigen::Index outOfGrid() const noexcept
108 {
109 return out_of_grid_;
110 }
111
113 [[nodiscard]] const Eigen::VectorXd& gridKernelRow() const noexcept
114 {
115 return kuu_row_;
116 }
117
119 [[nodiscard]] Eigen::VectorXd applyGridKernel(
120 const Eigen::VectorXd& v) const;
121
125 [[nodiscard]] Eigen::MatrixXd denseJoint() const;
126
129 [[nodiscard]] static Eigen::MatrixXd exactJoint(const Eigen::VectorXd& x,
130 double lengthscale);
131
133 [[nodiscard]] double approximationError() const;
134
135private:
136 UniformGrid grid_;
137 Eigen::MatrixXd W_;
138 Eigen::MatrixXd dW_;
139 Eigen::VectorXd kuu_row_;
140 Eigen::VectorXd x_;
141 double lengthscale_ = 1.0;
142 Eigen::Index n_ = 0;
143 Eigen::Index out_of_grid_ = 0;
144};
145
154 std::vector<Eigen::Index> rank_after_product;
155 double relative_error = 0.0;
156 Eigen::Index exact_rank = 0;
157 bool rank_bounded = false;
158};
159
162[[nodiscard]] Eigen::MatrixXd lanczosLowRank(const Eigen::MatrixXd& A,
163 double tol, Eigen::Index max_rank);
164
167[[nodiscard]] DSkipReport dskipProduct(const Eigen::MatrixXd& x,
168 const Eigen::VectorXd& lengthscales,
169 double tol, Eigen::Index max_rank);
170
171} // namespace ski
172} // namespace gpr
173
174#endif // GPR_ML_GP_DERIVATIVE_SKI_H_
@ x
Definition Enums.h:28
Eigen::VectorXd applyGridKernel(const Eigen::VectorXd &v) const
y = K_UU v, using the Toeplitz structure.
Eigen::Index gridSize() const noexcept
Eigen::Index outOfGrid() const noexcept
static Eigen::MatrixXd exactJoint(const Eigen::VectorXd &x, double lengthscale)
const Eigen::VectorXd & gridKernelRow() const noexcept
First row of the symmetric Toeplitz grid kernel.
double approximationError() const
Relative Frobenius error ||A_ski - A_exact|| / ||A_exact||.
DerivativeSKI(const Eigen::VectorXd &x, double lengthscale, Eigen::Index m)
Eigen::MatrixXd denseJoint() const
Eigen::Index numPoints() const noexcept
double spacing() const noexcept
double at(Eigen::Index i) const noexcept
UniformGrid(double lo, double hi, Eigen::Index m)
Eigen::Index size() const noexcept
double indexOf(double x) const noexcept
Grid coordinate of x in index units.
double cubicConvolutionWeight(double s) noexcept
DSkipReport dskipProduct(const Eigen::MatrixXd &x, const Eigen::VectorXd &lengthscales, double tol, Eigen::Index max_rank)
Eigen::MatrixXd lanczosLowRank(const Eigen::MatrixXd &A, double tol, Eigen::Index max_rank)
InterpolationWeights interpolate(const UniformGrid &grid, const Eigen::VectorXd &x)
double cubicConvolutionWeightDerivative(double s) noexcept
Gaussian-process regression, kernels, priors, and the searches that run on the surrogate.
Definition Macros.h:16
double relative_error
against the exact product
Eigen::Index exact_rank
numerical rank of the exact matrix
bool rank_bounded
did the rank stay below the matrix size
std::vector< Eigen::Index > rank_after_product
one entry per dimension
Eigen::MatrixXd W
n x m, rows sum to 1 on interior points
Eigen::Index out_of_grid
inputs with no support
Eigen::MatrixXd dW
n x m, d/dx of each row