class gpr::laplace::ScopedKernelState

Overview

RAII guard: snapshots (magnSigma2, lengthScales, sigma2) at construction and restores them at destruction. More…

#include <ScopedKernelState.h>
 
class ScopedKernelState {
public:
    // construction
 
    ScopedKernelState(SexpatCF& kernel, double& sigma2, LikGaussian* likelihood = nullptr);
    ScopedKernelState(const ScopedKernelState&);
    ScopedKernelState(ScopedKernelState&&);
    ~ScopedKernelState();
 
    // methods
 
    void restore();
    ScopedKernelState& operator=(const ScopedKernelState&);
    ScopedKernelState& operator=(ScopedKernelState&&);
    void applyTheta(const Eigen::VectorXd& theta);
};

Detailed Documentation

RAII guard: snapshots (magnSigma2, lengthScales, sigma2) at construction and restores them at destruction.

Used by Laplace and SVGD grid/particle loops to mutate hyperparameters without leaking rank-local state across early returns.

Non-copyable, non-movable: the guard owns a fixed scope.

Construction

ScopedKernelState(SexpatCF& kernel, double& sigma2, LikGaussian* likelihood = nullptr)

Parameters:

kernel

SexpAt covariance function whose magn + ls to snapshot

sigma2

reference to the noise variance member in the GPR

likelihood

optional Gaussian likelihood whose noise is theta-owned

Methods

void restore()

Restore the snapshot mid-scope. Called automatically by the dtor; exposed publicly so callers that need the snapshot’s state side-effects (e.g. re-decomposing the covariance matrix at theta_star while still owning the guard) don’t have to drop the guard. Idempotent.

void applyTheta(const Eigen::VectorXd& theta)

Apply a theta vector to the kernel state. theta = (log magn, log ls_1, …, log ls_nls, log noise).