queso-0.51.1
LogNormalVectorRealizer.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/LogNormalVectorRealizer.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 LogNormalVectorRealizer<V,M>::constructor() [1]"
48  << ": prefix = " << m_prefix
49  << std::endl;
50  }
51 
52  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 5)) {
53  *m_env.subDisplayFile() << "Leaving LogNormalVectorRealizer<V,M>::constructor() [1]"
54  << ": prefix = " << m_prefix
55  << std::endl;
56  }
57 }
58 // Constructor -------------------------------------
59 template<class V, class M>
61  const VectorSet<V,M>& unifiedImageSet,
62  const V& lawExpVector,
63  const M& matU,
64  const V& vecSsqrt,
65  const M& matVt)
66  :
67  BaseVectorRealizer<V,M>( ((std::string)(prefix)+"gau").c_str(), unifiedImageSet, std::numeric_limits<unsigned int>::max()), // 2011/Oct/02 - Correction thanks to Corey
68  m_unifiedLawExpVector (new V(lawExpVector)),
69  m_unifiedLawVarVector (unifiedImageSet.vectorSpace().newVector( INFINITY)), // FIX ME
70  m_lowerCholLawCovMatrix(NULL),
71  m_matU (new M(matU)),
72  m_vecSsqrt (new V(vecSsqrt)),
73  m_matVt (new M(matVt))
74 {
75  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 5)) {
76  *m_env.subDisplayFile() << "Entering LogNormalVectorRealizer<V,M>::constructor() [2]"
77  << ": prefix = " << m_prefix
78  << std::endl;
79  }
80 
81  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 5)) {
82  *m_env.subDisplayFile() << "Leaving LogNormalVectorRealizer<V,M>::constructor() [2]"
83  << ": prefix = " << m_prefix
84  << std::endl;
85  }
86 }
87 // Destructor --------------------------------------
88 template<class V, class M>
90 {
91  delete m_matVt;
92  delete m_vecSsqrt;
93  delete m_matU;
94  delete m_lowerCholLawCovMatrix;
95  delete m_unifiedLawVarVector;
96  delete m_unifiedLawExpVector;
97 }
98 // Realization-related methods----------------------
99 template <class V, class M>
100 const V&
102 {
103  return *m_unifiedLawExpVector;
104 }
105 //--------------------------------------------------
106 template <class V, class M>
107 const V&
109 {
110  return *m_unifiedLawVarVector;
111 }
112 //--------------------------------------------------
113 template<class V, class M>
114 void
116 {
117  V iidGaussianVector(m_unifiedImageSet.vectorSpace().zeroVector());
118 
119  bool outOfSupport = true;
120  do {
121  iidGaussianVector.cwSetGaussian(0.0, 1.0);
122 
123  if (m_lowerCholLawCovMatrix) {
124  nextValues = (*m_unifiedLawExpVector) + (*m_lowerCholLawCovMatrix)*iidGaussianVector;
125  }
126  else if (m_matU && m_vecSsqrt && m_matVt) {
127  nextValues = (*m_unifiedLawExpVector) + (*m_matU)*( (*m_vecSsqrt) * ((*m_matVt)*iidGaussianVector) );
128  }
129  else {
130  UQ_FATAL_TEST_MACRO(true,
131  m_env.worldRank(),
132  "LogNormalVectorRealizer<V,M>::realization()",
133  "inconsistent internal state");
134  }
135 
136  for (unsigned int i = 0; i < nextValues.sizeLocal(); ++i) {
137  nextValues[i] = std::exp(nextValues[i]);
138  }
139 
140  outOfSupport = !(this->m_unifiedImageSet.contains(nextValues));
141  } while (outOfSupport); // prudenci 2011-Oct-04
142 
143  return;
144 }
145 
146 } // End namespace QUESO
147 
A templated class for handling sets.
Definition: VectorSet.h:49
void realization(V &nextValues) const
Draws a realization.
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. ...
const V & unifiedLawVarVector() const
Access to the vector of variance values and private attribute: m_unifiedLawVarVector.
const BaseEnvironment & m_env
LogNormalVectorRealizer(const char *prefix, const VectorSet< V, M > &unifiedImageSet, const V &lawExpVector, const M &lowerCholLawCovMatrix)
Constructor.
A class for handling sampling from a Log-Normal probability density distribution. ...
unsigned int displayVerbosity() const
Definition: Environment.C:436
#define UQ_FATAL_TEST_MACRO(test, givenRank, where, what)
Definition: Defines.h:223

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