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;
455 T& upperValue)
const;
457 unsigned int initialPos,
461 T& upperValue)
const;
464 std::vector<double>& cdfStaccValues,
465 std::vector<double>& cdfStaccValuesup,
466 std::vector<double>& cdfStaccValueslow,
469 const std::vector<T>& evaluationPositions,
470 std::vector<double>& cdfStaccValues)
const;
474 std::vector<T>& mdfValues)
const;
477 const T& meanValue)
const;
479 unsigned int initialPos,
480 unsigned int localNumPos,
481 const T& unifiedMeanValue)
const;
496 void writeTxtHeader(std::ofstream & ofs,
double sequenceSize)
const;
502 unsigned int spacing,
510 unsigned int spacing,
512 std::vector<double>&
rawData)
const;
522 const std::vector<T>& leafData,
523 unsigned int treeLevel)
const;
549 unsigned int initialPos,
552 const std::vector<T>& evaluationPositions1,
553 const std::vector<T>& evaluationPositions2,
554 std::vector<double>& densityValues);
562 unsigned int initialPos,
563 double unifiedScaleValue1,
564 double unifiedScaleValue2,
565 const std::vector<T>& unifiedEvaluationPositions1,
566 const std::vector<T>& unifiedEvaluationPositions2,
567 std::vector<double>& unifiedDensityValues);
575 unsigned int subNumSamples,
581 #endif // UQ_SCALAR_SEQUENCE_H
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...
const T & subMaxPlain() const
Finds the maximum value of the sub-sequence of scalars.
T subInterQuantileRange(unsigned int initialPos) const
Returns the interquartile range of the values in the sub-sequence.
T * m_unifiedSampleVariancePlain
const T & subMeanPlain() const
Finds the mean value of the sub-sequence of scalars.
ScalarSequence(const BaseEnvironment &env, unsigned int subSequenceSize, const std::string &name)
Default constructor.
void resizeSequence(unsigned int newSequenceSize)
Resizes the size of the sequence of scalars.
const T & unifiedMinPlain(bool useOnlyInter0Comm) const
Finds the minimum value of the unified sequence of scalars.
unsigned int unifiedSequenceSize(bool useOnlyInter0Comm) const
Size of the unified sequence of scalars.
~ScalarSequence()
Destructor.
const T & subMinPlain() const
Finds the minimum value of the sub-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...
This (virtual) class sets up the environment underlying the use of the QUESO library by an executable...
void erasePositions(unsigned int initialPos, unsigned int numPos)
Erases numPos values of the sequence, starting at position initialPos.
T subMeanExtra(unsigned int initialPos, unsigned int numPos) const
Finds the mean value of the sub-sequence, considering numPos positions starting at position initialPo...
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 ...
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 brooksGelmanConvMeasure(bool useOnlyInter0Comm, unsigned int initialPos, unsigned int spacing) const
Estimates convergence rate using Brooks & Gelman method.
void writeUnifiedMatlabHeader(std::ofstream &ofs, double sequenceSize) const
Helper function to write header info for matlab files from all chains.
const T & unifiedMeanPlain(bool useOnlyInter0Comm) const
Finds the mean value of the unified sequence of scalars.
void unifiedCdfPercentageRange(bool useOnlyInter0Comm, unsigned int initialPos, unsigned int numPos, double range, T &lowerValue, T &upperValue) const
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...
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...
void unifiedWriteContents(const std::string &fileName, const std::string &fileType) const
Writes the unified sequence to a file.
std::vector< T >::const_iterator seqScalarPositionConstIteratorTypedef
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...
T unifiedMeanCltStd(bool useOnlyInter0Comm, unsigned int initialPos, unsigned int localNumPos, const T &unifiedMeanValue) const
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 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 autoCorrViaFft(unsigned int initialPos, unsigned int numPos, unsigned int maxLag, std::vector< T > &autoCorrs) const
Calculates the autocorrelation via Fast Fourier transforms (FFT).
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.
void extractScalarSeq(unsigned int initialPos, unsigned int spacing, unsigned int numPos, ScalarSequence< T > &scalarSeq) const
Extracts a sequence of scalars.
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...
std::vector< T > & rawData()
The sequence of scalars. Access to private attribute m_seq.
void psd(unsigned int initialPos, unsigned int numBlocks, double hopSizeRatio, std::vector< double > &psdSequence) const
T unifiedPositionsOfMaximum(const ScalarSequence< T > &subCorrespondingScalarValues, ScalarSequence< T > &unifiedPositionsOfMaximum)
Finds the positions where the maximum element occurs in the unified sequence.
void subCdfStacc(unsigned int initialPos, std::vector< double > &cdfStaccValues, std::vector< double > &cdfStaccValuesup, std::vector< double > &cdfStaccValueslow, const ScalarSequence< T > &sortedDataValues) const
void unifiedSort(bool useOnlyInter0Comm, unsigned int initialPos, ScalarSequence< T > &unifiedSortedSequence) const
Sorts 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...
void subUniformlySampledMdf(unsigned int numIntervals, T &minDomainValue, T &maxDomainValue, std::vector< T > &mdfValues) const
void subSort()
Sorts the sequence of scalars in the private attribute m_seq.
std::vector< T >::iterator seqScalarPositionIteratorTypedef
void writeSubMatlabHeader(std::ofstream &ofs, double sequenceSize) const
Helper function to write header info for matlab files from one chain.
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 ...
void clear()
Clears the sequence of scalars.
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)
void deleteStoredScalars()
Deletes all stored scalars.
void writeTxtHeader(std::ofstream &ofs, double sequenceSize) const
Helper function to write txt info for matlab files.
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.
const T & operator[](unsigned int posId) const
Access position posId of the sequence of scalars (const).
const T & subSampleVariancePlain() const
Finds the variance of a sample of the sub-sequence of scalars.
Class for handling scalar samples.
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 resetValues(unsigned int initialPos, unsigned int)
Sets numPos values of the sequence to zero, starting at position initialPos.
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.
void extractRawData(unsigned int initialPos, unsigned int spacing, unsigned int numPos, std::vector< double > &rawData) const
Extracts the raw data.
const BaseEnvironment & m_env
T autoCovariance(unsigned int initialPos, unsigned int numPos, const T &meanValue, unsigned int lag) const
Calculates the autocovariance.
T * m_subSampleVariancePlain
void ComputeCovCorrBetweenScalarSequences(const ScalarSequence< T > &subPSeq, const ScalarSequence< T > &subQSeq, unsigned int subNumSamples, T &covValue, T &corrValue)
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.
T bmm(unsigned int initialPos, unsigned int batchLength) const
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 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 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 T & unifiedSampleVariancePlain(bool useOnlyInter0Comm) const
Finds the variance of a sample of the unified sequence of scalars.
T subMeanCltStd(unsigned int initialPos, unsigned int numPos, const T &meanValue) const
const T & unifiedMaxPlain(bool useOnlyInter0Comm) const
Finds the maximum value of the unified 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 parallelMerge(std::vector< T > &sortedBuffer, const std::vector< T > &leafData, unsigned int treeLevel) const
Sorts/merges data in parallel using MPI.
T subMedianExtra(unsigned int initialPos, unsigned int numPos) const
Finds the median value of the sub-sequence, considering numPos positions starting at position initial...
void append(const ScalarSequence< T > &src, unsigned int srcInitialPos, unsigned int srcNumPos)
Appends the scalar sequence src to this sequence.
T meanStacc(unsigned int initialPos) const
Class for accommodating uniform one-dimensional grids.
T autoCorrViaDef(unsigned int initialPos, unsigned int numPos, unsigned int lag) const
Calculates the autocorrelation via definition.
const T & subMedianPlain() const
Finds the median 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...
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 subCdfPercentageRange(unsigned int initialPos, unsigned int numPos, double range, T &lowerValue, T &upperValue) const
void setName(const std::string &newName)
Sets a new name to the sequence of scalars.
const BaseEnvironment & env() const
Access to QUESO environment.
void getUnifiedContentsAtProc0Only(bool useOnlyInter0Comm, std::vector< T > &outputVec) const
Gets the unified contents of processor of rank equals to 0.
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.
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.
const T & unifiedMedianPlain(bool useOnlyInter0Comm) const
Finds the median value of the unified sequence of scalars.
T geweke(unsigned int initialPos, double ratioNa, double ratioNb) const
void unifiedReadContents(const std::string &fileName, const std::string &fileType, const unsigned int subSequenceSize)
Reads the unified sequence from a file.
T subPositionsOfMaximum(const ScalarSequence< T > &subCorrespondingScalarValues, ScalarSequence< T > &subPositionsOfMaximum)
Finds the positions where the maximum element occurs in the sub-sequence.
unsigned int subSequenceSize() const
Size of the sub-sequence of scalars.
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...
const std::string & name() const
Access to the name of the sequence of scalars.