queso-0.52.0
InvLogitGaussianVectorRV.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/InvLogitGaussianVectorRV.h>
26 #include <queso/InvLogitGaussianVectorRealizer.h>
27 #include <queso/InvLogitGaussianJointPdf.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 BoxSubset<V, M> & imageBoxSubset,
38  const V & lawExpVector,
39  const V & lawVarVector)
40  : BaseVectorRV<V, M>(((std::string)(prefix)+"invlogit_gau").c_str(),
41  imageBoxSubset)
42 {
43  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
44  *m_env.subDisplayFile() << "Entering InvLogitGaussianVectorRV<V,M>::constructor() [1]"
45  << ": prefix = " << m_prefix
46  << std::endl;
47  }
48 
49  UQ_FATAL_TEST_MACRO((lawVarVector.getMinValue() <= 0.0),
50  m_env.worldRank(),
51  "InvLogitGaussianVectorRV<V,M>::constructor() [1]",
52  "Covariance matrix is not symmetric positive definite.");
53 
55  dynamic_cast<const BoxSubset<V, M> & >(m_imageSet), lawExpVector,
56  lawVarVector);
57 
58  V cholDiag(lawVarVector);
59  cholDiag.cwSqrt();
60  M lowerCholLawCovMatrix(cholDiag);
61  lowerCholLawCovMatrix.zeroUpper(false);
62 
64  dynamic_cast<const BoxSubset<V, M> & >(m_imageSet), lawExpVector,
65  lowerCholLawCovMatrix);
66 
67  m_subCdf = NULL; // FIX ME: complete code
68  m_unifiedCdf = NULL; // FIX ME: complete code
69  m_mdf = NULL; // FIX ME: complete code
70 
71  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
72  *m_env.subDisplayFile() << "Leaving InvLogitGaussianVectorRV<V,M>::constructor() [1]"
73  << ": prefix = " << m_prefix
74  << std::endl;
75  }
76 }
77 
78 template<class V, class M>
80  const char * prefix,
81  const BoxSubset<V, M> & imageBoxSubset,
82  const V & lawExpVector,
83  const M & lawCovMatrix)
84  : BaseVectorRV<V, M>(((std::string)(prefix)+"invlogit_gau").c_str(),
85  imageBoxSubset)
86 {
87  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
88  *m_env.subDisplayFile() << "Entering InvLogitGaussianVectorRV<V,M>::constructor() [2]"
89  << ": prefix = " << m_prefix
90  << std::endl;
91  }
92 
94  dynamic_cast<const BoxSubset<V, M> & >(m_imageSet),
95  lawExpVector, lawCovMatrix);
96 
97  M lowerCholLawCovMatrix(lawCovMatrix);
98  int iRC = lowerCholLawCovMatrix.chol();
99  lowerCholLawCovMatrix.zeroUpper(false);
100  if (iRC) {
101  std::cerr << "In InvLogitGaussianVectorRV<V,M>::constructor() [2]: chol failed, will use svd\n";
102  if (m_env.subDisplayFile()) {
103  *m_env.subDisplayFile() << "In InvLogitGaussianVectorRV<V,M>::constructor() [2]: chol failed; will use svd; lawCovMatrix contents are\n";
104  *m_env.subDisplayFile() << lawCovMatrix; // FIX ME: might demand parallelism
105  *m_env.subDisplayFile() << std::endl;
106  }
107  M matU (lawCovMatrix);
108  M matVt(m_imageSet.vectorSpace().zeroVector());
109  V vecS (m_imageSet.vectorSpace().zeroVector());
110  iRC = lawCovMatrix.svd(matU,vecS,matVt);
112  m_env.worldRank(),
113  "InvLogitGaussianVectorRV<V,M>::constructor() [2]",
114  "Cholesky decomposition of covariance matrix failed.");
115 
116  vecS.cwSqrt();
118  dynamic_cast<const BoxSubset<V, M> & >(m_imageSet), lawExpVector, matU,
119  vecS, matVt);
120  }
121  else {
123  dynamic_cast<const BoxSubset<V, M> & >(m_imageSet), lawExpVector, lowerCholLawCovMatrix);
124  }
125 
126  m_subCdf = NULL; // FIX ME: complete code
127  m_unifiedCdf = NULL; // FIX ME: complete code
128  m_mdf = NULL; // FIX ME: complete code
129 
130  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
131  *m_env.subDisplayFile() << "Leaving InvLogitGaussianVectorRV<V,M>::constructor() [2]"
132  << ": prefix = " << m_prefix
133  << std::endl;
134  }
135 }
136 
137 template<class V, class M>
139 {
140  delete m_mdf;
141  delete m_unifiedCdf;
142  delete m_subCdf;
143  delete m_realizer;
144  delete m_pdf;
145 }
146 
147 template<class V, class M>
148 void
150 {
151  // We are sure that m_pdf (and m_realizer, etc) point to associated Gaussian
152  // classes, so all is well
153  (dynamic_cast<InvLogitGaussianJointPdf<V, M> * >(m_pdf))->updateLawExpVector(
154  newLawExpVector);
155  (dynamic_cast<InvLogitGaussianVectorRealizer<V, M> * >(m_realizer))->
156  updateLawExpVector(newLawExpVector);
157  return;
158 }
159 
160 template<class V, class M>
161 void
163 {
164  // We are sure that m_pdf (and m_realizer, etc) point to associated Gaussian
165  // classes, so all is well
166  (dynamic_cast<InvLogitGaussianJointPdf<V,M> * >(m_pdf))->updateLawCovMatrix(
167  newLawCovMatrix);
168 
169  M newLowerCholLawCovMatrix(newLawCovMatrix);
170  int iRC = newLowerCholLawCovMatrix.chol();
171  newLowerCholLawCovMatrix.zeroUpper(false);
172  if (iRC) {
173  std::cerr << "In InvLogitGaussianVectorRV<V,M>::updateLawCovMatrix(): chol failed, will use svd\n";
174  if (m_env.subDisplayFile()) {
175  *m_env.subDisplayFile() << "In InvLogitGaussianVectorRV<V,M>::updateLawCovMatrix(): chol failed; will use svd; newLawCovMatrix contents are\n";
176  *m_env.subDisplayFile() << newLawCovMatrix; // FIX ME: might demand parallelism
177  *m_env.subDisplayFile() << std::endl;
178  }
179  M matU (newLawCovMatrix);
180  M matVt(m_imageSet.vectorSpace().zeroVector());
181  V vecS (m_imageSet.vectorSpace().zeroVector());
182  iRC = newLawCovMatrix.svd(matU,vecS,matVt);
184  m_env.worldRank(),
185  "InvLogitGaussianVectorRV<V,M>::updateLawCovMatrix()",
186  "Cholesky decomposition of covariance matrix failed.");
187 
188  vecS.cwSqrt();
189  (dynamic_cast<InvLogitGaussianVectorRealizer<V, M> * >(m_realizer))->
190  updateLowerCholLawCovMatrix(matU, vecS, matVt);
191  }
192  else {
193  (dynamic_cast<InvLogitGaussianVectorRealizer<V, M> * >(m_realizer))->
194  updateLowerCholLawCovMatrix(newLowerCholLawCovMatrix);
195  }
196  return;
197 }
198 
199 template <class V, class M>
200 void
202 {
203  os << "InvLogitGaussianVectorRV<V,M>::print() says, 'Please implement me.'" << std::endl;
204  return;
205 }
206 
207 } // End namespace QUESO
208 
void print(std::ostream &os) const
TODO: Prints the vector RV.
int worldRank() const
Returns the process world rank.
Definition: Environment.C:235
std::string m_prefix
Definition: VectorRV.h:113
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:305
void updateLawCovMatrix(const M &newLawCovMatrix)
Updates the covariance matrix.
Class representing a subset of a vector space shaped like a hypercube.
Definition: BoxSubset.h:41
A class for handling sampling from (transformed) Gaussian probability density distributions with boun...
const BaseVectorMdf< V, M > * m_mdf
Definition: VectorRV.h:119
#define UQ_FATAL_TEST_MACRO(test, givenRank, where, what)
Definition: Defines.h:223
InvLogitGaussianVectorRV(const char *prefix, const BoxSubset< V, M > &imageBoxSubset, const V &lawExpVector, const V &lawVarVector)
Constructor.
const VectorSet< V, M > & m_imageSet
Definition: VectorRV.h:114
A class for handling hybrid (transformed) Gaussians with bounds.
A templated base class for handling vector RV.
Definition: VectorRV.h:51
BaseJointPdf< V, M > * m_pdf
Definition: VectorRV.h:115
const BaseVectorCdf< V, M > * m_subCdf
Definition: VectorRV.h:117
void updateLawExpVector(const V &newLawExpVector)
Updates the vector that contains the mean values for the underlying Gaussian.
const BaseVectorCdf< V, M > * m_unifiedCdf
Definition: VectorRV.h:118
const BaseEnvironment & m_env
Definition: VectorRV.h:112
virtual ~InvLogitGaussianVectorRV()
Virtual destructor.
unsigned int displayVerbosity() const
Definition: Environment.C:436
BaseVectorRealizer< V, M > * m_realizer
Definition: VectorRV.h:116
A class representing a (transformed) Gaussian vector RV with bounds.

Generated on Thu Apr 23 2015 19:30:54 for queso-0.52.0 by  doxygen 1.8.5