Loading...
Searching...
No Matches
gpr::FactorizedLikelihood Class Reference

#include <gpr/ml/FactorizedLikelihood.h>

Public Member Functions

void setEigendecomposition (const Eigen::VectorXd &eigenvalues, const EigenMatrix &eigenvectors, const Eigen::VectorXd &targets)
 Cache the eigendecomposition of K_XX for repeated noise sweeps.
double evaluateGP (double noise_variance) const
 GP negative log marginal likelihood at given noise level.
double evaluateTP (double noise_variance, double a, double b) const
 TP negative log marginal likelihood at given noise level.
double analyticalPrefactor (double noise_variance) const
 Analytically optimal GP prefactor (signal variance).
double tpPrefactor (double noise_variance, double a, double b) const
 TP prefactor from inverse-gamma hyperprior.
Eigen::Index dataSize () const

Detailed Description

Definition at line 29 of file FactorizedLikelihood.h.

Member Function Documentation

◆ analyticalPrefactor()

double gpr::FactorizedLikelihood::analyticalPrefactor ( double noise_variance) const

Analytically optimal GP prefactor (signal variance).

Parameters
noise_variancesigma_n^2
Returns
prefactor = mean(UTY^2 / D_n)

Definition at line 74 of file FactorizedLikelihood.cpp.

75{
76 double S = computeS(noise_variance);
77 return S / n_; // mean(UTY^2 / D_n)
78}

◆ dataSize()

Eigen::Index gpr::FactorizedLikelihood::dataSize ( ) const
inline

Definition at line 82 of file FactorizedLikelihood.h.

83 {
84 return n_;
85 }

◆ evaluateGP()

double gpr::FactorizedLikelihood::evaluateGP ( double noise_variance) const

GP negative log marginal likelihood at given noise level.

Uses the analytical prefactor: prefactor = mean(UTY^2 / D_n).

Parameters
noise_variancesigma_n^2 in linear space
Returns
NLML value (lower is better)

Definition at line 33 of file FactorizedLikelihood.cpp.

34{
35 // GP NLML with analytical prefactor:
36 // L = 0.5 * n * (1 + log(2*pi))
37 // + n * prefactor_log
38 // + 0.5 * sum(log(D_n))
39 //
40 // where prefactor_log = 0.5 * log(mean(UTY^2 / D_n))
41
42 double log_det = 0.0;
43 double S = 0.0;
44 for (Eigen::Index i = 0; i < n_; ++i) {
45 double D_n = D_(i) + noise_variance;
46 log_det += std::log(D_n);
47 S += UTY2_(i) / D_n;
48 }
49
50 double prefactor2 = S / n_; // mean(UTY^2 / D_n)
51 double prefactor_log = 0.5 * std::log(prefactor2);
52
53 return 0.5 * n_ * (1.0 + std::log(2.0 * M_PI)) + n_ * prefactor_log +
54 0.5 * log_det;
55}

◆ evaluateTP()

double gpr::FactorizedLikelihood::evaluateTP ( double noise_variance,
double a,
double b ) const

TP negative log marginal likelihood at given noise level.

Uses the inverse-gamma hyperprior on the signal variance.

Parameters
noise_variancesigma_n^2 in linear space
ainverse-gamma shape parameter
binverse-gamma scale parameter
Returns
NLML value (lower is better)

Definition at line 57 of file FactorizedLikelihood.cpp.

59{
60 // TP NLML:
61 // L = 0.5 * sum(log(D_n)) + 0.5 * (2a + n) * log(1 + S/(2b))
62
63 double log_det = 0.0;
64 double S = 0.0;
65 for (Eigen::Index i = 0; i < n_; ++i) {
66 double D_n = D_(i) + noise_variance;
67 log_det += std::log(D_n);
68 S += UTY2_(i) / D_n;
69 }
70
71 return 0.5 * log_det + 0.5 * (2.0 * a + n_) * std::log(1.0 + S / (2.0 * b));
72}

◆ setEigendecomposition()

void gpr::FactorizedLikelihood::setEigendecomposition ( const Eigen::VectorXd & eigenvalues,
const EigenMatrix & eigenvectors,
const Eigen::VectorXd & targets )

Cache the eigendecomposition of K_XX for repeated noise sweeps.

Parameters
eigenvaluesD from eigh(K_XX), shape (n,)
eigenvectorsU from eigh(K_XX), shape (n, n)
targetsy vector, shape (n,)

Definition at line 11 of file FactorizedLikelihood.cpp.

14{
15 D_ = eigenvalues;
16 n_ = eigenvalues.size();
17
18 // Project targets: UTY = U^T y
19 UTY_ = eigenvectors.transpose() * targets;
20 UTY2_ = UTY_.array().square();
21}

◆ tpPrefactor()

double gpr::FactorizedLikelihood::tpPrefactor ( double noise_variance,
double a,
double b ) const

TP prefactor from inverse-gamma hyperprior.

Parameters
noise_variancesigma_n^2
ashape parameter
bscale parameter
Returns
prefactor = (2b + S) / (2a + n - 2)

Definition at line 80 of file FactorizedLikelihood.cpp.

82{
83 double S = computeS(noise_variance);
84 double n_adjusted = (n_ > 2) ? static_cast<double>(n_ - 2) : 0.0;
85 return (2.0 * b + S) / (2.0 * a + n_adjusted);
86}

The documentation for this class was generated from the following files: