GPRidge v1.0.0
GPR-accelerated saddle point searches on potential energy surfaces
☾
Toggle main menu visibility
Loading...
Searching...
No Matches
PriorLogNormal.cpp
Go to the documentation of this file.
1
// SPDX-License-Identifier: MIT
2
// Copyright (c) gpridge developers
3
// See LICENSE for details.
4
5
#include "
PriorLogNormal.h
"
6
7
#include <cmath>
8
#include <limits>
9
10
#include "
../numerics/PortableMath.h
"
11
#include "
PriorScale.h
"
12
13
namespace
gpr
{
14
15
double
PriorLogNormal::calculateLogPrior
(
const
FieldMatrixd
&
x
)
16
{
17
// A non-positive scale is an illegal parameter. A non-positive
18
// amplitude is outside the support and stays non-finite.
19
requirePositiveFinitePriorParameter
(
"log-normal prior"
,
"s2"
,
s2
);
20
requireFinitePriorParameter
(
"log-normal prior"
,
"mu"
,
mu
);
21
22
double
lp = 0.;
23
double
log_2_pi_s2 =
numerics::log
(2 * M_PI *
s2
);
24
double
s2_rec = 1. /
s2
;
25
26
for
(Eigen::Index n = 0; n <
x
.size(); ++n) {
27
double
xn = *(
x
.data() + n);
28
if
(!(xn > 0.0) || !std::isfinite(xn))
29
return
-std::numeric_limits<double>::infinity();
30
double
log_xn =
numerics::log
(xn);
31
lp += -0.5 * log_2_pi_s2 - log_xn -
32
0.5 * s2_rec * (log_xn -
mu
) * (log_xn -
mu
);
33
}
34
35
return
lp;
36
}
37
38
FieldMatrixd
PriorLogNormal::calculateLogPriorGradient
(
const
FieldMatrixd
&
x
)
39
{
40
FieldMatrixd
lpg;
41
42
lpg.resize(
x
.rows(),
x
.cols());
43
44
requirePositiveFinitePriorParameter
(
"log-normal prior"
,
"s2"
,
s2
);
45
requireFinitePriorParameter
(
"log-normal prior"
,
"mu"
,
mu
);
46
double
s2_rec = 1. /
s2
;
47
for
(Eigen::Index n = 0; n < lpg.size(); ++n) {
48
double
xn = *(
x
.data() + n);
49
if
(!(xn > 0.0) || !std::isfinite(xn)) {
50
*(lpg.data() + n) = std::numeric_limits<double>::quiet_NaN();
51
continue
;
52
}
53
double
xn_rec = 1. / xn;
54
*(lpg.data() + n) = -(1. + (
numerics::log
(xn) -
mu
) * s2_rec) * xn_rec;
55
}
56
57
return
lpg;
58
}
59
60
}
/* namespace gpr */
x
@ x
Definition
Enums.h:28
PortableMath.h
PriorLogNormal.h
PriorScale.h
gpr::PriorBase::mu
double mu
Definition
PriorBase.h:86
gpr::PriorBase::s2
double s2
Definition
PriorBase.h:87
gpr::PriorLogNormal::calculateLogPrior
double calculateLogPrior(const FieldMatrixd &x) override
Definition
PriorLogNormal.cpp:15
gpr::PriorLogNormal::calculateLogPriorGradient
FieldMatrixd calculateLogPriorGradient(const FieldMatrixd &x) override
Definition
PriorLogNormal.cpp:38
gpr::numerics::log
double log(double x) noexcept
Definition
PortableMath.cpp:24
gpr
Gaussian-process regression, kernels, priors, and the searches that run on the surrogate.
Definition
Macros.h:16
gpr::requirePositiveFinitePriorParameter
void requirePositiveFinitePriorParameter(const char *density, const char *name, double value)
Definition
PriorScale.h:17
gpr::requireFinitePriorParameter
void requireFinitePriorParameter(const char *density, const char *name, double value)
Definition
PriorScale.h:26
gpr::FieldMatrixd
Eigen::Matrix< double, EigenDynamic, EigenDynamic, FieldMatrixStorage > FieldMatrixd
Definition
Macros.h:25
gpr
prior
PriorLogNormal.cpp
Generated by
1.17.0
Generated by
Doxygen 1.17.0
Analytics by
Antics
provided by
TurtleTech ehf