queso-0.53.0
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-2015 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  queso_require_greater_equal_msg(smallerOfMaxValues, 0, "invalid input: LogNormal distribution is only defined in (0, infinity), and min(m_maxValues)<0");
67 
68  }
69 // end kemelli 2013-April-23 --------------------------
70 
72  m_imageSet,
73  lawExpVector,
74  lawVarVector);
75 
76  M lowerCholLawCovMatrix(lawVarVector);
77  int iRC = lowerCholLawCovMatrix.chol();
78  lowerCholLawCovMatrix.zeroUpper(false);
79  if (iRC) {
80  std::cerr << "In LogNormalVectorRV<V,M>::constructor() [1]: chol failed, will use svd\n";
81  if (m_env.subDisplayFile()) {
82  *m_env.subDisplayFile() << "In LogNormalVectorRV<V,M>::constructor() [1]: chol failed; will use svd; lawVarVector contents are\n";
83  *m_env.subDisplayFile() << lawVarVector; // FIX ME: might demand parallelism
84  *m_env.subDisplayFile() << std::endl;
85  }
86  M matLaw(lawVarVector);
87  M matU (lawVarVector);
88  M matVt (m_imageSet.vectorSpace().zeroVector());
89  V vecS (m_imageSet.vectorSpace().zeroVector());
90  iRC = matLaw.svd(matU,vecS,matVt);
91  queso_require_msg(!(iRC), "Cholesky decomposition of covariance matrix failed.");
92 
93  vecS.cwSqrt();
95  m_imageSet,
96  lawExpVector,
97  matU,
98  vecS, // already square rooted
99  matVt);
100  }
101  else {
103  m_imageSet,
104  lawExpVector,
105  lowerCholLawCovMatrix);
106  }
107 
108  m_subCdf = NULL; // FIX ME: complete code
109  m_unifiedCdf = NULL; // FIX ME: complete code
110  m_mdf = NULL; // FIX ME: complete code
111 
112  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
113  *m_env.subDisplayFile() << "Leaving LogNormalVectorRV<V,M>::constructor() [1]"
114  << ": prefix = " << m_prefix
115  << std::endl;
116  }
117 }
118 // Destructor ---------------------------------------
119 template<class V, class M>
121 {
122  delete m_mdf;
123  delete m_unifiedCdf;
124  delete m_subCdf;
125  delete m_realizer;
126  delete m_pdf;
127 }
128 // I/O methods---------------------------------------
129 template <class V, class M>
130 void
131 LogNormalVectorRV<V,M>::print(std::ostream& os) const
132 {
133  os << "LogNormalVectorRV<V,M>::print() says, 'Please implement me.'" << std::endl;
134  return;
135 }
136 
137 
138 } // End namespace QUESO
139 
unsigned int displayVerbosity() const
Definition: Environment.C:396
A templated class for handling sets.
Definition: VectorSet.h:52
const VectorSet< V, M > & m_imageSet
Definition: VectorRV.h:117
A class representing a LogNormal vector RV.
A templated base class for handling vector RV.
Definition: VectorRV.h:54
void print(std::ostream &os) const
TODO: Prints the vector RV.
virtual ~LogNormalVectorRV()
Virtual destructor.
BaseJointPdf< V, M > * m_pdf
Definition: VectorRV.h:118
std::string m_prefix
Definition: VectorRV.h:116
#define queso_require_msg(asserted, msg)
Definition: asserts.h:69
A class for handling sampling from a Log-Normal probability density distribution. ...
const V & maxValues() const
Vector of the maximum values of the box subset.
Definition: BoxSubset.C:79
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:274
const V & minValues() const
Vector of the minimum values of the box subset.
Definition: BoxSubset.C:73
LogNormalVectorRV(const char *prefix, const VectorSet< V, M > &imageSet, const V &lawExpVector, const V &lawVarVector)
Constructor.
const BaseVectorCdf< V, M > * m_unifiedCdf
Definition: VectorRV.h:121
Class representing a subset of a vector space shaped like a hypercube.
Definition: BoxSubset.h:44
const BaseEnvironment & m_env
Definition: VectorRV.h:115
A class for handling Log-Normal joint PDFs.
const VectorSet< V, M > & imageSet() const
Image set of the vector RV; access to private attribute m_imageSet.
Definition: VectorRV.C:79
const BaseVectorMdf< V, M > * m_mdf
Definition: VectorRV.h:122
#define queso_require_greater_equal_msg(expr1, expr2, msg)
Definition: asserts.h:90
const BaseVectorCdf< V, M > * m_subCdf
Definition: VectorRV.h:120
BaseVectorRealizer< V, M > * m_realizer
Definition: VectorRV.h:119

Generated on Thu Jun 11 2015 13:52:32 for queso-0.53.0 by  doxygen 1.8.5