queso-0.52.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  UQ_FATAL_TEST_MACRO(m_rvs.size() == 0,
82  m_env.worldRank(),
83  "ScaledCovMatrixTKGroup<V,M>::rv1()",
84  "m_rvs.size() = 0");
85 
86  UQ_FATAL_TEST_MACRO(m_rvs[0] == NULL, // Yes, '0', because that is the id used below
87  m_env.worldRank(),
88  "ScaledCovMatrixTKGroup<V,M>::rv1()",
89  "m_rvs[0] == NULL");
90 
91  UQ_FATAL_TEST_MACRO(m_preComputingPositions.size() <= stageId,
92  m_env.worldRank(),
93  "ScaledCovMatrixTKGroup<V,M>::rv1()",
94  "m_preComputingPositions.size() <= stageId");
95 
96  UQ_FATAL_TEST_MACRO(m_preComputingPositions[stageId] == NULL,
97  m_env.worldRank(),
98  "ScaledCovMatrixTKGroup<V,M>::rv1()",
99  "m_preComputingPositions[stageId] == NULL");
100 
101  if ((m_env.subDisplayFile() ) &&
102  (m_env.displayVerbosity() >= 10)) {
103  *m_env.subDisplayFile() << "In ScaledCovMatrixTKGroup<V,M>::rv1()"
104  << ", stageId = " << stageId
105  << ": about to call m_rvs[0]->updateLawExpVector()"
106  << ", vector = " << *m_preComputingPositions[stageId] // FIX ME: might demand parallelism
107  << std::endl;
108  }
109 
110  GaussianVectorRV<V, M> * gaussian_rv = dynamic_cast<GaussianVectorRV<V, M> * >(m_rvs[0]);
111 
112  gaussian_rv->updateLawExpVector(*m_preComputingPositions[stageId]);
113 
114  return (*gaussian_rv);
115 }
116 //---------------------------------------------------
117 template<class V, class M>
119 ScaledCovMatrixTKGroup<V,M>::rv(const std::vector<unsigned int>& stageIds)
120 {
121  UQ_FATAL_TEST_MACRO(m_rvs.size() < stageIds.size(),
122  m_env.worldRank(),
123  "ScaledCovMatrixTKGroup<V,M>::rv2()",
124  "m_rvs.size() < stageIds.size()");
125 
126  UQ_FATAL_TEST_MACRO(m_rvs[stageIds.size()-1] == NULL,
127  m_env.worldRank(),
128  "ScaledCovMatrixTKGroup<V,M>::rv2()",
129  "m_rvs[stageIds.size()-1] == NULL");
130 
131  UQ_FATAL_TEST_MACRO(m_preComputingPositions.size() <= stageIds[0],
132  m_env.worldRank(),
133  "ScaledCovMatrixTKGroup<V,M>::rv2()",
134  "m_preComputingPositions.size() <= stageIds[0]");
135 
136  UQ_FATAL_TEST_MACRO(m_preComputingPositions[stageIds[0]] == NULL,
137  m_env.worldRank(),
138  "ScaledCovMatrixTKGroup<V,M>::rv2()",
139  "m_preComputingPositions[stageIds[0]] == NULL");
140 
141  if ((m_env.subDisplayFile() ) &&
142  (m_env.displayVerbosity() >= 10)) {
143  *m_env.subDisplayFile() << "In ScaledCovMatrixTKGroup<V,M>::rv2()"
144  << ", stageIds.size() = " << stageIds.size()
145  << ", stageIds[0] = " << stageIds[0]
146  << ": about to call m_rvs[stageIds.size()-1]->updateLawExpVector()"
147  << ", vector = " << *m_preComputingPositions[stageIds[0]] // FIX ME: might demand parallelism
148  << std::endl;
149  }
150 
151  GaussianVectorRV<V, M> * gaussian_rv = dynamic_cast<GaussianVectorRV<V, M> * >(m_rvs[stageIds.size()-1]);
152 
153  gaussian_rv->updateLawExpVector(*m_preComputingPositions[stageIds[0]]);
154 
155  return (*gaussian_rv);
156 }
157 //---------------------------------------------------
158 template<class V, class M>
159 void
161 {
162  for (unsigned int i = 0; i < m_scales.size(); ++i) {
163  double factor = 1./m_scales[i]/m_scales[i];
164  if ((m_env.subDisplayFile() ) &&
165  (m_env.displayVerbosity() >= 10)) {
166  *m_env.subDisplayFile() << "In ScaledCovMatrixTKGroup<V,M>::updateLawCovMatrix()"
167  << ", m_scales.size() = " << m_scales.size()
168  << ", i = " << i
169  << ", m_scales[i] = " << m_scales[i]
170  << ", factor = " << factor
171  << ": about to call m_rvs[i]->updateLawCovMatrix()"
172  << ", covMatrix = \n" << factor*covMatrix // FIX ME: might demand parallelism
173  << std::endl;
174  }
175  dynamic_cast<GaussianVectorRV<V, M> * >(m_rvs[i])->updateLawCovMatrix(factor*covMatrix);
176  }
177 
178  return;
179 }
180 
181 // Misc methods -------------------------------------
182 template<class V, class M>
183 bool
184 ScaledCovMatrixTKGroup<V,M>::setPreComputingPosition(const V& position, unsigned int stageId)
185 {
186  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 5)) {
187  *m_env.subDisplayFile() << "Entering ScaledCovMatrixTKGroup<V,M>::setPreComputingPosition()"
188  << ": position = " << position
189  << ", stageId = " << stageId
190  << std::endl;
191  }
192 
194  //setRVsWithZeroMean();
195 
196  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 5)) {
197  *m_env.subDisplayFile() << "In ScaledCovMatrixTKGroup<V,M>::setPreComputingPosition()"
198  << ", position = " << position
199  << ", stageId = " << stageId
200  << ": preComputingPos = " << *m_preComputingPositions[stageId];
201  if (stageId < m_scales.size()) {
202  *m_env.subDisplayFile() << ", factor = " << 1./m_scales[stageId]/m_scales[stageId];
203  }
204  if (stageId < m_rvs.size()) {
205  const GaussianJointPdf<V,M>* pdfPtr = dynamic_cast< const GaussianJointPdf<V,M>* >(&(m_rvs[stageId]->pdf()));
206  *m_env.subDisplayFile() << ", rvCov = " << pdfPtr->lawCovMatrix(); // FIX ME: might demand parallelism
207  }
208  *m_env.subDisplayFile() << std::endl;
209  }
210 
211  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 5)) {
212  *m_env.subDisplayFile() << "Leaving ScaledCovMatrixTKGroup<V,M>::setPreComputingPosition()"
213  << ": position = " << position
214  << ", stageId = " << stageId
215  << std::endl;
216  }
217 
218  return true;
219 }
220 //---------------------------------------------------
221 template<class V, class M>
222 void
224 {
226  return;
227 }
228 
229 
230 // Private methods------------------------------------
231 template<class V, class M>
232 void
234 {
235  UQ_FATAL_TEST_MACRO(m_rvs.size() == 0,
236  m_env.worldRank(),
237  "ScaledCovMatrixTKGroup<V,M>::setRVsWithZeroMean()",
238  "m_rvs.size() = 0");
239 
240  UQ_FATAL_TEST_MACRO(m_rvs.size() != m_scales.size(),
241  m_env.worldRank(),
242  "ScaledCovMatrixTKGroup<V,M>::setRVsWithZeroMean()",
243  "m_rvs.size() != m_scales.size()");
244 
245  for (unsigned int i = 0; i < m_scales.size(); ++i) {
246  double factor = 1./m_scales[i]/m_scales[i];
247  UQ_FATAL_TEST_MACRO(m_rvs[i] != NULL,
248  m_env.worldRank(),
249  "ScaledCovMatrixTKGroup<V,M>::setRVsWithZeroMean()",
250  "m_rvs[i] != NULL");
251  m_rvs[i] = new GaussianVectorRV<V,M>(m_prefix.c_str(),
252  *m_vectorSpace,
253  m_vectorSpace->zeroVector(),
254  factor*m_originalCovMatrix);
255  }
256 
257  return;
258 }
259 // I/O methods---------------------------------------
260 template<class V, class M>
261 void
262 ScaledCovMatrixTKGroup<V,M>::print(std::ostream& os) const
263 {
265  return;
266 }
267 
268 } // End namespace QUESO
269 
std::vector< double > m_scales
Definition: TKGroup.h:102
This base class allows the representation of a transition kernel.
Definition: TKGroup.h:49
void setRVsWithZeroMean()
Sets the mean of the RVs to zero.
const BaseEnvironment & m_env
Definition: TKGroup.h:99
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:305
virtual void clearPreComputingPositions()
Clears the pre-computing positions m_preComputingPositions[stageId].
Definition: TKGroup.C:121
void clearPreComputingPositions()
Clears the pre-computing positions m_preComputingPositions[stageId].
virtual void print(std::ostream &os) const
TODO: Prints the transition kernel.
Definition: TKGroup.C:135
A class for handling Gaussian joint PDFs.
#define UQ_FATAL_TEST_MACRO(test, givenRank, where, what)
Definition: Defines.h:223
void updateLawExpVector(const V &newLawExpVector)
Updates the vector that contains the mean values.
void updateLawCovMatrix(const M &covMatrix)
Scales the covariance matrix.
void print(std::ostream &os) const
TODO: Prints the transition kernel.
bool setPreComputingPosition(const V &position, unsigned int stageId)
Sets the pre-computing positions m_preComputingPositions[stageId] with a new vector of size position...
This class allows the representation of a transition kernel with a scaled covariance matrix...
unsigned int displayVerbosity() const
Definition: Environment.C:436
ScaledCovMatrixTKGroup(const char *prefix, const VectorSpace< V, M > &vectorSpace, const std::vector< double > &scales, const M &covMatrix)
Default constructor.
const M & lawCovMatrix() const
Returns the covariance matrix; access to protected attribute m_lawCovMatrix.
A class representing a vector space.
Definition: VectorSet.h:46
std::vector< const V * > m_preComputingPositions
Definition: TKGroup.h:103
A class representing a Gaussian vector RV.
const GaussianVectorRV< V, M > & rv(unsigned int stageId) const
Gaussian increment property to construct a transition kernel.
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:102
std::vector< BaseVectorRV< V, M > * > m_rvs
Definition: TKGroup.h:104
bool symmetric() const
Whether or not the matrix is symmetric. Always &#39;true&#39;.

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