28#ifndef GPR_ML_LAPLACEINLA_H_
29#define GPR_ML_LAPLACEINLA_H_
88 std::function<std::tuple<EigenMatrix, EigenMatrix, Eigen::VectorXd>(
89 const Eigen::VectorXd& theta)>;
93 using LogPrior = std::function<double(
const Eigen::VectorXd& theta)>;
96 void setTheta0(
const Eigen::VectorXd& theta_star);
107 const Eigen::MatrixXd& parameter_directions);
158 void buildGrid(
double f0 = -1.0,
bool include_corners =
true);
195 [[nodiscard]]
const std::vector<Eigen::VectorXd>&
gridPoints()
208 [[nodiscard]]
int p() const noexcept
210 return static_cast<int>(theta_star_.size());
214 return static_cast<int>(theta_k_.size());
217 [[nodiscard]]
const Eigen::VectorXd&
theta0() const noexcept
226 [[nodiscard]]
const Eigen::MatrixXd&
lScale() const noexcept
239 if (L_scale_.size() == 0)
return Eigen::MatrixXd{};
240 return L_scale_ * L_scale_.transpose();
247 if (U_.size() == 0 || lambda_.size() == 0)
return Eigen::MatrixXd{};
248 return U_ * lambda_.asDiagonal() * U_.transpose();
252 double evaluateNLMLAtTheta(
const Eigen::VectorXd&
y,
KernelBuilder kb,
253 const Eigen::VectorXd& theta)
const;
255 Eigen::VectorXd theta_star_;
258 Eigen::VectorXd lambda_;
259 Eigen::MatrixXd L_scale_;
262 std::vector<Eigen::VectorXd> theta_k_;
263 std::vector<Eigen::VectorXd> z_k_;
264 Eigen::VectorXd w_grid_;
265 Eigen::VectorXd w_final_;
268 double tp_a_ = 1e-20;
269 double tp_b_ = 1e-20;
271 std::shared_ptr<ObservationLikelihood> ol_;
273 bool fitted_ =
false;
Laplace / INLA uncertainty quantifier over GP/TP hyperparameters.
@ NON_GAUSSIAN
Inner Laplace via ObservationLikelihood (future).
@ T_CLOSED_FORM
FactorizedLikelihood::evaluateTP (MVT marginal).
@ GAUSSIAN_CLOSED_FORM
FactorizedLikelihood::evaluateGP.
INLAPrediction predict(const Eigen::VectorXd &y, KernelBuilder kernel_builder) const
Predictive moments at the test points embedded in the kernel builder's K_test_X / k_test_test outputs...
const Eigen::MatrixXd & lScale() const noexcept
void fit(const Eigen::VectorXd &y, KernelBuilder kernel_builder, LogPrior log_prior)
Evaluate the per-grid-point correction rho_k = exp(-Delta phi_k) and build the final normalised weigh...
const Eigen::VectorXd & theta0() const noexcept
MAP hyperparameter point set by setTheta0. Used by SVGD initFromCCD.
void setObservationLikelihood(std::shared_ptr< ObservationLikelihood > ol)
Likelihood likelihood() const
const Eigen::VectorXd & finalWeights() const noexcept
void setHessian(const Eigen::MatrixXd &H)
Eigen::MatrixXd precisionMatrix() const
Eigen::MatrixXd hessianInverse() const
std::function< double(const Eigen::VectorXd &theta)> LogPrior
const Eigen::VectorXd & gridWeights() const noexcept
void setTPHyperprior(double a, double b)
TP hyperprior (only used when lik_ == T_CLOSED_FORM).
void setTheta0(const Eigen::VectorXd &theta_star)
MAP hyperparameters (log space if using the project's conventions).
std::function< std::tuple< EigenMatrix, EigenMatrix, Eigen::VectorXd >( const Eigen::VectorXd &theta)> KernelBuilder
int nGridPoints() const noexcept
void buildGrid(double f0=-1.0, bool include_corners=true)
Build the CCD grid in theta-space from (theta*, H).
void setLikelihood(Likelihood lik)
const std::vector< Eigen::VectorXd > & gridPoints() const noexcept
Grid accessors (for testing).
Contract for non-Gaussian observation models used by the INLA inner Laplace step (Rasmussen-Williams ...
Dense and structured linear algebra behind the GP: Cholesky and eigen solvers, linear operators,...
Gaussian-process regression, kernels, priors, and the searches that run on the surrogate.
Eigen::VectorXd mean
INLA-averaged predictive mean.
int n_grid_points
1 + 2p + 2^p for a p-dim CCD
Eigen::VectorXd variance
law-of-total-variance over the grid