GPRidge v1.0.0
GPR-accelerated saddle point searches on potential energy surfaces
☾
Toggle main menu visibility
Loading...
Searching...
No Matches
ScopedKernelState.h
Go to the documentation of this file.
1
// SPDX-License-Identifier: MIT
2
// Copyright (c) gpridge developers
3
// See LICENSE for details.
4
5
#ifndef GPR_ML_LAPLACE_SCOPED_KERNEL_STATE_H_
6
#define GPR_ML_LAPLACE_SCOPED_KERNEL_STATE_H_
7
8
#include "
../../../data_types/EigenHelpers.h
"
9
#include "
../../covariance_functions/SexpatCF.h
"
10
#include "
../../observation_models/LikGaussian.h
"
11
12
namespace
gpr
{
13
namespace
laplace
{
14
22
class
ScopedKernelState
{
23
public
:
28
ScopedKernelState
(
SexpatCF
& kernel,
double
& sigma2,
29
LikGaussian
* likelihood =
nullptr
) noexcept
30
: kernel_(kernel),
31
sigma2_ref_(sigma2),
32
likelihood_(likelihood),
33
saved_magn_(kernel.getMagnSigma2()),
34
saved_ls_(kernel.getLengthScaleRef()),
35
saved_sigma2_(sigma2),
36
saved_likelihood_sigma2_(
37
likelihood !=
nullptr
? likelihood->getSigma2() : 0.0)
38
{
39
}
40
41
~ScopedKernelState
() noexcept
42
{
43
restore
();
44
}
45
51
void
restore
() noexcept
52
{
53
kernel_.setMagnSigma2(saved_magn_);
54
kernel_.getLengthScaleRef() = saved_ls_;
55
sigma2_ref_ = saved_sigma2_;
56
if
(likelihood_ !=
nullptr
) {
57
likelihood_->setSigma2(saved_likelihood_sigma2_);
58
}
59
}
60
61
ScopedKernelState
(
const
ScopedKernelState
&) =
delete
;
62
ScopedKernelState
(
ScopedKernelState
&&) =
delete
;
63
ScopedKernelState
&
operator=
(
const
ScopedKernelState
&) =
delete
;
64
ScopedKernelState
&
operator=
(
ScopedKernelState
&&) =
delete
;
65
68
void
applyTheta
(
const
Eigen::VectorXd& theta)
69
{
70
if
(theta.size() < 2)
return
;
71
kernel_.setMagnSigma2(std::exp(theta(0)));
72
auto
& ls = kernel_.getLengthScaleRef();
73
const
int
n_ls =
static_cast<
int
>
(ls.size());
74
const
int
n_cov = 1 + n_ls;
75
for
(
int
i = 0; i < n_ls && (1 + i) < theta.size(); ++i) {
76
ls(0, i) = std::exp(theta(1 + i));
77
}
78
if
(theta.size() > n_cov) {
79
const
double
noise = std::exp(theta(theta.size() - 1));
80
sigma2_ref_ = noise;
81
if
(likelihood_ !=
nullptr
) {
82
likelihood_->setSigma2(noise);
83
}
84
}
85
}
86
87
private
:
88
SexpatCF
& kernel_;
89
double
& sigma2_ref_;
90
LikGaussian
*
const
likelihood_;
91
const
double
saved_magn_;
92
const
FieldMatrixd
saved_ls_;
93
const
double
saved_sigma2_;
94
const
double
saved_likelihood_sigma2_;
95
};
96
97
}
// namespace laplace
98
}
// namespace gpr
99
100
#endif
// GPR_ML_LAPLACE_SCOPED_KERNEL_STATE_H_
EigenHelpers.h
LikGaussian.h
SexpatCF.h
gpr::LikGaussian
Gaussian noise with variance.
Definition
LikGaussian.h:29
gpr::SexpatCF
Pair-type inverse-distance squared-exponential primitive.
Definition
SexpatCF.h:74
gpr::laplace::ScopedKernelState::ScopedKernelState
ScopedKernelState(ScopedKernelState &&)=delete
gpr::laplace::ScopedKernelState::applyTheta
void applyTheta(const Eigen::VectorXd &theta)
Definition
ScopedKernelState.h:68
gpr::laplace::ScopedKernelState::~ScopedKernelState
~ScopedKernelState() noexcept
Definition
ScopedKernelState.h:41
gpr::laplace::ScopedKernelState::operator=
ScopedKernelState & operator=(ScopedKernelState &&)=delete
gpr::laplace::ScopedKernelState::ScopedKernelState
ScopedKernelState(SexpatCF &kernel, double &sigma2, LikGaussian *likelihood=nullptr) noexcept
Definition
ScopedKernelState.h:28
gpr::laplace::ScopedKernelState::operator=
ScopedKernelState & operator=(const ScopedKernelState &)=delete
gpr::laplace::ScopedKernelState::restore
void restore() noexcept
Definition
ScopedKernelState.h:51
gpr::laplace::ScopedKernelState::ScopedKernelState
ScopedKernelState(const ScopedKernelState &)=delete
gpr::laplace
Definition
GaussianProcessRegression.h:86
gpr
Gaussian-process regression, kernels, priors, and the searches that run on the surrogate.
Definition
Macros.h:16
gpr::FieldMatrixd
Eigen::Matrix< double, EigenDynamic, EigenDynamic, FieldMatrixStorage > FieldMatrixd
Definition
Macros.h:25
gpr
ml
laplace
ScopedKernelState.h
Generated by
1.17.0
Generated by
Doxygen 1.17.0
Analytics by
Antics
provided by
TurtleTech ehf