25 #ifndef UQ_SCALAR_SEQUENCE_H
26 #define UQ_SCALAR_SEQUENCE_H
28 #include <queso/Fft.h>
29 #include <queso/UniformOneDGrid.h>
30 #include <queso/Environment.h>
31 #include <queso/Miscellaneous.h>
32 #include <queso/Defines.h>
37 #define SCALAR_SEQUENCE_INIT_MPI_MSG 1
38 #define SCALAR_SEQUENCE_SIZE_MPI_MSG 1
39 #define SCALAR_SEQUENCE_DATA_MPI_MSG 1
53 template <
class T =
double>
67 const std::string&
name);
80 const T&
operator[] (
unsigned int posId)
const;
94 const std::string&
name ()
const;
97 void setName (
const std::string& newName);
115 void resetValues (
unsigned int initialPos,
unsigned int );
119 void erasePositions (
unsigned int initialPos,
unsigned int numPos);
123 std::vector<T>& outputVec)
const;
170 std::vector<T>& cdfValues)
const;
174 unsigned int numIntervals,
175 T& unifiedMinDomainValue,
176 T& unifiedMaxDomainValue,
177 std::vector<T>& unifiedCdfValues)
const;
181 std::vector<T>& cdfValues)
const;
184 std::vector<T>& gridValues,
185 std::vector<T>& cdfValues)
const;
190 std::vector<T>& cdfValues)
const;
194 unsigned int numPos)
const;
198 unsigned int initialPos,
199 unsigned int localNumPos)
const;
203 unsigned int numPos)
const;
207 unsigned int initialPos,
208 unsigned int localNumPos)
const;
218 const T& meanValue)
const;
222 unsigned int initialPos,
223 unsigned int localNumPos,
224 const T& unifiedMeanValue)
const;
228 const T& meanValue)
const;
231 unsigned int initialPos,
232 unsigned int localNumPos,
233 const T& unifiedMeanValue)
const;
243 const T& meanValue)
const;
247 unsigned int initialPos,
249 const T& unifiedMeanValue)
const;
258 unsigned int lag)
const;
268 unsigned int lag)
const;
274 std::vector<T>& autoCorrs)
const;
280 T& autoCorrsSum)
const;
288 unsigned int initialPos,
291 T& unifiedMaxValue)
const;
298 const T& minHorizontalValue,
299 const T& maxHorizontalValue,
300 std::vector<T>& centers,
301 std::vector<unsigned int>& bins)
const;
304 unsigned int initialPos,
305 const T& unifiedMinHorizontalValue,
306 const T& unifiedMaxHorizontalValue,
307 std::vector<T>& unifiedCenters,
308 std::vector<unsigned int>& unifiedBins)
const;
315 const T& minHorizontalValue,
316 const T& maxHorizontalValue,
318 std::vector<unsigned int>& bins)
const;
326 const T& minHorizontalValue,
327 const T& maxHorizontalValue,
329 std::vector<unsigned int>& bins)
const;
334 const T& minHorizontalValue,
335 const T& maxHorizontalValue,
336 std::vector<T>& gridValues,
337 std::vector<unsigned int>& bins)
const;
339 void subSort (
unsigned int initialPos,
343 unsigned int initialPos,
355 unsigned int initialPos)
const;
368 unsigned int kdeDimension)
const;
372 unsigned int initialPos,
373 const T& unifiedIqrValue,
374 unsigned int kdeDimension)
const;
382 const std::vector<T>& evaluationPositions,
383 std::vector<double>& densityValues)
const;
387 unsigned int initialPos,
388 double unifiedScaleValue,
389 const std::vector<T>& unifiedEvaluationPositions,
390 std::vector<double>& unifiedDensityValues)
const;
394 void filter (
unsigned int initialPos,
395 unsigned int spacing);
400 unsigned int initialPos,
401 unsigned int spacing)
const;
406 unsigned int srcInitialPos,
407 unsigned int srcNumPos);
422 const std::string& fileName,
423 const std::string& fileType,
424 const std::set<unsigned int>& allowedSubEnvIds)
const;
430 const std::string& fileType)
const;
434 const std::string& fileType)
const;
438 const std::string& fileType,
440 #ifdef QUESO_COMPUTES_EXTRA_POST_PROCESSING_STATISTICS
441 T bmm (
unsigned int initialPos,
442 unsigned int batchLength)
const;
443 void psd (
unsigned int initialPos,
444 unsigned int numBlocks,
446 std::vector<double>& psdSequence)
const;
447 T geweke (
unsigned int initialPos,
449 double ratioNb)
const;
450 T meanStacc (
unsigned int initialPos)
const;
451 void subCdfPercentageRange (
unsigned int initialPos,
455 T& upperValue)
const;
456 void unifiedCdfPercentageRange (
bool useOnlyInter0Comm,
457 unsigned int initialPos,
461 T& upperValue)
const;
463 void subCdfStacc (
unsigned int initialPos,
464 std::vector<double>& cdfStaccValues,
465 std::vector<double>& cdfStaccValuesup,
466 std::vector<double>& cdfStaccValueslow,
468 void subCdfStacc (
unsigned int initialPos,
469 const std::vector<T>& evaluationPositions,
470 std::vector<double>& cdfStaccValues)
const;
471 void subUniformlySampledMdf (
unsigned int numIntervals,
474 std::vector<T>& mdfValues)
const;
475 T subMeanCltStd (
unsigned int initialPos,
477 const T& meanValue)
const;
478 T unifiedMeanCltStd (
bool useOnlyInter0Comm,
479 unsigned int initialPos,
480 unsigned int localNumPos,
481 const T& unifiedMeanValue)
const;
493 unsigned int spacing,
501 unsigned int spacing,
503 std::vector<double>&
rawData)
const;
513 const std::vector<T>& leafData,
514 unsigned int treeLevel)
const;
540 unsigned int initialPos,
543 const std::vector<T>& evaluationPositions1,
544 const std::vector<T>& evaluationPositions2,
545 std::vector<double>& densityValues);
553 unsigned int initialPos,
554 double unifiedScaleValue1,
555 double unifiedScaleValue2,
556 const std::vector<T>& unifiedEvaluationPositions1,
557 const std::vector<T>& unifiedEvaluationPositions2,
558 std::vector<double>& unifiedDensityValues);
566 unsigned int subNumSamples,
572 #endif // UQ_SCALAR_SEQUENCE_H
void ComputeUnifiedGaussian2dKde(bool useOnlyInter0Comm, const ScalarSequence< T > &scalarSeq1, const ScalarSequence< T > &scalarSeq2, unsigned int initialPos, double unifiedScaleValue1, double unifiedScaleValue2, const std::vector< T > &unifiedEvaluationPositions1, const std::vector< T > &unifiedEvaluationPositions2, std::vector< double > &unifiedDensityValues)
T autoCorrViaDef(unsigned int initialPos, unsigned int numPos, unsigned int lag) const
Calculates the autocorrelation via definition.
void subUniformlySampledCdf(unsigned int numIntervals, T &minDomainValue, T &maxDomainValue, std::vector< T > &cdfValues) const
Uniformly samples from the CDF from the sub-sequence.
void copy(const ScalarSequence< T > &src)
Copies the scalar sequence src to this.
const T & subMeanPlain() const
Finds the mean value of the sub-sequence of scalars.
void ComputeSubGaussian2dKde(const ScalarSequence< T > &scalarSeq1, const ScalarSequence< T > &scalarSeq2, unsigned int initialPos, double scaleValue1, double scaleValue2, const std::vector< T > &evaluationPositions1, const std::vector< T > &evaluationPositions2, std::vector< double > &densityValues)
void setName(const std::string &newName)
Sets a new name to the sequence of scalars.
const BaseEnvironment & m_env
const T & operator[](unsigned int posId) const
Access position posId of the sequence of scalars (const).
T subInterQuantileRange(unsigned int initialPos) const
Returns the interquartile range of the values in the sub-sequence.
const std::string & name() const
Access to the name of the sequence of scalars.
std::vector< T > & rawData()
The sequence of scalars. Access to private attribute m_seq.
void subBasicCdf(unsigned int numIntervals, UniformOneDGrid< T > *&gridValues, std::vector< T > &cdfValues) const
Finds the Cumulative Distribution Function (CDF) of the sub-sequence of scalars.
void clear()
Clears the sequence of scalars.
std::vector< T >::const_iterator seqScalarPositionConstIteratorTypedef
const T & unifiedMaxPlain(bool useOnlyInter0Comm) const
Finds the maximum value of the unified sequence of scalars.
ScalarSequence< T > & operator=(const ScalarSequence< T > &rhs)
Assignment operator; it copies rhs to this.
T unifiedMeanExtra(bool useOnlyInter0Comm, unsigned int initialPos, unsigned int localNumPos) const
Finds the mean value of the unified sequence of numPos positions starting at position initialPos...
void subHistogram(unsigned int initialPos, const T &minHorizontalValue, const T &maxHorizontalValue, std::vector< T > ¢ers, std::vector< unsigned int > &bins) const
Calculates the histogram of the sub-sequence.
void parallelMerge(std::vector< T > &sortedBuffer, const std::vector< T > &leafData, unsigned int treeLevel) const
Sorts/merges data in parallel using MPI.
T autoCovariance(unsigned int initialPos, unsigned int numPos, const T &meanValue, unsigned int lag) const
Calculates the autocovariance.
const T & unifiedMeanPlain(bool useOnlyInter0Comm) const
Finds the mean value of the unified sequence of scalars.
T subMeanExtra(unsigned int initialPos, unsigned int numPos) const
Finds the mean value of the sub-sequence, considering numPos positions starting at position initialPo...
void resizeSequence(unsigned int newSequenceSize)
Resizes the size of the sequence of scalars.
void ComputeCovCorrBetweenScalarSequences(const ScalarSequence< T > &subPSeq, const ScalarSequence< T > &subQSeq, unsigned int subNumSamples, T &covValue, T &corrValue)
const T & unifiedSampleVariancePlain(bool useOnlyInter0Comm) const
Finds the variance of a sample of the unified sequence of scalars.
const T & subMinPlain() const
Finds the minimum value of the sub-sequence of scalars.
T subPositionsOfMaximum(const ScalarSequence< T > &subCorrespondingScalarValues, ScalarSequence< T > &subPositionsOfMaximum)
Finds the positions where the maximum element occurs in the sub-sequence.
void subMinMaxExtra(unsigned int initialPos, unsigned int numPos, T &minValue, T &maxValue) const
Finds the minimum and the maximum values of the sub-sequence, considering numPos positions starting a...
void setGaussian(const T &mean, const T &stdDev)
Sets the values of the sequence as a Gaussian distribution of mean given by meanVec and standard devi...
ScalarSequence(const BaseEnvironment &env, unsigned int subSequenceSize, const std::string &name)
Default constructor.
T unifiedPopulationVariance(bool useOnlyInter0Comm, unsigned int initialPos, unsigned int numPos, const T &unifiedMeanValue) const
Finds the population variance of the unified sequence, considering numPos positions starting at posit...
unsigned int unifiedSequenceSize(bool useOnlyInter0Comm) const
Size of the unified sequence of scalars.
T subMedianExtra(unsigned int initialPos, unsigned int numPos) const
Finds the median value of the sub-sequence, considering numPos positions starting at position initial...
T unifiedScaleForKde(bool useOnlyInter0Comm, unsigned int initialPos, const T &unifiedIqrValue, unsigned int kdeDimension) const
Selects the scales (bandwidth) for the kernel density estimation, considering the unified sequence...
void append(const ScalarSequence< T > &src, unsigned int srcInitialPos, unsigned int srcNumPos)
Appends the scalar sequence src to this sequence.
void autoCorrViaFft(unsigned int initialPos, unsigned int numPos, unsigned int maxLag, std::vector< T > &autoCorrs) const
Calculates the autocorrelation via Fast Fourier transforms (FFT).
const T & subMaxPlain() const
Finds the maximum value of the sub-sequence of scalars.
T subSampleStd(unsigned int initialPos, unsigned int numPos, const T &meanValue) const
Finds the sample standard deviation of the unified sequence, considering numPos positions starting at...
T subScaleForKde(unsigned int initialPos, const T &iqrValue, unsigned int kdeDimension) const
Selects the scales (output value) for the kernel density estimation, considering only the sub-sequenc...
const T & unifiedMinPlain(bool useOnlyInter0Comm) const
Finds the minimum value of the unified sequence of scalars.
void setUniform(const T &a, const T &b)
Sets the values of the sequence as a uniform distribution between the values given by vectors aVec an...
T * m_subSampleVariancePlain
T unifiedPositionsOfMaximum(const ScalarSequence< T > &subCorrespondingScalarValues, ScalarSequence< T > &unifiedPositionsOfMaximum)
Finds the positions where the maximum element occurs in the unified sequence.
void unifiedMinMaxExtra(bool useOnlyInter0Comm, unsigned int initialPos, unsigned int numPos, T &unifiedMinValue, T &unifiedMaxValue) const
Finds the minimum and the maximum values of the unified sequence, considering numPos positions starti...
T unifiedInterQuantileRange(bool useOnlyInter0Comm, unsigned int initialPos) const
Returns the interquartile range of the values in the unified sequence.
void unifiedHistogram(bool useOnlyInter0Comm, unsigned int initialPos, const T &unifiedMinHorizontalValue, const T &unifiedMaxHorizontalValue, std::vector< T > &unifiedCenters, std::vector< unsigned int > &unifiedBins) const
Calculates the histogram of the unified sequence.
void extractScalarSeq(unsigned int initialPos, unsigned int spacing, unsigned int numPos, ScalarSequence< T > &scalarSeq) const
Extracts a sequence of scalars.
T unifiedSampleStd(bool useOnlyInter0Comm, unsigned int initialPos, unsigned int localNumPos, const T &unifiedMeanValue) const
Finds the sample standard deviation of the unified sequence, considering localnumPos positions starti...
void erasePositions(unsigned int initialPos, unsigned int numPos)
Erases numPos values of the sequence, starting at position initialPos.
This (virtual) class sets up the environment underlying the use of the QUESO library by an executable...
void unifiedWriteContents(const std::string &fileName, const std::string &fileType) const
Writes the unified sequence to a file.
void extractRawData(unsigned int initialPos, unsigned int spacing, unsigned int numPos, std::vector< double > &rawData) const
Extracts the raw data.
void unifiedGaussian1dKde(bool useOnlyInter0Comm, unsigned int initialPos, double unifiedScaleValue, const std::vector< T > &unifiedEvaluationPositions, std::vector< double > &unifiedDensityValues) const
Gaussian kernel for the KDE estimate of the unified sequence.
T unifiedSampleVarianceExtra(bool useOnlyInter0Comm, unsigned int initialPos, unsigned int localNumPos, const T &unifiedMeanValue) const
Finds the sample variance of the unified sequence, considering numPos positions starting at position ...
Class for accommodating uniform one-dimensional grids.
void unifiedSort(bool useOnlyInter0Comm, unsigned int initialPos, ScalarSequence< T > &unifiedSortedSequence) const
Sorts the unified sequence of scalars.
void deleteStoredScalars()
Deletes all stored scalars.
std::vector< T >::iterator seqScalarPositionIteratorTypedef
T brooksGelmanConvMeasure(bool useOnlyInter0Comm, unsigned int initialPos, unsigned int spacing) const
Estimates convergence rate using Brooks & Gelman method.
~ScalarSequence()
Destructor.
void subSort()
Sorts the sequence of scalars in the private attribute m_seq.
void subWeightCdf(unsigned int numIntervals, std::vector< T > &gridValues, std::vector< T > &cdfValues) const
Finds the Weighted Cumulative Distribution Function (CDF) of the sub-sequence of scalars.
void unifiedUniformlySampledCdf(bool useOnlyInter0Comm, unsigned int numIntervals, T &unifiedMinDomainValue, T &unifiedMaxDomainValue, std::vector< T > &unifiedCdfValues) const
Uniformly samples from the CDF from the unified sequence.
const BaseEnvironment & env() const
Access to QUESO environment.
const T & subSampleVariancePlain() const
Finds the variance of a sample of the sub-sequence of scalars.
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 subGaussian1dKde(unsigned int initialPos, double scaleValue, const std::vector< T > &evaluationPositions, std::vector< double > &densityValues) const
Gaussian kernel for the KDE estimate of the sub-sequence.
void getUnifiedContentsAtProc0Only(bool useOnlyInter0Comm, std::vector< T > &outputVec) const
Gets the unified contents of processor of rank equals to 0.
T subPopulationVariance(unsigned int initialPos, unsigned int numPos, const T &meanValue) const
Finds the population variance of the sub-sequence, considering numPos positions starting at position ...
Class for handling scalar samples.
void subBasicHistogram(unsigned int initialPos, const T &minHorizontalValue, const T &maxHorizontalValue, UniformOneDGrid< T > *&gridValues, std::vector< unsigned int > &bins) const
Calculates the histogram of the sub-sequence.
unsigned int subSequenceSize() const
Size of the sub-sequence of scalars.
T * m_unifiedSampleVariancePlain
const T & subMedianPlain() const
Finds the median value of the sub-sequence of scalars.
void resetValues(unsigned int initialPos, unsigned int)
Sets numPos values of the sequence to zero, starting at position initialPos.
T subSampleVarianceExtra(unsigned int initialPos, unsigned int numPos, const T &meanValue) const
Finds the sample variance of the sub-sequence, considering numPos positions starting at position init...
void subWeightHistogram(unsigned int initialPos, const T &minHorizontalValue, const T &maxHorizontalValue, UniformOneDGrid< T > *&gridValues, std::vector< unsigned int > &bins) const
Calculates the weighted histogram of the sub-sequence.
void filter(unsigned int initialPos, unsigned int spacing)
Filters positions in the sequence of vectors.
const T & unifiedMedianPlain(bool useOnlyInter0Comm) const
Finds the median value of the unified sequence of scalars.
T unifiedMedianExtra(bool useOnlyInter0Comm, unsigned int initialPos, unsigned int localNumPos) const
Finds the median value of the unified sequence, considering numPos positions starting at position ini...
void unifiedReadContents(const std::string &fileName, const std::string &fileType, const unsigned int subSequenceSize)
Reads the unified sequence from a file.