queso-0.51.1
GaussianVectorRealizer.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 <queso/GaussianVectorRealizer.h>
26 #include <queso/GslVector.h>
27 #include <queso/GslMatrix.h>
28 
29 namespace QUESO {
30 
31 // Constructor -------------------------------------
32 template<class V, class M>
34  const VectorSet<V,M>& unifiedImageSet,
35  const V& lawExpVector,
36  const M& lowerCholLawCovMatrix)
37  :
38  BaseVectorRealizer<V,M>( ((std::string)(prefix)+"gau").c_str(), unifiedImageSet, std::numeric_limits<unsigned int>::max()), // 2011/Oct/02 - Correction thanks to Corey
39  m_unifiedLawExpVector (new V(lawExpVector)),
40  m_unifiedLawVarVector (unifiedImageSet.vectorSpace().newVector( INFINITY)), // FIX ME
41  m_lowerCholLawCovMatrix(new M(lowerCholLawCovMatrix)),
42  m_matU (NULL),
43  m_vecSsqrt (NULL),
44  m_matVt (NULL)
45 {
46  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 5)) {
47  *m_env.subDisplayFile() << "Entering GaussianVectorRealizer<V,M>::constructor() [1]"
48  << ": prefix = " << m_prefix
49  << std::endl;
50  }
51 
52  *m_unifiedLawExpVector = lawExpVector; // ????
53 
54  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 5)) {
55  *m_env.subDisplayFile() << "Leaving GaussianVectorRealizer<V,M>::constructor() [1]"
56  << ": prefix = " << m_prefix
57  << std::endl;
58  }
59 }
60 // Constructor -------------------------------------
61 template<class V, class M>
63  const VectorSet<V,M>& unifiedImageSet,
64  const V& lawExpVector,
65  const M& matU,
66  const V& vecSsqrt,
67  const M& matVt)
68  :
69  BaseVectorRealizer<V,M>( ((std::string)(prefix)+"gau").c_str(), unifiedImageSet, std::numeric_limits<unsigned int>::max()), // 2011/Oct/02 - Correction thanks to Corey
70  m_unifiedLawExpVector (new V(lawExpVector)),
71  m_unifiedLawVarVector (unifiedImageSet.vectorSpace().newVector( INFINITY)), // FIX ME
72  m_lowerCholLawCovMatrix(NULL),
73  m_matU (new M(matU)),
74  m_vecSsqrt (new V(vecSsqrt)),
75  m_matVt (new M(matVt))
76 {
77  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 5)) {
78  *m_env.subDisplayFile() << "Entering GaussianVectorRealizer<V,M>::constructor() [2]"
79  << ": prefix = " << m_prefix
80  << std::endl;
81  }
82 
83  *m_unifiedLawExpVector = lawExpVector; // ????
84 
85  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 5)) {
86  *m_env.subDisplayFile() << "Leaving GaussianVectorRealizer<V,M>::constructor() [2]"
87  << ": prefix = " << m_prefix
88  << std::endl;
89  }
90 }
91 // Destructor --------------------------------------
92 template<class V, class M>
94 {
95  delete m_matVt;
96  delete m_vecSsqrt;
97  delete m_matU;
98  delete m_lowerCholLawCovMatrix;
99  delete m_unifiedLawVarVector;
100  delete m_unifiedLawExpVector;
101 }
102 // Realization-related methods----------------------
103 template <class V, class M>
104 const V&
106 {
107  return *m_unifiedLawExpVector;
108 }
109 //--------------------------------------------------
110 template <class V, class M>
111 const V&
113 {
114  return *m_unifiedLawVarVector;
115 }
116 //--------------------------------------------------
117 template<class V, class M>
118 void
120 {
121  V iidGaussianVector(m_unifiedImageSet.vectorSpace().zeroVector());
122 
123  bool outOfSupport = true;
124  do {
125  iidGaussianVector.cwSetGaussian(0.0, 1.0);
126 
127  if (m_lowerCholLawCovMatrix) {
128  nextValues = (*m_unifiedLawExpVector) + (*m_lowerCholLawCovMatrix)*iidGaussianVector;
129  }
130  else if (m_matU && m_vecSsqrt && m_matVt) {
131  nextValues = (*m_unifiedLawExpVector) + (*m_matU)*( (*m_vecSsqrt) * ((*m_matVt)*iidGaussianVector) );
132  }
133  else {
134  UQ_FATAL_TEST_MACRO(true,
135  m_env.worldRank(),
136  "GaussianVectorRealizer<V,M>::realization()",
137  "inconsistent internal state");
138  }
139 
140  outOfSupport = !(this->m_unifiedImageSet.contains(nextValues));
141  } while (outOfSupport); // prudenci 2011-Oct-04
142 
143  return;
144 }
145 //--------------------------------------------------
146 template<class V, class M>
147 void
149 {
150  // delete old expected values (allocated at construction or last call to this function)
151  delete m_unifiedLawExpVector;
152 
153  m_unifiedLawExpVector = new V(newLawExpVector);
154 
155  return;
156 }
157 //--------------------------------------------------
158 template<class V, class M>
159 void
161 {
162  // delete old expected values (allocated at construction or last call to this function)
163  delete m_lowerCholLawCovMatrix;
164  delete m_matU;
165  delete m_vecSsqrt;
166  delete m_matVt;
167 
168  m_lowerCholLawCovMatrix = new M(newLowerCholLawCovMatrix);
169  m_matU = NULL;
170  m_vecSsqrt = NULL;
171  m_matVt = NULL;
172 
173  return;
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  return;
195 }
196 
197 } // End namespace QUESO
198 
void realization(V &nextValues) const
Draws a realization.
A templated class for handling sets.
Definition: VectorSet.h:49
A templated (base) class for handling sampling from vector RVs.
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:305
const V & unifiedLawExpVector() const
Access to the vector of mean values and private attribute: m_unifiedLawExpVector. ...
void updateLawExpVector(const V &newLawExpVector)
Updates the mean with the new value newLawExpVector.
const BaseEnvironment & m_env
const V & unifiedLawVarVector() const
Access to the vector of variance values and private attribute: m_unifiedLawVarVector.
A class for handling sampling from Gaussian probability density distributions.
GaussianVectorRealizer(const char *prefix, const VectorSet< V, M > &unifiedImageSet, const V &lawExpVector, const M &lowerCholLawCovMatrix)
Constructor.
unsigned int displayVerbosity() const
Definition: Environment.C:436
#define UQ_FATAL_TEST_MACRO(test, givenRank, where, what)
Definition: Defines.h:223
void updateLowerCholLawCovMatrix(const M &newLowerCholLawCovMatrix)
Updates the lower triangular matrix from Cholesky decomposition of the covariance matrix to the new v...

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