queso-0.57.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
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-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 #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>
136 ScaledCovMatrixTKGroup<V, M>::rv(const V & position) const
137 {
138  queso_require_not_equal_to_msg(m_rvs.size(), 0, "m_rvs.size() = 0");
139  queso_require_msg(m_rvs[0], "m_rvs[0] == NULL");
140  //queso_require_greater_msg(m_preComputingPositions.size(), this->m_stageId, "m_preComputingPositions.size() <= stageId");
141  //queso_require_msg(m_preComputingPositions[this->m_stageId], "m_preComputingPositions[stageId] == NULL");
142 
143  GaussianVectorRV<V, M> * gaussian_rv = dynamic_cast<GaussianVectorRV<V, M> * >(m_rvs[this->m_stageId]);
144 
145  gaussian_rv->updateLawExpVector(position);
146 
147  return (*gaussian_rv);
148 }
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  dynamic_cast<GaussianVectorRV<V, M> * >(m_rvs[i])->updateLawCovMatrix(factor*covMatrix);
169  }
170 }
171 
172 // Misc methods -------------------------------------
173 template<class V, class M>
174 bool
175 ScaledCovMatrixTKGroup<V,M>::setPreComputingPosition(const V& position, unsigned int stageId)
176 {
177  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 5)) {
178  *m_env.subDisplayFile() << "Entering ScaledCovMatrixTKGroup<V,M>::setPreComputingPosition()"
179  << ": position = " << position
180  << ", stageId = " << stageId
181  << std::endl;
182  }
183 
185  //setRVsWithZeroMean();
186 
187  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 5)) {
188  *m_env.subDisplayFile() << "In ScaledCovMatrixTKGroup<V,M>::setPreComputingPosition()"
189  << ", position = " << position
190  << ", stageId = " << stageId
191  << ": preComputingPos = " << *m_preComputingPositions[stageId];
192  if (stageId < m_scales.size()) {
193  *m_env.subDisplayFile() << ", factor = " << 1./m_scales[stageId]/m_scales[stageId];
194  }
195  if (stageId < m_rvs.size()) {
196  const GaussianJointPdf<V,M>* pdfPtr = dynamic_cast< const GaussianJointPdf<V,M>* >(&(m_rvs[stageId]->pdf()));
197  *m_env.subDisplayFile() << ", rvCov = " << pdfPtr->lawCovMatrix(); // FIX ME: might demand parallelism
198  }
199  *m_env.subDisplayFile() << std::endl;
200  }
201 
202  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 5)) {
203  *m_env.subDisplayFile() << "Leaving ScaledCovMatrixTKGroup<V,M>::setPreComputingPosition()"
204  << ": position = " << position
205  << ", stageId = " << stageId
206  << std::endl;
207  }
208 
209  return true;
210 }
211 //---------------------------------------------------
212 template<class V, class M>
213 void
215 {
217 }
218 
219 template <class V, class M>
220 unsigned int
222 {
223  unsigned int old_stageId = this->m_stageId;
224  this->m_stageId = stageId;
225  return old_stageId;
226 }
227 
228 // Private methods------------------------------------
229 template<class V, class M>
230 void
232 {
233  queso_require_not_equal_to_msg(m_rvs.size(), 0, "m_rvs.size() = 0");
234 
235  queso_require_equal_to_msg(m_rvs.size(), m_scales.size(), "m_rvs.size() != m_scales.size()");
236 
237  for (unsigned int i = 0; i < m_scales.size(); ++i) {
238  double factor = 1./m_scales[i]/m_scales[i];
239  queso_require_msg(!(m_rvs[i]), "m_rvs[i] != NULL");
240  m_rvs[i] = new GaussianVectorRV<V,M>(m_prefix.c_str(),
241  *m_vectorSpace,
242  m_vectorSpace->zeroVector(),
243  factor*m_originalCovMatrix);
244  }
245 }
246 // I/O methods---------------------------------------
247 template<class V, class M>
248 void
249 ScaledCovMatrixTKGroup<V,M>::print(std::ostream& os) const
250 {
252 }
253 
254 } // End namespace QUESO
255 
A class for handling Gaussian joint PDFs.
std::vector< const V * > m_preComputingPositions
Definition: TKGroup.h:132
A class representing a vector space.
Definition: VectorSet.h:49
A class representing a Gaussian vector RV.
virtual unsigned int set_dr_stage(unsigned int stageId)
Sets the internal m_stageId varialbe to stageId.
std::vector< BaseVectorRV< V, M > * > m_rvs
Definition: TKGroup.h:133
const BaseEnvironment & m_env
Definition: TKGroup.h:128
virtual void print(std::ostream &os) const
TODO: Prints the transition kernel.
Definition: TKGroup.C:133
MonteCarloSGOptions::MonteCarloSGOptions(const BaseEnvironment &env, const char *prefix queso_require_not_equal_to_msg)(m_env.optionsInputFileName(), std::string(""), std::string("this constructor is incompatible with the absence of an options input file"))
virtual void clearPreComputingPositions()
Clears the pre-computing positions m_preComputingPositions[stageId].
Definition: TKGroup.C:111
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.
bool symmetric() const
Whether or not the matrix is symmetric. Always &#39;true&#39;.
void updateLawExpVector(const V &newLawExpVector)
Updates the vector that contains the mean values.
std::vector< double > m_scales
Definition: TKGroup.h:131
const M & lawCovMatrix() const
Returns the covariance matrix; access to protected attribute m_lawCovMatrix.
This base class allows the representation of a transition kernel.
Definition: Algorithm.h:32
bool setPreComputingPosition(const V &position, unsigned int stageId)
Sets the pre-computing positions m_preComputingPositions[stageId] with a new vector of size position...
MonteCarloSGOptions::MonteCarloSGOptions(const BaseEnvironment &env, const char *prefix, const McOptionsValues &alternativeOptionsValues queso_require_equal_to_msg)(m_env.optionsInputFileName(), std::string(""), std::string("this constructor is incompatible with the existence of an options input file"))
ScaledCovMatrixTKGroup(const char *prefix, const VectorSpace< V, M > &vectorSpace, const std::vector< double > &scales, const M &covMatrix)
Default constructor.
void setRVsWithZeroMean()
Sets the mean of the RVs to zero.
unsigned int displayVerbosity() const
Definition: Environment.C:450
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:98
void print(std::ostream &os) const
TODO: Prints the transition kernel.
This class allows the representation of a transition kernel with a scaled covariance matrix...
void updateLawCovMatrix(const M &covMatrix)
Scales the covariance matrix.
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:320

Generated on Tue Jun 5 2018 19:48:56 for queso-0.57.1 by  doxygen 1.8.5