queso-0.51.1
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,2009,2010,2011,2012,2013 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 namespace QUESO {
32 
33 template<class V, class M>
35  const char * prefix,
36  const BoxSubset<V, M> & unifiedImageBoxSubset,
37  const V & lawExpVector,
38  const M & lowerCholLawCovMatrix)
39  : BaseVectorRealizer<V, M>(((std::string)(prefix)+"invlogit_gau").c_str(),
40  unifiedImageBoxSubset, std::numeric_limits<unsigned int>::max()),
41  m_unifiedLawExpVector(new V(lawExpVector)),
42  m_unifiedLawVarVector(
43  unifiedImageBoxSubset.vectorSpace().newVector(INFINITY)), // FIX ME
44  m_lowerCholLawCovMatrix(new M(lowerCholLawCovMatrix)),
45  m_matU(NULL),
46  m_vecSsqrt(NULL),
47  m_matVt(NULL),
48  m_unifiedImageBoxSubset(unifiedImageBoxSubset)
49 {
50  *m_unifiedLawExpVector = lawExpVector;
51 }
52 
53 template<class V, class M>
55  const char * prefix,
56  const BoxSubset<V, M> & unifiedImageBoxSubset,
57  const V & lawExpVector,
58  const M & matU,
59  const V & vecSsqrt,
60  const M & matVt)
61  : BaseVectorRealizer<V, M>(((std::string)(prefix)+"invlogit_gau").c_str(),
62  unifiedImageBoxSubset, std::numeric_limits<unsigned int>::max()),
63  m_unifiedLawExpVector(new V(lawExpVector)),
64  m_unifiedLawVarVector(
65  unifiedImageBoxSubset.vectorSpace().newVector( INFINITY)), // FIX ME
66  m_lowerCholLawCovMatrix(NULL),
67  m_matU(new M(matU)),
68  m_vecSsqrt(new V(vecSsqrt)),
69  m_matVt(new M(matVt)),
70  m_unifiedImageBoxSubset(unifiedImageBoxSubset)
71 {
72  *m_unifiedLawExpVector = lawExpVector; // ????
73 }
74 
75 template<class V, class M>
77 {
78  delete m_matVt;
79  delete m_vecSsqrt;
80  delete m_matU;
81  delete m_lowerCholLawCovMatrix;
82  delete m_unifiedLawVarVector;
83  delete m_unifiedLawExpVector;
84 }
85 
86 template <class V, class M>
87 const V &
89 {
90  return *m_unifiedLawExpVector;
91 }
92 
93 template <class V, class M>
94 const V &
96 {
97  return *m_unifiedLawVarVector;
98 }
99 
100 template<class V, class M>
101 void
103 {
104  V iidGaussianVector(m_unifiedImageSet.vectorSpace().zeroVector());
105 
106  iidGaussianVector.cwSetGaussian(0.0, 1.0);
107 
108  if (m_lowerCholLawCovMatrix) {
109  nextValues = (*m_unifiedLawExpVector) +
110  (*m_lowerCholLawCovMatrix) * iidGaussianVector;
111  }
112  else if (m_matU && m_vecSsqrt && m_matVt) {
113  nextValues = (*m_unifiedLawExpVector) +
114  (*m_matU) * ((*m_vecSsqrt) * ((*m_matVt) * iidGaussianVector));
115  }
116  else {
117  queso_error_msg("GaussianVectorRealizer<V,M>::realization() inconsistent internal state");
118  }
119 
120  V min_domain_bounds(this->m_unifiedImageBoxSubset.minValues());
121  V max_domain_bounds(this->m_unifiedImageBoxSubset.maxValues());
122 
123  for (unsigned int i = 0; i < nextValues.sizeLocal(); i++) {
124  double temp = std::exp(nextValues[i]);
125  double min_val = min_domain_bounds[i];
126  double max_val = max_domain_bounds[i];
127 
128  if (boost::math::isfinite(min_val) &&
129  boost::math::isfinite(max_val)) {
130  // Left- and right-hand sides are finite. Do full transform.
131  nextValues[i] = (max_val * temp + min_val) / (1.0 + temp);
132  }
133  else if (boost::math::isfinite(min_val) &&
134  !boost::math::isfinite(max_val)) {
135  // Left-hand side finite, but right-hand side is not.
136  // Do only left-hand transform.
137  nextValues[i] = temp + min_val;
138  }
139  else if (!boost::math::isfinite(min_val) &&
140  boost::math::isfinite(max_val)) {
141  // Right-hand side is finite, but left-hand side is not.
142  // Do only right-hand transform.
143  nextValues[i] = (max_val * temp - 1.0) / temp;
144  }
145  }
146 }
147 
148 template<class V, class M>
149 void
151  const V & newLawExpVector)
152 {
153  // delete old expected values (allocated at construction or last call to this function)
154  delete m_unifiedLawExpVector;
155 
156  m_unifiedLawExpVector = new V(newLawExpVector);
157 }
158 
159 template<class V, class M>
160 void
162  const M & newLowerCholLawCovMatrix)
163 {
164  // delete old expected values (allocated at construction or last call to this function)
165  delete m_lowerCholLawCovMatrix;
166  delete m_matU;
167  delete m_vecSsqrt;
168  delete m_matVt;
169 
170  m_lowerCholLawCovMatrix = new M(newLowerCholLawCovMatrix);
171  m_matU = NULL;
172  m_vecSsqrt = NULL;
173  m_matVt = NULL;
174 }
175 
176 template<class V, class M>
177 void
179  const M & matU,
180  const V & vecSsqrt,
181  const M & matVt)
182 {
183  // delete old expected values (allocated at construction or last call to this function)
184  delete m_lowerCholLawCovMatrix;
185  delete m_matU;
186  delete m_vecSsqrt;
187  delete m_matVt;
188 
189  m_lowerCholLawCovMatrix = NULL;
190  m_matU = new M(matU);
191  m_vecSsqrt = new V(vecSsqrt);
192  m_matVt = new M(matVt);
193 }
194 
195 } // End namespace QUESO
196 
const V & unifiedLawVarVector() const
Access to the vector of variance values and private attribute: m_unifiedLawVarVector.
A templated (base) class for handling sampling from vector RVs.
InvLogitGaussianVectorRealizer(const char *prefix, const BoxSubset< V, M > &unifiedImageBoxSubset, const V &lawExpVector, const M &lowerCholLawCovMatrix)
Constructor.
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...
#define queso_error_msg(msg)
Definition: asserts.h:91
void updateLawExpVector(const V &newLawExpVector)
Updates the mean of the Gaussian with the new value newLawExpVector.
void realization(V &nextValues) const
Draws a realization.
Class representing a subset of a vector space shaped like a hypercube.
Definition: BoxSubset.h:41
A class for handling sampling from (transformed) Gaussian probability density distributions with boun...

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