queso-0.51.1
LogNormalVectorRV.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/LogNormalVectorRV.h>
26 #include <queso/LogNormalJointPdf.h>
27 #include <queso/LogNormalVectorRealizer.h>
28 #include <queso/GslVector.h>
29 #include <queso/GslMatrix.h>
30 
31 namespace QUESO {
32 
33 // Constructor---------------------------------------
34 template<class V, class M>
36  const char* prefix,
37  const VectorSet<V,M>& imageSet,
38  const V& lawExpVector,
39  const V& lawVarVector)
40  :
41  BaseVectorRV<V,M>(((std::string)(prefix)+"gau").c_str(),imageSet)
42 {
43  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
44  *m_env.subDisplayFile() << "Entering LogNormalVectorRV<V,M>::constructor() [1]"
45  << ": prefix = " << m_prefix
46  << std::endl;
47  }
48 
49 // begin kemelli 2013-April-23 --------------------------
50 // LogNormal dist is defined only in (0,inf)
51 
52  const BoxSubset<V,M>* imageBox = dynamic_cast<const BoxSubset<V,M>* >(&imageSet);
53  double smallerOfMaxValues = imageBox->maxValues().getMinValue();
54  double smallerOfMinValues = imageBox->minValues().getMinValue();
55 
56  if( smallerOfMinValues < 0 )
57  {
58  std::cerr << "In LogNormalVectorRV<V,M>::constructor()\n"
59  << "LogNormal distribution is only defined in (0, infinity).\n"
60  << "The data provided is: \n"
61  << *imageBox
62  << "Sampling will not cover all interval.\n"
63  << std::endl;
64 
65 
66  UQ_FATAL_TEST_MACRO(smallerOfMaxValues < 0,
67  m_env.worldRank(),
68  "LogNormalVectorRealizer<V,M>::constructor()",
69  "invalid input: LogNormal distribution is only defined in (0, infinity), and min(m_maxValues)<0");
70 
71  }
72 // end kemelli 2013-April-23 --------------------------
73 
75  m_imageSet,
76  lawExpVector,
77  lawVarVector);
78 
79  M lowerCholLawCovMatrix(lawVarVector);
80  int iRC = lowerCholLawCovMatrix.chol();
81  lowerCholLawCovMatrix.zeroUpper(false);
82  if (iRC) {
83  std::cerr << "In LogNormalVectorRV<V,M>::constructor() [1]: chol failed, will use svd\n";
84  if (m_env.subDisplayFile()) {
85  *m_env.subDisplayFile() << "In LogNormalVectorRV<V,M>::constructor() [1]: chol failed; will use svd; lawVarVector contents are\n";
86  *m_env.subDisplayFile() << lawVarVector; // FIX ME: might demand parallelism
87  *m_env.subDisplayFile() << std::endl;
88  }
89  M matLaw(lawVarVector);
90  M matU (lawVarVector);
91  M matVt (m_imageSet.vectorSpace().zeroVector());
92  V vecS (m_imageSet.vectorSpace().zeroVector());
93  iRC = matLaw.svd(matU,vecS,matVt);
95  m_env.worldRank(),
96  "LogNormalVectorRV<V,M>::constructor() [1]",
97  "Cholesky decomposition of covariance matrix failed.");
98 
99  vecS.cwSqrt();
101  m_imageSet,
102  lawExpVector,
103  matU,
104  vecS, // already square rooted
105  matVt);
106  }
107  else {
109  m_imageSet,
110  lawExpVector,
111  lowerCholLawCovMatrix);
112  }
113 
114  m_subCdf = NULL; // FIX ME: complete code
115  m_unifiedCdf = NULL; // FIX ME: complete code
116  m_mdf = NULL; // FIX ME: complete code
117 
118  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
119  *m_env.subDisplayFile() << "Leaving LogNormalVectorRV<V,M>::constructor() [1]"
120  << ": prefix = " << m_prefix
121  << std::endl;
122  }
123 }
124 // Destructor ---------------------------------------
125 template<class V, class M>
127 {
128  delete m_mdf;
129  delete m_unifiedCdf;
130  delete m_subCdf;
131  delete m_realizer;
132  delete m_pdf;
133 }
134 // I/O methods---------------------------------------
135 template <class V, class M>
136 void
137 LogNormalVectorRV<V,M>::print(std::ostream& os) const
138 {
139  os << "LogNormalVectorRV<V,M>::print() says, 'Please implement me.'" << std::endl;
140  return;
141 }
142 
143 
144 } // End namespace QUESO
145 
const BaseVectorCdf< V, M > * m_unifiedCdf
Definition: VectorRV.h:118
A templated class for handling sets.
Definition: VectorSet.h:49
void print(std::ostream &os) const
TODO: Prints the vector RV.
const V & minValues() const
Vector of the minimum values of the box subset.
Definition: BoxSubset.C:82
int worldRank() const
Returns the process world rank.
Definition: Environment.C:235
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:305
const VectorSet< V, M > & m_imageSet
Definition: VectorRV.h:114
const BaseEnvironment & m_env
Definition: VectorRV.h:112
const V & maxValues() const
Vector of the maximum values of the box subset.
Definition: BoxSubset.C:88
const BaseVectorCdf< V, M > * m_subCdf
Definition: VectorRV.h:117
BaseVectorRealizer< V, M > * m_realizer
Definition: VectorRV.h:116
A class representing a LogNormal vector RV.
virtual ~LogNormalVectorRV()
Virtual destructor.
LogNormalVectorRV(const char *prefix, const VectorSet< V, M > &imageSet, const V &lawExpVector, const V &lawVarVector)
Constructor.
const VectorSet< V, M > & imageSet() const
Image set of the vector RV; access to private attribute m_imageSet.
Definition: VectorRV.C:79
Class representing a subset of a vector space shaped like a hypercube.
Definition: BoxSubset.h:41
A class for handling sampling from a Log-Normal probability density distribution. ...
A templated base class for handling vector RV.
Definition: VectorRV.h:51
unsigned int displayVerbosity() const
Definition: Environment.C:436
const BaseVectorMdf< V, M > * m_mdf
Definition: VectorRV.h:119
#define UQ_FATAL_TEST_MACRO(test, givenRank, where, what)
Definition: Defines.h:223
std::string m_prefix
Definition: VectorRV.h:113
BaseJointPdf< V, M > * m_pdf
Definition: VectorRV.h:115
A class for handling Log-Normal joint PDFs.

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