queso-0.52.0
MonteCarloSG.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/MonteCarloSG.h>
26 #include <queso/GslVector.h>
27 #include <queso/GslMatrix.h>
28 
29 namespace QUESO {
30 
31 // Default constructor -----------------------------
32 template <class P_V,class P_M,class Q_V,class Q_M>
33 MonteCarloSG<P_V,P_M,Q_V,Q_M>::MonteCarloSG( const char* prefix, const McOptionsValues* alternativeOptionsValues, // dakota const BaseVectorRV <P_V,P_M>& paramRv, const BaseVectorFunction<P_V,P_M,Q_V,Q_M>& qoiFunction)
38  :
39  m_env (paramRv.env()),
40  m_paramRv (paramRv),
41  m_qoiFunction (qoiFunction),
42  m_paramSpace (m_paramRv.imageSet().vectorSpace()),
43  m_qoiSpace (m_qoiFunction.imageSet().vectorSpace()),
44  m_qoiFunctionSynchronizer (new VectorFunctionSynchronizer<P_V,P_M,Q_V,Q_M>(m_qoiFunction,m_paramRv.imageSet().vectorSpace().zeroVector(),m_qoiFunction.imageSet().vectorSpace().zeroVector())),
45  m_numPsNotSubWritten (0),
46  m_numQsNotSubWritten (0),
47 #ifdef QUESO_USES_SEQUENCE_STATISTICAL_OPTIONS
48  m_alternativeOptionsValues(NULL,NULL),
49 #else
50  m_alternativeOptionsValues(),
51 #endif
52  m_optionsObj (NULL)
53 {
54  if (m_env.subDisplayFile()) {
55  *m_env.subDisplayFile() << "Entering MonteCarloSG<P_V,P_M,Q_V,Q_M>::constructor()"
56  << ": prefix = " << prefix
57  << ", alternativeOptionsValues = " << alternativeOptionsValues
58  << ", m_env.optionsInputFileName() = " << m_env.optionsInputFileName()
59  << std::endl;
60  }
61 
62  if (alternativeOptionsValues) m_alternativeOptionsValues = *alternativeOptionsValues;
63  if (m_env.optionsInputFileName() == "") {
64  m_optionsObj = new MonteCarloSGOptions(m_env,prefix,m_alternativeOptionsValues);
65  }
66  else {
67  m_optionsObj = new MonteCarloSGOptions(m_env,prefix);
68  m_optionsObj->scanOptionsValues();
69  }
70 
71  UQ_FATAL_TEST_MACRO(paramRv.imageSet().vectorSpace().dimLocal() != qoiFunction.domainSet().vectorSpace().dimLocal(),
72  m_env.worldRank(),
73  "MonteCarloSG<P_V,P_M,Q_V,Q_M>::constructor()",
74  "'paramRv' and 'qoiFunction' are related to vector spaces of different dimensions");
75 
76  if (m_env.subDisplayFile()) {
77  *m_env.subDisplayFile() << "Leaving MonteCarloSG<P_V,P_M,Q_V,Q_M>::constructor()"
78  << std::endl;
79  }
80 }
81 // Destructor ---------------------------------------
82 template <class P_V,class P_M,class Q_V,class Q_M>
84 {
85  if (m_optionsObj ) delete m_optionsObj;
86  if (m_qoiFunctionSynchronizer) delete m_qoiFunctionSynchronizer;
87 }
88 // Statistical methods ------------------------------
89 template <class P_V,class P_M,class Q_V,class Q_M>
90 void
92  BaseVectorSequence<P_V,P_M>& workingPSeq,
93  BaseVectorSequence<Q_V,Q_M>& workingQSeq)
94 {
95  UQ_FATAL_TEST_MACRO(m_qoiFunction.domainSet().vectorSpace().dimLocal() != workingPSeq.vectorSizeLocal(),
96  m_env.worldRank(),
97  "MonteCarloSG<P_V,P_M,Q_V,Q_M>::generateSequence()",
98  "'m_qoiFunction.domainSet' and 'workingPSeq' are related to vector spaces of different dimensions");
99 
100  UQ_FATAL_TEST_MACRO(m_qoiFunction.imageSet().vectorSpace().dimLocal() != workingQSeq.vectorSizeLocal(),
101  m_env.worldRank(),
102  "MonteCarloSG<P_V,P_M,Q_V,Q_M>::generateSequence()",
103  "'m_qoiFunction.imageSet' and 'workingQSeq' are related to vector spaces of different dimensions");
104 
105  MiscCheckTheParallelEnvironment<P_V,Q_V>(m_paramRv.imageSet().vectorSpace().zeroVector(),
106  m_qoiFunction.imageSet().vectorSpace().zeroVector());
107  internGenerateSequence(m_paramRv,workingPSeq,workingQSeq);
108 
109  return;
110 }
111 // I/O methods---------------------------------------
112 template <class P_V,class P_M,class Q_V,class Q_M>
113 void
115 {
116  return;
117 }
118 // Private methods----------------------------------
119 template <class P_V,class P_M,class Q_V,class Q_M>
120 void
122  const BaseVectorRV <P_V,P_M>& paramRv,
123  BaseVectorSequence<P_V,P_M>& workingPSeq,
124  BaseVectorSequence<Q_V,Q_M>& workingQSeq)
125 {
126  workingPSeq.setName(m_optionsObj->m_prefix+"ParamSeq");
127  workingQSeq.setName(m_optionsObj->m_prefix+"QoiSeq");
128 
129  //****************************************************
130  // Generate sequence of QoI values
131  //****************************************************
132  unsigned int subActualSizeBeforeGeneration = std::min(m_optionsObj->m_ov.m_qseqSize,paramRv.realizer().subPeriod());
133  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
134  *m_env.subDisplayFile() << "In MonteCarloSG<P_V,P_M,Q_V,Q_M>::internGenerateSequence()"
135  << ": m_optionsObj->m_ov.m_qseqSize = " << m_optionsObj->m_ov.m_qseqSize
136  << ", paramRv.realizer().subPeriod() = " << paramRv.realizer().subPeriod()
137  << ", about to call actualGenerateSequence() with subActualSize = " << subActualSizeBeforeGeneration
138  << std::endl;
139  }
140  if (m_optionsObj->m_ov.m_qseqDataInputFileName == UQ_MOC_SG_FILENAME_FOR_NO_FILE) {
141  actualGenerateSequence(paramRv,
142  workingPSeq,
143  workingQSeq,
144  subActualSizeBeforeGeneration);
145  }
146  else {
147  actualReadSequence(paramRv,
148  m_optionsObj->m_ov.m_qseqDataInputFileName,
149  m_optionsObj->m_ov.m_qseqDataInputFileType,
150  workingPSeq,
151  workingQSeq,
152  subActualSizeBeforeGeneration);
153  }
154  unsigned int subActualSizeAfterGeneration = workingPSeq.subSequenceSize();
155  UQ_FATAL_TEST_MACRO(subActualSizeAfterGeneration != workingQSeq.subSequenceSize(),
156  m_env.worldRank(),
157  "MonteCarloSG<P_V,P_M,Q_V,Q_M>::internGenerateSequence()",
158  "P and Q sequences should have the same size!");
159 
160  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
161  *m_env.subDisplayFile() << "In MonteCarloSG<P_V,P_M,Q_V,Q_M>::internGenerateSequence()"
162  << ": returned from call to actualGenerateSequence() with subActualSize = " << subActualSizeAfterGeneration
163  << std::endl;
164  }
165 
166  //****************************************************
167  // Open generic output file
168  //****************************************************
169  if (m_env.subDisplayFile()) {
170  *m_env.subDisplayFile() << "In MonteCarloSG<P_V,P_M,Q_V,Q_M>::internGenerateSequence()"
171  << ", prefix = " << m_optionsObj->m_prefix
172  << ": checking necessity of opening generic output file (qseq name is " << workingQSeq.name()
173  << ") ..."
174  << std::endl;
175  }
176  FilePtrSetStruct genericFilePtrSet;
177  m_env.openOutputFile(m_optionsObj->m_ov.m_dataOutputFileName,
178  UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT, // Yes, always ".m"
179  m_optionsObj->m_ov.m_dataOutputAllowedSet,
180  false,
181  genericFilePtrSet);
182 
183  //****************************************************
184  // Eventually:
185  // --> write parameter sequence
186  // --> compute statistics on it
187  //****************************************************
188  if (m_env.subDisplayFile()) {
189  *m_env.subDisplayFile() << "In MonteCarloSG<P_V,P_M,Q_V,Q_M>::internGenerateSequence()"
190  << ", prefix = " << m_optionsObj->m_prefix
191  << ": checking necessity of opening output files for pseq " << workingPSeq.name()
192  << "..."
193  << std::endl;
194  }
195 
196  // Take "sub" care of pseq
197  if ((m_numPsNotSubWritten > 0 ) &&
198  (m_optionsObj->m_ov.m_pseqDataOutputFileName != UQ_MOC_SG_FILENAME_FOR_NO_FILE)) {
199  workingPSeq.subWriteContents(subActualSizeBeforeGeneration - m_numPsNotSubWritten,
200  m_numPsNotSubWritten,
201  m_optionsObj->m_ov.m_pseqDataOutputFileName,
202  m_optionsObj->m_ov.m_pseqDataOutputFileType,
203  m_optionsObj->m_ov.m_pseqDataOutputAllowedSet);
204  if (m_env.subDisplayFile()) {
205  *m_env.subDisplayFile() << "In MonteCarloG<P_V,P_M>::internGenerateSequence()"
206  << ": just wrote remaining pseq positions (per period request)"
207  << std::endl;
208  }
209  m_numPsNotSubWritten = 0;
210  //if (m_env.subDisplayFile()) {
211  // *m_env.subDisplayFile() << "In MonteCarloSG<P_V,P_M,Q_V,Q_M>::internGenerateSequence()"
212  // << ", prefix = " << m_optionsObj->m_prefix
213  // << ": closed data output file '" << m_optionsObj->m_ov.m_pseqDataOutputFileName
214  // << "' for pseq " << workingPSeq.name()
215  // << std::endl;
216  //}
217  }
218 
219  // Take "unified" care of pseq
220  if (m_optionsObj->m_ov.m_pseqDataOutputFileName != UQ_MOC_SG_FILENAME_FOR_NO_FILE) {
221  workingPSeq.unifiedWriteContents(m_optionsObj->m_ov.m_pseqDataOutputFileName,m_optionsObj->m_ov.m_pseqDataOutputFileType);
222  if (m_env.subDisplayFile()) {
223  *m_env.subDisplayFile() << "In MonteCarloSG<P_V,P_M,Q_V,Q_M>::internGenerateSequence()"
224  << ", prefix = " << m_optionsObj->m_prefix
225  << ": closed unified data output file '" << m_optionsObj->m_ov.m_pseqDataOutputFileName
226  << "' for pseq " << workingPSeq.name()
227  << std::endl;
228  }
229  }
230 
231  // Take case of other aspects of pseq
232 #ifdef QUESO_USES_SEQUENCE_STATISTICAL_OPTIONS
233  if (m_optionsObj->m_ov.m_pseqComputeStats) {
234  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
235  *m_env.subDisplayFile() << "In MonteCarloSG<P_V,P_M,Q_V,Q_M>::internGenerateSequence()"
236  << ": about to call 'workingPSeq.computeStatistics()'"
237  << std::endl;
238  }
239  workingPSeq.computeStatistics(*m_optionsObj->m_pseqStatisticalOptionsObj,
240  genericFilePtrSet.ofsVar);
241  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
242  *m_env.subDisplayFile() << "In MonteCarloSG<P_V,P_M,Q_V,Q_M>::internGenerateSequence()"
243  << ": returned from call to 'workingPSeq.computeStatistics()'"
244  << std::endl;
245  }
246  }
247 #endif
248  //****************************************************
249  // Eventually:
250  // --> write QoI sequence
251  // --> compute statistics on it
252  //****************************************************
253  if (m_env.subDisplayFile()) {
254  *m_env.subDisplayFile() << "In MonteCarloSG<P_V,P_M,Q_V,Q_M>::internGenerateSequence()"
255  << ", prefix = " << m_optionsObj->m_prefix
256  << ": checking necessity of opening output files for qseq " << workingQSeq.name()
257  << "..."
258  << std::endl;
259  }
260 
261  // Take "sub" care of qseq
262  if ((m_numQsNotSubWritten > 0 ) &&
263  (m_optionsObj->m_ov.m_qseqDataOutputFileName != UQ_MOC_SG_FILENAME_FOR_NO_FILE)) {
264  workingQSeq.subWriteContents(subActualSizeBeforeGeneration - m_numQsNotSubWritten,
265  m_numQsNotSubWritten,
266  m_optionsObj->m_ov.m_qseqDataOutputFileName,
267  m_optionsObj->m_ov.m_qseqDataOutputFileType,
268  m_optionsObj->m_ov.m_qseqDataOutputAllowedSet);
269  if (m_env.subDisplayFile()) {
270  *m_env.subDisplayFile() << "In MonteCarloG<P_V,P_M>::internGenerateSequence()"
271  << ": just wrote remaining qseq positions (per period request)"
272  << std::endl;
273  }
274  m_numQsNotSubWritten = 0;
275  //if (m_env.subDisplayFile()) {
276  // *m_env.subDisplayFile() << "In MonteCarloSG<P_V,P_M,Q_V,Q_M>::internGenerateSequence()"
277  // << ", prefix = " << m_optionsObj->m_prefix
278  // << ": closed data output file '" << m_optionsObj->m_ov.m_qseqDataOutputFileName
279  // << "' for qseq " << workingQSeq.name()
280  // << std::endl;
281  //}
282  }
283 
284  // Take "unified" care of qseq
285  if (m_optionsObj->m_ov.m_qseqDataOutputFileName != UQ_MOC_SG_FILENAME_FOR_NO_FILE) {
286  workingQSeq.unifiedWriteContents(m_optionsObj->m_ov.m_qseqDataOutputFileName,m_optionsObj->m_ov.m_qseqDataOutputFileType);
287  if (m_env.subDisplayFile()) {
288  *m_env.subDisplayFile() << "In MonteCarloSG<P_V,P_M,Q_V,Q_M>::internGenerateSequence()"
289  << ", prefix = " << m_optionsObj->m_prefix
290  << ": closed unified data output file '" << m_optionsObj->m_ov.m_qseqDataOutputFileName
291  << "' for qseq " << workingQSeq.name()
292  << std::endl;
293  }
294  }
295 
296  // Take case of other aspects of qseq
297 #ifdef QUESO_USES_SEQUENCE_STATISTICAL_OPTIONS
298  if (m_optionsObj->m_ov.m_qseqComputeStats) {
299  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
300  *m_env.subDisplayFile() << "In MonteCarloSG<P_V,P_M,Q_V,Q_M>::internGenerateSequence()"
301  << ": about to call 'workingQSeq.computeStatistics()'"
302  << std::endl;
303  }
304  workingQSeq.computeStatistics(*m_optionsObj->m_qseqStatisticalOptionsObj,
305  genericFilePtrSet.ofsVar);
306  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
307  *m_env.subDisplayFile() << "In MonteCarloSG<P_V,P_M,Q_V,Q_M>::internGenerateSequence()"
308  << ": returned from call to 'workingQSeq.computeStatistics()'"
309  << std::endl;
310  }
311  }
312 #endif
313  //****************************************************
314  // Close generic output file
315  //****************************************************
316  if (genericFilePtrSet.ofsVar) {
317  //std::cout << "TODAY 000" << std::endl;
318  delete genericFilePtrSet.ofsVar;
319  //genericFilePtrSet.ofsVar->close();
320  //std::cout << "TODAY 001" << std::endl;
321  if (m_env.subDisplayFile()) {
322  *m_env.subDisplayFile() << "In MonteCarloSG<P_V,P_M,Q_V,Q_M>::internGenerateSequence()"
323  << ", prefix = " << m_optionsObj->m_prefix
324  << ": closed generic data output file '" << m_optionsObj->m_ov.m_dataOutputFileName
325  << "' for QoI sequence " << workingQSeq.name()
326  << std::endl;
327  }
328  }
329  if (m_env.subDisplayFile()) {
330  *m_env.subDisplayFile() << std::endl;
331  }
332 
333  return;
334 }
335 // --------------------------------------------------
336 template <class P_V,class P_M,class Q_V,class Q_M>
337 void
339  const BaseVectorRV <P_V,P_M>& paramRv,
340  BaseVectorSequence<P_V,P_M>& workingPSeq,
341  BaseVectorSequence<Q_V,Q_M>& workingQSeq,
342  unsigned int requestedSeqSize)
343 {
344  if (m_env.subDisplayFile()) {
345  *m_env.subDisplayFile() << "Starting the generation of qoi sequence " << workingQSeq.name()
346  << ", with " << requestedSeqSize
347  << " samples..."
348  << std::endl;
349  }
350 
351  int iRC = UQ_OK_RC;
352  struct timeval timevalSeq;
353  struct timeval timevalQoIFunction;
354 
355  double seqRunTime = 0;
356  double qoiFunctionRunTime = 0;
357 
358  iRC = gettimeofday(&timevalSeq, NULL);
359  if (iRC) {}; // just to remover compiler warning
360 
361  workingPSeq.resizeSequence(requestedSeqSize);
362  m_numPsNotSubWritten = 0;
363  workingQSeq.resizeSequence(requestedSeqSize);
364  m_numQsNotSubWritten = 0;
365 
366  P_V tmpP(m_paramSpace.zeroVector());
367  Q_V tmpQ(m_qoiSpace.zeroVector());
368 
369  unsigned int actualSeqSize = 0;
370  for (unsigned int i = 0; i < requestedSeqSize; ++i) {
371  paramRv.realizer().realization(tmpP);
372 
373  if (m_optionsObj->m_ov.m_qseqMeasureRunTimes) iRC = gettimeofday(&timevalQoIFunction, NULL);
374  m_qoiFunctionSynchronizer->callFunction(&tmpP,NULL,&tmpQ,NULL,NULL,NULL); // Might demand parallel environment
375  if (m_optionsObj->m_ov.m_qseqMeasureRunTimes) qoiFunctionRunTime += MiscGetEllapsedSeconds(&timevalQoIFunction);
376 
377  bool allQsAreFinite = true;
378  for (unsigned int j = 0; j < tmpQ.sizeLocal(); ++j) {
379  if ((tmpQ[j] == INFINITY) || (tmpQ[j] == -INFINITY)) {
380  std::cerr << "WARNING In MonteCarloSG<P_V,P_M,Q_V,Q_M>::actualGenerateSequence()"
381  << ", worldRank " << m_env.worldRank()
382  << ", fullRank " << m_env.fullRank()
383  << ", subEnvironment " << m_env.subId()
384  << ", subRank " << m_env.subRank()
385  << ", inter0Rank " << m_env.inter0Rank()
386  << ": i = " << i
387  << ", tmpQ[" << j << "] = " << tmpQ[j]
388  << ", tmpP = " << tmpP
389  << ", tmpQ = " << tmpQ
390  << std::endl;
391  allQsAreFinite = false;
392 
393  if (i > 0) {
394  workingPSeq.getPositionValues(i-1,tmpP); // FIXME: temporary code
395  workingQSeq.getPositionValues(i-1,tmpQ); // FIXME: temporary code
396  }
397 
398  break;
399  }
400  }
401  if (allQsAreFinite) {}; // just to remover compiler warning
402 
403  //if (allQsAreFinite) { // FIXME: this will cause different processors to have sequences of different sizes
404  workingPSeq.setPositionValues(i,tmpP);
405  m_numPsNotSubWritten++;
406  if ((m_optionsObj->m_ov.m_pseqDataOutputPeriod > 0 ) &&
407  (((i+1) % m_optionsObj->m_ov.m_pseqDataOutputPeriod) == 0 ) &&
408  (m_optionsObj->m_ov.m_pseqDataOutputFileName != ".")) {
409  workingPSeq.subWriteContents(i + 1 - m_optionsObj->m_ov.m_pseqDataOutputPeriod,
410  m_optionsObj->m_ov.m_pseqDataOutputPeriod,
411  m_optionsObj->m_ov.m_pseqDataOutputFileName,
412  m_optionsObj->m_ov.m_pseqDataOutputFileType,
413  m_optionsObj->m_ov.m_pseqDataOutputAllowedSet);
414  if (m_env.subDisplayFile()) {
415  *m_env.subDisplayFile() << "In MonteCarloG<P_V,P_M>::actualGenerateSequence()"
416  << ": just wrote pseq positions (per period request)"
417  << std::endl;
418  }
419  m_numPsNotSubWritten = 0;
420  }
421 
422  workingQSeq.setPositionValues(i,tmpQ);
423  m_numQsNotSubWritten++;
424  if ((m_optionsObj->m_ov.m_qseqDataOutputPeriod > 0 ) &&
425  (((i+1) % m_optionsObj->m_ov.m_qseqDataOutputPeriod) == 0 ) &&
426  (m_optionsObj->m_ov.m_qseqDataOutputFileName != ".")) {
427  workingQSeq.subWriteContents(i + 1 - m_optionsObj->m_ov.m_qseqDataOutputPeriod,
428  m_optionsObj->m_ov.m_qseqDataOutputPeriod,
429  m_optionsObj->m_ov.m_qseqDataOutputFileName,
430  m_optionsObj->m_ov.m_qseqDataOutputFileType,
431  m_optionsObj->m_ov.m_qseqDataOutputAllowedSet);
432  if (m_env.subDisplayFile()) {
433  *m_env.subDisplayFile() << "In MonteCarloG<P_V,P_M>::actualGenerateSequence()"
434  << ": just wrote qseq positions (per period request)"
435  << std::endl;
436  }
437  m_numQsNotSubWritten = 0;
438  }
439 
440  actualSeqSize++;
441 
442  //}
443 
444  if ((m_optionsObj->m_ov.m_qseqDisplayPeriod > 0) &&
445  (((i+1) % m_optionsObj->m_ov.m_qseqDisplayPeriod) == 0)) {
446  if (m_env.subDisplayFile()) {
447  *m_env.subDisplayFile() << "Finished generating " << i+1
448  << " qoi samples"
449  << std::endl;
450  }
451  }
452  }
453 
454  //if (actualSeqSize != requestedSeqSize) {
455  // workingPSeq.resizeSequence(actualSeqSize);
456  // workingQSeq.resizeSequence(actualSeqSize);
457  //}
458 
459  seqRunTime = MiscGetEllapsedSeconds(&timevalSeq);
460 
461  if (m_env.subDisplayFile()) {
462  *m_env.subDisplayFile() << "Finished the generation of qoi sequence " << workingQSeq.name()
463  << ", with sub " << workingQSeq.subSequenceSize()
464  << " samples"
465  << "\nSome information about this sequence:"
466  << "\n Sequence run time = " << seqRunTime
467  << " seconds"
468  << "\n\n Breaking of the seq run time:\n"
469  << "\n QoI function run time = " << qoiFunctionRunTime
470  << " seconds (" << 100.*qoiFunctionRunTime/seqRunTime
471  << "%)"
472  << std::endl;
473  }
474 
475  return;
476 }
477 // --------------------------------------------------
478 template <class P_V,class P_M,class Q_V,class Q_M>
479 void
481  const BaseVectorRV <P_V,P_M>& paramRv,
482  const std::string& dataInputFileName,
483  const std::string& dataInputFileType,
484  BaseVectorSequence<P_V,P_M>& workingPSeq,
485  BaseVectorSequence<Q_V,Q_M>& workingQSeq,
486  unsigned int requestedSeqSize)
487 {
488  workingPSeq.resizeSequence(requestedSeqSize);
489  P_V tmpP(m_paramSpace.zeroVector());
490  for (unsigned int i = 0; i < requestedSeqSize; ++i) {
491  paramRv.realizer().realization(tmpP);
492  workingPSeq.setPositionValues(i,tmpP);
493  }
494 
495  workingQSeq.unifiedReadContents(dataInputFileName,dataInputFileType,requestedSeqSize);
496 
497  return;
498 }
499 
500 } // End namespace QUESO
501 
void setName(const std::string &newName)
Changes the name of the sequence of vectors.
double MiscGetEllapsedSeconds(struct timeval *timeval0)
#define UQ_MOC_SG_FILENAME_FOR_NO_FILE
virtual void setPositionValues(unsigned int posId, const V &vec)=0
Set the values in vec at position posId of the sequence. See template specialization.
MonteCarloSG(const char *prefix, const McOptionsValues *alternativeOptionsValues, const BaseVectorRV< P_V, P_M > &paramRv, const BaseVectorFunction< P_V, P_M, Q_V, Q_M > &qoiFunction)
Constructor.
Definition: MonteCarloSG.C:33
virtual void unifiedReadContents(const std::string &fileName, const std::string &fileType, const unsigned int subSequenceSize)=0
Reads info of the unified sequence from a file. See template specialization.
virtual void unifiedWriteContents(const std::string &fileName, const std::string &fileType) const =0
Writes info of the unified sequence to a file. See template specialization.
const BaseVectorRealizer< V, M > & realizer() const
Finds a realization (sample) of the PDF of this vector RV; access to private attribute m_realizer...
Definition: VectorRV.C:98
A templated class that implements a Monte Carlo generator of samples.
Definition: MonteCarloSG.h:49
virtual void subWriteContents(unsigned int initialPos, unsigned int numPos, const std::string &fileName, const std::string &fileType, const std::set< unsigned int > &allowedSubEnvIds) const =0
Writes info of the sub-sequence to a file. See template specialization.
Struct for handling data input and output from files.
Definition: Environment.h:66
virtual void getPositionValues(unsigned int posId, V &vec) const =0
Gets the values of the sequence at position posId and stores them at vec. See template specialization...
This class provides options for the Monte Carlo sequence generator if no input file is available...
const int UQ_OK_RC
Definition: Defines.h:76
void actualReadSequence(const BaseVectorRV< P_V, P_M > &paramRv, const std::string &dataInputFileName, const std::string &dataInputFileType, BaseVectorSequence< P_V, P_M > &workingPSeq, BaseVectorSequence< Q_V, Q_M > &workingQSeq, unsigned int seqSize)
Reads the sequence.
Definition: MonteCarloSG.C:480
unsigned int vectorSizeLocal() const
Local dimension (size) of the vector space.
std::ofstream * ofsVar
Provides a stream interface to write data to files.
Definition: Environment.h:75
#define UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT
Definition: Defines.h:89
#define UQ_FATAL_TEST_MACRO(test, givenRank, where, what)
Definition: Defines.h:223
~MonteCarloSG()
Destructor.
Definition: MonteCarloSG.C:83
void internGenerateSequence(const BaseVectorRV< P_V, P_M > &paramRv, BaseVectorSequence< P_V, P_M > &workingPSeq, BaseVectorSequence< Q_V, Q_M > &workingQSeq)
Generates the QoI (output) sequence; it calls actualGenerateSequence().
Definition: MonteCarloSG.C:121
void actualGenerateSequence(const BaseVectorRV< P_V, P_M > &paramRv, BaseVectorSequence< P_V, P_M > &workingPSeq, BaseVectorSequence< Q_V, Q_M > &workingQSeq, unsigned int seqSize)
This method actually generates the QoI sequence.
Definition: MonteCarloSG.C:338
A templated class for synchronizing the calls of vector-valued functions.
const std::string & name() const
Access to protected attribute m_name: name of the sequence of vectors.
virtual void realization(V &nextValues) const =0
Performs a realization (sample) from a probability density function. See template specialization...
This class reads the options for the Monte Carlo sequence generator from an input file...
void print(std::ostream &os) const
Prints the sequence.
Definition: MonteCarloSG.C:114
virtual unsigned int subSequenceSize() const =0
Size of the sub-sequence of vectors. See template specialization.
void generateSequence(BaseVectorSequence< P_V, P_M > &workingPSeq, BaseVectorSequence< Q_V, Q_M > &workingQSeq)
Generates the QoI (output) sequence, it calls internGenerateSequence().
Definition: MonteCarloSG.C:91
unsigned int subPeriod() const
Sub-period of the realization. Access to protected attribute m_subPeriod.
virtual void resizeSequence(unsigned int newSubSequenceSize)=0
Resize the sequence. See template specialization.

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