queso-0.51.1
Protected Attributes | List of all members
QUESO::GaussianJointPdf< V, M > Class Template Reference

A class for handling Gaussian joint PDFs. More...

#include <GaussianJointPdf.h>

Inheritance diagram for QUESO::GaussianJointPdf< V, M >:
Inheritance graph
[legend]
Collaboration diagram for QUESO::GaussianJointPdf< V, M >:
Collaboration graph
[legend]

Public Member Functions

Constructor/Destructor methods
 GaussianJointPdf (const char *prefix, const VectorSet< V, M > &domainSet, const V &lawExpVector, const V &lawVarVector)
 Constructor. More...
 
 GaussianJointPdf (const char *prefix, const VectorSet< V, M > &domainSet, const V &lawExpVector, const M &lawCovMatrix)
 Constructor. More...
 
 ~GaussianJointPdf ()
 Destructor. More...
 
Math methods
double actualValue (const V &domainVector, const V *domainDirection, V *gradVector, M *hessianMatrix, V *hessianEffect) const
 Actual value of the Gaussian PDF: More...
 
double lnValue (const V &domainVector, const V *domainDirection, V *gradVector, M *hessianMatrix, V *hessianEffect) const
 Logarithm of the value of the Gaussian PDF (scalar function). 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 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 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
 Sets a value to be used in the normalization style (stored in the protected attribute m_normalizationStyle.) More...
 
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 >
 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...
 

Protected Attributes

V * m_lawExpVector
 
V * m_lawVarVector
 
bool m_diagonalCovMatrix
 
const M * m_lawCovMatrix
 
- 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...
 

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...
 

Detailed Description

template<class V, class M>
class QUESO::GaussianJointPdf< V, M >

A class for handling Gaussian joint PDFs.

This class allows the mathematical definition of a Gaussian Joint PDF.

Definition at line 49 of file GaussianJointPdf.h.

Constructor & Destructor Documentation

template<class V , class M >
QUESO::GaussianJointPdf< V, M >::GaussianJointPdf ( const char *  prefix,
const VectorSet< V, M > &  domainSet,
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, and a vector of covariance values lawVarVector (an alternative representation for a diagonal covariance matrix).

Definition at line 33 of file GaussianJointPdf.C.

References QUESO::BaseEnvironment::displayVerbosity(), QUESO::GaussianJointPdf< V, M >::lawExpVector(), QUESO::GaussianJointPdf< V, M >::lawVarVector(), QUESO::BaseScalarFunction< V, M >::m_env, QUESO::BaseScalarFunction< V, M >::m_prefix, and QUESO::BaseEnvironment::subDisplayFile().

38  :
39  BaseJointPdf<V,M>(((std::string)(prefix)+"gau").c_str(),domainSet),
42  m_diagonalCovMatrix(true),
43  m_lawCovMatrix (m_domainSet.vectorSpace().newDiagMatrix(lawVarVector))
44 {
45 
46  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
47  *m_env.subDisplayFile() << "Entering GaussianJointPdf<V,M>::constructor() [1]"
48  << ": prefix = " << m_prefix
49  << std::endl;
50  }
51 
52  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 55)) {
53  *m_env.subDisplayFile() << "In GaussianJointPdf<V,M>::constructor()"
54  //<< ", prefix = " << m_prefix
55  << ": meanVector = " << this->lawExpVector()
56  << ", Variances = " << this->lawVarVector()
57  << std::endl;
58  }
59 
60  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
61  *m_env.subDisplayFile() << "Leaving GaussianJointPdf<V,M>::constructor() [1]"
62  << ": prefix = " << m_prefix
63  << std::endl;
64  }
65 }
const VectorSet< V, M > & m_domainSet
Domain set of the scalar function.
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:305
const V & lawVarVector() const
Access to the vector of variance values and private attribute: m_lawVarVector.
const VectorSet< V, M > & domainSet() const
Access to the protected attribute m_domainSet: domain set of the scalar function. ...
const BaseEnvironment & m_env
unsigned int displayVerbosity() const
Definition: Environment.C:436
const V & lawExpVector() const
Access to the vector of mean values and private attribute: m_lawExpVector.
template<class V , class M >
QUESO::GaussianJointPdf< V, M >::GaussianJointPdf ( const char *  prefix,
const VectorSet< V, M > &  domainSet,
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, and a covariance matrix, lawCovMatrix.

Definition at line 68 of file GaussianJointPdf.C.

References QUESO::BaseEnvironment::displayVerbosity(), QUESO::GaussianJointPdf< V, M >::lawExpVector(), QUESO::BaseScalarFunction< V, M >::m_env, QUESO::BaseScalarFunction< V, M >::m_prefix, and QUESO::BaseEnvironment::subDisplayFile().

73  :
74  BaseJointPdf<V,M>(((std::string)(prefix)+"gau").c_str(),domainSet),
76  m_lawVarVector (domainSet.vectorSpace().newVector(INFINITY)), // FIX ME
77  m_diagonalCovMatrix(false),
79 {
80  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
81  *m_env.subDisplayFile() << "Entering GaussianJointPdf<V,M>::constructor() [2]"
82  << ": prefix = " << m_prefix
83  << std::endl;
84  }
85 
86  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 55)) {
87  *m_env.subDisplayFile() << "In GaussianJointPdf<V,M>::constructor()"
88  //<< ", prefix = " << m_prefix
89  << ": meanVector = " << this->lawExpVector()
90  << ", Covariance Matrix = " << lawCovMatrix
91  << std::endl;
92  }
93 
94  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
95  *m_env.subDisplayFile() << "Leaving GaussianJointPdf<V,M>::constructor() [2]"
96  << ": prefix = " << m_prefix
97  << std::endl;
98  }
99 }
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:305
const VectorSet< V, M > & domainSet() const
Access to the protected attribute m_domainSet: domain set of the scalar function. ...
const M & lawCovMatrix() const
Returns the covariance matrix; access to protected attribute m_lawCovMatrix.
const BaseEnvironment & m_env
unsigned int displayVerbosity() const
Definition: Environment.C:436
const V & lawExpVector() const
Access to the vector of mean values and private attribute: m_lawExpVector.
template<class V , class M >
QUESO::GaussianJointPdf< V, M >::~GaussianJointPdf ( )

Destructor.

Definition at line 102 of file GaussianJointPdf.C.

103 {
104  delete m_lawCovMatrix;
105  delete m_lawVarVector;
106  delete m_lawExpVector;
107 }

Member Function Documentation

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

Actual value of the Gaussian PDF:

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

Implements QUESO::BaseJointPdf< V, M >.

Definition at line 125 of file GaussianJointPdf.C.

References UQ_FATAL_TEST_MACRO.

131 {
132  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 55)) {
133  *m_env.subDisplayFile() << "Entering GaussianJointPdf<V,M>::actualValue()"
134  << ", meanVector = " << *m_lawExpVector
135  << ", lawCovMatrix = " << *m_lawCovMatrix
136  << ": domainVector = " << domainVector
137  << std::endl;
138  }
139 
140  UQ_FATAL_TEST_MACRO(domainVector.sizeLocal() != this->m_domainSet.vectorSpace().dimLocal(),
141  m_env.worldRank(),
142  "GaussianJointPdf<V,M>::actualValue()",
143  "invalid input");
144 
145  UQ_FATAL_TEST_MACRO((gradVector || hessianMatrix || hessianEffect),
146  m_env.worldRank(),
147  "GaussianJointPdf<V,M>::actualValue()",
148  "incomplete code for gradVector, hessianMatrix and hessianEffect calculations");
149 
150  double returnValue = 0.;
151 
152  if (this->m_domainSet.contains(domainVector) == false) { // prudenci 2011-Oct-04
153  returnValue = 0.;
154  }
155  else {
156  returnValue = std::exp(this->lnValue(domainVector,domainDirection,gradVector,hessianMatrix,hessianEffect));
157  }
158  //returnValue *= exp(m_logOfNormalizationFactor); // No need, because 'lnValue()' is called right above [PDF-03]
159 
160  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 55)) {
161  *m_env.subDisplayFile() << "Leaving GaussianJointPdf<V,M>::actualValue()"
162  << ", meanVector = " << *m_lawExpVector
163  << ", lawCovMatrix = " << *m_lawCovMatrix
164  << ": domainVector = " << domainVector
165  << ", returnValue = " << returnValue
166  << std::endl;
167  }
168 
169  return returnValue;
170 }
int worldRank() const
Returns the process world rank.
Definition: Environment.C:235
const VectorSet< V, M > & m_domainSet
Domain set of the scalar function.
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:305
double lnValue(const V &domainVector, const V *domainDirection, V *gradVector, M *hessianMatrix, V *hessianEffect) const
Logarithm of the value of the Gaussian PDF (scalar function).
const BaseEnvironment & m_env
unsigned int displayVerbosity() const
Definition: Environment.C:436
#define UQ_FATAL_TEST_MACRO(test, givenRank, where, what)
Definition: Defines.h:223
template<class V , class M >
double QUESO::GaussianJointPdf< 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 246 of file GaussianJointPdf.C.

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

247 {
248  double value = 0.;
249 
250  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
251  *m_env.subDisplayFile() << "Entering GaussianJointPdf<V,M>::computeLogOfNormalizationFactor()"
252  << std::endl;
253  }
254  value = BaseJointPdf<V,M>::commonComputeLogOfNormalizationFactor(numSamples, updateFactorInternally);
255  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
256  *m_env.subDisplayFile() << "Leaving GaussianJointPdf<V,M>::computeLogOfNormalizationFactor()"
257  << ", m_logOfNormalizationFactor = " << m_logOfNormalizationFactor
258  << std::endl;
259  }
260 
261  return value;
262 }
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:305
double m_logOfNormalizationFactor
Definition: JointPdf.h:104
const BaseEnvironment & m_env
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:77
unsigned int displayVerbosity() const
Definition: Environment.C:436
template<class V , class M >
const M & QUESO::GaussianJointPdf< V, M >::lawCovMatrix ( ) const

Returns the covariance matrix; access to protected attribute m_lawCovMatrix.

Definition at line 286 of file GaussianJointPdf.C.

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

287 {
288  return *m_lawCovMatrix;
289 }
template<class V , class M >
const V & QUESO::GaussianJointPdf< V, M >::lawExpVector ( ) const

Access to the vector of mean values and private attribute: m_lawExpVector.

Definition at line 111 of file GaussianJointPdf.C.

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

112 {
113  return *m_lawExpVector;
114 }
template<class V , class M >
const V & QUESO::GaussianJointPdf< V, M >::lawVarVector ( ) const

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

Definition at line 118 of file GaussianJointPdf.C.

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

119 {
120  return *m_lawVarVector;
121 }
template<class V , class M >
double QUESO::GaussianJointPdf< V, M >::lnValue ( const V &  domainVector,
const V *  domainDirection,
V *  gradVector,
M *  hessianMatrix,
V *  hessianEffect 
) const
virtual

Logarithm of the value of the 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}, \]

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

Implements QUESO::BaseJointPdf< V, M >.

Definition at line 174 of file GaussianJointPdf.C.

References UQ_FATAL_TEST_MACRO.

180 {
181  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 55)) {
182  *m_env.subDisplayFile() << "Entering GaussianJointPdf<V,M>::lnValue()"
183  << ", meanVector = " << *m_lawExpVector
184  << ", lawCovMatrix = " << *m_lawCovMatrix
185  << ": domainVector = " << domainVector
186  << std::endl;
187  }
188 
189  UQ_FATAL_TEST_MACRO((gradVector || hessianMatrix || hessianEffect),
190  m_env.worldRank(),
191  "GaussianJointPdf<V,M>::lnValue()",
192  "incomplete code for gradVector, hessianMatrix and hessianEffect calculations");
193 
194  if (domainDirection) {}; // just to remove compiler warning
195 
196  double returnValue = 0.;
197 
198  double lnDeterminant = 0.;
199  if (this->m_domainSet.contains(domainVector) == false) { // prudenci 2011-Oct-04
200  returnValue = -INFINITY;
201  }
202  else {
203  V diffVec(domainVector - this->lawExpVector());
204  if (m_diagonalCovMatrix) {
205  returnValue = ((diffVec*diffVec)/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); // normalization of pdf
222  returnValue += lnDeterminant; // normalization of pdf
223  }
224  returnValue *= -0.5;
225  }
226  returnValue += m_logOfNormalizationFactor; // [PDF-03]
227 
228  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 99)) {
229  *m_env.subDisplayFile() << "Leaving GaussianJointPdf<V,M>::lnValue()"
230  << ", m_normalizationStyle = " << m_normalizationStyle
231  << ", m_diagonalCovMatrix = " << m_diagonalCovMatrix
232  << ", m_logOfNormalizationFactor = " << m_logOfNormalizationFactor
233  << ", lnDeterminant = " << lnDeterminant
234  << ", meanVector = " << *m_lawExpVector
235  << ", lawCovMatrix = " << *m_lawCovMatrix
236  << ": domainVector = " << domainVector
237  << ", returnValue = " << returnValue
238  << std::endl;
239  }
240 
241  return returnValue;
242 }
int worldRank() const
Returns the process world rank.
Definition: Environment.C:235
unsigned int m_normalizationStyle
Definition: JointPdf.h:103
const VectorSet< V, M > & m_domainSet
Domain set of the scalar function.
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:305
double m_logOfNormalizationFactor
Definition: JointPdf.h:104
const V & lawVarVector() const
Access to the vector of variance values and private attribute: m_lawVarVector.
const BaseEnvironment & m_env
unsigned int displayVerbosity() const
Definition: Environment.C:436
#define UQ_FATAL_TEST_MACRO(test, givenRank, where, what)
Definition: Defines.h:223
const V & lawExpVector() const
Access to the vector of mean values and private attribute: m_lawExpVector.
template<class V , class M >
void QUESO::GaussianJointPdf< 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 276 of file GaussianJointPdf.C.

277 {
278  // delete old expected values (allocated at construction or last call to this function)
279  delete m_lawCovMatrix;
280  m_lawCovMatrix = new M(newLawCovMatrix);
281  return;
282 }
template<class V , class M >
void QUESO::GaussianJointPdf< V, M >::updateLawExpVector ( const V &  newLawExpVector)

Updates the mean with the new value newLawExpVector.

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

Definition at line 266 of file GaussianJointPdf.C.

267 {
268  // delete old expected values (allocated at construction or last call to this function)
269  delete m_lawExpVector;
270  m_lawExpVector = new V(newLawExpVector);
271  return;
272 }

Member Data Documentation

template<class V, class M>
bool QUESO::GaussianJointPdf< V, M >::m_diagonalCovMatrix
protected

Definition at line 115 of file GaussianJointPdf.h.

template<class V, class M>
const M* QUESO::GaussianJointPdf< V, M >::m_lawCovMatrix
protected

Definition at line 116 of file GaussianJointPdf.h.

template<class V, class M>
V* QUESO::GaussianJointPdf< V, M >::m_lawExpVector
protected

Definition at line 113 of file GaussianJointPdf.h.

template<class V, class M>
V* QUESO::GaussianJointPdf< V, M >::m_lawVarVector
protected

Definition at line 114 of file GaussianJointPdf.h.


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

Generated on Thu Apr 23 2015 19:26:17 for queso-0.51.1 by  doxygen 1.8.5