queso-0.53.0
ScaledCovMatrixTKGroup.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/ScaledCovMatrixTKGroup.h>
26 #include <queso/GslVector.h>
27 #include <queso/GslMatrix.h>
28 #include <queso/GaussianJointPdf.h>
29 
30 namespace QUESO {
31 
32 // Default constructor ------------------------------
33 template<class V, class M>
35  const char* prefix,
36  const VectorSpace<V,M>& vectorSpace, // FIX ME: vectorSubset ???
37  const std::vector<double>& scales,
38  const M& covMatrix)
39  :
40  BaseTKGroup<V,M>(prefix,vectorSpace,scales),
41  m_originalCovMatrix (covMatrix)
42 {
43  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 5)) {
44  *m_env.subDisplayFile() << "Entering ScaledCovMatrixTKGroup<V,M>::constructor()"
45  << std::endl;
46  }
47 
48  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 5)) {
49  *m_env.subDisplayFile() << "In ScaledCovMatrixTKGroup<V,M>::constructor()"
50  << ": m_scales.size() = " << m_scales.size()
51  << ", m_preComputingPositions.size() = " << m_preComputingPositions.size()
52  << ", m_rvs.size() = " << m_rvs.size()
53  << ", m_originalCovMatrix = " << m_originalCovMatrix
54  << std::endl;
55  }
56 
58 
59  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 5)) {
60  *m_env.subDisplayFile() << "Leaving ScaledCovMatrixTKGroup<V,M>::constructor()"
61  << std::endl;
62  }
63 }
64 // Destructor ---------------------------------------
65 template<class V, class M>
67 {
68 }
69 // Math/Stats methods--------------------------------
70 template<class V, class M>
71 bool
73 {
74  return true;
75 }
76 //---------------------------------------------------
77 template<class V, class M>
79 ScaledCovMatrixTKGroup<V,M>::rv(unsigned int stageId) const
80 {
81  queso_require_not_equal_to_msg(m_rvs.size(), 0, "m_rvs.size() = 0");
82 
83  queso_require_msg(m_rvs[0], "m_rvs[0] == NULL");
84 
85  queso_require_greater_msg(m_preComputingPositions.size(), stageId, "m_preComputingPositions.size() <= stageId");
86 
87  queso_require_msg(m_preComputingPositions[stageId], "m_preComputingPositions[stageId] == NULL");
88 
89  if ((m_env.subDisplayFile() ) &&
90  (m_env.displayVerbosity() >= 10)) {
91  *m_env.subDisplayFile() << "In ScaledCovMatrixTKGroup<V,M>::rv1()"
92  << ", stageId = " << stageId
93  << ": about to call m_rvs[0]->updateLawExpVector()"
94  << ", vector = " << *m_preComputingPositions[stageId] // FIX ME: might demand parallelism
95  << std::endl;
96  }
97 
98  GaussianVectorRV<V, M> * gaussian_rv = dynamic_cast<GaussianVectorRV<V, M> * >(m_rvs[0]);
99 
100  gaussian_rv->updateLawExpVector(*m_preComputingPositions[stageId]);
101 
102  return (*gaussian_rv);
103 }
104 //---------------------------------------------------
105 template<class V, class M>
107 ScaledCovMatrixTKGroup<V,M>::rv(const std::vector<unsigned int>& stageIds)
108 {
109  queso_require_greater_equal_msg(m_rvs.size(), stageIds.size(), "m_rvs.size() < stageIds.size()");
110 
111  queso_require_msg(m_rvs[stageIds.size()-1], "m_rvs[stageIds.size()-1] == NULL");
112 
113  queso_require_greater_msg(m_preComputingPositions.size(), stageIds[0], "m_preComputingPositions.size() <= stageIds[0]");
114 
115  queso_require_msg(m_preComputingPositions[stageIds[0]], "m_preComputingPositions[stageIds[0]] == NULL");
116 
117  if ((m_env.subDisplayFile() ) &&
118  (m_env.displayVerbosity() >= 10)) {
119  *m_env.subDisplayFile() << "In ScaledCovMatrixTKGroup<V,M>::rv2()"
120  << ", stageIds.size() = " << stageIds.size()
121  << ", stageIds[0] = " << stageIds[0]
122  << ": about to call m_rvs[stageIds.size()-1]->updateLawExpVector()"
123  << ", vector = " << *m_preComputingPositions[stageIds[0]] // FIX ME: might demand parallelism
124  << std::endl;
125  }
126 
127  GaussianVectorRV<V, M> * gaussian_rv = dynamic_cast<GaussianVectorRV<V, M> * >(m_rvs[stageIds.size()-1]);
128 
129  gaussian_rv->updateLawExpVector(*m_preComputingPositions[stageIds[0]]);
130 
131  return (*gaussian_rv);
132 }
133 //---------------------------------------------------
134 template<class V, class M>
135 void
137 {
138  for (unsigned int i = 0; i < m_scales.size(); ++i) {
139  double factor = 1./m_scales[i]/m_scales[i];
140  if ((m_env.subDisplayFile() ) &&
141  (m_env.displayVerbosity() >= 10)) {
142  *m_env.subDisplayFile() << "In ScaledCovMatrixTKGroup<V,M>::updateLawCovMatrix()"
143  << ", m_scales.size() = " << m_scales.size()
144  << ", i = " << i
145  << ", m_scales[i] = " << m_scales[i]
146  << ", factor = " << factor
147  << ": about to call m_rvs[i]->updateLawCovMatrix()"
148  << ", covMatrix = \n" << factor*covMatrix // FIX ME: might demand parallelism
149  << std::endl;
150  }
151  dynamic_cast<GaussianVectorRV<V, M> * >(m_rvs[i])->updateLawCovMatrix(factor*covMatrix);
152  }
153 
154  return;
155 }
156 
157 // Misc methods -------------------------------------
158 template<class V, class M>
159 bool
160 ScaledCovMatrixTKGroup<V,M>::setPreComputingPosition(const V& position, unsigned int stageId)
161 {
162  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 5)) {
163  *m_env.subDisplayFile() << "Entering ScaledCovMatrixTKGroup<V,M>::setPreComputingPosition()"
164  << ": position = " << position
165  << ", stageId = " << stageId
166  << std::endl;
167  }
168 
170  //setRVsWithZeroMean();
171 
172  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 5)) {
173  *m_env.subDisplayFile() << "In ScaledCovMatrixTKGroup<V,M>::setPreComputingPosition()"
174  << ", position = " << position
175  << ", stageId = " << stageId
176  << ": preComputingPos = " << *m_preComputingPositions[stageId];
177  if (stageId < m_scales.size()) {
178  *m_env.subDisplayFile() << ", factor = " << 1./m_scales[stageId]/m_scales[stageId];
179  }
180  if (stageId < m_rvs.size()) {
181  const GaussianJointPdf<V,M>* pdfPtr = dynamic_cast< const GaussianJointPdf<V,M>* >(&(m_rvs[stageId]->pdf()));
182  *m_env.subDisplayFile() << ", rvCov = " << pdfPtr->lawCovMatrix(); // FIX ME: might demand parallelism
183  }
184  *m_env.subDisplayFile() << std::endl;
185  }
186 
187  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 5)) {
188  *m_env.subDisplayFile() << "Leaving ScaledCovMatrixTKGroup<V,M>::setPreComputingPosition()"
189  << ": position = " << position
190  << ", stageId = " << stageId
191  << std::endl;
192  }
193 
194  return true;
195 }
196 //---------------------------------------------------
197 template<class V, class M>
198 void
200 {
202  return;
203 }
204 
205 
206 // Private methods------------------------------------
207 template<class V, class M>
208 void
210 {
211  queso_require_not_equal_to_msg(m_rvs.size(), 0, "m_rvs.size() = 0");
212 
213  queso_require_equal_to_msg(m_rvs.size(), m_scales.size(), "m_rvs.size() != m_scales.size()");
214 
215  for (unsigned int i = 0; i < m_scales.size(); ++i) {
216  double factor = 1./m_scales[i]/m_scales[i];
217  queso_require_msg(!(m_rvs[i]), "m_rvs[i] != NULL");
218  m_rvs[i] = new GaussianVectorRV<V,M>(m_prefix.c_str(),
219  *m_vectorSpace,
220  m_vectorSpace->zeroVector(),
221  factor*m_originalCovMatrix);
222  }
223 
224  return;
225 }
226 // I/O methods---------------------------------------
227 template<class V, class M>
228 void
229 ScaledCovMatrixTKGroup<V,M>::print(std::ostream& os) const
230 {
232  return;
233 }
234 
235 } // End namespace QUESO
236 
unsigned int displayVerbosity() const
Definition: Environment.C:396
virtual void print(std::ostream &os) const
TODO: Prints the transition kernel.
Definition: TKGroup.C:123
void print(std::ostream &os) const
TODO: Prints the transition kernel.
This base class allows the representation of a transition kernel.
Definition: TKGroup.h:50
void clearPreComputingPositions()
Clears the pre-computing positions m_preComputingPositions[stageId].
const GaussianVectorRV< V, M > & rv(unsigned int stageId) const
Gaussian increment property to construct a transition kernel.
void updateLawCovMatrix(const M &covMatrix)
Scales the covariance matrix.
#define queso_require_not_equal_to_msg(expr1, expr2, msg)
Definition: asserts.h:86
bool symmetric() const
Whether or not the matrix is symmetric. Always &#39;true&#39;.
This class allows the representation of a transition kernel with a scaled covariance matrix...
virtual bool setPreComputingPosition(const V &position, unsigned int stageId)
Sets the pre-computing positions m_preComputingPositions[stageId] with a new vector of size position...
Definition: TKGroup.C:96
const BaseEnvironment & m_env
Definition: TKGroup.h:100
A class for handling Gaussian joint PDFs.
#define queso_require_equal_to_msg(expr1, expr2, msg)
Definition: asserts.h:85
bool setPreComputingPosition(const V &position, unsigned int stageId)
Sets the pre-computing positions m_preComputingPositions[stageId] with a new vector of size position...
virtual void clearPreComputingPositions()
Clears the pre-computing positions m_preComputingPositions[stageId].
Definition: TKGroup.C:109
#define queso_require_msg(asserted, msg)
Definition: asserts.h:69
A class representing a Gaussian vector RV.
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:274
std::vector< const V * > m_preComputingPositions
Definition: TKGroup.h:104
const M & lawCovMatrix() const
Returns the covariance matrix; access to protected attribute m_lawCovMatrix.
std::vector< BaseVectorRV< V, M > * > m_rvs
Definition: TKGroup.h:105
void updateLawExpVector(const V &newLawExpVector)
Updates the vector that contains the mean values.
#define queso_require_greater_equal_msg(expr1, expr2, msg)
Definition: asserts.h:90
std::vector< double > m_scales
Definition: TKGroup.h:103
void setRVsWithZeroMean()
Sets the mean of the RVs to zero.
#define queso_require_greater_msg(expr1, expr2, msg)
Definition: asserts.h:88
A class representing a vector space.
Definition: VectorSet.h:49
ScaledCovMatrixTKGroup(const char *prefix, const VectorSpace< V, M > &vectorSpace, const std::vector< double > &scales, const M &covMatrix)
Default constructor.

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