Laplace / INLA uncertainty quantifier over GP/TP hyperparameters. More...
#include <gpr/ml/LaplaceINLA.h>
Public Types | |
| enum class | Likelihood { GAUSSIAN_CLOSED_FORM , T_CLOSED_FORM , NON_GAUSSIAN } |
| using | KernelBuilder |
| using | LogPrior = std::function<double(const Eigen::VectorXd& theta)> |
Public Member Functions | |
| void | setTheta0 (const Eigen::VectorXd &theta_star) |
| MAP hyperparameters (log space if using the project's conventions). | |
| void | setHessian (const Eigen::MatrixXd &H) |
| void | setHessian (const Eigen::MatrixXd &H, const Eigen::MatrixXd ¶meter_directions) |
| void | setLikelihood (Likelihood lik) |
| Likelihood | likelihood () const |
| void | setTPHyperprior (double a, double b) |
| TP hyperprior (only used when lik_ == T_CLOSED_FORM). | |
| void | setObservationLikelihood (std::shared_ptr< ObservationLikelihood > ol) |
| void | buildGrid (double f0=-1.0, bool include_corners=true) |
| Build the CCD grid in theta-space from (theta*, H). | |
| 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 weights. | |
| 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. | |
| INLAPrediction | predict (const Eigen::VectorXd &y, KernelBuilder kb, linalg::BackendContext &workspace) const |
| const std::vector< Eigen::VectorXd > & | gridPoints () const noexcept |
| Grid accessors (for testing). | |
| const Eigen::VectorXd & | gridWeights () const noexcept |
| const Eigen::VectorXd & | finalWeights () const noexcept |
| int | p () const noexcept |
| int | nGridPoints () const noexcept |
| const Eigen::VectorXd & | theta0 () const noexcept |
| MAP hyperparameter point set by setTheta0. Used by SVGD initFromCCD. | |
| const Eigen::MatrixXd & | lScale () const noexcept |
| Eigen::MatrixXd | hessianInverse () const |
| Eigen::MatrixXd | precisionMatrix () const |
Laplace / INLA uncertainty quantifier over GP/TP hyperparameters.
Usage: LaplaceINLA inla; inla.setTheta0(theta_star); // MAP from SCG inla.setHessian(H); // p x p, from assembleExactHessian inla.buildGrid(); // 1 + 2p + 2^p CCD points inla.fit(y, kernel_builder, log_prior); INLAPrediction p = inla.predict(y, kernel_builder);
The KernelBuilder callback signature takes the RAW hyperparameter vector theta directly (caller owns the log-base convention). This differs from BayesianModelAveraging::KernelBuilder, which takes (lengthscale, noise) in linear space; callers who want to share a kernel closure across LaplaceINLA and BMA should write two adapters rather than rely on implicit coercion inside either class.
LOAD-BEARING CONTRACT: the LAST element of theta is always log-noise (natural log). LaplaceINLA extracts it internally for FactorizedLikelihood::evaluateGP / evaluateTP.
Definition at line 73 of file LaplaceINLA.h.
Builds kernel matrices from the RAW hyperparameter vector theta. CONVENTION: the last element of theta is always log-noise (natural log). Callers own the log-base for the other components. Returns (K_XX, K_test_X, k_test_test_diag).
Definition at line 87 of file LaplaceINLA.h.
| using gpr::LaplaceINLA::LogPrior = std::function<double(const Eigen::VectorXd& theta)> |
Log prior over hyperparameters. Called at every grid point. Return 0.0 for a flat improper prior; any log density otherwise.
Definition at line 93 of file LaplaceINLA.h.
|
strong |
Closed-form NLML path used per-grid-point. Inner-Laplace (NON_GAUSSIAN) is opt-in scaffolding covered by a separate bead.
| Enumerator | |
|---|---|
| GAUSSIAN_CLOSED_FORM | |
| T_CLOSED_FORM | FactorizedLikelihood::evaluateTP (MVT marginal). |
| NON_GAUSSIAN | Inner Laplace via ObservationLikelihood (future). |
Definition at line 77 of file LaplaceINLA.h.
| void gpr::LaplaceINLA::buildGrid | ( | double | f0 = -1.0, |
| bool | include_corners = true ) |
Build the CCD grid in theta-space from (theta*, H).
Places 1 center, 2p axial, and 2^p factorial-corner points at z = 0, +/- f0 * e_i, and (+/- f0/sqrt(p), ..., +/- f0/sqrt(p)) in standardised z-space, then maps back to theta-space via theta_k = theta* + U Lambda^{-1/2} z_k.
Grid-rule weights w_k^grid are chosen so the rule integrates z (to zero) and z z^T (to identity) exactly against N(0, I). These match Rue et al. 2009 eq. 6.5 and the moments validated by test_ccd_grid_moments_p2 in python/tests/test_sympy_laplace.py.
| f0 | Radius in standardised space. Pass a negative value (default) to use Rue's default sqrt(p + 2). |
| include_corners | Include the 2^p factorial corner points (default true). When false, only the 1 + 2p axial subset is built; the corner Cholesky factorisations that dominate per-call BMA / LAPLACE-CCD wall are skipped. Both rules preserve the Gaussian first and second moments; the corner points change higher mixed moments. At p = 4 the axial rule uses K = 9 points instead of K = 25, with weights normalized for those nine points. |
Definition at line 165 of file LaplaceINLA.cpp.
|
inlinenodiscardnoexcept |
Definition at line 204 of file LaplaceINLA.h.
| void gpr::LaplaceINLA::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 weights.
Needs the kernel builder so it can evaluate the true log p(y|theta_k)
log p(theta_k) at each grid point. The Rue correction ratio is
rho_k = [ p(y|theta_k) * p(theta_k) * pi_G(theta*) ] / [ p(y|theta*) * p(theta*) * pi_G(theta_k) ]
where pi_G is the Laplace Gaussian surrogate N(theta*, H^-1). In the linear-Gaussian limit phi is exactly quadratic and rho_k = 1 everywhere (see test_rho_k_is_one_on_quadratic_phi).
| y | Training targets. |
| kernel_builder | Same callback as BMA uses. |
| log_prior | Log prior over hyperparameters (pass a zero-returning lambda for a flat improper prior). |
Definition at line 277 of file LaplaceINLA.cpp.
|
inlinenodiscardnoexcept |
Grid accessors (for testing).
Definition at line 195 of file LaplaceINLA.h.
|
inlinenodiscardnoexcept |
Definition at line 200 of file LaplaceINLA.h.
|
inlinenodiscard |
Ambient covariance of the posterior at theta*. Tied directions have zero variance normal to their parameter subspace. Assembled as L_scale * L_scale^T from the cached eigendecomposition; cheaper than calling inverse() and numerically stable because setHessian() stores a strictly positive spectrum. Returns an empty matrix if setHessian was never called.
Definition at line 237 of file LaplaceINLA.h.
|
inline |
Definition at line 113 of file LaplaceINLA.h.
|
inlinenodiscardnoexcept |
Posterior-covariance square root L_scale = U * Lambda^{-1/2} in z-space. The posterior covariance is H^{-1} = L_scale * L_scale^T. Used by the 2nd-order TCOV correction in GaussianProcessRegression::calculatePotentialLaplace.
Definition at line 226 of file LaplaceINLA.h.
|
inlinenodiscardnoexcept |
Definition at line 212 of file LaplaceINLA.h.
|
inlinenodiscardnoexcept |
Definition at line 208 of file LaplaceINLA.h.
|
inlinenodiscard |
Effective observed-information precision used to map the CCD grid. This includes any precision-form regularization applied by setHessian().
Definition at line 245 of file LaplaceINLA.h.
| INLAPrediction gpr::LaplaceINLA::predict | ( | const Eigen::VectorXd & | y, |
| KernelBuilder | kb, | ||
| linalg::BackendContext & | workspace ) const |
Definition at line 332 of file LaplaceINLA.cpp.
| INLAPrediction gpr::LaplaceINLA::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.
Definition at line 325 of file LaplaceINLA.cpp.
| void gpr::LaplaceINLA::setHessian | ( | const Eigen::MatrixXd & | H | ) |
p x p observed-information Hessian at theta*. The spectrum must contain at least one positive finite curvature direction; mixed-curvature weak directions are converted to a proper posterior precision by setHessian().
Definition at line 47 of file LaplaceINLA.cpp.
| void gpr::LaplaceINLA::setHessian | ( | const Eigen::MatrixXd & | H, |
| const Eigen::MatrixXd & | parameter_directions ) |
Observed information in q free coordinates, with a full-column-rank p x q map from free increments to the ambient theta coordinates.
Definition at line 52 of file LaplaceINLA.cpp.
|
inline |
Definition at line 109 of file LaplaceINLA.h.
|
inline |
Attach a non-Gaussian observation likelihood. Only consulted when lik_ == NON_GAUSSIAN; the branch throws if this was never attached (fail fast rather than silently falling back to Gaussian).
Definition at line 128 of file LaplaceINLA.h.
| void gpr::LaplaceINLA::setTheta0 | ( | const Eigen::VectorXd & | theta_star | ) |
MAP hyperparameters (log space if using the project's conventions).
Definition at line 41 of file LaplaceINLA.cpp.
|
inline |
TP hyperprior (only used when lik_ == T_CLOSED_FORM).
Definition at line 119 of file LaplaceINLA.h.
|
inlinenodiscardnoexcept |
MAP hyperparameter point set by setTheta0. Used by SVGD initFromCCD.
Definition at line 217 of file LaplaceINLA.h.