25 #include <queso/LogNormalJointPdf.h>
26 #include <queso/GslVector.h>
27 #include <queso/GslMatrix.h>
32 template<
class V,
class M>
36 const V& lawExpVector,
37 const V& lawVarVector)
39 BaseJointPdf<V,M>(((std::string)(prefix)+
"gau").c_str(),domainSet),
40 m_lawExpVector (new V(lawExpVector)),
41 m_lawVarVector (new V(lawVarVector)),
42 m_diagonalCovMatrix(true)
65 template<
class V,
class M>
68 delete m_lawVarVector;
69 delete m_lawExpVector;
72 template <
class V,
class M>
76 return *m_lawExpVector;
79 template <
class V,
class M>
83 return *m_lawVarVector;
86 template<
class V,
class M>
89 const V& domainVector,
90 const V* domainDirection,
93 V* hessianEffect)
const
95 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 55)) {
96 *m_env.subDisplayFile() <<
"Entering LogNormalJointPdf<V,M>::actualValue()"
97 <<
", meanVector = " << *m_lawExpVector
98 <<
": domainVector = " << domainVector
99 <<
", domainVector.sizeLocal() = " << domainVector.sizeLocal()
100 <<
", this->m_domainSet.vectorSpace().dimLocal() = " << this->m_domainSet.vectorSpace().dimLocal()
106 queso_require_msg(!(gradVector || hessianMatrix || hessianEffect),
"incomplete code for gradVector, hessianMatrix and hessianEffect calculations");
108 double returnValue = 0.;
110 V zeroVector(domainVector);
111 zeroVector.cwSet(0.);
112 if (domainVector.atLeastOneComponentSmallerOrEqualThan(zeroVector)) {
115 else if (this->m_domainSet.contains(domainVector) ==
false) {
119 returnValue = std::exp(this->lnValue(domainVector,domainDirection,gradVector,hessianMatrix,hessianEffect));
123 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 55)) {
124 *m_env.subDisplayFile() <<
"Leaving LogNormalJointPdf<V,M>::actualValue()"
125 <<
", meanVector = " << *m_lawExpVector
126 <<
": domainVector = " << domainVector
127 <<
", returnValue = " << returnValue
134 template<
class V,
class M>
137 const V& domainVector,
138 const V* domainDirection,
141 V* hessianEffect)
const
143 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 55)) {
144 *m_env.subDisplayFile() <<
"Entering LogNormalJointPdf<V,M>::lnValue()"
145 <<
", meanVector = " << *m_lawExpVector
146 <<
": domainVector = " << domainVector
150 queso_require_msg(!(gradVector || hessianMatrix || hessianEffect),
"incomplete code for gradVector, hessianMatrix and hessianEffect calculations");
152 if (domainDirection) {};
154 double returnValue = 0.;
156 V zeroVector(domainVector);
157 zeroVector.cwSet(0.);
158 if (domainVector.atLeastOneComponentSmallerOrEqualThan(zeroVector)) {
159 returnValue = -INFINITY;
161 else if (this->m_domainSet.contains(domainVector) ==
false) {
162 returnValue = -INFINITY;
165 if (m_diagonalCovMatrix) {
166 V diffVec(zeroVector);
167 for (
unsigned int i = 0; i < domainVector.sizeLocal(); ++i) {
168 diffVec[i] = std::log(domainVector[i]) - this->lawExpVector()[i];
170 returnValue = ((diffVec*diffVec)/this->lawVarVector()).sumOfComponents();
172 if (m_normalizationStyle == 0) {
173 for (
unsigned int i = 0; i < domainVector.sizeLocal(); ++i) {
174 returnValue -= std::log(domainVector[i] * std::sqrt(2. * M_PI * this->lawVarVector()[i]));
179 queso_error_msg(
"situation with a non-diagonal covariance matrix makes no sense");
181 returnValue += m_logOfNormalizationFactor;
184 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 55)) {
185 *m_env.subDisplayFile() <<
"Leaving LogNormalJointPdf<V,M>::lnValue()"
186 <<
", meanVector = " << *m_lawExpVector
187 <<
": domainVector = " << domainVector
188 <<
", returnValue = " << returnValue
195 template<
class V,
class M>
201 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
202 *m_env.subDisplayFile() <<
"Entering LogNormalJointPdf<V,M>::computeLogOfNormalizationFactor()"
206 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
207 *m_env.subDisplayFile() <<
"Leaving LogNormalJointPdf<V,M>::computeLogOfNormalizationFactor()"
208 <<
", m_logOfNormalizationFactor = " << m_logOfNormalizationFactor
unsigned int displayVerbosity() const
A templated class for handling sets.
~LogNormalJointPdf()
Destructor.
A templated (base) class for handling joint PDFs.
const V & lawVarVector() const
Access to the vector of variance values and private attribute: m_lawVarVector.
double commonComputeLogOfNormalizationFactor(unsigned int numSamples, bool updateFactorInternally) const
Common method (to the derived classes) to compute the logarithm of the normalization factor...
#define queso_error_msg(msg)
double actualValue(const V &domainVector, const V *domainDirection, V *gradVector, M *hessianMatrix, V *hessianEffect) const
Actual value of the Log-Normal PDF (scalar function).
double lnValue(const V &domainVector, const V *domainDirection, V *gradVector, M *hessianMatrix, V *hessianEffect) const
Logarithm of the value of the Log-Normal PDF (scalar function).
LogNormalJointPdf(const char *prefix, const VectorSet< V, M > &domainSet, const V &lawExpVector, const V &lawVarVector)
Constructor.
#define queso_require_equal_to_msg(expr1, expr2, msg)
const BaseEnvironment & m_env
#define queso_require_msg(asserted, msg)
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
const V & lawExpVector() const
Access to the vector of mean values and private attribute: m_lawExpVector.
A class for handling Log-Normal joint PDFs.
double computeLogOfNormalizationFactor(unsigned int numSamples, bool updateFactorInternally) const
Computes the logarithm of the normalization factor.