queso-0.57.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
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-2017 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 <limits>
26 #include <queso/LogNormalVectorRealizer.h>
27 #include <queso/GslVector.h>
28 #include <queso/GslMatrix.h>
29 
30 namespace QUESO {
31 
32 // Constructor -------------------------------------
33 template<class V, class M>
35  const VectorSet<V,M>& unifiedImageSet,
36  const V& lawExpVector,
37  const M& lowerCholLawCovMatrix)
38  :
39  BaseVectorRealizer<V,M>( ((std::string)(prefix)+"gau").c_str(), unifiedImageSet, std::numeric_limits<unsigned int>::max()), // 2011/Oct/02 - Correction thanks to Corey
40  m_unifiedLawExpVector (new V(lawExpVector)),
41  m_unifiedLawVarVector (unifiedImageSet.vectorSpace().newVector( INFINITY)), // FIX ME
42  m_lowerCholLawCovMatrix(new M(lowerCholLawCovMatrix)),
43  m_matU (NULL),
44  m_vecSsqrt (NULL),
45  m_matVt (NULL)
46 {
47  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 5)) {
48  *m_env.subDisplayFile() << "Entering LogNormalVectorRealizer<V,M>::constructor() [1]"
49  << ": prefix = " << m_prefix
50  << std::endl;
51  }
52 
53  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 5)) {
54  *m_env.subDisplayFile() << "Leaving LogNormalVectorRealizer<V,M>::constructor() [1]"
55  << ": prefix = " << m_prefix
56  << std::endl;
57  }
58 }
59 // Constructor -------------------------------------
60 template<class V, class M>
62  const VectorSet<V,M>& unifiedImageSet,
63  const V& lawExpVector,
64  const M& matU,
65  const V& vecSsqrt,
66  const M& matVt)
67  :
68  BaseVectorRealizer<V,M>( ((std::string)(prefix)+"gau").c_str(), unifiedImageSet, std::numeric_limits<unsigned int>::max()), // 2011/Oct/02 - Correction thanks to Corey
69  m_unifiedLawExpVector (new V(lawExpVector)),
70  m_unifiedLawVarVector (unifiedImageSet.vectorSpace().newVector( INFINITY)), // FIX ME
71  m_lowerCholLawCovMatrix(NULL),
72  m_matU (new M(matU)),
73  m_vecSsqrt (new V(vecSsqrt)),
74  m_matVt (new M(matVt))
75 {
76  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 5)) {
77  *m_env.subDisplayFile() << "Entering LogNormalVectorRealizer<V,M>::constructor() [2]"
78  << ": prefix = " << m_prefix
79  << std::endl;
80  }
81 
82  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 5)) {
83  *m_env.subDisplayFile() << "Leaving LogNormalVectorRealizer<V,M>::constructor() [2]"
84  << ": prefix = " << m_prefix
85  << std::endl;
86  }
87 }
88 // Destructor --------------------------------------
89 template<class V, class M>
91 {
92  delete m_matVt;
93  delete m_vecSsqrt;
94  delete m_matU;
95  delete m_lowerCholLawCovMatrix;
96  delete m_unifiedLawVarVector;
97  delete m_unifiedLawExpVector;
98 }
99 // Realization-related methods----------------------
100 template <class V, class M>
101 const V&
103 {
104  return *m_unifiedLawExpVector;
105 }
106 //--------------------------------------------------
107 template <class V, class M>
108 const V&
110 {
111  return *m_unifiedLawVarVector;
112 }
113 //--------------------------------------------------
114 template<class V, class M>
115 void
117 {
118  V iidGaussianVector(m_unifiedImageSet.vectorSpace().zeroVector());
119 
120  bool outOfSupport = true;
121  do {
122  iidGaussianVector.cwSetGaussian(0.0, 1.0);
123 
124  if (m_lowerCholLawCovMatrix) {
125  nextValues = (*m_unifiedLawExpVector) + (*m_lowerCholLawCovMatrix)*iidGaussianVector;
126  }
127  else if (m_matU && m_vecSsqrt && m_matVt) {
128  nextValues = (*m_unifiedLawExpVector) + (*m_matU)*( (*m_vecSsqrt) * ((*m_matVt)*iidGaussianVector) );
129  }
130  else {
131  queso_error_msg("inconsistent internal state");
132  }
133 
134  for (unsigned int i = 0; i < nextValues.sizeLocal(); ++i) {
135  nextValues[i] = std::exp(nextValues[i]);
136  }
137 
138  outOfSupport = !(this->m_unifiedImageSet.contains(nextValues));
139  } while (outOfSupport); // prudenci 2011-Oct-04
140 
141  return;
142 }
143 
144 } // End namespace QUESO
145 
A templated (base) class for handling sampling from vector RVs.
const BaseEnvironment & m_env
const V & unifiedLawVarVector() const
Access to the vector of variance values and private attribute: m_unifiedLawVarVector.
LogNormalVectorRealizer(const char *prefix, const VectorSet< V, M > &unifiedImageSet, const V &lawExpVector, const M &lowerCholLawCovMatrix)
Constructor.
A templated class for handling sets.
Definition: VectorSet.h:52
const V & unifiedLawExpVector() const
Access to the vector of mean values and private attribute: m_unifiedLawExpVector. ...
unsigned int displayVerbosity() const
Definition: Environment.C:450
A class for handling sampling from a Log-Normal probability density distribution. ...
void realization(V &nextValues) const
Draws a realization.
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:320

Generated on Tue Jun 5 2018 19:48:55 for queso-0.57.1 by  doxygen 1.8.5