queso-0.57.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
QUESO::InvLogitGaussianJointPdf< V, M > Class Template Reference

A class for handling hybrid (transformed) Gaussians with bounds. More...

#include <InvLogitGaussianJointPdf.h>

Inheritance diagram for QUESO::InvLogitGaussianJointPdf< V, M >:
QUESO::BaseJointPdf< V, M > QUESO::BaseScalarFunction< V, M >

Public Member Functions

virtual void print (std::ostream &os) const
 Prints the distribution. More...
 
Constructor/Destructor methods
 InvLogitGaussianJointPdf (const char *prefix, const BoxSubset< V, M > &domainBoxSubset, const V &lawExpVector, const V &lawVarVector)
 Constructor. More...
 
 InvLogitGaussianJointPdf (const char *prefix, const BoxSubset< V, M > &domainBoxSubset, const V &lawExpVector, const M &lawCovMatrix)
 Constructor. More...
 
 ~InvLogitGaussianJointPdf ()
 Destructor. More...
 
Math methods
double actualValue (const V &domainVector, const V *domainDirection, V *gradVector, M *hessianMatrix, V *hessianEffect) const
 Actual value of the (transformed) Gaussian PDF. More...
 
double lnValue (const V &domainVector, const V *domainDirection, V *gradVector, M *hessianMatrix, V *hessianEffect) const
 Logarithm of the value of the (transformed) Gaussian PDF (scalar function). More...
 
virtual void distributionMean (V &meanVector) const
 Mean value of the underlying random variable. More...
 
virtual void distributionVariance (M &covMatrix) const
 Covariance matrix of the underlying random variable. More...
 
double computeLogOfNormalizationFactor (unsigned int numSamples, bool updateFactorInternally) const
 Computes the logarithm of the normalization factor. More...
 
void updateLawExpVector (const V &newLawExpVector)
 Updates the mean of the Gaussian (not transformed) with the new value newLawExpVector. More...
 
void updateLawCovMatrix (const M &newLawCovMatrix)
 Updates the lower triangular matrix from Cholesky decomposition of the covariance matrix to the new value newLowerCholLawCovMatrix. More...
 
const M & lawCovMatrix () const
 Returns the covariance matrix; access to protected attribute m_lawCovMatrix. More...
 
const V & lawExpVector () const
 Access to the vector of mean values of the Gaussian (not transformed) and private attribute: m_lawExpVector. More...
 
const V & lawVarVector () const
 Access to the vector of variance values and private attribute: m_lawVarVector. More...
 
- Public Member Functions inherited from QUESO::BaseJointPdf< V, M >
 BaseJointPdf (const char *prefix, const VectorSet< V, M > &domainSet)
 Default constructor. More...
 
virtual ~BaseJointPdf ()
 Destructor. More...
 
virtual void setNormalizationStyle (unsigned int value) const
 
void setLogOfNormalizationFactor (double value) const
 Sets a logarithmic value to be used in the normalization factor (stored in the protected attribute m_normalizationStyle.) More...
 
- Public Member Functions inherited from QUESO::BaseScalarFunction< V, M >
void setFiniteDifferenceStepSize (double fdStepSize)
 Sets the step size for finite differencing gradients. More...
 
void setFiniteDifferenceStepSize (unsigned int i, double fdStepSize)
 
 BaseScalarFunction (const char *prefix, const VectorSet< V, M > &domainSet)
 Default constructor. More...
 
virtual ~BaseScalarFunction ()
 Destructor. More...
 
const VectorSet< V, M > & domainSet () const
 Access to the protected attribute m_domainSet: domain set of the scalar function. More...
 
virtual double lnValue (const V &domainVector) const
 Returns the logarithm of the function at domainVector. More...
 
virtual double lnValue (const V &domainVector, V &gradVector) const
 Returns the logarithm of the function and its gradient at domainVector. More...
 
virtual double lnValue (const V &domainVector, V &gradVector, const V &domainDirection, V &hessianEffect) const
 

Private Attributes

V * m_lawExpVector
 
V * m_lawVarVector
 
bool m_diagonalCovMatrix
 
const M * m_lawCovMatrix
 
const BoxSubset< V, M > & m_domainBoxSubset
 

Additional Inherited Members

- Protected Member Functions inherited from QUESO::BaseJointPdf< V, M >
double commonComputeLogOfNormalizationFactor (unsigned int numSamples, bool updateFactorInternally) const
 Common method (to the derived classes) to compute the logarithm of the normalization factor. More...
 
- Protected Attributes inherited from QUESO::BaseJointPdf< V, M >
unsigned int m_normalizationStyle
 
double m_logOfNormalizationFactor
 
- Protected Attributes inherited from QUESO::BaseScalarFunction< V, M >
const BaseEnvironmentm_env
 
std::string m_prefix
 
const VectorSet< V, M > & m_domainSet
 Domain set of the scalar function. More...
 

Detailed Description

template<class V = GslVector, class M = GslMatrix>
class QUESO::InvLogitGaussianJointPdf< V, M >

A class for handling hybrid (transformed) Gaussians with bounds.

This class allows the mathematical definition of a Gaussian PDF in dimensions of a VectorSubset that are unbounded, and a logit transformed Gaussian PDF in dimensions that have a lower or upper (or both) bound. For the bounded directions, the PDF is

\[ p(x) = \frac{1}{2 \sigma^2 \pi} \exp \left( - \frac12 (\mbox{logit} x - \mu)^2 \right) \mbox{logit}'(x), \quad x \in [a, b], \]

where logit is defined as

\[ \mbox{logit}(x) = \log \left( \frac{x - a}{b - x} \right), \quad x \in [a, b]. \]

Definition at line 58 of file InvLogitGaussianJointPdf.h.

Constructor & Destructor Documentation

template<class V , class M >
QUESO::InvLogitGaussianJointPdf< V, M >::InvLogitGaussianJointPdf ( const char *  prefix,
const BoxSubset< V, M > &  domainBoxSubset,
const V &  lawExpVector,
const V &  lawVarVector 
)

Constructor.

Constructs a new object, given a prefix and the domain of the PDF, a vector of mean values, lawExpVector (for the Gaussian, not the transformed Gaussian), and a vector of covariance values lawVarVector (an alternative representation for a diagonal covariance matrix).

Definition at line 33 of file InvLogitGaussianJointPdf.C.

38  :
39  BaseJointPdf<V,M>(((std::string)(prefix)+"invlogit_gau").c_str(),
40  domainBoxSubset),
43  m_diagonalCovMatrix(true),
44  m_lawCovMatrix(m_domainSet.vectorSpace().newDiagMatrix(lawVarVector)),
45  m_domainBoxSubset(domainBoxSubset)
46 {
47 }
const V & lawExpVector() const
Access to the vector of mean values of the Gaussian (not transformed) and private attribute: m_lawExp...
const BoxSubset< V, M > & m_domainBoxSubset
const VectorSet< V, M > & m_domainSet
Domain set of the scalar function.
const V & lawVarVector() const
Access to the vector of variance values and private attribute: m_lawVarVector.
template<class V , class M >
QUESO::InvLogitGaussianJointPdf< V, M >::InvLogitGaussianJointPdf ( const char *  prefix,
const BoxSubset< V, M > &  domainBoxSubset,
const V &  lawExpVector,
const M &  lawCovMatrix 
)

Constructor.

Constructs a new object, given a prefix and the image set of the vector realizer, a vector of mean values, lawExpVector (for the Gaussian, not the transformed Gaussian), and a covariance matrix, lawCovMatrix.

Definition at line 51 of file InvLogitGaussianJointPdf.C.

56  :
57  BaseJointPdf<V,M>(((std::string)(prefix)+"invlogit_gau").c_str(),
58  domainBoxSubset),
60  m_lawVarVector(domainBoxSubset.vectorSpace().newVector(INFINITY)), // FIX ME
61  m_diagonalCovMatrix(false),
63  m_domainBoxSubset(domainBoxSubset)
64 {
65 }
const M & lawCovMatrix() const
Returns the covariance matrix; access to protected attribute m_lawCovMatrix.
const V & lawExpVector() const
Access to the vector of mean values of the Gaussian (not transformed) and private attribute: m_lawExp...
const BoxSubset< V, M > & m_domainBoxSubset
template<class V , class M >
QUESO::InvLogitGaussianJointPdf< V, M >::~InvLogitGaussianJointPdf ( )

Member Function Documentation

template<class V , class M >
double QUESO::InvLogitGaussianJointPdf< V, M >::actualValue ( const V &  domainVector,
const V *  domainDirection,
V *  gradVector,
M *  hessianMatrix,
V *  hessianEffect 
) const
virtual

Actual value of the (transformed) Gaussian PDF.

This method calls lnValue() and applies the exponential to it.

Implements QUESO::BaseJointPdf< V, M >.

Definition at line 117 of file InvLogitGaussianJointPdf.C.

123 {
124  double returnValue;
125 
126  returnValue = std::exp(this->lnValue(domainVector,domainDirection,gradVector,hessianMatrix,hessianEffect));
127 
128  return returnValue;
129 }
double lnValue(const V &domainVector, const V *domainDirection, V *gradVector, M *hessianMatrix, V *hessianEffect) const
Logarithm of the value of the (transformed) Gaussian PDF (scalar function).
template<class V , class M >
double QUESO::InvLogitGaussianJointPdf< V, M >::computeLogOfNormalizationFactor ( unsigned int  numSamples,
bool  updateFactorInternally 
) const
virtual

Computes the logarithm of the normalization factor.

This routine calls BaseJointPdf::commonComputeLogOfNormalizationFactor().

Implements QUESO::BaseJointPdf< V, M >.

Definition at line 257 of file InvLogitGaussianJointPdf.C.

References QUESO::BaseJointPdf< V, M >::commonComputeLogOfNormalizationFactor().

258 {
259  double value = 0.;
260 
261  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
262  *m_env.subDisplayFile() << "Entering GaussianJointPdf<V,M>::computeLogOfNormalizationFactor()"
263  << std::endl;
264  }
265  value = BaseJointPdf<V,M>::commonComputeLogOfNormalizationFactor(numSamples, updateFactorInternally);
266  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
267  *m_env.subDisplayFile() << "Leaving GaussianJointPdf<V,M>::computeLogOfNormalizationFactor()"
268  << ", m_logOfNormalizationFactor = " << m_logOfNormalizationFactor
269  << std::endl;
270  }
271 
272  return value;
273 }
double m_logOfNormalizationFactor
Definition: JointPdf.h:122
double commonComputeLogOfNormalizationFactor(unsigned int numSamples, bool updateFactorInternally) const
Common method (to the derived classes) to compute the logarithm of the normalization factor...
Definition: JointPdf.C:115
const BaseEnvironment & m_env
unsigned int displayVerbosity() const
Definition: Environment.C:450
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:320
template<class V , class M >
void QUESO::InvLogitGaussianJointPdf< V, M >::distributionMean ( V &  meanVector) const
virtual

Mean value of the underlying random variable.

Reimplemented from QUESO::BaseJointPdf< V, M >.

Definition at line 233 of file InvLogitGaussianJointPdf.C.

234 {
235  // AFAIK there's no simple closed form here, and taking the inverse
236  // transformation of the mean in the transformed space probably
237  // isn't accurate enough in cases where the mean is too near the
238  // bounds.
239  queso_not_implemented();
240 }
template<class V , class M >
void QUESO::InvLogitGaussianJointPdf< V, M >::distributionVariance ( M &  covMatrix) const
virtual

Covariance matrix of the underlying random variable.

Reimplemented from QUESO::BaseJointPdf< V, M >.

Definition at line 245 of file InvLogitGaussianJointPdf.C.

246 {
247  // AFAIK there's no simple closed form here, and taking the inverse
248  // transformation of the variance in the transformed space probably
249  // isn't accurate enough in cases where the mean is too near the
250  // bounds.
251  queso_not_implemented();
252 }
template<class V , class M >
const M & QUESO::InvLogitGaussianJointPdf< V, M >::lawCovMatrix ( ) const

Returns the covariance matrix; access to protected attribute m_lawCovMatrix.

Definition at line 295 of file InvLogitGaussianJointPdf.C.

Referenced by QUESO::TransformedScaledCovMatrixTKGroup< V, M >::setPreComputingPosition().

296 {
297  return *m_lawCovMatrix;
298 }
template<class V , class M >
const V & QUESO::InvLogitGaussianJointPdf< V, M >::lawExpVector ( ) const

Access to the vector of mean values of the Gaussian (not transformed) and private attribute: m_lawExpVector.

Definition at line 77 of file InvLogitGaussianJointPdf.C.

template<class V , class M >
const V & QUESO::InvLogitGaussianJointPdf< V, M >::lawVarVector ( ) const

Access to the vector of variance values and private attribute: m_lawVarVector.

Definition at line 84 of file InvLogitGaussianJointPdf.C.

template<class V , class M >
double QUESO::InvLogitGaussianJointPdf< V, M >::lnValue ( const V &  domainVector,
const V *  domainDirection,
V *  gradVector,
M *  hessianMatrix,
V *  hessianEffect 
) const
virtual

Logarithm of the value of the (transformed) Gaussian PDF (scalar function).

The ln(value) comes from a summation of the Gaussian density:

\[ lnValue =- \sum_i \frac{1}{\sqrt{|covMatrix|} \sqrt{2 \pi}} exp(-\frac{(domainVector_i - lawExpVector_i) * covMatrix^{-1} * (domainVector_i - lawExpVector_i) }{2} + \log \mbox{logit}'(domainVector_i), \]

where the \( covMatrix \) may recovered via this->lawVarVector(), in case of diagonal matrices or via this->m_lawCovMatrix, otherwise.

Reimplemented from QUESO::BaseScalarFunction< V, M >.

Definition at line 133 of file InvLogitGaussianJointPdf.C.

References QUESO::queso_isfinite().

139 {
140  double returnValue;
141  double lnDeterminant = 0.0;
142  V transformedDomainVector(domainVector);
143 
144  V min_domain_bounds(this->m_domainBoxSubset.minValues());
145  V max_domain_bounds(this->m_domainBoxSubset.maxValues());
146 
147  double lnjacobian = 0.0;
148  for (unsigned int i = 0; i < domainVector.sizeLocal(); i++) {
149  double min_val = min_domain_bounds[i];
150  double max_val = max_domain_bounds[i];
151 
152  if (queso_isfinite(min_val) &&
153  queso_isfinite(max_val)) {
154 
155  if (domainVector[i] == min_val || domainVector[i] == max_val) {
156  // Exit early if we can
157  return -INFINITY;
158  }
159 
160  // Left- and right-hand sides are finite. Do full transform.
161  transformedDomainVector[i] = std::log(domainVector[i] - min_val) -
162  std::log(max_val - domainVector[i]);
163 
164  lnjacobian += std::log(max_val - min_val) -
165  std::log(domainVector[i] - min_val) -
166  std::log(max_val - domainVector[i]);
167  }
168  else if (queso_isfinite(min_val) &&
169  !queso_isfinite(max_val)) {
170 
171  if (domainVector[i] == min_val) {
172  // Exit early if we can
173  return -INFINITY;
174  }
175 
176  // Left-hand side finite, but right-hand side is not.
177  // Do only left-hand transform.
178  transformedDomainVector[i] = std::log(domainVector[i] - min_val);
179 
180  lnjacobian += -std::log(domainVector[i] - min_val);
181  }
182  else if (!queso_isfinite(min_val) &&
183  queso_isfinite(max_val)) {
184 
185  if (domainVector[i] == max_val) {
186  // Exit early if we can
187  return -INFINITY;
188  }
189 
190  // Right-hand side is finite, but left-hand side is not.
191  // Do only right-hand transform.
192  transformedDomainVector[i] = -std::log(max_val - domainVector[i]);
193 
194  lnjacobian += -std::log(max_val - domainVector[i]);
195  }
196  else {
197  // No transform.
198  transformedDomainVector[i] = domainVector[i];
199  }
200  }
201 
202  V diffVec(transformedDomainVector - this->lawExpVector());
203  if (m_diagonalCovMatrix) {
204  returnValue = ((diffVec * diffVec) /
205  this->lawVarVector()).sumOfComponents();
206  if (m_normalizationStyle == 0) {
207  unsigned int iMax = this->lawVarVector().sizeLocal();
208  for (unsigned int i = 0; i < iMax; ++i) {
209  lnDeterminant += log(this->lawVarVector()[i]);
210  }
211  }
212  }
213  else {
214  V tmpVec = this->m_lawCovMatrix->invertMultiply(diffVec);
215  returnValue = (diffVec * tmpVec).sumOfComponents();
216  if (m_normalizationStyle == 0) {
217  lnDeterminant = this->m_lawCovMatrix->lnDeterminant();
218  }
219  }
220  if (m_normalizationStyle == 0) {
221  returnValue += ((double) this->lawVarVector().sizeLocal()) * log(2 * M_PI);
222  returnValue += lnDeterminant;
223  }
224  returnValue *= -0.5;
225  returnValue += m_logOfNormalizationFactor;
226  returnValue += lnjacobian;
227 
228  return returnValue;
229 }
bool queso_isfinite(T arg)
Definition: math_macros.h:51
double m_logOfNormalizationFactor
Definition: JointPdf.h:122
const V & lawExpVector() const
Access to the vector of mean values of the Gaussian (not transformed) and private attribute: m_lawExp...
const BoxSubset< V, M > & m_domainBoxSubset
unsigned int m_normalizationStyle
Definition: JointPdf.h:121
const V & lawVarVector() const
Access to the vector of variance values and private attribute: m_lawVarVector.
template<class V , class M >
void QUESO::InvLogitGaussianJointPdf< V, M >::print ( std::ostream &  os) const
virtual

Prints the distribution.

When the mean and variance are printed, what's printed is the mean and variance of the underlying Gaussian distribution, not the output of the distributionMean and distributionVariance methods.

Reimplemented from QUESO::BaseJointPdf< V, M >.

Definition at line 91 of file InvLogitGaussianJointPdf.C.

92 {
93  // Print m_env?
94 
95  os << "Start printing InvLogitGaussianJointPdf<V, M>" << std::endl;
96  os << "m_prefix:" << std::endl;
97  os << this->m_prefix << std::endl;
98  os << "m_domainSet:" << std::endl;
99  os << this->m_domainBoxSubset << std::endl;
100  os << "m_normalizationStyle:" << std::endl;
101  os << this->m_normalizationStyle << std::endl;
102  os << "m_logOfNormalizationFactor:" << std::endl;
103  os << this->m_logOfNormalizationFactor << std::endl;
104  os << "Mean:" << std::endl;
105  os << this->lawExpVector() << std::endl;
106  os << "Variance vector:" << std::endl;
107  os << this->lawVarVector() << std::endl;
108  os << "Covariance matrix:" << std::endl;
109  os << this->lawCovMatrix() << std::endl;
110  os << "Diagonal covariance?" << std::endl;
111  os << this->m_diagonalCovMatrix << std::endl;
112  os << "End printing InvLogitGaussianJointPdf<V, M>" << std::endl;
113 }
const M & lawCovMatrix() const
Returns the covariance matrix; access to protected attribute m_lawCovMatrix.
double m_logOfNormalizationFactor
Definition: JointPdf.h:122
const V & lawExpVector() const
Access to the vector of mean values of the Gaussian (not transformed) and private attribute: m_lawExp...
const BoxSubset< V, M > & m_domainBoxSubset
unsigned int m_normalizationStyle
Definition: JointPdf.h:121
const V & lawVarVector() const
Access to the vector of variance values and private attribute: m_lawVarVector.
template<class V , class M >
void QUESO::InvLogitGaussianJointPdf< V, M >::updateLawCovMatrix ( const M &  newLawCovMatrix)

Updates the lower triangular matrix from Cholesky decomposition of the covariance matrix to the new value newLowerCholLawCovMatrix.

This method deletes old expected values (allocated at construction or last call to this method).

Definition at line 286 of file InvLogitGaussianJointPdf.C.

287 {
288  // delete old expected values (allocated at construction or last call to this function)
289  delete m_lawCovMatrix;
290  m_lawCovMatrix = new M(newLawCovMatrix);
291 }
template<class V , class M >
void QUESO::InvLogitGaussianJointPdf< V, M >::updateLawExpVector ( const V &  newLawExpVector)

Updates the mean of the Gaussian (not transformed) with the new value newLawExpVector.

This method deletes old expected values (allocated at construction or last call to this method).

Definition at line 277 of file InvLogitGaussianJointPdf.C.

278 {
279  // delete old expected values (allocated at construction or last call to this function)
280  delete m_lawExpVector;
281  m_lawExpVector = new V(newLawExpVector);
282 }

Member Data Documentation

template<class V = GslVector, class M = GslMatrix>
bool QUESO::InvLogitGaussianJointPdf< V, M >::m_diagonalCovMatrix
private

Definition at line 165 of file InvLogitGaussianJointPdf.h.

template<class V = GslVector, class M = GslMatrix>
const BoxSubset<V, M>& QUESO::InvLogitGaussianJointPdf< V, M >::m_domainBoxSubset
private

Definition at line 168 of file InvLogitGaussianJointPdf.h.

template<class V = GslVector, class M = GslMatrix>
const M* QUESO::InvLogitGaussianJointPdf< V, M >::m_lawCovMatrix
private

Definition at line 166 of file InvLogitGaussianJointPdf.h.

template<class V = GslVector, class M = GslMatrix>
V* QUESO::InvLogitGaussianJointPdf< V, M >::m_lawExpVector
private

Definition at line 163 of file InvLogitGaussianJointPdf.h.

template<class V = GslVector, class M = GslMatrix>
V* QUESO::InvLogitGaussianJointPdf< V, M >::m_lawVarVector
private

Definition at line 164 of file InvLogitGaussianJointPdf.h.


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

Generated on Tue Jun 5 2018 19:49:30 for queso-0.57.1 by  doxygen 1.8.5