queso-0.57.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
ValidationCycle.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/ValidationCycle.h>
26 #include <queso/GslVector.h>
27 #include <queso/GslMatrix.h>
28 
29 namespace QUESO {
30 
31 // Constructor -------------------------------------
32 template <class P_V,class P_M,class Q_V,class Q_M>
34  const BaseEnvironment& env,
35  const char* prefix,
36  const VectorSpace<P_V,P_M>& paramSpace,
37  const VectorSpace<P_V,P_M>& qoiSpace)
38  :
39  m_env (env),
40  m_prefix ((std::string)(prefix) + "cycle_"),
41  m_paramSpace (paramSpace),
42  m_qoiSpace (qoiSpace),
43  m_calLikelihoodFunctionObj(NULL),
44  m_calPostRv (NULL),
45  m_calIP (NULL),
46  m_calQoiFunctionObj (NULL),
47  m_calQoiRv (NULL),
48  m_calFP (NULL),
49  m_valLikelihoodFunctionObj(NULL),
50  m_valPostRv (NULL),
51  m_valIP (NULL),
52  m_valQoiFunctionObj (NULL),
53  m_valQoiRv (NULL),
54  m_valFP (NULL)
55 {
56  if (m_env.subDisplayFile()) {
57  *m_env.subDisplayFile() << "Entering ValidationCycle<P_V,P_M,Q_V,Q_M>::constructor()"
58  << ": prefix = " << m_prefix
59  << std::endl;
60  }
61 
62  if (m_env.subDisplayFile()) {
63  *m_env.subDisplayFile() << "Leaving ValidationCycle<P_V,P_M,Q_V,Q_M>::constructor()"
64  << ": prefix = " << m_prefix
65  << std::endl;
66  }
67 
68  return;
69 }
70 // Destructor---------------------------------------
71 template <class P_V,class P_M,class Q_V,class Q_M>
73 {
74  if (m_env.subDisplayFile()) {
75  *m_env.subDisplayFile() << "Entering ValidationCycle::destructor()"
76  << ": prefix = " << m_prefix
77  << std::endl;
78  }
79 
80  if (m_valFP) delete m_valFP;
81  if (m_valQoiRv) delete m_valQoiRv;
82  if (m_valQoiFunctionObj) delete m_valQoiFunctionObj;
83  if (m_valIP) delete m_valIP;
84  if (m_valPostRv) delete m_valPostRv;
85  if (m_calFP) delete m_calFP;
86  if (m_calQoiRv) delete m_calQoiRv;
87  if (m_calQoiFunctionObj) delete m_calQoiFunctionObj;
88  if (m_calIP) delete m_calIP;
89  if (m_calPostRv) delete m_calPostRv;
90 
91  if (m_env.subDisplayFile()) {
92  *m_env.subDisplayFile() << "Leaving ValidationCycle::destructor()"
93  << ": prefix = " << m_prefix
94  << std::endl;
95  }
96 }
97 // Misc methods-------------------------------------
98 template <class P_V,class P_M,class Q_V,class Q_M>
99 const BaseEnvironment&
101 {
102  return m_env;
103 }
104 // Statistical methods------------------------------
105 template <class P_V,class P_M,class Q_V,class Q_M>
106 void
108  SipOptionsValues* optionsValues,
109  const BaseVectorRV <P_V,P_M>& priorRv,
110  const BaseScalarFunction<P_V,P_M>& likelihoodFunctionObj)
111  //double (*likelihoodRoutinePtr)(const P_V& paramValues, const void* routineDataPtr),
112  //const void* likelihoodRoutineDataPtr,
113  //bool routineComputesMinus2LogOfDensity)
114 {
115  // Calibration stage: Prior vector RV
116  m_calPriorRv = &priorRv;
117 
118  // Calibration stage: Likelihood function object (e.g., ln[likelihood])
119  m_calLikelihoodFunctionObj = &likelihoodFunctionObj;
120 
121  // Calibration stage: Posterior vector RV
122  m_calPostRv = new GenericVectorRV<P_V,P_M> ("cal_post_", // Extra prefix before the default "RV_" prefix
123  m_paramSpace);
124 
125  // Calibration stage: Inverse problem
126  m_calIP = new StatisticalInverseProblem<P_V,P_M> ((m_prefix+"cal_").c_str(), // Extra prefix before the default "ip_" prefix
127  optionsValues,
128  *m_calPriorRv,
129  *m_calLikelihoodFunctionObj,
130  *m_calPostRv);
131 
132  return;
133 }
134 //--------------------------------------------------
135 template <class P_V,class P_M,class Q_V,class Q_M>
138 {
139  return *m_calIP;
140 }
141 //--------------------------------------------------
142 template <class P_V,class P_M,class Q_V,class Q_M>
145 {
146  return *m_calIP;
147 }
148 //--------------------------------------------------
149 template <class P_V,class P_M,class Q_V,class Q_M>
150 void
152  SfpOptionsValues* optionsValues,
153  void (*qoiRoutinePtr)(const P_V& domainVector,
154  const P_V* domainDirection,
155  const void* functionDataPtr,
156  Q_V& imageVector,
157  DistArray<P_V*>* gradVectors,
158  DistArray<P_M*>* hessianMatrices,
159  DistArray<P_V*>* hessianEffects),
160  const void* qoiRoutineDataPtr)
161 {
162  // Calibration stage: Input parameter vector RV for forward = output posterior vector RV of inverse
163 
164  // Calibration stage: QoI function object
165  m_calQoiFunctionObj = new GenericVectorFunction<P_V,P_M,Q_V,Q_M> ("cal_qoi_", // Extra prefix before the default "func_" prefix
166  m_paramSpace,
167  m_qoiSpace,
168  qoiRoutinePtr,
169  qoiRoutineDataPtr);
170 
171  // Calibration stage: QoI vector RV
172  m_calQoiRv = new GenericVectorRV<Q_V,Q_M> ("cal_qoi_", // Extra prefix before the default "RV_" prefix
173  m_qoiSpace);
174 
175  // Calibration stage: Forward problem
176  m_calFP = new StatisticalForwardProblem<P_V,P_M,Q_V,Q_M> ((m_prefix+"cal_").c_str(), // Extra prefix before the default "fp_" prefix
177  optionsValues,
178  *m_calPostRv, // forward input = inverse output
179  *m_calQoiFunctionObj,
180  *m_calQoiRv);
181 
182  return;
183 }
184 //--------------------------------------------------
185 template <class P_V,class P_M,class Q_V,class Q_M>
188 {
189  return *m_calFP;
190 }
191 //--------------------------------------------------
192 template <class P_V,class P_M,class Q_V,class Q_M>
195 {
196  return *m_calFP;
197 }
198 //--------------------------------------------------
199 template <class P_V,class P_M,class Q_V,class Q_M>
200 void
202  SipOptionsValues* optionsValues,
203  const BaseScalarFunction<P_V,P_M>& likelihoodFunctionObj)
204  //double (*likelihoodRoutinePtr)(const P_V& paramValues, const void* routineDataPtr),
205  //const void* likelihoodRoutineDataPtr,
206  //bool routineComputesMinus2LogOfDensity)
207 {
208  // Validation stage: Prior vector RV = posterior vector RV from calibration stage
209 
210  // Validation stage: Likelihood function object (e.g., ln[likelihood])
211  m_valLikelihoodFunctionObj = &likelihoodFunctionObj;
212 
213  // Validation stage: Posterior vector RV
214  m_valPostRv = new GenericVectorRV<P_V,P_M> ("val_post_", // Extra prefix before the default "RV_" prefix
215  m_paramSpace);
216 
217  // Validation stage: Inverse problem
218  m_valIP = new StatisticalInverseProblem<P_V,P_M> ((m_prefix+"val_").c_str(), // Extra prefix before the default "ip_" prefix
219  optionsValues,
220  *m_calPostRv, // 'validation stage' inverse input = 'calibration stage' inverse output
221  *m_valLikelihoodFunctionObj,
222  *m_valPostRv);
223 
224  return;
225 }
226 //--------------------------------------------------
227 template <class P_V,class P_M,class Q_V,class Q_M>
230 {
231  return *m_valIP;
232 }
233 //--------------------------------------------------
234 template <class P_V,class P_M,class Q_V,class Q_M>
237 {
238  return *m_valIP;
239 }
240 //--------------------------------------------------
241 template <class P_V,class P_M,class Q_V,class Q_M>
242 void
244  SfpOptionsValues* optionsValues,
245  void (*qoiRoutinePtr)(const P_V& domainVector,
246  const P_V* domainDirection,
247  const void* functionDataPtr,
248  Q_V& imageVector,
249  DistArray<P_V*>* gradVectors,
250  DistArray<P_M*>* hessianMatrices,
251  DistArray<P_V*>* hessianEffects),
252  const void* qoiRoutineDataPtr)
253 {
254  // Validation stage: Input parameter vector RV for forward = output posterior vector RV of inverse
255 
256  // Validation stage: QoI function object
257  m_valQoiFunctionObj = new GenericVectorFunction<P_V,P_M,Q_V,Q_M> ("val_qoi_", // Extra prefix before the default "func_" prefix
258  m_paramSpace,
259  m_qoiSpace,
260  qoiRoutinePtr,
261  qoiRoutineDataPtr);
262 
263  // Validation stage: QoI vector RV
264  m_valQoiRv = new GenericVectorRV<Q_V,Q_M> ("val_qoi_", // Extra prefix before the default "RV_" prefix
265  m_qoiSpace);
266 
267  // Validation stage: Forward problem
268  m_valFP = new StatisticalForwardProblem<P_V,P_M,Q_V,Q_M> ((m_prefix+"val_").c_str(), // Extra prefix before the default "fp_" prefix
269  optionsValues,
270  *m_valPostRv, // forward input = inverse output
271  *m_valQoiFunctionObj,
272  *m_valQoiRv);
273 
274  return;
275 }
276 //--------------------------------------------------
277 template <class P_V,class P_M,class Q_V,class Q_M>
280 {
281  return *m_valFP;
282 }
283 //--------------------------------------------------
284 template <class P_V,class P_M,class Q_V,class Q_M>
287 {
288  return *m_valFP;
289 }
290 
291 } // End namespace QUESO
292 
~ValidationCycle()
Destructor.
void instantiateCalFP(SfpOptionsValues *optionsValues, void(*qoiRoutinePtr)(const P_V &domainVector, const P_V *domainDirection, const void *functionDataPtr, Q_V &imageVector, DistArray< P_V * > *gradVectors, DistArray< P_M * > *hessianMatrices, DistArray< P_V * > *hessianEffects), const void *qoiRoutineDataPtr)
Instantiate a forward problem for the calibration stage.
void instantiateValFP(SfpOptionsValues *optionsValues, void(*qoiRoutinePtr)(const P_V &domainVector, const P_V *domainDirection, const void *functionDataPtr, Q_V &imageVector, DistArray< P_V * > *gradVectors, DistArray< P_M * > *hessianMatrices, DistArray< P_V * > *hessianEffects), const void *qoiRoutineDataPtr)
Instantiate a forward problem for the validation stage.
This class provides options for a Statistical Forward Problem if no input file is available...
This (virtual) class sets up the environment underlying the use of the QUESO library by an executable...
Definition: Environment.h:198
ValidationCycle(const BaseEnvironment &env, const char *prefix, const VectorSpace< P_V, P_M > &paramSpace, const VectorSpace< P_V, P_M > &qoiSpace)
Constructor.
const StatisticalInverseProblem< P_V, P_M > & calIP() const
Inverse problem of the calibration stage (const) .
const BaseEnvironment & env() const
Access to the environment variable (m_env).
This class provides options for a Statistical Inverse Problem if no input file is available...
This templated class represents a Statistical Forward Problem.
A class for handling generic vector functions.
void instantiateCalIP(SipOptionsValues *optionsValues, const BaseVectorRV< P_V, P_M > &priorRv, const BaseScalarFunction< P_V, P_M > &likelihoodFunctionObj)
Instantiate an inverse problem for the calibration stage.
const BaseEnvironment & m_env
const StatisticalForwardProblem< P_V, P_M, Q_V, Q_M > & valFP() const
Forward problem of the validation stage (const) .
This templated class represents a Statistical Inverse Problem.
A class for partitioning vectors and matrices.
Definition: DistArray.h:56
void instantiateValIP(SipOptionsValues *optionsValues, const BaseScalarFunction< P_V, P_M > &likelihoodFunctionObj)
Instantiate an inverse problem for the validation stage.
const StatisticalInverseProblem< P_V, P_M > & valIP() const
Inverse problem of the validation stage (const) .
const StatisticalForwardProblem< P_V, P_M, Q_V, Q_M > & calFP() const
Forward problem of the calibration stage (const) .
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:320
A templated class for validation cycle of the examples validationCycle and validationCycle2.

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