queso-0.53.0
InvLogitGaussianVectorRealizer.C
Go to the documentation of this file.
1 //-----------------------------------------------------------------------bl-
2 //--------------------------------------------------------------------------
3 //
4 // QUESO - a library to support the Quantification of Uncertainty
5 // for Estimation, Simulation and Optimization
6 //
7 // Copyright (C) 2008-2015 The PECOS Development Team
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the Version 2.1 GNU Lesser General
11 // Public License as published by the Free Software Foundation.
12 //
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Lesser General Public License for more details.
17 //
18 // You should have received a copy of the GNU Lesser General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc. 51 Franklin Street, Fifth Floor,
21 // Boston, MA 02110-1301 USA
22 //
23 //-----------------------------------------------------------------------el-
24 
25 #include <cmath>
26 
27 #include <queso/InvLogitGaussianVectorRealizer.h>
28 #include <queso/GslVector.h>
29 #include <queso/GslMatrix.h>
30 
31 #include <boost/math/special_functions/fpclassify.hpp>
32 
33 namespace QUESO {
34 
35 template<class V, class M>
37  const char * prefix,
38  const BoxSubset<V, M> & unifiedImageBoxSubset,
39  const V & lawExpVector,
40  const M & lowerCholLawCovMatrix)
41  : BaseVectorRealizer<V, M>(((std::string)(prefix)+"invlogit_gau").c_str(),
42  unifiedImageBoxSubset, std::numeric_limits<unsigned int>::max()),
43  m_unifiedLawExpVector(new V(lawExpVector)),
44  m_unifiedLawVarVector(
45  unifiedImageBoxSubset.vectorSpace().newVector(INFINITY)), // FIX ME
46  m_lowerCholLawCovMatrix(new M(lowerCholLawCovMatrix)),
47  m_matU(NULL),
48  m_vecSsqrt(NULL),
49  m_matVt(NULL),
50  m_unifiedImageBoxSubset(unifiedImageBoxSubset)
51 {
52  *m_unifiedLawExpVector = lawExpVector;
53 }
54 
55 template<class V, class M>
57  const char * prefix,
58  const BoxSubset<V, M> & unifiedImageBoxSubset,
59  const V & lawExpVector,
60  const M & matU,
61  const V & vecSsqrt,
62  const M & matVt)
63  : BaseVectorRealizer<V, M>(((std::string)(prefix)+"invlogit_gau").c_str(),
64  unifiedImageBoxSubset, std::numeric_limits<unsigned int>::max()),
65  m_unifiedLawExpVector(new V(lawExpVector)),
66  m_unifiedLawVarVector(
67  unifiedImageBoxSubset.vectorSpace().newVector( INFINITY)), // FIX ME
68  m_lowerCholLawCovMatrix(NULL),
69  m_matU(new M(matU)),
70  m_vecSsqrt(new V(vecSsqrt)),
71  m_matVt(new M(matVt)),
72  m_unifiedImageBoxSubset(unifiedImageBoxSubset)
73 {
74  *m_unifiedLawExpVector = lawExpVector; // ????
75 }
76 
77 template<class V, class M>
79 {
80  delete m_matVt;
81  delete m_vecSsqrt;
82  delete m_matU;
83  delete m_lowerCholLawCovMatrix;
84  delete m_unifiedLawVarVector;
85  delete m_unifiedLawExpVector;
86 }
87 
88 template <class V, class M>
89 const V &
91 {
92  return *m_unifiedLawExpVector;
93 }
94 
95 template <class V, class M>
96 const V &
98 {
99  return *m_unifiedLawVarVector;
100 }
101 
102 template<class V, class M>
103 void
105 {
106  V iidGaussianVector(m_unifiedImageSet.vectorSpace().zeroVector());
107 
108  iidGaussianVector.cwSetGaussian(0.0, 1.0);
109 
110  if (m_lowerCholLawCovMatrix) {
111  nextValues = (*m_unifiedLawExpVector) +
112  (*m_lowerCholLawCovMatrix) * iidGaussianVector;
113  }
114  else if (m_matU && m_vecSsqrt && m_matVt) {
115  nextValues = (*m_unifiedLawExpVector) +
116  (*m_matU) * ((*m_vecSsqrt) * ((*m_matVt) * iidGaussianVector));
117  }
118  else {
119  queso_error_msg("GaussianVectorRealizer<V,M>::realization() inconsistent internal state");
120  }
121 
122  V min_domain_bounds(this->m_unifiedImageBoxSubset.minValues());
123  V max_domain_bounds(this->m_unifiedImageBoxSubset.maxValues());
124 
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];
129 
130  if (boost::math::isfinite(min_val) &&
131  boost::math::isfinite(max_val)) {
132  // Left- and right-hand sides are finite. Do full transform.
133  nextValues[i] = (max_val * temp + min_val) / (1.0 + temp);
134  }
135  else if (boost::math::isfinite(min_val) &&
136  !boost::math::isfinite(max_val)) {
137  // Left-hand side finite, but right-hand side is not.
138  // Do only left-hand transform.
139  nextValues[i] = temp + min_val;
140  }
141  else if (!boost::math::isfinite(min_val) &&
142  boost::math::isfinite(max_val)) {
143  // Right-hand side is finite, but left-hand side is not.
144  // Do only right-hand transform.
145  nextValues[i] = (max_val * temp - 1.0) / temp;
146  }
147  }
148 }
149 
150 template<class V, class M>
151 void
153  const V & newLawExpVector)
154 {
155  // delete old expected values (allocated at construction or last call to this function)
156  delete m_unifiedLawExpVector;
157 
158  m_unifiedLawExpVector = new V(newLawExpVector);
159 }
160 
161 template<class V, class M>
162 void
164  const M & newLowerCholLawCovMatrix)
165 {
166  // delete old expected values (allocated at construction or last call to this function)
167  delete m_lowerCholLawCovMatrix;
168  delete m_matU;
169  delete m_vecSsqrt;
170  delete m_matVt;
171 
172  m_lowerCholLawCovMatrix = new M(newLowerCholLawCovMatrix);
173  m_matU = NULL;
174  m_vecSsqrt = NULL;
175  m_matVt = NULL;
176 }
177 
178 template<class V, class M>
179 void
181  const M & matU,
182  const V & vecSsqrt,
183  const M & matVt)
184 {
185  // delete old expected values (allocated at construction or last call to this function)
186  delete m_lowerCholLawCovMatrix;
187  delete m_matU;
188  delete m_vecSsqrt;
189  delete m_matVt;
190 
191  m_lowerCholLawCovMatrix = NULL;
192  m_matU = new M(matU);
193  m_vecSsqrt = new V(vecSsqrt);
194  m_matVt = new M(matVt);
195 }
196 
197 } // End namespace QUESO
198 
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)
Definition: asserts.h:47
A templated (base) class for handling sampling from vector RVs.
Class representing a subset of a vector space shaped like a hypercube.
Definition: BoxSubset.h:44
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...

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