queso-0.53.0
List of all members
QUESO::GaussianVectorRV< V, M > Class Template Reference

A class representing a Gaussian vector RV. More...

#include <GaussianVectorRV.h>

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

Public Member Functions

Constructor/Destructor methods
 GaussianVectorRV (const char *prefix, const VectorSet< V, M > &imageSet, const V &lawExpVector, const V &lawVarVector)
 Constructor. More...
 
 GaussianVectorRV (const char *prefix, const VectorSet< V, M > &imageSet, const V &lawExpVector, const M &lawCovMatrix)
 Constructor. More...
 
virtual ~GaussianVectorRV ()
 Virtual destructor. More...
 
Statistical methods
void updateLawExpVector (const V &newLawExpVector)
 Updates the vector that contains the mean values. More...
 
void updateLawCovMatrix (const M &newLawCovMatrix)
 Updates the covariance matrix. More...
 
I/O methods
void print (std::ostream &os) const
 TODO: Prints the vector RV. More...
 
- Public Member Functions inherited from QUESO::BaseVectorRV< V, M >
 BaseVectorRV (const char *prefix, const VectorSet< V, M > &imageSet)
 Constructor. More...
 
virtual ~BaseVectorRV ()
 Virtual destructor. More...
 
const BaseEnvironmentenv () const
 QUESO environment; access to private attribute m_env. More...
 
const VectorSet< V, M > & imageSet () const
 Image set of the vector RV; access to private attribute m_imageSet. More...
 
const BaseJointPdf< V, M > & pdf () const
 Posterior Density Function of the vector RV; access to private attribute m_pdf. More...
 
const BaseVectorRealizer< V, M > & realizer () const
 Finds a realization (sample) of the PDF of this vector RV; access to private attribute m_realizer. More...
 
const BaseVectorCdf< V, M > & subCdf () const
 Finds the Cumulative Distribution Function of this vector RV, considering only the sub-sequence of data; access to private attribute m_subCdf. More...
 
const BaseVectorCdf< V, M > & unifiedCdf () const
 Finds the Cumulative Distribution Function of this vector RV, considering the unified sequence of data; access to private attribute m_unifiedCdf. More...
 
const BaseVectorMdf< V, M > & mdf () const
 Finds the Mass Density Function of this vector RV; access to private attribute m_mdf. More...
 

Additional Inherited Members

- Protected Attributes inherited from QUESO::BaseVectorRV< V, M >
const BaseEnvironmentm_env
 
std::string m_prefix
 
const VectorSet< V, M > & m_imageSet
 
BaseJointPdf< V, M > * m_pdf
 
BaseVectorRealizer< V, M > * m_realizer
 
const BaseVectorCdf< V, M > * m_subCdf
 
const BaseVectorCdf< V, M > * m_unifiedCdf
 
const BaseVectorMdf< V, M > * m_mdf
 

Detailed Description

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

A class representing a Gaussian vector RV.

This class allows the user to compute the value of a Gaussian PDF and to generate realizations (samples) from it.

In probability theory, the normal (or Gaussian) distribution is a continuous probability distribution, defined by the formula:

\[ f(x| \mu,\sigma) = \frac{1}{\sigma\sqrt{2\pi}} e^{ -\frac{(x-\mu)^2}{2\sigma^2} }. \]

The parameter $ \mu $ in this formula is the mean or expectation of the distribution (and also its median and mode). The parameter $ \sigma $ is its standard deviation; its variance is therefore $ \sigma^2 $ .

Definition at line 63 of file GaussianVectorRV.h.

Constructor & Destructor Documentation

template<class V, class M>
QUESO::GaussianVectorRV< V, M >::GaussianVectorRV ( const char *  prefix,
const VectorSet< V, M > &  imageSet,
const V &  lawExpVector,
const V &  lawVarVector 
)

Constructor.

Construct a Gaussian vector RV with mean lawExpVector and diagonal covariance matrix lawVarVector whose variates live in imageSet.

Definition at line 35 of file GaussianVectorRV.C.

References QUESO::BaseEnvironment::displayVerbosity(), QUESO::BaseVectorRV< V, M >::m_env, QUESO::BaseVectorRV< V, M >::m_imageSet, QUESO::BaseVectorRV< V, M >::m_mdf, QUESO::BaseVectorRV< V, M >::m_pdf, QUESO::BaseVectorRV< V, M >::m_prefix, QUESO::BaseVectorRV< V, M >::m_realizer, QUESO::BaseVectorRV< V, M >::m_subCdf, QUESO::BaseVectorRV< V, M >::m_unifiedCdf, queso_require_greater_msg, and QUESO::BaseEnvironment::subDisplayFile().

40  :
41  BaseVectorRV<V,M>(((std::string)(prefix)+"gau").c_str(),imageSet)
42 {
43  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
44  *m_env.subDisplayFile() << "Entering GaussianVectorRV<V,M>::constructor() [1]"
45  << ": prefix = " << m_prefix
46  << std::endl;
47  }
48 
49  queso_require_greater_msg(lawVarVector.getMinValue(), 0.0, "Covariance matrix is not symmetric positive definite.");
50 
51  m_pdf = new GaussianJointPdf<V,M>(m_prefix.c_str(),
52  m_imageSet,
53  lawExpVector,
54  lawVarVector);
55 
56  V cholDiag(lawVarVector);
57  cholDiag.cwSqrt();
58  M lowerCholLawCovMatrix(cholDiag);
59  lowerCholLawCovMatrix.zeroUpper(false);
60 
61  m_realizer = new GaussianVectorRealizer<V,M>(m_prefix.c_str(),
62  m_imageSet,
63  lawExpVector,
64  lowerCholLawCovMatrix);
65 
66  m_subCdf = NULL; // FIX ME: complete code
67  m_unifiedCdf = NULL; // FIX ME: complete code
68  m_mdf = NULL; // FIX ME: complete code
69 
70  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
71  *m_env.subDisplayFile() << "Leaving GaussianVectorRV<V,M>::constructor() [1]"
72  << ": prefix = " << m_prefix
73  << std::endl;
74  }
75 }
unsigned int displayVerbosity() const
Definition: Environment.C:396
const VectorSet< V, M > & m_imageSet
Definition: VectorRV.h:117
BaseJointPdf< V, M > * m_pdf
Definition: VectorRV.h:118
std::string m_prefix
Definition: VectorRV.h:116
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:274
const BaseVectorCdf< V, M > * m_unifiedCdf
Definition: VectorRV.h:121
const BaseEnvironment & m_env
Definition: VectorRV.h:115
const VectorSet< V, M > & imageSet() const
Image set of the vector RV; access to private attribute m_imageSet.
Definition: VectorRV.C:79
const BaseVectorMdf< V, M > * m_mdf
Definition: VectorRV.h:122
#define queso_require_greater_msg(expr1, expr2, msg)
Definition: asserts.h:88
const BaseVectorCdf< V, M > * m_subCdf
Definition: VectorRV.h:120
BaseVectorRealizer< V, M > * m_realizer
Definition: VectorRV.h:119
template<class V, class M>
QUESO::GaussianVectorRV< V, M >::GaussianVectorRV ( const char *  prefix,
const VectorSet< V, M > &  imageSet,
const V &  lawExpVector,
const M &  lawCovMatrix 
)

Constructor.

Construct a Gaussian vector RV with mean lawExpVector and covariance matrix lawCovMatrix whose variates live in imageSet.

Definition at line 78 of file GaussianVectorRV.C.

References QUESO::BaseEnvironment::displayVerbosity(), QUESO::BaseVectorRV< V, M >::m_env, QUESO::BaseVectorRV< V, M >::m_imageSet, QUESO::BaseVectorRV< V, M >::m_mdf, QUESO::BaseVectorRV< V, M >::m_pdf, QUESO::BaseVectorRV< V, M >::m_prefix, QUESO::BaseVectorRV< V, M >::m_realizer, QUESO::BaseVectorRV< V, M >::m_subCdf, QUESO::BaseVectorRV< V, M >::m_unifiedCdf, queso_require_msg, and QUESO::BaseEnvironment::subDisplayFile().

83  :
84  BaseVectorRV<V,M>(((std::string)(prefix)+"gau").c_str(),imageSet)
85 {
86  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
87  *m_env.subDisplayFile() << "Entering GaussianVectorRV<V,M>::constructor() [2]"
88  << ": prefix = " << m_prefix
89  << std::endl;
90  }
91 
92  m_pdf = new GaussianJointPdf<V,M>(m_prefix.c_str(),
93  m_imageSet,
94  lawExpVector,
95  lawCovMatrix);
96 
97  M lowerCholLawCovMatrix(lawCovMatrix);
98  int iRC = lowerCholLawCovMatrix.chol();
99  lowerCholLawCovMatrix.zeroUpper(false);
100  if (iRC) {
101  std::cerr << "In GaussianVectorRV<V,M>::constructor() [2]: chol failed, will use svd\n";
102  if (m_env.subDisplayFile()) {
103  *m_env.subDisplayFile() << "In GaussianVectorRV<V,M>::constructor() [2]: chol failed; will use svd; lawCovMatrix contents are\n";
104  *m_env.subDisplayFile() << lawCovMatrix; // FIX ME: might demand parallelism
105  *m_env.subDisplayFile() << std::endl;
106  }
107  M matU (lawCovMatrix);
108  M matVt(m_imageSet.vectorSpace().zeroVector());
109  V vecS (m_imageSet.vectorSpace().zeroVector());
110  iRC = lawCovMatrix.svd(matU,vecS,matVt);
111  queso_require_msg(!(iRC), "Cholesky decomposition of covariance matrix failed.");
112 
113  vecS.cwSqrt();
114  m_realizer = new GaussianVectorRealizer<V,M>(m_prefix.c_str(),
115  m_imageSet,
116  lawExpVector,
117  matU,
118  vecS, // already square rooted
119  matVt);
120  }
121  else {
122  m_realizer = new GaussianVectorRealizer<V,M>(m_prefix.c_str(),
123  m_imageSet,
124  lawExpVector,
125  lowerCholLawCovMatrix);
126  }
127 
128  m_subCdf = NULL; // FIX ME: complete code
129  m_unifiedCdf = NULL; // FIX ME: complete code
130  m_mdf = NULL; // FIX ME: complete code
131 
132  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
133  *m_env.subDisplayFile() << "Leaving GaussianVectorRV<V,M>::constructor() [2]"
134  << ": prefix = " << m_prefix
135  << std::endl;
136  }
137 }
unsigned int displayVerbosity() const
Definition: Environment.C:396
const VectorSet< V, M > & m_imageSet
Definition: VectorRV.h:117
BaseJointPdf< V, M > * m_pdf
Definition: VectorRV.h:118
std::string m_prefix
Definition: VectorRV.h:116
#define queso_require_msg(asserted, msg)
Definition: asserts.h:69
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:274
const BaseVectorCdf< V, M > * m_unifiedCdf
Definition: VectorRV.h:121
const BaseEnvironment & m_env
Definition: VectorRV.h:115
const VectorSet< V, M > & imageSet() const
Image set of the vector RV; access to private attribute m_imageSet.
Definition: VectorRV.C:79
const BaseVectorMdf< V, M > * m_mdf
Definition: VectorRV.h:122
const BaseVectorCdf< V, M > * m_subCdf
Definition: VectorRV.h:120
BaseVectorRealizer< V, M > * m_realizer
Definition: VectorRV.h:119
template<class V , class M >
QUESO::GaussianVectorRV< V, M >::~GaussianVectorRV ( )
virtual

Virtual destructor.

Definition at line 140 of file GaussianVectorRV.C.

141 {
142  delete m_mdf;
143  delete m_unifiedCdf;
144  delete m_subCdf;
145  delete m_realizer;
146  delete m_pdf;
147 }
BaseJointPdf< V, M > * m_pdf
Definition: VectorRV.h:118
const BaseVectorCdf< V, M > * m_unifiedCdf
Definition: VectorRV.h:121
const BaseVectorMdf< V, M > * m_mdf
Definition: VectorRV.h:122
const BaseVectorCdf< V, M > * m_subCdf
Definition: VectorRV.h:120
BaseVectorRealizer< V, M > * m_realizer
Definition: VectorRV.h:119

Member Function Documentation

template<class V , class M >
void QUESO::GaussianVectorRV< V, M >::print ( std::ostream &  os) const
virtual

TODO: Prints the vector RV.

Todo:
: implement me!

Implements QUESO::BaseVectorRV< V, M >.

Definition at line 195 of file GaussianVectorRV.C.

196 {
197  os << "GaussianVectorRV<V,M>::print() says, 'Please implement me.'" << std::endl;
198  return;
199 }
template<class V , class M>
void QUESO::GaussianVectorRV< V, M >::updateLawCovMatrix ( const M &  newLawCovMatrix)

Updates the covariance matrix.

This method tries to use Cholesky decomposition; and if it fails, the method then calls a SVD decomposition.

Definition at line 161 of file GaussianVectorRV.C.

References queso_require_msg.

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

162 {
163  // We are sure that m_pdf (and m_realizer, etc) point to associated Gaussian classes, so all is well
164  ( dynamic_cast< GaussianJointPdf<V,M>* >(m_pdf) )->updateLawCovMatrix(newLawCovMatrix);
165 
166  M newLowerCholLawCovMatrix(newLawCovMatrix);
167  int iRC = newLowerCholLawCovMatrix.chol();
168  newLowerCholLawCovMatrix.zeroUpper(false);
169  if (iRC) {
170  std::cerr << "In GaussianVectorRV<V,M>::updateLawCovMatrix(): chol failed, will use svd\n";
171  if (m_env.subDisplayFile()) {
172  *m_env.subDisplayFile() << "In GaussianVectorRV<V,M>::updateLawCovMatrix(): chol failed; will use svd; newLawCovMatrix contents are\n";
173  *m_env.subDisplayFile() << newLawCovMatrix; // FIX ME: might demand parallelism
174  *m_env.subDisplayFile() << std::endl;
175  }
176  M matU (newLawCovMatrix);
177  M matVt(m_imageSet.vectorSpace().zeroVector());
178  V vecS (m_imageSet.vectorSpace().zeroVector());
179  iRC = newLawCovMatrix.svd(matU,vecS,matVt);
180  queso_require_msg(!(iRC), "Cholesky decomposition of covariance matrix failed.");
181 
182  vecS.cwSqrt();
183  ( dynamic_cast< GaussianVectorRealizer<V,M>* >(m_realizer) )->updateLowerCholLawCovMatrix(matU,
184  vecS, // already square rooted
185  matVt);
186  }
187  else {
188  ( dynamic_cast< GaussianVectorRealizer<V,M>* >(m_realizer) )->updateLowerCholLawCovMatrix(newLowerCholLawCovMatrix);
189  }
190  return;
191 }
const VectorSet< V, M > & m_imageSet
Definition: VectorRV.h:117
BaseJointPdf< V, M > * m_pdf
Definition: VectorRV.h:118
#define queso_require_msg(asserted, msg)
Definition: asserts.h:69
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:274
const BaseEnvironment & m_env
Definition: VectorRV.h:115
BaseVectorRealizer< V, M > * m_realizer
Definition: VectorRV.h:119
template<class V, class M >
void QUESO::GaussianVectorRV< V, M >::updateLawExpVector ( const V &  newLawExpVector)

Updates the vector that contains the mean values.

Definition at line 151 of file GaussianVectorRV.C.

Referenced by QUESO::ScaledCovMatrixTKGroup< V, M >::rv(), and QUESO::HessianCovMatricesTKGroup< V, M >::rv().

152 {
153  // We are sure that m_pdf (and m_realizer, etc) point to associated Gaussian classes, so all is well
154  ( dynamic_cast< GaussianJointPdf <V,M>* >(m_pdf ) )->updateLawExpVector(newLawExpVector);
155  ( dynamic_cast< GaussianVectorRealizer<V,M>* >(m_realizer) )->updateLawExpVector(newLawExpVector);
156  return;
157 }
BaseJointPdf< V, M > * m_pdf
Definition: VectorRV.h:118
BaseVectorRealizer< V, M > * m_realizer
Definition: VectorRV.h:119

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

Generated on Thu Jun 11 2015 13:52:35 for queso-0.53.0 by  doxygen 1.8.5