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

Generated on Thu Apr 23 2015 19:18:34 for queso-0.50.1 by  doxygen 1.8.5