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

Gaussian noise with variance. More...

#include <gpr/observation_models/LikGaussian.h>

Public Member Functions

 LikGaussian ()
virtual ~LikGaussian ()
double evaluateLogPrior ()
 Evaluate the log prior of covariance function parameters.
void evaluateLogPriorGradient (FieldMatrixd &lpg)
 Evaluate gradient of the log prior with respect to the parameters.
void evaluateTrainingCovarianceMatrix (const Coord &x, FieldMatrixd &C)
 Evaluate training covariance matrix of inputs.
Eigen::VectorXd evaluateTrainingVariance (const Coord &x)
 Noise on each assembly row, including virtual and robust geometry tags.
void setSigma2 (const double value)
 Set sigma2 value.
double getSigma2 () const noexcept
 Get sigma2 value (the per-row noise variance added to the energy diagonal of the training kernel by evaluateTrainingCovarianceMatrix).
void setOptimizeSigma2 (bool optimize) noexcept
bool getOptimizeSigma2 () const noexcept
void setVirtualGeometryNoise (const Coord &geometries, double extra_sigma2)
 Register virtual (conditioning-only) geometries whose covariance rows carry extra heteroscedastic noise.
Eigen::Index virtualGeometryCount () const noexcept
void setGeometryExtraNoise (const Coord &geometries, const Eigen::VectorXd &extra_sigma2)
 Register per-geometry extra noise for every row of a geometry (energy and derivatives alike): the robust-row weights of the Student-t scale mixture, applied as heteroscedastic Gaussian noise. Rows are matched by bitwise coordinate equality, as for the virtual tag. An empty matrix clears the registration.
const Eigen::VectorXd & geometryExtraNoise () const noexcept
std::uint64_t geometryNoiseRevision () const noexcept
 Revision of the virtual and per-geometry noise registrations.
void setPriorParametersGaussian (const PriorBase &prior)
void setPriorParametersSqrtt (const PriorBase &prior)
void setParameters (const Eigen::VectorXd &w)
Eigen::VectorXd combineParameters ()
 Combine parameters of the gaussian likelihood into one Eigen vector.

Detailed Description

Gaussian noise with variance.

Definition at line 29 of file LikGaussian.h.

Constructor & Destructor Documentation

◆ LikGaussian()

gpr::LikGaussian::LikGaussian ( )
inline

Definition at line 31 of file LikGaussian.h.

31: sigma2(0.) { }

◆ ~LikGaussian()

virtual gpr::LikGaussian::~LikGaussian ( )
inlinevirtual

Definition at line 32 of file LikGaussian.h.

32{ }

Member Function Documentation

◆ combineParameters()

Eigen::VectorXd gpr::LikGaussian::combineParameters ( )
inline

Combine parameters of the gaussian likelihood into one Eigen vector.

Empty unless noise learning is enabled; with it, the single entry log(sigma2) appends AFTER the covariance parameters in the shared optimization vector, which is what arms the GP layer's trailing-noise detection (hasTrailingLikelihoodNoiseParameter).

Definition at line 50 of file LikGaussian.inl.

51{
52 Eigen::VectorXd res;
53 if (optimize_sigma2_ && std::isfinite(sigma2) && sigma2 > 0.0) {
54 res.resize(1);
55 res(0) = numerics::log(sigma2);
56 }
57 return res;
58}
double log(double x) noexcept

◆ evaluateLogPrior()

double gpr::LikGaussian::evaluateLogPrior ( )

Evaluate the log prior of covariance function parameters.

This function returns

\[ log(p(th)) \]

, where th collects the parameters. This function is needed when there are likelihood parameters.

Definition at line 17 of file LikGaussian.cpp.

18{
19 return 0.;
20}

◆ evaluateLogPriorGradient()

void gpr::LikGaussian::evaluateLogPriorGradient ( FieldMatrixd & lpg)

Evaluate gradient of the log prior with respect to the parameters.

This function takes a Gaussian likelihood and returns

\[ LPG = d log (p(th))/dth \]

, where th is the vector of parameters. This function is needed when there are likelihood parameters.

Parameters
lpgResult

Definition at line 22 of file LikGaussian.cpp.

23{
24 lpg.resize(0, 0);
25}

◆ evaluateTrainingCovarianceMatrix()

void gpr::LikGaussian::evaluateTrainingCovarianceMatrix ( const Coord & x,
FieldMatrixd & C )

Evaluate training covariance matrix of inputs.

Parameters
xSet of coordinates
CCovariance matrix

Definition at line 85 of file LikGaussian.cpp.

87{
88 C = evaluateTrainingVariance(x).asDiagonal();
89}
@ x
Definition Enums.h:28
Eigen::VectorXd evaluateTrainingVariance(const Coord &x)
Noise on each assembly row, including virtual and robust geometry tags.

◆ evaluateTrainingVariance()

Eigen::VectorXd gpr::LikGaussian::evaluateTrainingVariance ( const Coord & x)

Noise on each assembly row, including virtual and robust geometry tags.

Definition at line 27 of file LikGaussian.cpp.

28{
29 const Eigen::Index n = x.rows();
30 Eigen::VectorXd variance = Eigen::VectorXd::Constant(n, sigma2);
31
32 // Heteroscedastic tag for virtual (conditioning-only) rows: any
33 // assembly row whose coordinates bitwise-match a registered virtual
34 // geometry gets extra noise on its diagonal. Both sides are pure
35 // copies of the same observation rows, so exact comparison is the
36 // correct identity test and no index bookkeeping survives row
37 // permutation or subset selection incorrectly. The repetitive
38 // layout appends the block id as a trailing column of x; only the
39 // leading coordinate columns participate in the match.
40 // Robust rows: every channel of a geometry whose leave-one-geometry-
41 // out residual exceeded the model's expectation carries the extra
42 // noise its Student-t weight prescribes (see updateRobustRowWeights).
43 const Eigen::Index n_robust = robust_geometries_.rows();
44 if (n_robust > 0 && robust_extra_sigma2_.size() == n_robust &&
45 (x.cols() == robust_geometries_.cols() ||
46 x.cols() == robust_geometries_.cols() + 1)) {
47 const Eigen::Index dr = robust_geometries_.cols();
48 for (Eigen::Index i = 0; i < n; ++i) {
49 for (Eigen::Index v = 0; v < n_robust; ++v) {
50 if (!(robust_extra_sigma2_(v) > 0.0)) continue;
51 if ((x.row(i).head(dr).array() ==
52 robust_geometries_.row(v).array())
53 .all()) {
54 variance(i) += robust_extra_sigma2_(v);
55 break;
56 }
57 }
58 }
59 }
60 const Eigen::Index n_virtual = virtual_geometries_.rows();
61 if (n_virtual == 0 || !(virtual_noise_sigma2_ > 0.0)) return variance;
62 const Eigen::Index d = virtual_geometries_.cols();
63 if (x.cols() != d && x.cols() != d + 1) return variance;
64 const bool has_block_column = x.cols() == d + 1;
65 for (Eigen::Index i = 0; i < n; ++i) {
66 for (Eigen::Index v = 0; v < n_virtual; ++v) {
67 if ((x.row(i).head(d).array() == virtual_geometries_.row(v).array())
68 .all()) {
69 // Derivative-only constraint: the energy row of a
70 // virtual geometry is effectively removed (the raw
71 // energy scale is absorbed by the constant-offset
72 // block, so a prior-mean energy target would build an
73 // artificial wall); the derivative rows carry the soft
74 // pin noise.
75 const bool is_energy_row = has_block_column && x(i, d) == 0.0;
76 variance(i) += is_energy_row ? kVirtualEnergyRowNoise
77 : virtual_noise_sigma2_;
78 break;
79 }
80 }
81 }
82 return variance;
83}
double variance(const Weights &w, const Matrix &covariance)

◆ geometryExtraNoise()

const Eigen::VectorXd & gpr::LikGaussian::geometryExtraNoise ( ) const
inlinenodiscardnoexcept

Definition at line 134 of file LikGaussian.h.

136 {
137 return robust_extra_sigma2_;
138 }

◆ geometryNoiseRevision()

std::uint64_t gpr::LikGaussian::geometryNoiseRevision ( ) const
inlinenodiscardnoexcept

Revision of the virtual and per-geometry noise registrations.

Definition at line 141 of file LikGaussian.h.

142 {
143 return geometry_noise_revision_;
144 }

◆ getOptimizeSigma2()

bool gpr::LikGaussian::getOptimizeSigma2 ( ) const
inlinenodiscardnoexcept

Definition at line 86 of file LikGaussian.h.

87 {
88 return optimize_sigma2_;
89 }

◆ getSigma2()

double gpr::LikGaussian::getSigma2 ( ) const
inlinenodiscardnoexcept

Get sigma2 value (the per-row noise variance added to the energy diagonal of the training kernel by evaluateTrainingCovarianceMatrix).

Definition at line 74 of file LikGaussian.h.

75 {
76 return sigma2;
77 }

◆ setGeometryExtraNoise()

void gpr::LikGaussian::setGeometryExtraNoise ( const Coord & geometries,
const Eigen::VectorXd & extra_sigma2 )
inline

Register per-geometry extra noise for every row of a geometry (energy and derivatives alike): the robust-row weights of the Student-t scale mixture, applied as heteroscedastic Gaussian noise. Rows are matched by bitwise coordinate equality, as for the virtual tag. An empty matrix clears the registration.

Definition at line 122 of file LikGaussian.h.

124 {
125 ++geometry_noise_revision_;
126 if (geometries.rows() != extra_sigma2.size()) {
127 robust_geometries_.resize(0, 0);
128 robust_extra_sigma2_.resize(0);
129 return;
130 }
131 robust_geometries_ = geometries;
132 robust_extra_sigma2_ = extra_sigma2;
133 }

◆ setOptimizeSigma2()

void gpr::LikGaussian::setOptimizeSigma2 ( bool optimize)
inlinenoexcept

Include log(sigma2) in the shared optimization vector so SCG learns the likelihood noise (Empirical Bayes on the joint [E,F] misfit scale). Off keeps the fixed-sigma2 published behavior.

Definition at line 82 of file LikGaussian.h.

83 {
84 optimize_sigma2_ = optimize;
85 }

◆ setParameters()

void gpr::LikGaussian::setParameters ( const Eigen::VectorXd & w)
inline

Definition at line 34 of file LikGaussian.inl.

35{
36 // No-op even when sigma2 is in the optimization set: the GP layer
37 // owns the trailing-noise unpack (setParameters routes exp(w_last)
38 // through trainingToPhysicalNoiseVariance before calling setSigma2),
39 // matching the MATLAB lik_gaussian_unpak split of pak/unpak duties.
40}

◆ setPriorParametersGaussian()

void gpr::LikGaussian::setPriorParametersGaussian ( const PriorBase & prior)
inline

Definition at line 24 of file LikGaussian.inl.

25{
26 prior_parameters_gaussian.setParameters(prior);
27}

◆ setPriorParametersSqrtt()

void gpr::LikGaussian::setPriorParametersSqrtt ( const PriorBase & prior)
inline

Definition at line 29 of file LikGaussian.inl.

30{
31 prior_parameters_sqrtt.setParameters(prior);
32}

◆ setSigma2()

void gpr::LikGaussian::setSigma2 ( const double value)
inline

Set sigma2 value.

Definition at line 19 of file LikGaussian.inl.

20{
21 sigma2 = value;
22}

◆ setVirtualGeometryNoise()

void gpr::LikGaussian::setVirtualGeometryNoise ( const Coord & geometries,
double extra_sigma2 )
inline

Register virtual (conditioning-only) geometries whose covariance rows carry extra heteroscedastic noise.

evaluateTrainingCovarianceMatrix matches assembly rows against these geometries by bitwise coordinate equality (both sides are pure copies of the same observation rows), so the tag survives row permutation, tiled layouts, and subset assemblies without index bookkeeping. Assemblies that contain none of the geometries (hyperparameter fitting on real rows only) are untouched. An empty matrix clears the tag.

Definition at line 103 of file LikGaussian.h.

105 {
106 virtual_geometries_ = geometries;
107 virtual_noise_sigma2_ = extra_sigma2;
108 ++geometry_noise_revision_;
109 }

◆ virtualGeometryCount()

Eigen::Index gpr::LikGaussian::virtualGeometryCount ( ) const
inlinenodiscardnoexcept

Definition at line 110 of file LikGaussian.h.

111 {
112 return virtual_geometries_.rows();
113 }

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