27 #include <queso/InvLogitGaussianVectorRealizer.h>
28 #include <queso/GslVector.h>
29 #include <queso/GslMatrix.h>
31 #include <boost/math/special_functions/fpclassify.hpp>
35 template<
class V,
class M>
39 const V & lawExpVector,
40 const M & lowerCholLawCovMatrix)
42 unifiedImageBoxSubset, std::numeric_limits<unsigned int>::max()),
43 m_unifiedLawExpVector(new V(lawExpVector)),
44 m_unifiedLawVarVector(
45 unifiedImageBoxSubset.vectorSpace().newVector(INFINITY)),
46 m_lowerCholLawCovMatrix(new M(lowerCholLawCovMatrix)),
50 m_unifiedImageBoxSubset(unifiedImageBoxSubset)
55 template<
class V,
class M>
59 const V & lawExpVector,
64 unifiedImageBoxSubset, std::numeric_limits<unsigned int>::max()),
65 m_unifiedLawExpVector(new V(lawExpVector)),
66 m_unifiedLawVarVector(
67 unifiedImageBoxSubset.vectorSpace().newVector( INFINITY)),
68 m_lowerCholLawCovMatrix(NULL),
70 m_vecSsqrt(new V(vecSsqrt)),
71 m_matVt(new M(matVt)),
72 m_unifiedImageBoxSubset(unifiedImageBoxSubset)
77 template<
class V,
class M>
83 delete m_lowerCholLawCovMatrix;
84 delete m_unifiedLawVarVector;
85 delete m_unifiedLawExpVector;
88 template <
class V,
class M>
92 return *m_unifiedLawExpVector;
95 template <
class V,
class M>
99 return *m_unifiedLawVarVector;
102 template<
class V,
class M>
106 V iidGaussianVector(m_unifiedImageSet.vectorSpace().zeroVector());
108 iidGaussianVector.cwSetGaussian(0.0, 1.0);
110 if (m_lowerCholLawCovMatrix) {
111 nextValues = (*m_unifiedLawExpVector) +
112 (*m_lowerCholLawCovMatrix) * iidGaussianVector;
114 else if (m_matU && m_vecSsqrt && m_matVt) {
115 nextValues = (*m_unifiedLawExpVector) +
116 (*m_matU) * ((*m_vecSsqrt) * ((*m_matVt) * iidGaussianVector));
119 queso_error_msg(
"GaussianVectorRealizer<V,M>::realization() inconsistent internal state");
122 V min_domain_bounds(this->m_unifiedImageBoxSubset.minValues());
123 V max_domain_bounds(this->m_unifiedImageBoxSubset.maxValues());
125 for (
unsigned int i = 0; i < nextValues.sizeLocal(); i++) {
126 double temp = std::exp(nextValues[i]);
127 double min_val = min_domain_bounds[i];
128 double max_val = max_domain_bounds[i];
130 if (boost::math::isfinite(min_val) &&
131 boost::math::isfinite(max_val)) {
133 nextValues[i] = (max_val * temp + min_val) / (1.0 + temp);
135 else if (boost::math::isfinite(min_val) &&
136 !boost::math::isfinite(max_val)) {
139 nextValues[i] = temp + min_val;
141 else if (!boost::math::isfinite(min_val) &&
142 boost::math::isfinite(max_val)) {
145 nextValues[i] = (max_val * temp - 1.0) / temp;
150 template<
class V,
class M>
153 const V & newLawExpVector)
156 delete m_unifiedLawExpVector;
158 m_unifiedLawExpVector =
new V(newLawExpVector);
161 template<
class V,
class M>
164 const M & newLowerCholLawCovMatrix)
167 delete m_lowerCholLawCovMatrix;
172 m_lowerCholLawCovMatrix =
new M(newLowerCholLawCovMatrix);
178 template<
class V,
class M>
186 delete m_lowerCholLawCovMatrix;
191 m_lowerCholLawCovMatrix = NULL;
192 m_matU =
new M(matU);
193 m_vecSsqrt =
new V(vecSsqrt);
194 m_matVt =
new M(matVt);
~InvLogitGaussianVectorRealizer()
Destructor.
void realization(V &nextValues) const
Draws a realization.
A class for handling sampling from (transformed) Gaussian probability density distributions with boun...
#define queso_error_msg(msg)
A templated (base) class for handling sampling from vector RVs.
Class representing a subset of a vector space shaped like a hypercube.
const V & unifiedLawVarVector() const
Access to the vector of variance values and private attribute: m_unifiedLawVarVector.
InvLogitGaussianVectorRealizer(const char *prefix, const BoxSubset< V, M > &unifiedImageBoxSubset, const V &lawExpVector, const M &lowerCholLawCovMatrix)
Constructor.
void updateLawExpVector(const V &newLawExpVector)
Updates the mean of the Gaussian with the new value newLawExpVector.
const V & unifiedLawExpVector() const
Access to the vector of mean values of the Gaussian and private attribute: m_unifiedLawExpVector.
void updateLowerCholLawCovMatrix(const M &newLowerCholLawCovMatrix)
Updates the lower triangular matrix from Cholesky decomposition of the covariance matrix to the new v...
V * m_unifiedLawExpVector