queso-0.53.0
ExperimentStorage.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/ExperimentStorage.h>
26 #include <queso/GslVector.h>
27 #include <queso/GslMatrix.h>
28 
29 namespace QUESO {
30 
31 template<class S_V,class S_M,class D_V,class D_M>
33  const VectorSpace<S_V,S_M>& scenarioSpace,
34  unsigned int numExperiments)
35  :
36  m_env (scenarioSpace.env()),
37  m_scenarioSpace (scenarioSpace),
38  m_paper_n (numExperiments),
39  m_paper_n_ys_transformed (m_paper_n,0),
40  m_paper_n_y (0),
41  m_addId (0),
42  m_scenarioVecs_standard (m_paper_n, (S_V*) NULL),
43  m_dataVecs_transformed (m_paper_n, (D_V*) NULL),
44  m_covMats_transformed_inv(m_paper_n, (D_M*) NULL),
45  m_y_space (NULL),
46  m_yVec_transformed (NULL),
47  m_Wy (NULL)
48 {
49  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
50  *m_env.subDisplayFile() << "Entering ExperimentStorage<S_V,S_M,D_V,D_M>::constructor()"
51  << "\n m_paper_n = " << m_paper_n
52  << std::endl;
53  }
54 
55  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
56  *m_env.subDisplayFile() << "Leaving ExperimentStorage<S_V,S_M,D_V,D_M>::constructor()"
57  << std::endl;
58  }
59 }
60 
61 template<class S_V,class S_M,class D_V,class D_M>
63 {
64  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
65  *m_env.subDisplayFile() << "Entering ExperimentStorage<S_V,S_M,P_V,P_M,Q_V,Q_M>::destructor()..."
66  << std::endl;
67  }
68 
69  delete m_Wy;
70  delete m_yVec_transformed;
71  delete m_y_space;
72 
73  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
74  *m_env.subDisplayFile() << "Leaving ExperimentStorage<S_V,S_M,P_V,P_M,Q_V,Q_M>::destructor()"
75  << std::endl;
76  }
77 }
78 
79 template<class S_V,class S_M,class D_V,class D_M>
80 void
82  const S_V& scenarioVec_standard,
83  const D_V& dataVec_transformed,
84  const D_M& covMat_transformed_inv)
85 {
86  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
87  *m_env.subDisplayFile() << "Entering ExperimentStorage<S_V,S_M,D_V,D_M>::addExperiment()"
88  << ": m_addId = " << m_addId
89  << "\n scenarioVec_standard = " << scenarioVec_standard
90  << "\n dataVec_transformed = " << dataVec_transformed
91  << "\n covMat_transformed_inv = " << covMat_transformed_inv
92  << std::endl;
93  }
94 
95  queso_require_less_msg(m_addId, m_paper_n, "too many adds...");
96 
97  m_scenarioVecs_standard [m_addId] = &scenarioVec_standard;
98  m_dataVecs_transformed [m_addId] = &dataVec_transformed;
99  m_covMats_transformed_inv[m_addId] = &covMat_transformed_inv;
100  m_paper_n_ys_transformed[m_addId] = dataVec_transformed.sizeLocal();
101  m_paper_n_y += m_paper_n_ys_transformed[m_addId];
102  m_addId++;
103 
104  if (m_addId == m_paper_n) {
105  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
106  *m_env.subDisplayFile() << "KEY In ExperimentStorage<S_V,S_M,D_V,D_M>::addExperiment()"
107  << ": m_addId = " << m_addId
108  << ", m_paper_n_y = " << m_paper_n_y
109  << std::endl;
110  }
111 
112  //***********************************************************************
113  // Form 'yVec_transformed', 'Wy' matrix, and compute its inverse
114  //***********************************************************************
115  m_y_space = new VectorSpace<D_V,D_M>(m_env, "m_y_exp_storage", m_paper_n_y, NULL),
116  m_yVec_transformed = new D_V(m_y_space->zeroVector());
117  m_yVec_transformed->cwSetConcatenated(m_dataVecs_transformed);
118 
119  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 3)) {
120  *m_env.subDisplayFile() << "In ExperimentStorage<S_V,S_M,D_V,D_M>::addExperiment()"
121  << ": populated yVec_transformed of size = " << m_yVec_transformed->sizeLocal()
122  << "\n *m_yVec_transformed = " << *m_yVec_transformed
123  << std::endl;
124  }
125 
126  m_Wy = new D_M(m_y_space->zeroVector());
127  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
128  *m_env.subDisplayFile() << "In ExperimentStorage<S_V,S_M,D_V,D_M>::addExperiment()"
129  << ": key-debug"
130  << ", m_Wy just created (not yet populated)"
131  << ", numRowsLocal = " << m_Wy->numRowsLocal()
132  << ", numCols = " << m_Wy->numCols()
133  << std::endl;
134  }
135 
136  m_Wy->fillWithBlocksDiagonally(0,0,m_covMats_transformed_inv,true,true);
137  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
138  *m_env.subDisplayFile() << "In ExperimentStorage<S_V,S_M,D_V,D_M>::addExperiment()"
139  << ": key-debug"
140  << ", m_Wy just populated"
141  << std::endl;
142  }
143 
144  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 3)) {
145  *m_env.subDisplayFile() << "In ExperimentStorage<S_V,S_M,D_V,D_M>::addExperiment()"
146  << ": m_Wy->lnDeterminant() = " << m_Wy->lnDeterminant()
147  << std::endl;
148  }
149  }
150 
151  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
152  *m_env.subDisplayFile() << "Leaving ExperimentStorage<S_V,S_M,D_V,D_M>::addExperiment()"
153  << ": m_addId = " << m_addId
154  << std::endl;
155  }
156 
157  return;
158 }
159 
160 template<class S_V,class S_M,class D_V,class D_M>
161 const std::vector<const S_V* >&
163 {
164  return m_scenarioVecs_standard;
165 }
166 
167 template<class S_V,class S_M,class D_V,class D_M>
168 unsigned int
170 {
171  return m_paper_n;
172 }
173 
174 template<class S_V,class S_M,class D_V,class D_M>
177 {
178  return m_scenarioSpace;
179 }
180 
181 template<class S_V,class S_M,class D_V,class D_M>
182 const std::vector<unsigned int>&
184 {
185  return m_paper_n_ys_transformed;
186 }
187 
188 template<class S_V,class S_M,class D_V,class D_M>
189 unsigned int
191 {
192  return m_paper_n_y;
193 }
194 
195 template<class S_V,class S_M,class D_V,class D_M>
196 const S_V&
198 {
199  queso_require_less_msg(experimentId, m_scenarioVecs_standard.size(), "experimentId is too large");
200 
201  queso_require_msg(m_scenarioVecs_standard[experimentId], "vector is NULL");
202 
203  return *(m_scenarioVecs_standard[experimentId]);
204 }
205 
206 template<class S_V,class S_M,class D_V,class D_M>
207 const D_V&
209 {
210  queso_require_less_msg(experimentId, m_dataVecs_transformed.size(), "experimentId is too large");
211 
212  queso_require_msg(m_dataVecs_transformed[experimentId], "vector is NULL");
213 
214  return *(m_dataVecs_transformed[experimentId]);
215 }
216 
217 template<class S_V,class S_M,class D_V,class D_M>
218 const D_V&
220 {
221  queso_require_msg(m_yVec_transformed, "'m_yVec_transformed' is NULL");
222 
223  return *m_yVec_transformed;
224 }
225 
226 template<class S_V,class S_M,class D_V,class D_M>
227 const D_M&
229 {
230  queso_require_msg(m_Wy, "'m_Wy' is NULL");
231 
232  return *m_Wy;
233 }
234 
235 template<class S_V,class S_M,class D_V,class D_M>
236 const BaseEnvironment&
238 {
239  return m_env;
240 }
241 
242 template<class S_V,class S_M,class D_V,class D_M>
243 void
245 {
246  return;
247 }
248 
249 } // End namespace QUESO
250 
unsigned int displayVerbosity() const
Definition: Environment.C:396
void addExperiment(const S_V &scenarioVec_standard, const D_V &dataVec_transformed, const D_M &covMat_transformed_inv)
unsigned int numExperiments() const
ExperimentStorage(const VectorSpace< S_V, S_M > &scenarioSpace, unsigned int numExperiments)
const D_V & dataVec_transformed(unsigned int experimentId) const
unsigned int n_y() const
#define queso_require_msg(asserted, msg)
Definition: asserts.h:69
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:274
#define queso_require_less_msg(expr1, expr2, msg)
Definition: asserts.h:87
const std::vector< const S_V * > & xs_standard() const
This (virtual) class sets up the environment underlying the use of the QUESO library by an executable...
Definition: Environment.h:193
const S_V & scenarioVec_standard(unsigned int experimentId) const
const D_V & yVec_transformed() const
const std::vector< unsigned int > & n_ys_transformed() const
const BaseEnvironment & env() const
const BaseEnvironment & m_env
void print(std::ostream &os) const
const VectorSpace< S_V, S_M > & scenarioSpace() const
const D_M & Wy() const

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