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

Constant covariance function. More...

#include <gpr/covariance_functions/ConstantCF.h>

Public Member Functions

 ConstantCF ()
 ~ConstantCF ()
double calculateLogPrior ()
 Evaluate the log prior of covariance function parameters.
FieldMatrixd calculateLogPriorGradient ()
 Evaluate gradient of the log prior with respect to the parameters.
void calculateGradOfCovMatrix (const Coord &x, Coord &x2, std::vector< FieldMatrixd > &DKff)
 The function takes a matrix x of input vectors and returns DKff, the gradients of covariance matrix Kff = k(X,X2) with respect to th (cell array with matrix elements).
void calculateGradOfCovMatrixWithDerivatives (const Coord &x, Coord &x2, FieldMatrixIdx &dims, std::vector< FieldMatrixd > &DKff)
 Evaluate gradient of covariance function, of which has been taken partial derivative with respect to x, with respect to parameters.
void calculateGradOfCovMatrixWithDerivatives2 (const Coord &x, Coord &x2, FieldMatrixIdx &dims1, FieldMatrixIdx &dims2, std::vector< FieldMatrixd > &DKff)
 Evaluate gradient of covariance function, of which has been taken partial derivatives with respect to both input variables x, with respect to parameters.
void ginput2 (const Coord &x, Coord &x2, FieldMatrixIdx &dims, std::vector< FieldMatrixd > &DKff)
 Evaluate gradient of covariance function with respect to both input variables x and x2 (in same dimension).
void ginput3 (const Coord &x, Coord &x2, FieldMatrixIdx &dims1, FieldMatrixIdx &dims2, std::vector< FieldMatrixd > &DKff)
 Evaluate gradient of covariance function with respect to both input variables x and x2 (in different dimensions).
void ginput4 (const Coord &x, Coord &x2, FieldMatrixIdx &dims, std::vector< FieldMatrixd > &DKff)
 Evaluate gradient of covariance function with respect to x. Simplified and faster version of constant_ginput, returns full matrices.
void calculateCovarianceMatrix (const Coord &x, Coord &x2, FieldMatrixd &C)
 Evaluate covariance matrix between two input vectors.
void setConstSigma2 (const double _constSigma2)
 Set the constSigma2 value.
void setParameters (const Eigen::VectorXd &w)
 Set parameters of this covariance function using the provided vector.
double getConstSigma2 ()
double getConstSigma2 () const noexcept
Eigen::VectorXd combineParameters ()
 Combine parameters of the covariance function into one Eigen vector.

Detailed Description

Constant covariance function.

Definition at line 21 of file ConstantCF.h.

Constructor & Destructor Documentation

◆ ConstantCF()

gpr::ConstantCF::ConstantCF ( )

Definition at line 9 of file ConstantCF.cpp.

10{
11 constSigma2 = 0.;
12}

◆ ~ConstantCF()

gpr::ConstantCF::~ConstantCF ( )
inline

Definition at line 24 of file ConstantCF.h.

24{ }

Member Function Documentation

◆ calculateCovarianceMatrix()

void gpr::ConstantCF::calculateCovarianceMatrix ( const Coord & x,
Coord & x2,
FieldMatrixd & C )

Evaluate covariance matrix between two input vectors.

C = GP_CONSTANT_COV(GP, TX, X) takes in covariance function of a Gaussian process GP and two matrixes TX and X that contain input vectors to GP. Returns covariance matrix C. Every element ij of C contains covariance between inputs i in TX and j in X. This is a mandatory subfunction used for example in prediction and energy computations.

Parameters
xConfigurations supplying the rows of the covariance matrix.
x2Configurations supplying the columns of the covariance matrix.
COutput covariance matrix between x and x2.

Definition at line 72 of file ConstantCF.cpp.

74{
75 C.resize(x.rows(), x2.rows());
76 C.setConstant(this->constSigma2);
77}
@ x
Definition Enums.h:28

◆ calculateGradOfCovMatrix()

void gpr::ConstantCF::calculateGradOfCovMatrix ( const Coord & x,
Coord & x2,
std::vector< FieldMatrixd > & DKff )

The function takes a matrix x of input vectors and returns DKff, the gradients of covariance matrix Kff = k(X,X2) with respect to th (cell array with matrix elements).

This is a mandatory subfunction used in gradient computations.

Parameters
xConfigurations for the first covariance argument.
x2Configurations for the second covariance argument.
DKffOutput covariance-matrix derivatives with respect to the covariance hyperparameters.

Definition at line 24 of file ConstantCF.cpp.

26{
27 if (x2.size() == 0) x2 = x;
28}

◆ calculateGradOfCovMatrixWithDerivatives()

void gpr::ConstantCF::calculateGradOfCovMatrixWithDerivatives ( const Coord & x,
Coord & x2,
FieldMatrixIdx & dims,
std::vector< FieldMatrixd > & DKff )

Evaluate gradient of covariance function, of which has been taken partial derivative with respect to x, with respect to parameters.

Parameters
xConfigurations for the first covariance argument.
x2Configurations for the second covariance argument.
dimsCoordinate-dimension indices for the derivative observations.
DKffOutput derivative-covariance blocks differentiated with respect to the covariance hyperparameters.

Definition at line 30 of file ConstantCF.cpp.

33{
34}

◆ calculateGradOfCovMatrixWithDerivatives2()

void gpr::ConstantCF::calculateGradOfCovMatrixWithDerivatives2 ( const Coord & x,
Coord & x2,
FieldMatrixIdx & dims1,
FieldMatrixIdx & dims2,
std::vector< FieldMatrixd > & DKff )

Evaluate gradient of covariance function, of which has been taken partial derivatives with respect to both input variables x, with respect to parameters.

Returns DKff, the gradients of derivative covariance matrix dK(df,df)/dhyp = d(d^2 k(X1,X2)/dX1dX2)/dhyp with respect to the parameters.

Parameters
xConfigurations for the first covariance argument.
x2Configurations for the second covariance argument.
dims1Coordinate-dimension indices for derivatives with respect to the first input.
dims2Coordinate-dimension indices for derivatives with respect to the second input.
DKffOutput second-derivative covariance blocks differentiated with respect to the covariance hyperparameters.

Definition at line 36 of file ConstantCF.cpp.

39{
40}

◆ calculateLogPrior()

double gpr::ConstantCF::calculateLogPrior ( )

Evaluate the log prior of covariance function parameters.

Returns
Result

Definition at line 14 of file ConstantCF.cpp.

15{
16 return 0;
17}

◆ calculateLogPriorGradient()

FieldMatrixd gpr::ConstantCF::calculateLogPriorGradient ( )

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

Returns
Result

Definition at line 19 of file ConstantCF.cpp.

20{
21 return FieldMatrixd();
22}
Eigen::Matrix< double, EigenDynamic, EigenDynamic, FieldMatrixStorage > FieldMatrixd
Definition Macros.h:25

◆ combineParameters()

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

Combine parameters of the covariance function into one Eigen vector.

Definition at line 35 of file ConstantCF.inl.

36{
37 Eigen::VectorXd res;
38 return res;
39}

◆ getConstSigma2() [1/2]

double gpr::ConstantCF::getConstSigma2 ( )
inline

Definition at line 30 of file ConstantCF.inl.

31{
32 return constSigma2;
33}

◆ getConstSigma2() [2/2]

double gpr::ConstantCF::getConstSigma2 ( ) const
inlinenodiscardnoexcept

Definition at line 179 of file ConstantCF.h.

180 {
181 return constSigma2;
182 }

◆ ginput2()

void gpr::ConstantCF::ginput2 ( const Coord & x,
Coord & x2,
FieldMatrixIdx & dims,
std::vector< FieldMatrixd > & DKff )

Evaluate gradient of covariance function with respect to both input variables x and x2 (in same dimension).

Returns DKff, the gradients of twice derivatived covariance matrix K(df,df) = dk(X1,X2)/dX1dX2 (cell array with matrix elements). Input variable's dimensions are expected to be same.

Parameters
xConfigurations for the first covariance argument.
x2Configurations for the second covariance argument.
dimsCoordinate-dimension indices for derivative observations.
DKffOutput second-derivative covariance blocks.

Definition at line 42 of file ConstantCF.cpp.

44{
45 DKff.resize(dims.size());
46 for (Eigen::Index i = 0; i < dims.size(); ++i) {
47 DKff[i].resize(x.rows(), x2.rows());
48 DKff[i].setZero();
49 }
50}

◆ ginput3()

void gpr::ConstantCF::ginput3 ( const Coord & x,
Coord & x2,
FieldMatrixIdx & dims1,
FieldMatrixIdx & dims2,
std::vector< FieldMatrixd > & DKff )

Evaluate gradient of covariance function with respect to both input variables x and x2 (in different dimensions).

DKff = GPCF_CONSTANT_GINPUT3(GPCF, X, X2) takes a covariance function structure GPCF, a matrix X of input vectors and returns DKff, the gradients of twice derivatived covariance matrix K(df,df) = dk(X1,X2)/dX1dX2 (cell array with matrix elements). The derivative is calculated in multidimensional problem between input's observation dimensions which are not same. This subfunction is needed when using derivative observations.

Parameters
xConfigurations for the first covariance argument.
x2Configurations for the second covariance argument.
dims1Coordinate-dimension indices for derivatives with respect to the first input.
dims2Coordinate-dimension indices for derivatives with respect to the second input.
DKffOutput second-derivative covariance blocks.

Definition at line 52 of file ConstantCF.cpp.

54{
55 DKff.resize(dims1.size() * dims2.size());
56 for (Eigen::Index i = 0; i < (dims1.size() * dims2.size()); ++i) {
57 DKff[i].resize(x.rows(), x2.rows());
58 DKff[i].setZero();
59 }
60}

◆ ginput4()

void gpr::ConstantCF::ginput4 ( const Coord & x,
Coord & x2,
FieldMatrixIdx & dims,
std::vector< FieldMatrixd > & DKff )

Evaluate gradient of covariance function with respect to x. Simplified and faster version of constant_ginput, returns full matrices.

Returns DKff, the gradients of covariance matrix Kff = k(X,X2) with respect to X (whole matrix). This function is needed when using derivative observations.

Parameters
xConfigurations for the first covariance argument.
x2Configurations for the second covariance argument.
dimsCoordinate-dimension indices for derivatives with respect to the first input.
DKffOutput covariance-derivative blocks.

Definition at line 62 of file ConstantCF.cpp.

64{
65 DKff.resize(dims.size());
66 for (Eigen::Index i = 0; i < dims.size(); ++i) {
67 DKff[i].resize(x.rows(), x2.rows());
68 DKff[i].setZero();
69 }
70}

◆ setConstSigma2()

void gpr::ConstantCF::setConstSigma2 ( const double _constSigma2)
inline

Set the constSigma2 value.

Definition at line 17 of file ConstantCF.inl.

18{
19 constSigma2 = _constSigma2;
20}

◆ setParameters()

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

Set parameters of this covariance function using the provided vector.

Parameters
wVector of hyperparameters

Definition at line 22 of file ConstantCF.inl.

23{
24 // No-op: constSigma2 is not optimized by SCG (combineParameters returns
25 // empty), so it must not be unpacked from the shared parameter vector w.
26 // The MATLAB gpcf_constant_unpak only unpacks when the parameter is in the
27 // optimization set; since combineParameters() is empty, it never is.
28}

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