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 #ifndef UQ_INV_LOGIT_GAUSSIAN_REALIZER_H
26 #define UQ_INV_LOGIT_GAUSSIAN_REALIZER_H
27 
28 #include <queso/VectorRealizer.h>
29 
30 namespace QUESO {
31 
32 class GslVector;
33 class GslMatrix;
34 
35 /*!
36  * \class InvLogitGaussianVectorRealizer
37  * \brief A class for handling sampling from (transformed) Gaussian probability density distributions with bounds
38  *
39  * To get a realization from a transformed Gaussian (i.e. with bounds), an
40  * inverse \c logit transform is applied.  I.e., samples are \f$ f(X) \f$ where
41  * \f$ X \f$ is drawn from a Gaussian and where
42  *
43  * \f[
44  *   f(x) = \frac{b \exp(x) + a}{1 + \exp(x)}.
45  * \f]
46  *
47  * This will produce a sample in the closed interval [a, b].
48  */
49 
50 template <class V = GslVector, class M = GslMatrix>
51 class InvLogitGaussianVectorRealizer : public BaseVectorRealizer<V,M> {
52 public:
53 
54   //! @name Constructor/Destructor methods
55   //@{
56   //! Constructor
57   /*!
58    * Constructs a new object, given a prefix and the image set of the vector
59    * realizer, a vector of mean values, \c lawExpVector (of the Gaussian, not
60    * the transformed Gaussian), and a lower triangular matrix resulting from
61    * Cholesky decomposition of the covariance matrix, \c lowerCholLawCovMatrix.
62    */
63   InvLogitGaussianVectorRealizer(const char * prefix,
64       const VectorSet<V, M> & unifiedImageSet, const V & lawExpVector,
65       const M & lowerCholLawCovMatrix);
66 
67   //! Constructor
68   /*!
69    * Constructs a new object, given a prefix and the image set of the vector
70    * realizer, a vector of mean values, \c lawExpVector (of the Gaussian, not
71    * the transformed Gaussian), and a set of two matrices and one vector
72    * resulting from the Single Value Decomposition of the covariance matrix,
73    * \c matU, \c vecSsqrt and \c matVt.
74    */
75   InvLogitGaussianVectorRealizer(const char * prefix,
76       const VectorSet<V, M> & unifiedImageSet, const V & lawExpVector,
77       const M & matU, const V & vecSsqrt, const M & matVt);
78 
79   //! Destructor
80   ~InvLogitGaussianVectorRealizer();
81   //@}
82 
83   //! @name Realization-related methods
84   //@{
85   //! Access to the vector of mean values of the Gaussian and private attribute:  m_unifiedLawExpVector.
86   const V & unifiedLawExpVector() const;
87 
88   //! Access to the vector of variance values and private attribute:  m_unifiedLawVarVector.
89   const V & unifiedLawVarVector() const;
90 
91   //! Draws a realization.
92   /*!
93    * This function draws a realization of a (transformed) Gaussian
94    * distribution with mean \c m_unifiedLawExpVector and variance
95    * \c m_unifiedLawVarVector and saves it in \c nextValues.
96    */
97   void realization(V & nextValues) const;
98 
99   //! Updates the mean of the Gaussian with the new value \c newLawExpVector.
100   void updateLawExpVector(const V & newLawExpVector);
101 
102   //! Updates the lower triangular matrix from Cholesky decomposition of the covariance matrix to the new value \c newLowerCholLawCovMatrix.
103   /*! The lower triangular matrix results resulting from a Cholesky
104    * decomposition of the covariance matrix. This routine deletes old expected
105    * values: m_lowerCholLawCovMatrix; m_matU, m_vecSsqrt, m_matVt.
106    */
107   void updateLowerCholLawCovMatrix(const M & newLowerCholLawCovMatrix);
108 
109   //! Updates the SVD matrices from SVD decomposition of the covariance matrix to the new values: \c matU, \c vecSsqrt, and \c matVt.
110   /*! The lower triangular matrix results resulting from a Cholesky
111    * decomposition of the covariance matrix. This routine deletes old expected
112    * values: m_lowerCholLawCovMatrix; m_matU, m_vecSsqrt, m_matVt.
113    */
114   void updateLowerCholLawCovMatrix(const M & matU, const V & vecSsqrt,
115       const M & matVt);
116   //@}
117 
118 private:
119   V * m_unifiedLawExpVector;
120   V * m_unifiedLawVarVector;
121   M * m_lowerCholLawCovMatrix;
122   M * m_matU;
123   V * m_vecSsqrt;
124   M * m_matVt;
125 
126   using BaseVectorRealizer<V, M>::m_env;
127   using BaseVectorRealizer<V, M>::m_prefix;
128   using BaseVectorRealizer<V, M>::m_unifiedImageSet;
129   using BaseVectorRealizer<V, M>::m_subPeriod;
130 };
131 
132 }  // End namespace QUESO
133 
134 #endif // UQ_INV_LOGIT_GAUSSIAN_REALIZER_H
135