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

Log-normal prior. More...

#include <gpr/prior/PriorLogNormal.h>

Inheritance diagram for gpr::PriorLogNormal:

Public Member Functions

 PriorLogNormal ()
virtual ~PriorLogNormal ()
double calculateLogPrior (const FieldMatrixd &x) override
FieldMatrixd calculateLogPriorGradient (const FieldMatrixd &x) override
Public Member Functions inherited from gpr::PriorBase
 PriorBase ()
void clear ()
double getMu () const
double getS2 () const
double getNu () const
void setMu (const double value)
void setS2 (const double value)
void setNu (const double value)
void setParameters (const PriorBase &other)

Additional Inherited Members

Protected Attributes inherited from gpr::PriorBase
double mu
double s2
double nu

Detailed Description

Log-normal prior.

Creates a log-normal prior where the log of the variable is normally distributed with mean mu and variance s2. The variable x must be positive.

log p(x) = -0.5*log(2*pi*s2) - log(x) - (log(x) - mu)^2 / (2*s2)

Definition at line 23 of file PriorLogNormal.h.

Constructor & Destructor Documentation

◆ PriorLogNormal()

gpr::PriorLogNormal::PriorLogNormal ( )
inline

Definition at line 25 of file PriorLogNormal.h.

25{ }

◆ ~PriorLogNormal()

virtual gpr::PriorLogNormal::~PriorLogNormal ( )
inlinevirtual

Definition at line 26 of file PriorLogNormal.h.

26{ }

Member Function Documentation

◆ calculateLogPrior()

double gpr::PriorLogNormal::calculateLogPrior ( const FieldMatrixd & x)
overridevirtual

Reimplemented from gpr::PriorBase.

Definition at line 15 of file PriorLogNormal.cpp.

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}
@ x
Definition Enums.h:28
double log(double x) noexcept
void requirePositiveFinitePriorParameter(const char *density, const char *name, double value)
Definition PriorScale.h:17
void requireFinitePriorParameter(const char *density, const char *name, double value)
Definition PriorScale.h:26

◆ calculateLogPriorGradient()

FieldMatrixd gpr::PriorLogNormal::calculateLogPriorGradient ( const FieldMatrixd & x)
overridevirtual

Reimplemented from gpr::PriorBase.

Definition at line 38 of file PriorLogNormal.cpp.

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}
Eigen::Matrix< double, EigenDynamic, EigenDynamic, FieldMatrixStorage > FieldMatrixd
Definition Macros.h:25

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