queso-0.53.0
SequenceOfVectors.h
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 #ifndef UQ_SEQUENCE_OF_VECTORS_H
26 #define UQ_SEQUENCE_OF_VECTORS_H
27 
28 #include <queso/VectorSequence.h>
29 #define UQ_SEQ_VEC_USES_SCALAR_SEQ_CODE
30 #undef UQ_SEQ_VEC_USES_OPERATOR
31 
32 namespace QUESO {
33 
34 class GslVector;
35 class GslMatrix;
36 
48 template <class V = GslVector, class M = GslMatrix>
50 {
51 public:
52 
54 
55  typedef typename std::vector<const V*>::const_iterator seqVectorPositionConstIteratorTypedef;
56  typedef typename std::vector<const V*>::iterator seqVectorPositionIteratorTypedef;
58 
60 
63  unsigned int subSequenceSize,
64  const std::string& name);
68 
70 
74 
76 
77  unsigned int subSequenceSize () const;
79 
81 
82  void resizeSequence (unsigned int newSubSequenceSize);
83 
85 
86  void resetValues (unsigned int initialPos, unsigned int numPos);
87 
89 
90  void erasePositions (unsigned int initialPos, unsigned int numPos);
91 
93  void getPositionValues (unsigned int posId, V& vec) const;
94 
96 
97  void setPositionValues (unsigned int posId, const V& vec);
98 
100  void subUniformlySampledCdf (const V& numEvaluationPointsVec,
101  ArrayOfOneDGrids <V,M>& cdfGrids,
102  ArrayOfOneDTables<V,M>& cdfValues) const;
103 
105  void unifiedUniformlySampledCdf (const V& numEvaluationPointsVec,
106  ArrayOfOneDGrids <V,M>& unifiedCdfGrids,
107  ArrayOfOneDTables<V,M>& unifiedCdfValues) const;
109 
110  void subMeanExtra (unsigned int initialPos,
111  unsigned int numPos,
112  V& meanVec) const;
113 
115 
116  void unifiedMeanExtra (unsigned int initialPos,
117  unsigned int numPos,
118  V& unifiedMeanVec) const;
119 
121 
122  void subMedianExtra (unsigned int initialPos,
123  unsigned int numPos,
124  V& medianVec) const;
125 
127 
128  void unifiedMedianExtra (unsigned int initialPos,
129  unsigned int numPos,
130  V& unifiedMedianVec) const;
132 
137  void subSampleVarianceExtra (unsigned int initialPos,
138  unsigned int numPos,
139  const V& meanVec,
140  V& samVec) const;
142 
143  void unifiedSampleVarianceExtra (unsigned int initialPos,
144  unsigned int numPos,
145  const V& unifiedMeanVec,
146  V& unifiedSamVec) const;
147 
149 
150  void subSampleStd (unsigned int initialPos,
151  unsigned int numPos,
152  const V& meanVec,
153  V& stdVec) const;
155 
156  void unifiedSampleStd (unsigned int initialPos,
157  unsigned int numPos,
158  const V& unifiedMeanVec,
159  V& unifiedStdVec) const;
160 
162 
168  void subPopulationVariance (unsigned int initialPos,
169  unsigned int numPos,
170  const V& meanVec,
171  V& popVec) const;
172 
174 
175  void unifiedPopulationVariance (unsigned int initialPos,
176  unsigned int numPos,
177  const V& unifiedMeanVec,
178  V& unifiedPopVec) const;
179 
181 
185  void autoCovariance (unsigned int initialPos,
186  unsigned int numPos,
187  const V& meanVec,
188  unsigned int lag,
189  V& covVec) const;
190 
192 
197  void autoCorrViaDef (unsigned int initialPos,
198  unsigned int numPos,
199  unsigned int lag,
200  V& corrVec) const;
202  void autoCorrViaFft (unsigned int initialPos,
203  unsigned int numPos,
204  const std::vector<unsigned int>& lags,
205  std::vector<V*>& corrVecs) const;
206 
208  void autoCorrViaFft (unsigned int initialPos,
209  unsigned int numPos,
210  unsigned int numSum,
211  V& autoCorrsSumVec) const;
213  void subMinMaxExtra (unsigned int initialPos,
214  unsigned int numPos,
215  V& minVec,
216  V& maxVec) const;
218  void unifiedMinMaxExtra (unsigned int initialPos,
219  unsigned int numPos,
220  V& unifiedMinVec,
221  V& unifiedMaxVec) const;
223 
225  // TODO explain params minVec and maxVec
226  void subHistogram (unsigned int initialPos,
227  const V& minVec,
228  const V& maxVec,
229  std::vector<V*>& centersForAllBins,
230  std::vector<V*>& quanttsForAllBins) const;
232  void unifiedHistogram (unsigned int initialPos,
233  const V& unifiedMinVec,
234  const V& unifiedMaxVec,
235  std::vector<V*>& unifiedCentersForAllBins,
236  std::vector<V*>& unifiedQuanttsForAllBins) const;
237 
239 
244  void subInterQuantileRange (unsigned int initialPos,
245  V& iqrVec) const;
246 
248  void unifiedInterQuantileRange (unsigned int initialPos,
249  V& unifiedIqrVec) const;
250 
252 
260  void subScalesForKde (unsigned int initialPos,
261  const V& iqrVec,
262  unsigned int kdeDimension,
263  V& scaleVec) const;
265  void unifiedScalesForKde (unsigned int initialPos,
266  const V& unifiedIqrVec,
267  unsigned int kdeDimension,
268  V& unifiedScaleVec) const;
270 
274  void subGaussian1dKde (unsigned int initialPos,
275  const V& scaleVec,
276  const std::vector<V*>& evalParamVecs,
277  std::vector<V*>& densityVecs) const;
279  void unifiedGaussian1dKde (unsigned int initialPos,
280  const V& unifiedScaleVec,
281  const std::vector<V*>& unifiedEvalParamVecs,
282  std::vector<V*>& unifiedDensityVecs) const;
284 
290  void subWriteContents (unsigned int initialPos,
291  unsigned int numPos,
292  const std::string& fileName,
293  const std::string& fileType,
294  const std::set<unsigned int>& allowedSubEnvIds) const;
296 
297  void subWriteContents (unsigned int initialPos,
298  unsigned int numPos,
299  FilePtrSetStruct& filePtrSet,
300  const std::string& fileType) const;
302 
303  void subWriteContents (unsigned int initialPos,
304  unsigned int numPos,
305  std::ofstream& ofs,
306  const std::string& fileType) const;
309  void unifiedWriteContents (const std::string& fileName,
310  const std::string& fileType) const;
311 
313  void unifiedReadContents (const std::string& fileName,
314  const std::string& fileType,
315  const unsigned int subSequenceSize);
317  void select (const std::vector<unsigned int>& idsOfUniquePositions);
318 
320 
321  void filter (unsigned int initialPos,
322  unsigned int spacing);
323 
325  double estimateConvBrooksGelman (unsigned int initialPos,
326  unsigned int numPos) const;
327 
329 
331  void extractScalarSeq (unsigned int initialPos,
332  unsigned int spacing,
333  unsigned int numPos,
334  unsigned int paramId,
335  ScalarSequence<double>& scalarSeq) const;
336 
337 #ifdef UQ_SEQ_VEC_USES_OPERATOR
338  const V* operator[] (unsigned int posId) const;
339  const V*& operator[] (unsigned int posId);
340 #endif
341 
342 #ifdef UQ_ALSO_COMPUTE_MDFS_WITHOUT_KDE
343  void subUniformlySampledMdf (const V& numEvaluationPointsVec,
344  ArrayOfOneDGrids <V,M>& mdfGrids,
345  ArrayOfOneDTables<V,M>& mdfValues) const;
346 #endif
347 
348 #ifdef QUESO_COMPUTES_EXTRA_POST_PROCESSING_STATISTICS
349  void subMeanCltStd (unsigned int initialPos,
350  unsigned int numPos,
351  const V& meanVec,
352  V& samVec) const;
353  void unifiedMeanCltStd (unsigned int initialPos,
354  unsigned int numPos,
355  const V& unifiedMeanVec,
356  V& unifiedSamVec) const;
357  void bmm (unsigned int initialPos,
358  unsigned int batchLength,
359  V& bmmVec) const;
360  void fftForward (unsigned int initialPos,
361  unsigned int fftSize,
362  unsigned int paramId,
363  std::vector<std::complex<double> >& fftResult) const;
364  //void fftInverse (unsigned int fftSize);
365  void psd (unsigned int initialPos,
366  unsigned int numBlocks,
367  double hopSizeRatio,
368  unsigned int paramId,
369  std::vector<double>& psdResult) const;
370  void psdAtZero (unsigned int initialPos,
371  unsigned int numBlocks,
372  double hopSizeRatio,
373  V& psdVec) const;
374  void geweke (unsigned int initialPos,
375  double ratioNa,
376  double ratioNb,
377  V& gewVec) const;
378  void meanStacc (unsigned int initialPos,
379  V& meanStaccVec) const;
380  void subCdfPercentageRange (unsigned int initialPos,
381  unsigned int numPos,
382  double range, // \in [0,1]
383  V& lowerVec,
384  V& upperVec) const;
385  void unifiedCdfPercentageRange (unsigned int initialPos,
386  unsigned int numPos,
387  double range, // \in [0,1]
388  V& lowerVec,
389  V& upperVec) const;
390  void subCdfStacc (unsigned int initialPos,
391  std::vector<V*>& cdfStaccVecs,
392  std::vector<V*>& cdfStaccVecsUp,
393  std::vector<V*>& cdfStaccVecsLow,
394  std::vector<V*>& sortedDataVecs) const;
395  void subCdfStacc (unsigned int initialPos,
396  const std::vector<V*>& evalPositionsVecs,
397  std::vector<V*>& cdfStaccVecs) const;
398 #endif
399 
400 private:
402  void copy (const SequenceOfVectors<V,M>& src);
403 
405 
408  void extractRawData (unsigned int initialPos,
409  unsigned int spacing,
410  unsigned int numPos,
411  unsigned int paramId,
412  std::vector<double>& rawData) const;
413 
418 
420  std::vector<const V*> m_seq;
421 
422 #ifdef UQ_CODE_HAS_MONITORS
423  void subMeanMonitorAlloc (unsigned int numberOfMonitorPositions);
424  void subMeanInter0MonitorAlloc (unsigned int numberOfMonitorPositions);
425  void unifiedMeanMonitorAlloc (unsigned int numberOfMonitorPositions);
426  void subMeanMonitorRun (unsigned int monitorPosition,
427  V& subMeanVec,
428  V& subMeanCltStd);
429  void subMeanInter0MonitorRun (unsigned int currentPosition,
430  V& subMeanInter0Mean,
431  V& subMeanInter0Clt95,
432  V& subMeanInter0Empirical90,
433  V& subMeanInter0Min,
434  V& subMeanInter0Max);
435  void unifiedMeanMonitorRun (unsigned int currentPosition,
436  V& unifiedMeanVec,
437  V& unifiedMeanCltStd);
438  void subMeanMonitorStore (unsigned int i,
439  unsigned int monitorPosition,
440  const V& subMeanVec,
441  const V& subMeanCltStd);
442  void subMeanInter0MonitorStore (unsigned int i,
443  unsigned int monitorPosition,
444  const V& subMeanInter0Mean,
445  const V& subMeanInter0Clt95,
446  const V& subMeanInter0Empirical90,
447  const V& subMeanInter0Min,
448  const V& subMeanInter0Max);
449  void unifiedMeanMonitorStore (unsigned int i,
450  unsigned int monitorPosition,
451  V& unifiedMeanVec,
452  V& unifiedMeanCltStd);
453  void subMeanMonitorFree ();
454  void subMeanInter0MonitorFree ();
455  void unifiedMeanMonitorFree ();
456  void subMeanMonitorWrite (std::ofstream& ofs);
457  void subMeanInter0MonitorWrite (std::ofstream& ofs);
458  void unifiedMeanMonitorWrite (std::ofstream& ofs);
459 #endif
460 
461 #ifdef UQ_CODE_HAS_MONITORS
462  ScalarSequence<double>* m_subMeanMonitorPosSeq;
463  SequenceOfVectors<V,M>* m_subMeanVecSeq;
464  SequenceOfVectors<V,M>* m_subMeanCltStdSeq;
465 
466  ScalarSequence<double>* m_subMeanInter0MonitorPosSeq;
467  SequenceOfVectors<V,M>* m_subMeanInter0Mean;
468  SequenceOfVectors<V,M>* m_subMeanInter0Clt95;
469  SequenceOfVectors<V,M>* m_subMeanInter0Empirical90;
470  SequenceOfVectors<V,M>* m_subMeanInter0Min;
471  SequenceOfVectors<V,M>* m_subMeanInter0Max;
472 
473  ScalarSequence<double>* m_unifiedMeanMonitorPosSeq;
474  SequenceOfVectors<V,M>* m_unifiedMeanVecSeq;
475  SequenceOfVectors<V,M>* m_unifiedMeanCltStdSeq;
476 #endif
477 };
478 
479 } // End namespace QUESO
480 
481 #endif // UQ_SEQUENCE_OF_VECTORS_H
Class to accommodate arrays of one-dimensional grid.
void autoCovariance(unsigned int initialPos, unsigned int numPos, const V &meanVec, unsigned int lag, V &covVec) const
Calculates the autocovariance.
void unifiedPopulationVariance(unsigned int initialPos, unsigned int numPos, const V &unifiedMeanVec, V &unifiedPopVec) const
Finds the population variance of the unified sequence, considering numPos positions starting at posit...
void subMeanExtra(unsigned int initialPos, unsigned int numPos, V &meanVec) const
Finds the mean value of the sub-sequence, considering numPos positions starting at position initialPo...
void extractScalarSeq(unsigned int initialPos, unsigned int spacing, unsigned int numPos, unsigned int paramId, ScalarSequence< double > &scalarSeq) const
Extracts a sequence of scalars.
void subScalesForKde(unsigned int initialPos, const V &iqrVec, unsigned int kdeDimension, V &scaleVec) const
Selects the scales (bandwidth, scaleVec) for the kernel density estimation, considering only the sub-...
void unifiedGaussian1dKde(unsigned int initialPos, const V &unifiedScaleVec, const std::vector< V * > &unifiedEvalParamVecs, std::vector< V * > &unifiedDensityVecs) const
Gaussian kernel for the KDE estimate of the unified sequence.
SequenceOfVectors< V, M > & operator=(const SequenceOfVectors< V, M > &rhs)
Copies values from rhs to this.
void subMinMaxExtra(unsigned int initialPos, unsigned int numPos, V &minVec, V &maxVec) const
Finds the minimum and the maximum values of the sub-sequence, considering numPos positions starting a...
SequenceOfVectors(const VectorSpace< V, M > &vectorSpace, unsigned int subSequenceSize, const std::string &name)
Default constructor.
std::vector< const V * > m_seq
Sequence of vectors.
void filter(unsigned int initialPos, unsigned int spacing)
Filters positions in the sequence of vectors.
void unifiedReadContents(const std::string &fileName, const std::string &fileType, const unsigned int subSequenceSize)
Reads the unified sequence from a file.
Struct for handling data input and output from files.
Definition: Environment.h:72
std::vector< const V * >::const_iterator seqVectorPositionConstIteratorTypedef
void subSampleVarianceExtra(unsigned int initialPos, unsigned int numPos, const V &meanVec, V &samVec) const
Finds the sample variance of the sub-sequence, considering numPos positions starting at position init...
void subInterQuantileRange(unsigned int initialPos, V &iqrVec) const
Returns the interquartile range of the values in the sub-sequence.
~SequenceOfVectors()
Destructor.
void select(const std::vector< unsigned int > &idsOfUniquePositions)
TODO: It shall select positions in the sequence of vectors.
void resetValues(unsigned int initialPos, unsigned int numPos)
Resets a total of numPos values of the sequence starting at position initialPos.
void unifiedUniformlySampledCdf(const V &numEvaluationPointsVec, ArrayOfOneDGrids< V, M > &unifiedCdfGrids, ArrayOfOneDTables< V, M > &unifiedCdfValues) const
Uniformly samples from the CDF from the sub-sequence.
void unifiedMeanExtra(unsigned int initialPos, unsigned int numPos, V &unifiedMeanVec) const
Finds the mean value of the unified sequence, considering numPos positions starting at position initi...
void subPopulationVariance(unsigned int initialPos, unsigned int numPos, const V &meanVec, V &popVec) const
Finds the population variance of the sub-sequence, considering numPos positions starting at position ...
void subSampleStd(unsigned int initialPos, unsigned int numPos, const V &meanVec, V &stdVec) const
Finds the sample standard deviation of the sub-sequence, considering numPos positions starting at pos...
void subUniformlySampledCdf(const V &numEvaluationPointsVec, ArrayOfOneDGrids< V, M > &cdfGrids, ArrayOfOneDTables< V, M > &cdfValues) const
Uniformly samples from the CDF from the sub-sequence.
void autoCorrViaDef(unsigned int initialPos, unsigned int numPos, unsigned int lag, V &corrVec) const
Calculates the autocorrelation via definition.
void subWriteContents(unsigned int initialPos, unsigned int numPos, const std::string &fileName, const std::string &fileType, const std::set< unsigned int > &allowedSubEnvIds) const
Writes the sub-sequence to a file.
void setPositionValues(unsigned int posId, const V &vec)
Set the values in vec at position posId of the sequence.
const VectorSpace< V, M > & vectorSpace() const
Vector space; access to protected attribute VectorSpace&lt;V,M&gt;&amp; m_vectorSpace.
double estimateConvBrooksGelman(unsigned int initialPos, unsigned int numPos) const
Estimates convergence rate using Brooks &amp; Gelman method.
std::vector< const V * >::iterator seqVectorPositionIteratorTypedef
void unifiedSampleVarianceExtra(unsigned int initialPos, unsigned int numPos, const V &unifiedMeanVec, V &unifiedSamVec) const
Finds the sample variance of the unified sequence, considering numPos positions starting at position ...
void unifiedScalesForKde(unsigned int initialPos, const V &unifiedIqrVec, unsigned int kdeDimension, V &unifiedScaleVec) const
Selects the scales (bandwidth) for the kernel density estimation, considering the unified sequence...
Class to accommodate arrays of one-dimensional tables.
void extractRawData(unsigned int initialPos, unsigned int spacing, unsigned int numPos, unsigned int paramId, std::vector< double > &rawData) const
Extracts the raw data.
const std::string & name() const
Access to protected attribute m_name: name of the sequence of vectors.
unsigned int subSequenceSize() const
Size of the sub-sequence of vectors.
void subMedianExtra(unsigned int initialPos, unsigned int numPos, V &medianVec) const
Finds the median value of the sub-sequence, considering numPos positions starting at position initial...
void getPositionValues(unsigned int posId, V &vec) const
Gets the values of the sequence at position posId and stores them at vec.
void unifiedInterQuantileRange(unsigned int initialPos, V &unifiedIqrVec) const
Returns the interquartile range of the values in the unified sequence.
void unifiedHistogram(unsigned int initialPos, const V &unifiedMinVec, const V &unifiedMaxVec, std::vector< V * > &unifiedCentersForAllBins, std::vector< V * > &unifiedQuanttsForAllBins) const
Calculates the histogram of the unified sequence.
void resizeSequence(unsigned int newSubSequenceSize)
Resizes the sequence.
A class representing a vector space.
Definition: VectorSet.h:49
void unifiedMedianExtra(unsigned int initialPos, unsigned int numPos, V &unifiedMedianVec) const
Finds the median value of the unfed sequence, considering numPos positions starting at position initi...
void subHistogram(unsigned int initialPos, const V &minVec, const V &maxVec, std::vector< V * > &centersForAllBins, std::vector< V * > &quanttsForAllBins) const
Calculates the histogram of the sub-sequence.
void erasePositions(unsigned int initialPos, unsigned int numPos)
Erases numPos elements of the sequence starting at position initialPos.
void unifiedMinMaxExtra(unsigned int initialPos, unsigned int numPos, V &unifiedMinVec, V &unifiedMaxVec) const
Finds the minimum and the maximum values of the unified sequence, considering numPos positions starti...
Class for handling vector samples (sequence of vectors).
void subGaussian1dKde(unsigned int initialPos, const V &scaleVec, const std::vector< V * > &evalParamVecs, std::vector< V * > &densityVecs) const
Gaussian kernel for the KDE estimate of the sub-sequence.
Base class for handling vector and array samples (sequence of vectors or arrays). ...
void unifiedSampleStd(unsigned int initialPos, unsigned int numPos, const V &unifiedMeanVec, V &unifiedStdVec) const
Finds the sample standard deviation of the unified sequence, considering numPos positions starting at...
void unifiedWriteContents(const std::string &fileName, const std::string &fileType) const
void copy(const SequenceOfVectors< V, M > &src)
Copies vector sequence src to this.
void autoCorrViaFft(unsigned int initialPos, unsigned int numPos, const std::vector< unsigned int > &lags, std::vector< V * > &corrVecs) const
Calculates the autocorrelation via Fast Fourier transforms (FFT).

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