25 #include <queso/GaussianVectorRV.h>
26 #include <queso/GaussianVectorRealizer.h>
27 #include <queso/GaussianJointPdf.h>
28 #include <queso/GslVector.h>
29 #include <queso/GslMatrix.h>
34 template<
class V,
class M>
38 const V& lawExpVector,
39 const V& lawVarVector)
41 BaseVectorRV<V,M>(((std::string)(prefix)+
"gau").c_str(),imageSet)
49 queso_require_greater_msg(lawVarVector.getMinValue(), 0.0,
"Covariance matrix is not symmetric positive definite.");
56 V cholDiag(lawVarVector);
58 M lowerCholLawCovMatrix(cholDiag);
59 lowerCholLawCovMatrix.zeroUpper(
false);
64 lowerCholLawCovMatrix);
77 template<
class V,
class M>
81 const V& lawExpVector,
82 const M& lawCovMatrix)
84 BaseVectorRV<V,M>(((std::string)(prefix)+
"gau").c_str(),imageSet)
97 M lowerCholLawCovMatrix(lawCovMatrix);
98 int iRC = lowerCholLawCovMatrix.chol();
99 lowerCholLawCovMatrix.zeroUpper(
false);
101 std::cerr <<
"In GaussianVectorRV<V,M>::constructor() [2]: chol failed, will use svd\n";
103 *
m_env.
subDisplayFile() <<
"In GaussianVectorRV<V,M>::constructor() [2]: chol failed; will use svd; lawCovMatrix contents are\n";
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.");
125 lowerCholLawCovMatrix);
139 template<
class V,
class M>
149 template<
class V,
class M>
159 template<
class V,
class M>
166 M newLowerCholLawCovMatrix(newLawCovMatrix);
167 int iRC = newLowerCholLawCovMatrix.chol();
168 newLowerCholLawCovMatrix.zeroUpper(
false);
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;
174 *m_env.subDisplayFile() << std::endl;
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.");
193 template <
class V,
class M>
197 os <<
"GaussianVectorRV<V,M>::print() says, 'Please implement me.'" << std::endl;
205 template<
class V,
class M>
216 M& sigmaMat11_cond_on_2)
219 unsigned int dim1 = muVec1.sizeLocal();
220 unsigned int dim2 = muVec2.sizeLocal();
222 queso_require_msg(!((sigmaMat11.numRowsLocal() != dim1) || (sigmaMat11.numCols() != dim1)),
"invalid sigmaMat11");
224 queso_require_msg(!((sigmaMat12.numRowsLocal() != dim1) || (sigmaMat12.numCols() != dim2)),
"invalid sigmaMat12");
226 queso_require_msg(!((sigmaMat21.numRowsLocal() != dim2) || (sigmaMat21.numCols() != dim1)),
"invalid sigmaMat21");
228 queso_require_msg(!((sigmaMat22.numRowsLocal() != dim2) || (sigmaMat22.numCols() != dim2)),
"invalid sigmaMat22");
231 M mat_tt(sigmaMat12);
233 mat_tt.fillWithTranspose(0,0,sigmaMat21,
true,
true);
234 double auxNorm = (mat_tt - sigmaMat12).normFrob();
235 if (auxNorm >= 1.e-12) {
237 *env.
subDisplayFile() <<
"In ComputeConditionalGaussianVectorRV()"
238 <<
": WARNING, ||sigmaMat21^T - sigmaMat12||_2 = " << auxNorm
242 queso_require_less_msg(auxNorm, 1.e-12,
"sigmaMat12 and sigmaMat21 are not transpose of each other");
248 queso_require_msg(!((sigmaMat11_cond_on_2.numRowsLocal() != dim1) || (sigmaMat11_cond_on_2.numCols() != dim1)),
"invalid sigmaMat11_cond_on_2");
250 muVec1_cond_on_2 = muVec1 + sigmaMat12 * sigmaMat22.invertMultiply(sampleVec2 - muVec2);
251 sigmaMat11_cond_on_2 = sigmaMat11 - sigmaMat12 * sigmaMat22.invertMultiply(sigmaMat21);
void print(std::ostream &os) const
TODO: Prints the vector RV.
A class for handling Gaussian joint PDFs.
const BaseVectorCdf< V, M > * m_unifiedCdf
This (virtual) class sets up the environment underlying the use of the QUESO library by an executable...
A class representing a Gaussian vector RV.
virtual ~GaussianVectorRV()
Virtual destructor.
const BaseEnvironment & m_env
Class for matrix operations using GSL library.
A templated class for handling sets.
BaseVectorRealizer< V, M > * m_realizer
A class for handling sampling from Gaussian probability density distributions.
void ComputeConditionalGaussianVectorRV(const V &muVec1, const V &muVec2, const M &sigmaMat11, const M &sigmaMat12, const M &sigmaMat21, const M &sigmaMat22, const V &sampleVec2, V &muVec1_cond_on_2, M &sigmaMat11_cond_on_2)
void updateLawExpVector(const V &newLawExpVector)
Updates the vector that contains the mean values.
Class for vector operations using GSL library.
BaseJointPdf< V, M > * m_pdf
MonteCarloSGOptions::MonteCarloSGOptions(const BaseEnvironment &env, const char *prefix, const McOptionsValues &alternativeOptionsValues queso_require_equal_to_msg)(m_env.optionsInputFileName(), std::string(""), std::string("this constructor is incompatible with the existence of an options input file"))
void updateLawCovMatrix(const M &newLawCovMatrix)
Updates the covariance matrix.
A templated base class for handling vector RV.
const BaseVectorCdf< V, M > * m_subCdf
GaussianVectorRV(const char *prefix, const VectorSet< V, M > &imageSet, const V &lawExpVector, const V &lawVarVector)
Constructor.
unsigned int displayVerbosity() const
const VectorSet< V, M > & m_imageSet
const BaseVectorMdf< V, M > * m_mdf
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).