queso-0.57.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
QUESO::ScalarSequence< T > Class Template Reference

Class for handling scalar samples. More...

#include <ScalarSequence.h>

Public Types

Class typedefs
typedef std::vector< T >::iterator seqScalarPositionIteratorTypedef
 
typedef std::vector< T >
::const_iterator 
seqScalarPositionConstIteratorTypedef
 

Public Member Functions

Constructor/Destructor methods
 ScalarSequence (const BaseEnvironment &env, unsigned int subSequenceSize, const std::string &name)
 Default constructor. More...
 
 ~ScalarSequence ()
 Destructor. More...
 
Set methods
ScalarSequence< T > & operator= (const ScalarSequence< T > &rhs)
 Assignment operator; it copies rhs to this. More...
 
Access methods
const T & operator[] (unsigned int posId) const
 Access position posId of the sequence of scalars (const). More...
 
T & operator[] (unsigned int posId)
 Access position posId of the sequence of scalars (non-const). More...
 
Sequence methods
const BaseEnvironmentenv () const
 Access to QUESO environment. More...
 
const std::string & name () const
 Access to the name of the sequence of scalars. More...
 
void setName (const std::string &newName)
 Sets a new name to the sequence of scalars. More...
 
void clear ()
 Clears the sequence of scalars. More...
 
unsigned int subSequenceSize () const
 Size of the sub-sequence of scalars. More...
 
unsigned int unifiedSequenceSize (bool useOnlyInter0Comm) const
 Size of the unified sequence of scalars. More...
 
void resizeSequence (unsigned int newSequenceSize)
 Resizes the size of the sequence of scalars. More...
 
void resetValues (unsigned int initialPos, unsigned int)
 Sets numPos values of the sequence to zero, starting at position initialPos. More...
 
void erasePositions (unsigned int initialPos, unsigned int numPos)
 Erases numPos values of the sequence, starting at position initialPos. More...
 
void getUnifiedContentsAtProc0Only (bool useOnlyInter0Comm, std::vector< T > &outputVec) const
 Gets the unified contents of processor of rank equals to 0. More...
 
const T & subMinPlain () const
 Finds the minimum value of the sub-sequence of scalars. More...
 
const T & unifiedMinPlain (bool useOnlyInter0Comm) const
 Finds the minimum value of the unified sequence of scalars. More...
 
const T & subMaxPlain () const
 Finds the maximum value of the sub-sequence of scalars. More...
 
const T & unifiedMaxPlain (bool useOnlyInter0Comm) const
 Finds the maximum value of the unified sequence of scalars. More...
 
const T & subMeanPlain () const
 Finds the mean value of the sub-sequence of scalars. More...
 
const T & unifiedMeanPlain (bool useOnlyInter0Comm) const
 Finds the mean value of the unified sequence of scalars. More...
 
const T & subMedianPlain () const
 Finds the median value of the sub-sequence of scalars. More...
 
const T & unifiedMedianPlain (bool useOnlyInter0Comm) const
 Finds the median value of the unified sequence of scalars. More...
 
const T & subSampleVariancePlain () const
 Finds the variance of a sample of the sub-sequence of scalars. More...
 
const T & unifiedSampleVariancePlain (bool useOnlyInter0Comm) const
 Finds the variance of a sample of the unified sequence of scalars. More...
 
void deleteStoredScalars ()
 Deletes all stored scalars. More...
 
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 deviation by stdDevVec. More...
 
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 and bVec. More...
 
void subUniformlySampledCdf (unsigned int numIntervals, T &minDomainValue, T &maxDomainValue, std::vector< T > &cdfValues) const
 Uniformly samples from the CDF from the sub-sequence. More...
 
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. More...
 
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. More...
 
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. More...
 
void subWeightCdf (unsigned int numIntervals, UniformOneDGrid< T > *&gridValues, std::vector< T > &cdfValues) const
 Finds the Weighted Cumulative Distribution Function (CDF) of the sub-sequence of scalars. More...
 
subMeanExtra (unsigned int initialPos, unsigned int numPos) const
 Finds the mean value of the sub-sequence, considering numPos positions starting at position initialPos. More...
 
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. More...
 
subMedianExtra (unsigned int initialPos, unsigned int numPos) const
 Finds the median value of the sub-sequence, considering numPos positions starting at position initialPos. More...
 
unifiedMedianExtra (bool useOnlyInter0Comm, unsigned int initialPos, unsigned int localNumPos) const
 Finds the median value of the unified sequence, considering numPos positions starting at position initialPos. More...
 
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 initialPos and of mean meanVec. More...
 
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 initialPos and of mean meanVec. More...
 
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 position initialPos and of mean meanValue. More...
 
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 starting at position initialPos and of mean unifiedMeanValue. More...
 
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 initialPos and of mean meanValue. More...
 
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 position initialPos and of mean meanValue. More...
 
autoCovariance (unsigned int initialPos, unsigned int numPos, const T &meanValue, unsigned int lag) const
 Calculates the autocovariance. More...
 
autoCorrViaDef (unsigned int initialPos, unsigned int numPos, unsigned int lag) const
 Calculates the autocorrelation via definition. More...
 
void autoCorrViaFft (unsigned int initialPos, unsigned int numPos, unsigned int maxLag, std::vector< T > &autoCorrs) const
 Calculates the autocorrelation via Fast Fourier transforms (FFT). More...
 
void autoCorrViaFft (unsigned int initialPos, unsigned int numPos, unsigned int numSum, T &autoCorrsSum) const
 Calculates the sum of autocorrelation via Fast Fourier transforms (FFT). More...
 
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 at position initialPos. More...
 
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 starting at position initialPos. More...
 
void subHistogram (unsigned int initialPos, const T &minHorizontalValue, const T &maxHorizontalValue, std::vector< T > &centers, std::vector< unsigned int > &bins) const
 Calculates the histogram of the sub-sequence. More...
 
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. More...
 
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. More...
 
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. More...
 
void subWeightHistogram (unsigned int initialPos, const T &minHorizontalValue, const T &maxHorizontalValue, std::vector< T > &gridValues, std::vector< unsigned int > &bins) const
 Calculates the weighted histogram of the sub-sequence. More...
 
void subSort (unsigned int initialPos, ScalarSequence< T > &sortedSequence) const
 Sorts the sub-sequence of scalars. More...
 
void unifiedSort (bool useOnlyInter0Comm, unsigned int initialPos, ScalarSequence< T > &unifiedSortedSequence) const
 Sorts the unified sequence of scalars. More...
 
subInterQuantileRange (unsigned int initialPos) const
 Returns the interquartile range of the values in the sub-sequence. More...
 
unifiedInterQuantileRange (bool useOnlyInter0Comm, unsigned int initialPos) const
 Returns the interquartile range of the values in the unified sequence. More...
 
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-sequence. More...
 
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. More...
 
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. More...
 
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. More...
 
void filter (unsigned int initialPos, unsigned int spacing)
 Filters positions in the sequence of vectors. More...
 
brooksGelmanConvMeasure (bool useOnlyInter0Comm, unsigned int initialPos, unsigned int spacing) const
 Estimates convergence rate using Brooks & Gelman method. More...
 
void append (const ScalarSequence< T > &src, unsigned int srcInitialPos, unsigned int srcNumPos)
 Appends the scalar sequence src to this sequence. More...
 
subPositionsOfMaximum (const ScalarSequence< T > &subCorrespondingScalarValues, ScalarSequence< T > &subPositionsOfMaximum)
 Finds the positions where the maximum element occurs in the sub-sequence. More...
 
unifiedPositionsOfMaximum (const ScalarSequence< T > &subCorrespondingScalarValues, ScalarSequence< T > &unifiedPositionsOfMaximum)
 Finds the positions where the maximum element occurs in the unified sequence. More...
 
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. More...
 
void subWriteContents (unsigned int initialPos, unsigned int numPos, std::ofstream &ofs, const std::string &fileType) const
 Writes the sub-sequence to a file. More...
 
void unifiedWriteContents (const std::string &fileName, const std::string &fileType) const
 Writes the unified sequence to a file. More...
 
void unifiedReadContents (const std::string &fileName, const std::string &fileType, const unsigned int subSequenceSize)
 Reads the unified sequence from a file. More...
 
bmm (unsigned int initialPos, unsigned int batchLength) const
 
void psd (unsigned int initialPos, unsigned int numBlocks, double hopSizeRatio, std::vector< double > &psdSequence) const
 
geweke (unsigned int initialPos, double ratioNa, double ratioNb) const
 
meanStacc (unsigned int initialPos) const
 
void subCdfPercentageRange (unsigned int initialPos, unsigned int numPos, double range, T &lowerValue, T &upperValue) const
 
void unifiedCdfPercentageRange (bool useOnlyInter0Comm, unsigned int initialPos, unsigned int numPos, double range, T &lowerValue, T &upperValue) const
 
void subCdfStacc (unsigned int initialPos, std::vector< double > &cdfStaccValues, std::vector< double > &cdfStaccValuesup, std::vector< double > &cdfStaccValueslow, const ScalarSequence< T > &sortedDataValues) const
 
void subCdfStacc (unsigned int initialPos, const std::vector< T > &evaluationPositions, std::vector< double > &cdfStaccValues) const
 
void subUniformlySampledMdf (unsigned int numIntervals, T &minDomainValue, T &maxDomainValue, std::vector< T > &mdfValues) const
 
subMeanCltStd (unsigned int initialPos, unsigned int numPos, const T &meanValue) const
 
unifiedMeanCltStd (bool useOnlyInter0Comm, unsigned int initialPos, unsigned int localNumPos, const T &unifiedMeanValue) const
 

Private Member Functions

void copy (const ScalarSequence< T > &src)
 Copies the scalar sequence src to this. More...
 
void writeUnifiedMatlabHeader (std::ofstream &ofs, double sequenceSize) const
 Helper function to write header info for matlab files from all chains. More...
 
void writeSubMatlabHeader (std::ofstream &ofs, double sequenceSize) const
 Helper function to write header info for matlab files from one chain. More...
 
void writeTxtHeader (std::ofstream &ofs, double sequenceSize) const
 Helper function to write txt info for matlab files. More...
 
void extractScalarSeq (unsigned int initialPos, unsigned int spacing, unsigned int numPos, ScalarSequence< T > &scalarSeq) const
 Extracts a sequence of scalars. More...
 
void extractRawData (unsigned int initialPos, unsigned int spacing, unsigned int numPos, std::vector< double > &rawData) const
 Extracts the raw data. More...
 
std::vector< T > & rawData ()
 The sequence of scalars. Access to private attribute m_seq. More...
 
void subSort ()
 Sorts the sequence of scalars in the private attribute m_seq. More...
 
void parallelMerge (std::vector< T > &sortedBuffer, const std::vector< T > &leafData, unsigned int treeLevel) const
 Sorts/merges data in parallel using MPI. More...
 

Private Attributes

const BaseEnvironmentm_env
 
std::string m_name
 
std::vector< T > m_seq
 
T * m_subMinPlain
 
T * m_unifiedMinPlain
 
T * m_subMaxPlain
 
T * m_unifiedMaxPlain
 
T * m_subMeanPlain
 
T * m_unifiedMeanPlain
 
T * m_subMedianPlain
 
T * m_unifiedMedianPlain
 
T * m_subSampleVariancePlain
 
T * m_unifiedSampleVariancePlain
 

Detailed Description

template<class T = double>
class QUESO::ScalarSequence< T >

Class for handling scalar samples.

This class handles scalar samples generated by an algorithm, as well as operations that can be carried over them, e.g., calculation of means, correlation and covariance matrices.

Definition at line 54 of file ScalarSequence.h.

Member Typedef Documentation

template<class T = double>
typedef std::vector<T>::const_iterator QUESO::ScalarSequence< T >::seqScalarPositionConstIteratorTypedef

Definition at line 60 of file ScalarSequence.h.

template<class T = double>
typedef std::vector<T>::iterator QUESO::ScalarSequence< T >::seqScalarPositionIteratorTypedef

Definition at line 59 of file ScalarSequence.h.

Constructor & Destructor Documentation

template<class T >
QUESO::ScalarSequence< T >::ScalarSequence ( const BaseEnvironment env,
unsigned int  subSequenceSize,
const std::string &  name 
)

Default constructor.

Definition at line 32 of file ScalarSequence.C.

36  :
37  m_env (env),
38  m_name (name),
40  m_subMinPlain (NULL),
41  m_unifiedMinPlain (NULL),
42  m_subMaxPlain (NULL),
43  m_unifiedMaxPlain (NULL),
44  m_subMeanPlain (NULL),
45  m_unifiedMeanPlain (NULL),
46  m_subMedianPlain (NULL),
47  m_unifiedMedianPlain (NULL),
50 {
51 }
std::vector< T > m_seq
const BaseEnvironment & m_env
const BaseEnvironment & env() const
Access to QUESO environment.
unsigned int subSequenceSize() const
Size of the sub-sequence of scalars.
const std::string & name() const
Access to the name of the sequence of scalars.
template<class T >
QUESO::ScalarSequence< T >::~ScalarSequence ( )

Destructor.

Definition at line 54 of file ScalarSequence.C.

55 {
57 }
void deleteStoredScalars()
Deletes all stored scalars.

Member Function Documentation

template<class T>
void QUESO::ScalarSequence< T >::append ( const ScalarSequence< T > &  src,
unsigned int  srcInitialPos,
unsigned int  srcNumPos 
)

Appends the scalar sequence src to this sequence.

This routine deletes all stored computed scalars.

Definition at line 2456 of file ScalarSequence.C.

References QUESO::ScalarSequence< T >::m_seq, and QUESO::ScalarSequence< T >::subSequenceSize().

Referenced by QUESO::MLSampling< P_V, P_M >::generateBalLinkedChains_all(), and QUESO::MLSampling< P_V, P_M >::generateUnbLinkedChains_all().

2460 {
2461  queso_require_greater_equal_msg(src.subSequenceSize(), (srcInitialPos+1), "srcInitialPos is too big");
2462 
2463  queso_require_greater_equal_msg(src.subSequenceSize(), (srcInitialPos+srcNumPos), "srcNumPos is too big");
2464 
2466  unsigned int currentSize = this->subSequenceSize();
2467  m_seq.resize(currentSize+srcNumPos,0.);
2468  for (unsigned int i = 0; i < srcNumPos; ++i) {
2469  m_seq[currentSize+i] = src.m_seq[srcInitialPos+i];
2470  }
2471 
2472  return;
2473 }
void deleteStoredScalars()
Deletes all stored scalars.
std::vector< T > m_seq
unsigned int subSequenceSize() const
Size of the sub-sequence of scalars.
template<class T >
T QUESO::ScalarSequence< T >::autoCorrViaDef ( unsigned int  initialPos,
unsigned int  numPos,
unsigned int  lag 
) const

Calculates the autocorrelation via definition.

Autocorrelation is the cross-correlation of a variable with itself; it describes the correlation between values of the process at different times, as a function of the two times. It is calculated over a sequence of vectors with initial position initialPos, considering numPos positions, a lag of lag, with mean given by meanValue. Output: the calculated autocorrelations of the sequence of vectors.

Definition at line 1302 of file ScalarSequence.C.

Referenced by QUESO::SequenceOfVectors< V, M >::autoCorrViaDef().

1306 {
1307  bool bRC = ((initialPos < this->subSequenceSize()) &&
1308  (0 < numPos ) &&
1309  ((initialPos+numPos) <= this->subSequenceSize()) &&
1310  (lag < numPos )); // lag should not be too large
1311  queso_require_msg(bRC, "invalid input data");
1312 
1313  T meanValue = this->subMeanExtra(initialPos,
1314  numPos);
1315 
1316  T covValueZero = this->autoCovariance(initialPos,
1317  numPos,
1318  meanValue,
1319  0); // lag
1320 
1321  T corrValue = this->autoCovariance(initialPos,
1322  numPos,
1323  meanValue,
1324  lag);
1325 
1326  return corrValue/covValueZero;
1327 }
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 autoCovariance(unsigned int initialPos, unsigned int numPos, const T &meanValue, unsigned int lag) const
Calculates the autocovariance.
unsigned int subSequenceSize() const
Size of the sub-sequence of scalars.
template<class T>
void QUESO::ScalarSequence< T >::autoCorrViaFft ( unsigned int  initialPos,
unsigned int  numPos,
unsigned int  maxLag,
std::vector< T > &  autoCorrs 
) const

Calculates the autocorrelation via Fast Fourier transforms (FFT).

Definition at line 1331 of file ScalarSequence.C.

References QUESO::Fft< T >::forward(), and QUESO::Fft< T >::inverse().

Referenced by QUESO::ArrayOfSequences< V, M >::autoCorrViaFft(), and QUESO::SequenceOfVectors< V, M >::autoCorrViaFft().

1336 {
1337  double tmp = log((double) numPos)/log(2.);
1338  double fractionalPart = tmp - ((double) ((unsigned int) tmp));
1339  if (fractionalPart > 0.) tmp += (1. - fractionalPart);
1340  unsigned int fftSize = (unsigned int) std::pow(2.,tmp+1);
1341 
1342  std::vector<double> rawDataVec(numPos,0.);
1343  std::vector<std::complex<double> > resultData(0,std::complex<double>(0.,0.));
1344  Fft<T> fftObj(m_env);
1345 
1346  // Forward FFT
1347  this->extractRawData(initialPos,
1348  1, // spacing
1349  numPos,
1350  rawDataVec);
1351  T meanValue = this->subMeanExtra(initialPos,
1352  numPos);
1353  for (unsigned int j = 0; j < numPos; ++j) {
1354  rawDataVec[j] -= meanValue; // IMPORTANT
1355  }
1356 
1357  rawDataVec.resize(fftSize,0.);
1358 
1359  //if (m_env.subDisplayFile()) {
1360  // *m_env.subDisplayFile() << "In ScalarSequence<T>::autoCorrViaFft()"
1361  // << ": about to call fftObj.forward()"
1362  // << " with rawDataVec.size() = " << rawDataVec.size()
1363  // << ", fftSize = " << fftSize
1364  // << ", resultData.size() = " << resultData.size()
1365  // << std::endl;
1366  //}
1367  fftObj.forward(rawDataVec,fftSize,resultData);
1368 
1369  // Inverse FFT
1370  for (unsigned int j = 0; j < fftSize; ++j) {
1371  rawDataVec[j] = std::norm(resultData[j]);
1372  }
1373  //if (m_env.subDisplayFile()) {
1374  // *m_env.subDisplayFile() << "In ScalarSequence<T>::autoCorrViaFft()"
1375  // << ": about to call fftObj.inverse()"
1376  // << " with rawDataVec.size() = " << rawDataVec.size()
1377  // << ", fftSize = " << fftSize
1378  // << ", resultData.size() = " << resultData.size()
1379  // << std::endl;
1380  //}
1381  fftObj.inverse(rawDataVec,fftSize,resultData);
1382  //if (m_env.subDisplayFile()) {
1383  // *m_env.subDisplayFile() << "In ScalarSequence<T>::autoCorrViaFft()"
1384  // << ": returned succesfully from fftObj.inverse()"
1385  // << std::endl;
1386  //}
1387 
1388  // Prepare return data
1389  autoCorrs.resize(maxLag+1,0.); // Yes, +1
1390  for (unsigned int j = 0; j < autoCorrs.size(); ++j) {
1391  double ratio = ((double) j)/((double) (numPos-1));
1392  autoCorrs[j] = ( resultData[j].real()/resultData[0].real() )*(1.-ratio);
1393  }
1394 
1395  return;
1396 }
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 extractRawData(unsigned int initialPos, unsigned int spacing, unsigned int numPos, std::vector< double > &rawData) const
Extracts the raw data.
const BaseEnvironment & m_env
template<class T>
void QUESO::ScalarSequence< T >::autoCorrViaFft ( unsigned int  initialPos,
unsigned int  numPos,
unsigned int  numSum,
T &  autoCorrsSum 
) const

Calculates the sum of autocorrelation via Fast Fourier transforms (FFT).

Definition at line 1400 of file ScalarSequence.C.

References QUESO::Fft< T >::forward(), and QUESO::Fft< T >::inverse().

1405 {
1406  //if (m_env.subDisplayFile()) {
1407  // *m_env.subDisplayFile() << "Entering ScalarSequence<T>::autoCorrViaFft(), for sum"
1408  // << ": initialPos = " << initialPos
1409  // << ", numPos = " << numPos
1410  // << std::endl;
1411  //}
1412 
1413  double tmp = log((double) numPos)/log(2.);
1414  double fractionalPart = tmp - ((double) ((unsigned int) tmp));
1415  if (fractionalPart > 0.) tmp += (1. - fractionalPart);
1416  unsigned int fftSize = (unsigned int) std::pow(2.,tmp+1);
1417 
1418  std::vector<double> rawDataVec(numPos,0.);
1419  std::vector<std::complex<double> > resultData(0,std::complex<double>(0.,0.));
1420  Fft<T> fftObj(m_env);
1421 
1422  // Forward FFT
1423  this->extractRawData(initialPos,
1424  1, // spacing
1425  numPos,
1426  rawDataVec);
1427  T meanValue = this->subMeanExtra(initialPos,
1428  numPos);
1429  for (unsigned int j = 0; j < numPos; ++j) {
1430  rawDataVec[j] -= meanValue; // IMPORTANT
1431  }
1432  rawDataVec.resize(fftSize,0.);
1433 
1434  //if (m_env.subDisplayFile()) {
1435  // *m_env.subDisplayFile() << "In ScalarSequence<T>::autoCorrViaFft(), for sum"
1436  // << ": about to call fftObj.forward()"
1437  // << " with rawDataVec.size() = " << rawDataVec.size()
1438  // << ", fftSize = " << fftSize
1439  // << ", resultData.size() = " << resultData.size()
1440  // << std::endl;
1441  //}
1442  fftObj.forward(rawDataVec,fftSize,resultData);
1443 
1444  // Inverse FFT
1445  for (unsigned int j = 0; j < fftSize; ++j) {
1446  rawDataVec[j] = std::norm(resultData[j]);
1447  }
1448  fftObj.inverse(rawDataVec,fftSize,resultData);
1449 
1450  //if (m_env.subDisplayFile()) {
1451  // *m_env.subDisplayFile() << "In ScalarSequence<T>::autoCorrViaFft(), for sum"
1452  // << ": computed auto covariance for lag 0 = " << resultData[0].real()/((double) (numPos))
1453  // << ", computed resultData[0].imag() = " << resultData[0].imag()
1454  // << std::endl;
1455  //}
1456 
1457  // Prepare return data
1458  autoCorrsSum = 0.;
1459  for (unsigned int j = 0; j < numSum; ++j) { // Yes, begin at lag '0'
1460  double ratio = ((double) j)/((double) (numPos-1));
1461  autoCorrsSum += ( resultData[j].real()/resultData[0].real() )*(1.-ratio);
1462  }
1463 
1464  return;
1465 }
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 extractRawData(unsigned int initialPos, unsigned int spacing, unsigned int numPos, std::vector< double > &rawData) const
Extracts the raw data.
const BaseEnvironment & m_env
template<class T>
T QUESO::ScalarSequence< T >::autoCovariance ( unsigned int  initialPos,
unsigned int  numPos,
const T &  meanValue,
unsigned int  lag 
) const

Calculates the autocovariance.

The autocovariance is the covariance of a variable with itself at some other time. It is calculated over a sequence of scalars with initial position initialPos, considering numPos positions, a lag of lag, with mean given by meanValue. Output: the calculated autocovariances of the sequence of scalars.

Definition at line 1272 of file ScalarSequence.C.

Referenced by QUESO::SequenceOfVectors< V, M >::autoCovariance().

1277 {
1278  bool bRC = ((initialPos < this->subSequenceSize()) &&
1279  (0 < numPos ) &&
1280  ((initialPos+numPos) <= this->subSequenceSize()) &&
1281  (lag < numPos )); // lag should not be too large
1282  queso_require_msg(bRC, "invalid input data");
1283 
1284  unsigned int loopSize = numPos - lag;
1285  unsigned int finalPosPlus1 = initialPos + loopSize;
1286  T diff1;
1287  T diff2;
1288  T covValue = 0.;
1289  for (unsigned int j = initialPos; j < finalPosPlus1; ++j) {
1290  diff1 = m_seq[j ] - meanValue;
1291  diff2 = m_seq[j+lag] - meanValue;
1292  covValue += diff1*diff2;
1293  }
1294 
1295  covValue /= (T) loopSize;
1296 
1297  return covValue;
1298 }
std::vector< T > m_seq
unsigned int subSequenceSize() const
Size of the sub-sequence of scalars.
template<class T >
T QUESO::ScalarSequence< T >::bmm ( unsigned int  initialPos,
unsigned int  batchLength 
) const

Definition at line 3494 of file ScalarSequence.C.

References QUESO::ScalarSequence< T >::subMeanExtra(), QUESO::ScalarSequence< T >::subSampleVarianceExtra(), and QUESO::ScalarSequence< T >::subSequenceSize().

Referenced by QUESO::SequenceOfVectors< V, M >::bmm().

3497 {
3498  bool bRC = ((initialPos < this->subSequenceSize() ) &&
3499  (batchLength < (this->subSequenceSize()-initialPos)));
3500  queso_require_msg(bRC, "invalid input data");
3501 
3502  unsigned int numberOfBatches = (this->subSequenceSize() - initialPos)/batchLength;
3503  ScalarSequence<T> batchMeans(m_env,numberOfBatches,"");
3504 
3505  for (unsigned int batchId = 0; batchId < numberOfBatches; batchId++) {
3506  batchMeans[batchId] = this->subMeanExtra(initialPos + batchId*batchLength,
3507  batchLength);
3508  }
3509 
3510  T meanOfBatchMeans = batchMeans.subMeanExtra(0,
3511  batchMeans.subSequenceSize());
3512 
3513  //T covLag0OfBatchMeans = batchMeans.autoCovariance(0,
3514  // batchMeans.subSequenceSize(),
3515  // meanOfBatchMeans,
3516  // 0); // lag
3517 
3518  T bmmValue = batchMeans.subSampleVarianceExtra(0,
3519  batchMeans.subSequenceSize(),
3520  meanOfBatchMeans);
3521 
3522  bmmValue /= (T) batchMeans.subSequenceSize(); // CHECK
3523 //bmmValue *= (T) (this->subSequenceSize() - initialPos); // CHECK
3524 
3525  return bmmValue;
3526 }
T subMeanExtra(unsigned int initialPos, unsigned int numPos) const
Finds the mean value of the sub-sequence, considering numPos positions starting at position initialPo...
const BaseEnvironment & m_env
unsigned int subSequenceSize() const
Size of the sub-sequence of scalars.
template<class T >
T QUESO::ScalarSequence< T >::brooksGelmanConvMeasure ( bool  useOnlyInter0Comm,
unsigned int  initialPos,
unsigned int  spacing 
) const

Estimates convergence rate using Brooks & Gelman method.

TODO: implement me!

Definition at line 2427 of file ScalarSequence.C.

2431 {
2432  double resultValue = 0.;
2433 
2434  // FIX ME: put logic if (numSubEnvs == 1) ...
2435 
2436  if (useOnlyInter0Comm) {
2437  if (m_env.inter0Rank() >= 0) {
2438  queso_not_implemented();
2439  }
2440  else {
2441  // Node not in the 'inter0' communicator
2442  // Do nothing
2443  }
2444  }
2445  else {
2446  queso_error_msg("parallel vectors not supported yet");
2447  }
2448 
2449  //m_env.fullComm().Barrier();
2450 
2451  return resultValue;
2452 }
const BaseEnvironment & m_env
int inter0Rank() const
Returns the process inter0 rank.
Definition: Environment.C:307
template<class T >
void QUESO::ScalarSequence< T >::clear ( )

Clears the sequence of scalars.

Resets its values and then its size to zero.

Definition at line 123 of file ScalarSequence.C.

Referenced by QUESO::MLSampling< P_V, P_M >::generateSequence_Step02_inter0().

124 {
125  unsigned int numPos = this->subSequenceSize();
126  if (numPos) {
127  this->resetValues(0,numPos);
128  this->resizeSequence(0);
129  }
130 
131  return;
132 }
void resizeSequence(unsigned int newSequenceSize)
Resizes the size of the sequence of scalars.
void resetValues(unsigned int initialPos, unsigned int)
Sets numPos values of the sequence to zero, starting at position initialPos.
unsigned int subSequenceSize() const
Size of the sub-sequence of scalars.
template<class T>
void QUESO::ScalarSequence< T >::copy ( const ScalarSequence< T > &  src)
private

Copies the scalar sequence src to this.

This routine deletes all stored computed scalars.

Definition at line 3136 of file ScalarSequence.C.

References QUESO::ScalarSequence< T >::m_name, QUESO::ScalarSequence< T >::m_seq, and QUESO::ScalarSequence< T >::subSequenceSize().

3137 {
3138  m_name = src.m_name;
3139  m_seq.clear();
3140  m_seq.resize(src.subSequenceSize(),0.);
3141  for (unsigned int i = 0; i < m_seq.size(); ++i) {
3142  m_seq[i] = src.m_seq[i];
3143  }
3145 
3146  return;
3147 }
void deleteStoredScalars()
Deletes all stored scalars.
std::vector< T > m_seq
template<class T >
void QUESO::ScalarSequence< T >::deleteStoredScalars ( )

Deletes all stored scalars.

Definition at line 467 of file ScalarSequence.C.

468 {
469  if (m_subMinPlain) {
470  delete m_subMinPlain;
471  m_subMinPlain = NULL;
472  }
473  if (m_unifiedMinPlain) {
474  delete m_unifiedMinPlain;
475  m_unifiedMinPlain = NULL;
476  }
477  if (m_subMaxPlain) {
478  delete m_subMaxPlain;
479  m_subMaxPlain = NULL;
480  }
481  if (m_unifiedMaxPlain) {
482  delete m_unifiedMaxPlain;
483  m_unifiedMaxPlain = NULL;
484  }
485  if (m_subMeanPlain) {
486  delete m_subMeanPlain;
487  m_subMeanPlain = NULL;
488  }
489  if (m_unifiedMeanPlain) {
490  delete m_unifiedMeanPlain;
491  m_unifiedMeanPlain = NULL;
492  }
493  if (m_subMedianPlain) {
494  delete m_subMedianPlain;
495  m_subMedianPlain = NULL;
496  }
497  if (m_unifiedMedianPlain) {
498  delete m_unifiedMedianPlain;
499  m_unifiedMedianPlain = NULL;
500  }
504  }
508  }
509 
510  return;
511 }
template<class T >
const BaseEnvironment & QUESO::ScalarSequence< T >::env ( ) const

Access to QUESO environment.

Definition at line 101 of file ScalarSequence.C.

Referenced by QUESO::ComputeCovCorrBetweenScalarSequences(), and QUESO::ComputeUnifiedGaussian2dKde().

102 {
103  return m_env;
104 }
const BaseEnvironment & m_env
template<class T >
void QUESO::ScalarSequence< T >::erasePositions ( unsigned int  initialPos,
unsigned int  numPos 
)

Erases numPos values of the sequence, starting at position initialPos.

This routine deletes all stored computed scalars.

Definition at line 206 of file ScalarSequence.C.

References QUESO::queso_require_equal_to_msg.

Referenced by QUESO::ArrayOfSequences< V, M >::erasePositions().

207 {
208  if (this->subSequenceSize() == 0) return;
209 
210  bool bRC = ((initialPos < this->subSequenceSize()) &&
211  (0 < numPos ) &&
212  ((initialPos+numPos) <= this->subSequenceSize()));
213  queso_require_msg(bRC, "invalid input data");
214 
215  seqScalarPositionIteratorTypedef posIteratorBegin = m_seq.begin();
216  if (initialPos < this->subSequenceSize()) std::advance(posIteratorBegin,initialPos);
217  else posIteratorBegin = m_seq.end();
218 
219  unsigned int posEnd = initialPos + numPos;
220  seqScalarPositionIteratorTypedef posIteratorEnd = m_seq.begin();
221  if (posEnd < this->subSequenceSize()) std::advance(posIteratorEnd,posEnd);
222  else posIteratorEnd = m_seq.end();
223 
224  unsigned int oldSequenceSize = this->subSequenceSize();
225  m_seq.erase(posIteratorBegin,posIteratorEnd);
226  queso_require_equal_to_msg((oldSequenceSize - numPos), this->subSequenceSize(), "(oldSequenceSize - numPos) != this->subSequenceSize()");
227 
229 
230  return;
231 }
std::vector< T >::iterator seqScalarPositionIteratorTypedef
void deleteStoredScalars()
Deletes all stored scalars.
std::vector< T > m_seq
MonteCarloSGOptions::MonteCarloSGOptions(const BaseEnvironment &env, const char *prefix, const McOptionsValues &alternativeOptionsValues queso_require_equal_to_msg)(m_env.optionsInputFileName(), std::string(""), std::string("this constructor is incompatible with the existence of an options input file"))
unsigned int subSequenceSize() const
Size of the sub-sequence of scalars.
template<class T >
void QUESO::ScalarSequence< T >::extractRawData ( unsigned int  initialPos,
unsigned int  spacing,
unsigned int  numPos,
std::vector< double > &  rawData 
) const
private

Extracts the raw data.

This method saves in rawData the data from the sequence of scalars (in private attribute m_seq) starting at position (initialPos), with a spacing of spacing until numPos positions have been extracted.

Definition at line 3192 of file ScalarSequence.C.

3197 {
3198  rawDataVec.resize(numPos);
3199  if (spacing == 1) {
3200  for (unsigned int j = 0; j < numPos; ++j) {
3201  rawDataVec[j] = m_seq[initialPos+j ];
3202  }
3203  }
3204  else {
3205  for (unsigned int j = 0; j < numPos; ++j) {
3206  rawDataVec[j] = m_seq[initialPos+j*spacing];
3207  }
3208  }
3209 
3210  return;
3211 }
std::vector< T > m_seq
template<class T>
void QUESO::ScalarSequence< T >::extractScalarSeq ( unsigned int  initialPos,
unsigned int  spacing,
unsigned int  numPos,
ScalarSequence< T > &  scalarSeq 
) const
private

Extracts a sequence of scalars.

The sequence of scalars has size numPos, and it will be extracted starting at position (initialPos) of this sequence of scalars, given spacing spacing.

Definition at line 3151 of file ScalarSequence.C.

References QUESO::ScalarSequence< T >::resizeSequence().

3156 {
3157  scalarSeq.resizeSequence(numPos);
3158  if (spacing == 1) {
3159  for (unsigned int j = 0; j < numPos; ++j) {
3160  //if ((initialPos+j*spacing) > m_seq.size()) {
3161  // std::cerr << "In ScalarSequence<T>::extraScalarSeq()"
3162  // << ": initialPos = " << initialPos
3163  // << ", spacing = " << spacing
3164  // << ", numPos = " << numPos
3165  // << ", j = " << j
3166  // << ", position got too large"
3167  // << std::endl;
3168  //}
3169  scalarSeq[j] = m_seq[initialPos+j ];
3170  }
3171  }
3172  else {
3173  for (unsigned int j = 0; j < numPos; ++j) {
3174  //if ((initialPos+j*spacing) > m_seq.size()) {
3175  // std::cerr << "In ScalarSequence<T>::extraScalarSeq()"
3176  // << ": initialPos = " << initialPos
3177  // << ", spacing = " << spacing
3178  // << ", numPos = " << numPos
3179  // << ", j = " << j
3180  // << ", position got too large"
3181  // << std::endl;
3182  //}
3183  scalarSeq[j] = m_seq[initialPos+j*spacing];
3184  }
3185  }
3186 
3187  return;
3188 }
std::vector< T > m_seq
template<class T >
void QUESO::ScalarSequence< T >::filter ( unsigned int  initialPos,
unsigned int  spacing 
)

Filters positions in the sequence of vectors.

Filtered positions will start at initialPos, and with spacing given by spacing.

Definition at line 2388 of file ScalarSequence.C.

Referenced by QUESO::MLSampling< P_V, P_M >::generateSequence(), QUESO::MetropolisHastingsSG< P_V, P_M >::generateSequence(), and QUESO::MLSampling< P_V, P_M >::generateSequence_Step11_inter0().

2391 {
2392  if (m_env.subDisplayFile()) {
2393  *m_env.subDisplayFile() << "Entering ScalarSequence<V,M>::filter()"
2394  << ": initialPos = " << initialPos
2395  << ", spacing = " << spacing
2396  << ", subSequenceSize = " << this->subSequenceSize()
2397  << std::endl;
2398  }
2399 
2400  unsigned int i = 0;
2401  unsigned int j = initialPos;
2402  unsigned int originalSubSequenceSize = this->subSequenceSize();
2403  while (j < originalSubSequenceSize) {
2404  if (i != j) {
2405  //*m_env.subDisplayFile() << i << "--" << j << " ";
2406  m_seq[i] = m_seq[j];
2407  }
2408  i++;
2409  j += spacing;
2410  }
2411 
2412  this->resizeSequence(i);
2413 
2414  if (m_env.subDisplayFile()) {
2415  *m_env.subDisplayFile() << "Leaving ScalarSequence<V,M>::filter()"
2416  << ": initialPos = " << initialPos
2417  << ", spacing = " << spacing
2418  << ", subSequenceSize = " << this->subSequenceSize()
2419  << std::endl;
2420  }
2421 
2422  return;
2423 }
void resizeSequence(unsigned int newSequenceSize)
Resizes the size of the sequence of scalars.
std::vector< T > m_seq
const BaseEnvironment & m_env
unsigned int subSequenceSize() const
Size of the sub-sequence of scalars.
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:320
template<class T>
void QUESO::ScalarSequence< T >::getUnifiedContentsAtProc0Only ( bool  useOnlyInter0Comm,
std::vector< T > &  outputVec 
) const

Gets the unified contents of processor of rank equals to 0.

Definition at line 235 of file ScalarSequence.C.

References QUESO::queso_require_equal_to_msg.

Referenced by QUESO::MLSampling< P_V, P_M >::generateSequence_Step05_inter0(), and QUESO::MLSampling< P_V, P_M >::generateSequence_Step09_all().

238 {
239  // The logic (numSubEnvs == 1) does *not* apply here because 'outputVec' needs to be filled
240  //if (m_env.numSubEnvironments() == 1) {
241  // // No need to do anything
242  // return;
243  //}
244 
245  if (useOnlyInter0Comm) {
246  if (m_env.inter0Rank() >= 0) {
247  int auxSubSize = (int) this->subSequenceSize();
248  unsigned int auxUnifiedSize = this->unifiedSequenceSize(useOnlyInter0Comm);
249  outputVec.resize(auxUnifiedSize,0.);
250 
251  //******************************************************************
252  // Use MPI_Gatherv for the case different nodes have different amount of data // KAUST4
253  //******************************************************************
254  std::vector<int> recvcnts(m_env.inter0Comm().NumProc(),0); // '0' is NOT the correct value for recvcnts[0]
255  m_env.inter0Comm().template Gather<int>(&auxSubSize, 1, &recvcnts[0], (int) 1, 0,
256  "ScalarSequence<T>::getUnifiedContentsAtProc0Only()",
257  "failed MPI.Gather()");
258  if (m_env.inter0Rank() == 0) {
259  //recvcnts[0] = (int) this->subSequenceSize(); // FIX ME: really necessary????
260  queso_require_equal_to_msg(recvcnts[0], (int) this->subSequenceSize(), "failed MPI.Gather() result at proc 0");
261  }
262 
263  std::vector<int> displs(m_env.inter0Comm().NumProc(),0);
264  for (unsigned int r = 1; r < (unsigned int) m_env.inter0Comm().NumProc(); ++r) { // Yes, from '1' on
265  displs[r] = displs[r-1] + recvcnts[r-1];
266  }
267 
268 #if 0 // for debug only
269  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
270  for (unsigned int r = 0; r < (unsigned int) m_env.inter0Comm().NumProc(); ++r) {
271  *m_env.subDisplayFile() << " auxSubSize = " << auxSubSize
272  << ", recvcnts[" << r << "] = " << recvcnts[r]
273  << ", displs[" << r << "] = " << displs[r]
274  << ", m_seq.size() = " << m_seq.size()
275  << ", outputVec.size() = " << outputVec.size()
276  << std::endl;
277  }
278  for (unsigned int i = 0; i < m_seq.size(); ++i) {
279  *m_env.subDisplayFile() << " (before gatherv) m_seq[" << i << "]= " << m_seq[i]
280  << std::endl;
281  }
282  }
283 #endif
284 
285  m_env.inter0Comm().template Gatherv<double>(&m_seq[0], auxSubSize,
286  &outputVec[0], (int *) &recvcnts[0], (int *) &displs[0], 0,
287  "ScalarSequence<T>::getUnifiedContentsAtProc0Only()",
288  "failed MPI.Gatherv()");
289 
290 #if 0 // for debug only
291  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
292  for (unsigned int i = 0; i < m_seq.size(); ++i) {
293  *m_env.subDisplayFile() << " (after gatherv) m_seq[" << i << "]= " << m_seq[i]
294  << std::endl;
295  }
296  for (unsigned int i = 0; i < outputVec.size(); ++i) {
297  *m_env.subDisplayFile() << " (after gatherv) outputVec[" << i << "]= " << outputVec[i]
298  << std::endl;
299  }
300  }
301 #endif
302 
303 #if 0 // for debug only
304  if (m_env.inter0Rank() == 0) {
305  for (unsigned int i = 0; i < auxSubSize; ++i) {
306  outputVec[i] = m_seq[i];
307  }
308  m_env.inter0Comm().Gatherv(RawValue_MPI_IN_PLACE, auxSubSize, RawValue_MPI_DOUBLE, (void *) &outputVec[0], (int *) &recvcnts[0], (int *) &displs[0], RawValue_MPI_DOUBLE, 0,
309  "ScalarSequence<T>::getUnifiedContentsAtProc0Only(1)",
310  "failed MPI.Gatherv()");
311  }
312  else {
313  m_env.inter0Comm().Gatherv((void *) &m_seq[0], auxSubSize, RawValue_MPI_DOUBLE, (void *) &outputVec[0], (int *) &recvcnts[0], (int *) &displs[0], RawValue_MPI_DOUBLE, 0,
314  "ScalarSequence<T>::getUnifiedContentsAtProc0Only(2)",
315  "failed MPI.Gatherv()");
316  }
317  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
318  for (unsigned int i = 0; i < m_seq.size(); ++i) {
319  *m_env.subDisplayFile() << " (after 2nd gatherv) m_seq[" << i << "]= " << m_seq[i]
320  << std::endl;
321  }
322  for (unsigned int i = 0; i < outputVec.size(); ++i) {
323  *m_env.subDisplayFile() << " (after 2nd gatherv) outputVec[" << i << "]= " << outputVec[i]
324  << std::endl;
325  }
326  }
327 #endif
328  }
329  else {
330  // Node not in the 'inter0' communicator
331  // No need to do anything
332  }
333  }
334  else {
335  queso_error_msg("parallel vectors not supported yet");
336  }
337 
338  return;
339 }
unsigned int unifiedSequenceSize(bool useOnlyInter0Comm) const
Size of the unified sequence of scalars.
const MpiComm & inter0Comm() const
Access function for MpiComm communicator for processes with subRank() 0.
Definition: Environment.C:313
std::vector< T > m_seq
const BaseEnvironment & m_env
void Gatherv(void *sendbuf, int sendcnt, RawType_MPI_Datatype sendtype, void *recvbuf, int *recvcnts, int *displs, RawType_MPI_Datatype recvtype, int root, const char *whereMsg, const char *whatMsg) const
Gathers into specified locations from all processes in a group.
Definition: MpiComm.C:254
MonteCarloSGOptions::MonteCarloSGOptions(const BaseEnvironment &env, const char *prefix, const McOptionsValues &alternativeOptionsValues queso_require_equal_to_msg)(m_env.optionsInputFileName(), std::string(""), std::string("this constructor is incompatible with the existence of an options input file"))
int NumProc() const
Returns total number of processes.
Definition: MpiComm.C:133
unsigned int displayVerbosity() const
Definition: Environment.C:450
int inter0Rank() const
Returns the process inter0 rank.
Definition: Environment.C:307
unsigned int subSequenceSize() const
Size of the sub-sequence of scalars.
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:320
template<class T >
T QUESO::ScalarSequence< T >::geweke ( unsigned int  initialPos,
double  ratioNa,
double  ratioNb 
) const

Definition at line 3653 of file ScalarSequence.C.

References QUESO::ScalarSequence< T >::psd(), and QUESO::ScalarSequence< T >::subMeanExtra().

Referenced by QUESO::SequenceOfVectors< V, M >::geweke().

3657 {
3658  double doubleFullDataSize = (double) (this->subSequenceSize() - initialPos);
3659  ScalarSequence<T> tmpSeq(m_env,0,"");
3660  std::vector<double> psdResult(0,0.);
3661 
3662  unsigned int dataSizeA = (unsigned int) (doubleFullDataSize * ratioNa);
3663  double doubleDataSizeA = (double) dataSizeA;
3664  unsigned int initialPosA = initialPos;
3665  this->extractScalarSeq(initialPosA,
3666  1,
3667  dataSizeA,
3668  tmpSeq);
3669  double meanA = tmpSeq.subMeanExtra(0,
3670  dataSizeA);
3671  tmpSeq.psd(0,
3672  (unsigned int) std::sqrt((double) dataSizeA), // numBlocks
3673  .5, // hopSizeRatio
3674  psdResult);
3675  double psdA = psdResult[0];
3676  double varOfMeanA = 2.*M_PI*psdA/doubleDataSizeA;
3677 
3678  unsigned int dataSizeB = (unsigned int) (doubleFullDataSize * ratioNb);
3679  double doubleDataSizeB = (double) dataSizeB;
3680  unsigned int initialPosB = this->subSequenceSize() - dataSizeB;
3681  this->extractScalarSeq(initialPosB,
3682  1,
3683  dataSizeB,
3684  tmpSeq);
3685  double meanB = tmpSeq.subMeanExtra(0,
3686  dataSizeB);
3687  tmpSeq.psd(0,
3688  (unsigned int) std::sqrt((double) dataSizeB), // numBlocks
3689  .5, // hopSizeRatio
3690  psdResult);
3691  double psdB = psdResult[0];
3692  double varOfMeanB = 2.*M_PI*psdB/doubleDataSizeB;
3693 
3694  if (m_env.subDisplayFile()) {
3695  *m_env.subDisplayFile() << "In ScalarSequence<T>::geweke()"
3696  << ", before computation of gewCoef"
3697  << ":\n"
3698  << ", dataSizeA = " << dataSizeA
3699  << ", numBlocksA = " << (unsigned int) std::sqrt((double) dataSizeA)
3700  << ", meanA = " << meanA
3701  << ", psdA = " << psdA
3702  << ", varOfMeanA = " << varOfMeanA
3703  << "\n"
3704  << ", dataSizeB = " << dataSizeB
3705  << ", numBlocksB = " << (unsigned int) std::sqrt((double) dataSizeB)
3706  << ", meanB = " << meanB
3707  << ", psdB = " << psdB
3708  << ", varOfMeanB = " << varOfMeanB
3709  << std::endl;
3710  }
3711  double gewCoef = (meanA - meanB)/std::sqrt(varOfMeanA + varOfMeanB);
3712 
3713  return gewCoef;
3714 }
void extractScalarSeq(unsigned int initialPos, unsigned int spacing, unsigned int numPos, ScalarSequence< T > &scalarSeq) const
Extracts a sequence of scalars.
const BaseEnvironment & m_env
unsigned int subSequenceSize() const
Size of the sub-sequence of scalars.
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:320
template<class T >
T QUESO::ScalarSequence< T >::meanStacc ( unsigned int  initialPos) const

Definition at line 3718 of file ScalarSequence.C.

Referenced by QUESO::SequenceOfVectors< V, M >::meanStacc().

3720 {
3721  queso_not_implemented(); // ERNESTO
3722 
3723  double value = 0.;
3724 
3725  return value;
3726 }
template<class T >
const std::string & QUESO::ScalarSequence< T >::name ( ) const

Access to the name of the sequence of scalars.

Definition at line 108 of file ScalarSequence.C.

109 {
110  return m_name;
111 }
template<class T>
ScalarSequence< T > & QUESO::ScalarSequence< T >::operator= ( const ScalarSequence< T > &  rhs)

Assignment operator; it copies rhs to this.

Definition at line 61 of file ScalarSequence.C.

62 {
63  this->copy(rhs);
64  return *this;
65 }
void copy(const ScalarSequence< T > &src)
Copies the scalar sequence src to this.
template<class T >
const T & QUESO::ScalarSequence< T >::operator[] ( unsigned int  posId) const

Access position posId of the sequence of scalars (const).

Definition at line 69 of file ScalarSequence.C.

70 {
71  if (posId >= this->subSequenceSize()) {
72  std::cerr << "In ScalarSequence<T>::operator[]() const"
73  << ": posId = " << posId
74  << ", this->subSequenceSize() = " << this->subSequenceSize()
75  << std::endl;
76  }
77  queso_require_less_msg(posId, this->subSequenceSize(), "posId > subSequenceSize()");
78 
79  return m_seq[posId];
80 }
std::vector< T > m_seq
unsigned int subSequenceSize() const
Size of the sub-sequence of scalars.
template<class T >
T & QUESO::ScalarSequence< T >::operator[] ( unsigned int  posId)

Access position posId of the sequence of scalars (non-const).

This routine deletes all stored computed scalars.

Definition at line 84 of file ScalarSequence.C.

85 {
86  if (posId >= this->subSequenceSize()) {
87  std::cerr << "In ScalarSequence<T>::operator[]()"
88  << ": posId = " << posId
89  << ", this->subSequenceSize() = " << this->subSequenceSize()
90  << std::endl;
91  }
92  queso_require_less_msg(posId, this->subSequenceSize(), "posId > subSequenceSize()");
93 
95 
96  return m_seq[posId];
97 }
void deleteStoredScalars()
Deletes all stored scalars.
std::vector< T > m_seq
unsigned int subSequenceSize() const
Size of the sub-sequence of scalars.
template<class T>
void QUESO::ScalarSequence< T >::parallelMerge ( std::vector< T > &  sortedBuffer,
const std::vector< T > &  leafData,
unsigned int  treeLevel 
) const
private

Sorts/merges data in parallel using MPI.

Definition at line 3233 of file ScalarSequence.C.

3237 {
3238  int parentNode = m_env.inter0Rank() & ~(1 << currentTreeLevel);
3239 
3240  if (m_env.inter0Rank() >= 0) { // KAUST
3241  if (currentTreeLevel == 0) {
3242  // Leaf node: sort own local data.
3243  unsigned int leafDataSize = leafData.size();
3244  sortedBuffer.resize(leafDataSize,0.);
3245  for (unsigned int i = 0; i < leafDataSize; ++i) {
3246  sortedBuffer[i] = leafData[i];
3247  }
3248  std::sort(sortedBuffer.begin(), sortedBuffer.end());
3249  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
3250  *m_env.subDisplayFile() << "In ScalarSequence<T>::parallelMerge()"
3251  << ": tree node " << m_env.inter0Rank()
3252  << ", leaf sortedBuffer[0] = " << sortedBuffer[0]
3253  << ", leaf sortedBuffer[" << sortedBuffer.size()-1 << "] = " << sortedBuffer[sortedBuffer.size()-1]
3254  << std::endl;
3255  }
3256  }
3257  else {
3258  int nextTreeLevel = currentTreeLevel - 1;
3259  int rightChildNode = m_env.inter0Rank() | (1 << nextTreeLevel);
3260 
3261  if (rightChildNode >= m_env.inter0Comm().NumProc()) { // No right child. Move down one level.
3262  this->parallelMerge(sortedBuffer,
3263  leafData,
3264  nextTreeLevel);
3265  }
3266  else {
3267  unsigned int uintBuffer[1];
3268  uintBuffer[0] = nextTreeLevel;
3269  m_env.inter0Comm().Send((void *) uintBuffer, 1, RawValue_MPI_UNSIGNED, rightChildNode, SCALAR_SEQUENCE_INIT_MPI_MSG,
3270  "ScalarSequence<T>::parallelMerge()",
3271  "failed MPI.Send() for init");
3272 
3273  this->parallelMerge(sortedBuffer,
3274  leafData,
3275  nextTreeLevel);
3276 
3277  // Prepare variable 'leftSortedBuffer': just copy own current sorted data.
3278  unsigned int leftSize = sortedBuffer.size();
3279  std::vector<T> leftSortedBuffer(leftSize,0.);
3280  for (unsigned int i = 0; i < leftSize; ++i) {
3281  leftSortedBuffer[i] = sortedBuffer[i];
3282  }
3283 
3284  // Prepare variable 'rightSortedBuffer': receive data from right child node.
3285  RawType_MPI_Status status;
3286  m_env.inter0Comm().Recv((void *) uintBuffer, 1, RawValue_MPI_UNSIGNED, rightChildNode, SCALAR_SEQUENCE_SIZE_MPI_MSG, &status,
3287  "ScalarSequence<T>::parallelMerge()",
3288  "failed MPI.Recv() for size");
3289  //if (status) {}; // just to remove compiler warning
3290 
3291  unsigned int rightSize = uintBuffer[0];
3292  std::vector<T> rightSortedBuffer(rightSize,0.);
3293  m_env.inter0Comm().Recv((void *) &rightSortedBuffer[0], (int) rightSize, RawValue_MPI_DOUBLE, rightChildNode, SCALAR_SEQUENCE_DATA_MPI_MSG, &status,
3294  "ScalarSequence<T>::parallelMerge()",
3295  "failed MPI.Recv() for data");
3296 
3297  // Merge the two results into 'sortedBuffer'.
3298  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
3299  *m_env.subDisplayFile() << "In ScalarSequence<T>::parallelMerge()"
3300  << ": tree node " << m_env.inter0Rank()
3301  << " is combining " << leftSortedBuffer.size()
3302  << " left doubles with " << rightSortedBuffer.size()
3303  << " right doubles"
3304  << std::endl;
3305  }
3306 
3307  sortedBuffer.clear();
3308  sortedBuffer.resize(leftSortedBuffer.size()+rightSortedBuffer.size(),0.);
3309  unsigned int i = 0;
3310  unsigned int j = 0;
3311  unsigned int k = 0;
3312  while ((i < leftSize ) &&
3313  (j < rightSize)) {
3314  if (leftSortedBuffer[i] > rightSortedBuffer[j]) sortedBuffer[k++] = rightSortedBuffer[j++];
3315  else sortedBuffer[k++] = leftSortedBuffer [i++];
3316  }
3317  while (i < leftSize ) sortedBuffer[k++] = leftSortedBuffer [i++];
3318  while (j < rightSize) sortedBuffer[k++] = rightSortedBuffer[j++];
3319  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
3320  *m_env.subDisplayFile() << "In ScalarSequence<T>::parallelMerge()"
3321  << ": tree node " << m_env.inter0Rank()
3322  << ", merged sortedBuffer[0] = " << sortedBuffer[0]
3323  << ", merged sortedBuffer[" << sortedBuffer.size()-1 << "] = " << sortedBuffer[sortedBuffer.size()-1]
3324  << std::endl;
3325  }
3326  }
3327  }
3328 
3329  if (parentNode != m_env.inter0Rank()) {
3330  // Transmit data to parent node.
3331  unsigned int uintBuffer[1];
3332  uintBuffer[0] = sortedBuffer.size();
3333  m_env.inter0Comm().Send((void *) uintBuffer, 1, RawValue_MPI_UNSIGNED, parentNode, SCALAR_SEQUENCE_SIZE_MPI_MSG,
3334  "ScalarSequence<T>::parallelMerge()",
3335  "failed MPI.Send() for size");
3336 
3337  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 10)) {
3338  *m_env.subDisplayFile() << "In ScalarSequence<T>::parallelMerge()"
3339  << ": tree node " << m_env.inter0Rank()
3340  << " is sending " << sortedBuffer.size()
3341  << " doubles to tree node " << parentNode
3342  << ", with sortedBuffer[0] = " << sortedBuffer[0]
3343  << " and sortedBuffer[" << sortedBuffer.size()-1 << "] = " << sortedBuffer[sortedBuffer.size()-1]
3344  << std::endl;
3345  }
3346 
3347  m_env.inter0Comm().Send((void *) &sortedBuffer[0], (int) sortedBuffer.size(), RawValue_MPI_DOUBLE, parentNode, SCALAR_SEQUENCE_DATA_MPI_MSG,
3348  "ScalarSequence<T>::parallelMerge()",
3349  "failed MPI.Send() for data");
3350  }
3351  } // KAUST
3352 
3353  return;
3354 }
const MpiComm & inter0Comm() const
Access function for MpiComm communicator for processes with subRank() 0.
Definition: Environment.C:313
void Recv(void *buf, int count, RawType_MPI_Datatype datatype, int source, int tag, RawType_MPI_Status *status, const char *whereMsg, const char *whatMsg) const
Blocking receive of data from this process to another process.
Definition: MpiComm.C:307
const BaseEnvironment & m_env
void Send(void *buf, int count, RawType_MPI_Datatype datatype, int dest, int tag, const char *whereMsg, const char *whatMsg) const
Possibly blocking send of data from this process to another process.
Definition: MpiComm.C:320
void parallelMerge(std::vector< T > &sortedBuffer, const std::vector< T > &leafData, unsigned int treeLevel) const
Sorts/merges data in parallel using MPI.
int NumProc() const
Returns total number of processes.
Definition: MpiComm.C:133
unsigned int displayVerbosity() const
Definition: Environment.C:450
MPI_Status RawType_MPI_Status
Definition: MpiComm.h:46
int inter0Rank() const
Returns the process inter0 rank.
Definition: Environment.C:307
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:320
template<class T >
void QUESO::ScalarSequence< T >::psd ( unsigned int  initialPos,
unsigned int  numBlocks,
double  hopSizeRatio,
std::vector< double > &  psdSequence 
) const

Definition at line 3530 of file ScalarSequence.C.

References QUESO::Fft< T >::forward(), and QUESO::MiscHammingWindow().

Referenced by QUESO::ArrayOfSequences< V, M >::geweke(), QUESO::ScalarSequence< T >::geweke(), QUESO::SequenceOfVectors< V, M >::psd(), QUESO::ArrayOfSequences< V, M >::psdAtZero(), and QUESO::SequenceOfVectors< V, M >::psdAtZero().

3535 {
3536  bool bRC = ((initialPos < this->subSequenceSize() ) &&
3537  (hopSizeRatio != 0. ) &&
3538  (numBlocks < (this->subSequenceSize() - initialPos)) &&
3539  (fabs(hopSizeRatio) < (double) (this->subSequenceSize() - initialPos)));
3540  queso_require_msg(bRC, "invalid input data");
3541 
3542  unsigned int dataSize = this->subSequenceSize() - initialPos;
3543 
3544  T meanValue = this->subMeanExtra(initialPos,
3545  dataSize);
3546 
3547  // Determine hopSize and blockSize
3548  unsigned int hopSize = 0;
3549  unsigned int blockSize = 0;
3550  if (hopSizeRatio <= -1.) {
3551  double overlapSize = -hopSizeRatio;
3552  double tmp = ((double) (dataSize + (numBlocks - 1)*overlapSize))/((double) numBlocks);
3553  blockSize = (unsigned int) tmp;
3554  }
3555  else if (hopSizeRatio < 0.) {
3556  double tmp = ((double) dataSize)/(( ((double) numBlocks) - 1. )*(-hopSizeRatio) + 1.);
3557  blockSize = (unsigned int) tmp;
3558  hopSize = (unsigned int) ( ((double) blockSize) * (-hopSizeRatio) );
3559  }
3560  else if (hopSizeRatio == 0.) {
3561  queso_error_msg("hopSizeRatio == 0");
3562  }
3563  else if (hopSizeRatio < 1.) {
3564  double tmp = ((double) dataSize)/(( ((double) numBlocks) - 1. )*hopSizeRatio + 1.);
3565  blockSize = (unsigned int) tmp;
3566  hopSize = (unsigned int) ( ((double) blockSize) * hopSizeRatio );
3567  }
3568  else {
3569  hopSize = (unsigned int) hopSizeRatio;
3570  blockSize = dataSize - (numBlocks - 1)*hopSize;
3571  }
3572 
3573  int numberOfDiscardedDataElements = dataSize - (numBlocks-1)*hopSize - blockSize;
3574  //if (m_env.subDisplayFile()) {
3575  // *m_env.subDisplayFile() << "initialPos = " << initialPos
3576  // << ", N = " << dataSize
3577  // << ", #Blocks = " << numBlocks
3578  // << ", R (hop size) = " << hopSize
3579  // << ", B (block size) = " << blockSize
3580  // << ", overlap = " << blockSize - hopSize
3581  // << ", [(#Blocks - 1) * R + B] = " << (numBlocks-1)*hopSize + blockSize
3582  // << ", numberOfDiscardedDataElements = " << numberOfDiscardedDataElements
3583  // << std::endl;
3584  //}
3585  queso_require_greater_equal_msg(numberOfDiscardedDataElements, 0., "eventual extra space for last block should not be negative");
3586 
3587  double tmp = log((double) blockSize)/log(2.);
3588  double fractionalPart = tmp - ((double) ((unsigned int) tmp));
3589  if (fractionalPart > 0.) tmp += (1. - fractionalPart);
3590  unsigned int fftSize = (unsigned int) std::pow(2.,tmp);
3591  //if (m_env.subDisplayFile()) {
3592  // *m_env.subDisplayFile() << "fractionalPart = " << fractionalPart
3593  // << ", B = " << blockSize
3594  // << ", fftSize = " << fftSize
3595  // << std::endl;
3596  //}
3597 
3598  double modificationScale = 0.;
3599  for (unsigned int j = 0; j < blockSize; ++j) {
3600  double tmpValue = MiscHammingWindow(blockSize-1,j);
3601  modificationScale += tmpValue*tmpValue;
3602  }
3603  modificationScale = 1./modificationScale;
3604 
3605  std::vector<double> blockData(blockSize,0.);
3606  Fft<T> fftObj(m_env);
3607  std::vector<std::complex<double> > fftResult(0,std::complex<double>(0.,0.));
3608 
3609 #if 0
3610  unsigned int halfFFTSize = fftSize/2;
3611  psdResult.clear();
3612  psdResult.resize(1+halfFFTSize,0.);
3613  double factor = 1./M_PI/((double) numBlocks); // /((double) blockSize);
3614 #else
3615  psdResult.clear();
3616  psdResult.resize(fftSize,0.);
3617  double factor = 1./2./M_PI/((double) numBlocks); // /((double) blockSize);
3618 #endif
3619 
3620  for (unsigned int blockId = 0; blockId < numBlocks; blockId++) {
3621  // Fill block using Hamming window
3622  unsigned int initialDataPos = initialPos + blockId*hopSize;
3623  for (unsigned int j = 0; j < blockSize; ++j) {
3624  unsigned int dataPos = initialDataPos + j;
3625  queso_require_less_msg(dataPos, dataSize, "too large position to be accessed in data");
3626  blockData[j] = MiscHammingWindow(blockSize-1,j) * ( m_seq[dataPos] - meanValue ); // IMPORTANT
3627  }
3628 
3629  fftObj.forward(blockData,fftSize,fftResult);
3630 
3631  //if (m_env.subDisplayFile()) {
3632  // *m_env.subDisplayFile() << "blockData.size() = " << blockData.size()
3633  // << ", fftSize = " << fftSize
3634  // << ", fftResult.size() = " << fftResult.size()
3635  // << ", psdResult.size() = " << psdResult.size()
3636  // << std::endl;
3637  //}
3638  // Normalized spectral density: power per radians per sample
3639  for (unsigned int j = 0; j < psdResult.size(); ++j) {
3640  psdResult[j] += norm(fftResult[j])*modificationScale;
3641  }
3642  }
3643 
3644  for (unsigned int j = 0; j < psdResult.size(); ++j) {
3645  psdResult[j] *= factor;
3646  }
3647 
3648  return;
3649 }
T subMeanExtra(unsigned int initialPos, unsigned int numPos) const
Finds the mean value of the sub-sequence, considering numPos positions starting at position initialPo...
double MiscHammingWindow(unsigned int N, unsigned int j)
std::vector< T > m_seq
const BaseEnvironment & m_env
unsigned int subSequenceSize() const
Size of the sub-sequence of scalars.
template<class T >
std::vector< T > & QUESO::ScalarSequence< T >::rawData ( )
private

The sequence of scalars. Access to private attribute m_seq.

Definition at line 3215 of file ScalarSequence.C.

Referenced by QUESO::ScalarSequence< T >::unifiedSort().

3216 {
3217  return m_seq;
3218 }
std::vector< T > m_seq
template<class T >
void QUESO::ScalarSequence< T >::resetValues ( unsigned int  initialPos,
unsigned int  numPos 
)

Sets numPos values of the sequence to zero, starting at position initialPos.

This routine deletes all stored computed scalars.

Definition at line 186 of file ScalarSequence.C.

187 {
188  if (this->subSequenceSize() == 0) return;
189 
190  bool bRC = ((initialPos < this->subSequenceSize()) &&
191  (0 < numPos ) &&
192  ((initialPos+numPos) <= this->subSequenceSize()));
193  queso_require_msg(bRC, "invalid input data");
194 
195  for (unsigned int j = 0; j < numPos; ++j) {
196  m_seq[initialPos+j] = 0.;
197  }
198 
200 
201  return;
202 }
void deleteStoredScalars()
Deletes all stored scalars.
std::vector< T > m_seq
unsigned int subSequenceSize() const
Size of the sub-sequence of scalars.
template<class T >
void QUESO::ScalarSequence< T >::resizeSequence ( unsigned int  newSequenceSize)
template<class T>
void QUESO::ScalarSequence< T >::setGaussian ( const T &  mean,
const T &  stdDev 
)

Sets the values of the sequence as a Gaussian distribution of mean given by meanVec and standard deviation by stdDevVec.

This routine deletes all stored computed scalars.

Definition at line 515 of file ScalarSequence.C.

Referenced by QUESO::ArrayOfSequences< V, M >::setGaussian().

516 {
517  unsigned int maxJ = this->subSequenceSize();
518  for (unsigned int j = 0; j < maxJ; ++j) {
519  m_seq[j] = meanValue + m_env.rngObject()->gaussianSample(stdDev);
520  }
521 
523 }
virtual double gaussianSample(double stdDev) const =0
Samples a value from a Gaussian distribution with standard deviation given by stdDev.
const RngBase * rngObject() const
Access to the RNG object.
Definition: Environment.C:471
void deleteStoredScalars()
Deletes all stored scalars.
std::vector< T > m_seq
const BaseEnvironment & m_env
unsigned int subSequenceSize() const
Size of the sub-sequence of scalars.
template<class T >
void QUESO::ScalarSequence< T >::setName ( const std::string &  newName)
template<class T>
void QUESO::ScalarSequence< T >::setUniform ( const T &  a,
const T &  b 
)

Sets the values of the sequence as a uniform distribution between the values given by vectors aVec and bVec.

This routine deletes all stored computed scalars.

Definition at line 527 of file ScalarSequence.C.

Referenced by QUESO::ArrayOfSequences< V, M >::setUniform().

528 {
529  unsigned int maxJ = this->subSequenceSize();
530  for (unsigned int j = 0; j < maxJ; ++j) {
531  m_seq[j] = a + (b-a)*m_env.rngObject()->uniformSample();
532  }
533 
535 }
const RngBase * rngObject() const
Access to the RNG object.
Definition: Environment.C:471
void deleteStoredScalars()
Deletes all stored scalars.
std::vector< T > m_seq
const BaseEnvironment & m_env
virtual double uniformSample() const =0
Samples a value from a uniform distribution.
unsigned int subSequenceSize() const
Size of the sub-sequence of scalars.
template<class T>
void QUESO::ScalarSequence< T >::subBasicCdf ( unsigned int  numIntervals,
UniformOneDGrid< T > *&  gridValues,
std::vector< T > &  cdfValues 
) const

Finds the Cumulative Distribution Function (CDF) of the sub-sequence of scalars.

Definition at line 680 of file ScalarSequence.C.

684 {
685  T tmpMinValue;
686  T tmpMaxValue;
687  std::vector<unsigned int> bins(numEvaluationPoints,0);
688 
689  subMinMaxExtra(0, // initialPos
690  this->subSequenceSize(),
691  tmpMinValue,
692  tmpMaxValue);
693  subBasicHistogram(0, // initialPos,
694  tmpMinValue,
695  tmpMaxValue,
696  gridValues,
697  bins);
698 
699  unsigned int sumOfBins = 0;
700  for (unsigned int i = 0; i < numEvaluationPoints; ++i) {
701  sumOfBins += bins[i];
702  }
703 
704  cdfValues.clear();
705  cdfValues.resize(numEvaluationPoints);
706  unsigned int partialSum = 0;
707  for (unsigned int i = 0; i < numEvaluationPoints; ++i) {
708  partialSum += bins[i];
709  cdfValues[i] = ((T) partialSum)/((T) sumOfBins);
710  }
711 
712  return;
713 }
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 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...
unsigned int subSequenceSize() const
Size of the sub-sequence of scalars.
template<class T>
void QUESO::ScalarSequence< T >::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.

It requires the specification of the maximum (maxHorizontalValue) and the minimum (minHorizontalValue) values if the data and the initial position (initialPos) from where the data will be considered. Output: grid values that will act as the center of each bin (gridValues) and the number of data occurrences in each bin (bins).

Definition at line 1706 of file ScalarSequence.C.

1712 {
1713  queso_require_greater_equal_msg(bins.size(), 3, "number of 'bins' is too small: should be at least 3");
1714 
1715  for (unsigned int j = 0; j < bins.size(); ++j) {
1716  bins[j] = 0;
1717  }
1718 
1719  double horizontalDelta = (maxHorizontalValue - minHorizontalValue)/(((double) bins.size()) - 2.); // IMPORTANT: -2
1720  double minCenter = minHorizontalValue - horizontalDelta/2.;
1721  double maxCenter = maxHorizontalValue + horizontalDelta/2.;
1722  gridValues = new UniformOneDGrid<T>(m_env,
1723  "",
1724  bins.size(),
1725  minCenter,
1726  maxCenter);
1727 
1728  unsigned int dataSize = this->subSequenceSize();
1729  for (unsigned int j = 0; j < dataSize; ++j) {
1730  double value = m_seq[j];
1731  if (value < minHorizontalValue) {
1732  bins[0]++;
1733  }
1734  else if (value >= maxHorizontalValue) {
1735  bins[bins.size()-1]++;
1736  }
1737  else {
1738  unsigned int index = 1 + (unsigned int) ((value - minHorizontalValue)/horizontalDelta);
1739  bins[index]++;
1740  }
1741  }
1742 
1743  return;
1744 }
std::vector< T > m_seq
const BaseEnvironment & m_env
unsigned int subSequenceSize() const
Size of the sub-sequence of scalars.
template<class T>
void QUESO::ScalarSequence< T >::subCdfPercentageRange ( unsigned int  initialPos,
unsigned int  numPos,
double  range,
T &  lowerValue,
T &  upperValue 
) const

Definition at line 3730 of file ScalarSequence.C.

References QUESO::ScalarSequence< T >::resizeSequence(), and QUESO::ScalarSequence< T >::subSort().

Referenced by QUESO::SequenceOfVectors< V, M >::subCdfPercentageRange().

3736 {
3737  queso_require_less_equal_msg((initialPos+numPos), this->subSequenceSize(), "invalid input");
3738 
3739  queso_require_msg(!((range < 0) || (range > 1.)), "invalid 'range' value");
3740 
3741  ScalarSequence<T> sortedSequence(m_env,0,"");;
3742  sortedSequence.resizeSequence(numPos);
3743  this->extractScalarSeq(initialPos,
3744  1,
3745  numPos,
3746  sortedSequence);
3747  sortedSequence.subSort();
3748 
3749  unsigned int lowerId = (unsigned int) round( 0.5*(1.-range)*((double) numPos) );
3750  lowerValue = sortedSequence[lowerId];
3751 
3752  unsigned int upperId = (unsigned int) round( 0.5*(1.+range)*((double) numPos) );
3753  if (upperId == numPos) {
3754  upperId = upperId-1;
3755  }
3756  queso_require_less_msg(upperId, numPos, "'upperId' got too big");
3757  upperValue = sortedSequence[upperId];
3758 
3759  return;
3760 }
void extractScalarSeq(unsigned int initialPos, unsigned int spacing, unsigned int numPos, ScalarSequence< T > &scalarSeq) const
Extracts a sequence of scalars.
const BaseEnvironment & m_env
unsigned int subSequenceSize() const
Size of the sub-sequence of scalars.
template<class T>
void QUESO::ScalarSequence< T >::subCdfStacc ( unsigned int  initialPos,
std::vector< double > &  cdfStaccValues,
std::vector< double > &  cdfStaccValuesup,
std::vector< double > &  cdfStaccValueslow,
const ScalarSequence< T > &  sortedDataValues 
) const

Definition at line 3808 of file ScalarSequence.C.

Referenced by QUESO::SequenceOfVectors< V, M >::subCdfStacc().

3814 {
3815  queso_require_msg(!(false), "not implemented yet"); // Joseph
3816  bool bRC = (initialPos < this->subSequenceSize() );
3817  queso_require_msg(bRC, "invalid input data");
3818 
3819  unsigned int numPoints = subSequenceSize()-initialPos;
3820  double auxNumPoints = numPoints;
3821  double maxLamb = 0.;
3822  std::vector<double> ro (numPoints,0.);
3823  std::vector<double> Isam_mat(numPoints,0.);
3824 
3825  for (unsigned int pointId = 0; pointId < numPoints; pointId++) {
3826  double p = ( ((double) pointId) + 1.0 )/auxNumPoints;
3827  double ro0 = p*(1.0-p);
3828  cdfStaccValues[pointId] = p;
3829 
3830  //std::cout << "x-data" << data[pointId]
3831  // << std::endl;
3832 
3833  for (unsigned int k = 0; k < numPoints; k++) {
3834  if (m_seq[k] <= sortedDataValues[pointId]) {
3835  Isam_mat[k] = 1;
3836  }
3837  else {
3838  Isam_mat[k] = 0;
3839  }
3840  }
3841 
3842  for (unsigned int tau = 0; tau < (numPoints-1); tau++) {
3843  ro[tau] = 0.;
3844  for (unsigned int kk = 0; kk < numPoints-(tau+1); kk++) {
3845  ro[tau] += (Isam_mat[kk+tau+1]-p)*(Isam_mat[kk]-p);
3846  }
3847  ro[tau] *= 1.0/auxNumPoints;
3848  }
3849  double lamb = 0.;
3850  for (unsigned int tau = 0; tau < (numPoints-1); tau++) {
3851  double auxTau = tau;
3852  lamb += (1.-(auxTau+1.)/auxNumPoints)*ro[tau]/ro0;
3853  if (lamb > maxLamb) maxLamb = lamb;
3854  }
3855  lamb = 2.*maxLamb;
3856 
3857  //double ll=gsl_cdf_gaussian_Pinv(-0.05);
3858  cdfStaccValuesUp [pointId] = cdfStaccValues[pointId]+1.96*sqrt(ro0/auxNumPoints*(1.+lamb));
3859  cdfStaccValuesLow[pointId] = cdfStaccValues[pointId]-1.96*sqrt(ro0/auxNumPoints*(1.+lamb));
3860  if (cdfStaccValuesLow[pointId] < 0.) cdfStaccValuesLow[pointId] = 0.;
3861  if (cdfStaccValuesUp [pointId] > 1.) cdfStaccValuesUp [pointId] = 1.;
3862  //if (pointId==1 | pointId==100 | pointId==900) {
3863  // std::cout<<lamb<<ll<<std::endl;
3864  // std::cout<<lamb<<std::endl;
3865  //}
3866  }
3867 
3868 #if 0
3869  unsigned int dataSize = this->subSequenceSize() - initialPos;
3870  unsigned int numEvals = evaluationPositions.size();
3871 
3872  for (unsigned int j = 0; j < numEvals; ++j) {
3873  double x = evaluationPositions[j];
3874  double value = 0.;
3875  for (unsigned int k = 0; k < dataSize; ++k) {
3876  double xk = m_seq[initialPos+k];
3877  value += 0.;//MiscGaussianDensity((x-xk)*scaleInv,0.,1.);
3878  }
3879  cdfStaccValues[j] = value/(double) dataSize;
3880  }
3881 #endif
3882 
3883  return;
3884 }
std::vector< T > m_seq
unsigned int subSequenceSize() const
Size of the sub-sequence of scalars.
template<class T>
void QUESO::ScalarSequence< T >::subCdfStacc ( unsigned int  initialPos,
const std::vector< T > &  evaluationPositions,
std::vector< double > &  cdfStaccValues 
) const

Definition at line 3888 of file ScalarSequence.C.

3892 {
3893  queso_not_implemented();
3894 
3895  bool bRC = ((initialPos < this->subSequenceSize() ) &&
3896  (0 < evaluationPositions.size()) &&
3897  (evaluationPositions.size() == cdfStaccValues.size() ));
3898  queso_require_msg(bRC, "invalid input data");
3899 
3900  // For Joseph:
3901  // Maybe sort first
3902  // For each of the evaluation positions:
3903  // --> 1) form temporary scalar seq that contains only 0 and 1
3904  // --> 2) call "temporary scalar seq"->meanStacc()
3905 
3906 #if 0
3907  unsigned int dataSize = this->subSequenceSize() - initialPos;
3908  unsigned int numEvals = evaluationPositions.size();
3909 
3910  for (unsigned int j = 0; j < numEvals; ++j) {
3911  //double x = evaluationPositions[j];
3912  double value = 0.;
3913  for (unsigned int k = 0; k < dataSize; ++k) {
3914  //double xk = m_seq[initialPos+k];
3915  value += 0.;//MiscGaussianDensity((x-xk)*scaleInv,0.,1.);
3916  }
3917  cdfStaccValues[j] = value/(double) dataSize;
3918  }
3919 #endif
3920 
3921  return;
3922 }
unsigned int subSequenceSize() const
Size of the sub-sequence of scalars.
template<class T>
void QUESO::ScalarSequence< T >::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.

Computes a probability density estimate of the sample in this sub-sequence, starting at position initialPos. densityValues is the vector of density values evaluated at the points in evaluationPositions. The estimate is based on Gaussian (normal) kernel function, using a window parameter (scaleValue).

Definition at line 2278 of file ScalarSequence.C.

References QUESO::MiscGaussianDensity().

Referenced by QUESO::SequenceOfVectors< V, M >::subGaussian1dKde().

2283 {
2284  bool bRC = ((initialPos < this->subSequenceSize() ) &&
2285  (0 < evaluationPositions.size()) &&
2286  (evaluationPositions.size() == densityValues.size() ));
2287  queso_require_msg(bRC, "invalid input data");
2288 
2289  unsigned int dataSize = this->subSequenceSize() - initialPos;
2290  unsigned int numEvals = evaluationPositions.size();
2291 
2292  double scaleInv = 1./scaleValue;
2293  for (unsigned int j = 0; j < numEvals; ++j) {
2294  double x = evaluationPositions[j];
2295  double value = 0.;
2296  for (unsigned int k = 0; k < dataSize; ++k) {
2297  double xk = m_seq[initialPos+k];
2298  value += MiscGaussianDensity((x-xk)*scaleInv,0.,1.);
2299  }
2300  densityValues[j] = scaleInv * (value/(double) dataSize);
2301  }
2302 
2303  return;
2304 }
double MiscGaussianDensity(double x, double mu, double sigma)
std::vector< T > m_seq
unsigned int subSequenceSize() const
Size of the sub-sequence of scalars.
template<class T>
void QUESO::ScalarSequence< T >::subHistogram ( unsigned int  initialPos,
const T &  minHorizontalValue,
const T &  maxHorizontalValue,
std::vector< T > &  centers,
std::vector< unsigned int > &  bins 
) const

Calculates the histogram of the sub-sequence.

It requires the specification of the maximum (maxHorizontalValue) and the minimum (minHorizontalValue) values if the data and the initial position (initialPos) from where the data will be considered. Output: the center of each bin (centers) and the number of data occurrences in each bin (bins).

Definition at line 1569 of file ScalarSequence.C.

References QUESO::queso_require_equal_to_msg.

Referenced by QUESO::SequenceOfVectors< V, M >::subHistogram().

1575 {
1576  queso_require_equal_to_msg(centers.size(), bins.size(), "vectors 'centers' and 'bins' have different sizes");
1577 
1578  queso_require_greater_equal_msg(bins.size(), 3, "number of 'bins' is too small: should be at least 3");
1579 
1580  if (initialPos) {}; // just to remove compiler warning
1581 
1582  for (unsigned int j = 0; j < bins.size(); ++j) {
1583  centers[j] = 0.;
1584  bins[j] = 0;
1585  }
1586 
1587  double horizontalDelta = (maxHorizontalValue - minHorizontalValue)/(((double) bins.size()) - 2.); // IMPORTANT: -2
1588 
1589  double minCenter = minHorizontalValue - horizontalDelta/2.;
1590  double maxCenter = maxHorizontalValue + horizontalDelta/2.;
1591  for (unsigned int j = 0; j < centers.size(); ++j) {
1592  double factor = ((double) j)/(((double) centers.size()) - 1.);
1593  centers[j] = (1. - factor) * minCenter + factor * maxCenter;
1594  }
1595 
1596  unsigned int dataSize = this->subSequenceSize();
1597  for (unsigned int j = 0; j < dataSize; ++j) {
1598  double value = m_seq[j];
1599  if (value < minHorizontalValue) {
1600  bins[0]++;
1601  }
1602  else if (value >= maxHorizontalValue) {
1603  bins[bins.size()-1]++;
1604  }
1605  else {
1606  unsigned int index = 1 + (unsigned int) ((value - minHorizontalValue)/horizontalDelta);
1607  bins[index]++;
1608  }
1609  }
1610 
1611  return;
1612 }
std::vector< T > m_seq
MonteCarloSGOptions::MonteCarloSGOptions(const BaseEnvironment &env, const char *prefix, const McOptionsValues &alternativeOptionsValues queso_require_equal_to_msg)(m_env.optionsInputFileName(), std::string(""), std::string("this constructor is incompatible with the existence of an options input file"))
unsigned int subSequenceSize() const
Size of the sub-sequence of scalars.
template<class T >
T QUESO::ScalarSequence< T >::subInterQuantileRange ( unsigned int  initialPos) const

Returns the interquartile range of the values in the sub-sequence.

The IQR is a robust estimate of the spread of the data, since changes in the upper and lower 25% of the data do not affect it. If there are outliers in the data, then the IQR is more representative than the standard deviation as an estimate of the spread of the body of the data. The IQR is less efficient than the standard deviation as an estimate of the spread when the data is all from the normal distribution. (from Matlab)

Definition at line 1963 of file ScalarSequence.C.

References QUESO::queso_require_equal_to_msg, QUESO::ScalarSequence< T >::subSequenceSize(), and QUESO::BaseEnvironment::worldRank().

Referenced by QUESO::SequenceOfVectors< V, M >::subInterQuantileRange().

1964 {
1965  queso_require_less_msg(initialPos, this->subSequenceSize(), "'initialPos' is too big");
1966 
1967  ScalarSequence sortedSequence(m_env,0,"");
1968  this->subSort(initialPos,
1969  sortedSequence);
1970 
1971  // The test above guarantees that 'dataSize >= 1'
1972  unsigned int dataSize = this->subSequenceSize() - initialPos;
1973 
1974  queso_require_equal_to_msg(dataSize, sortedSequence.subSequenceSize(), "inconsistent size variables");
1975 
1976  bool everythingOk = true;
1977 
1978  // pos1 = (dataSize+1)/4 - 1
1979  // pos1 >= 0 <==> dataSize >= 3
1980  // pos1 < (dataSize-1) <==> 3*dataSize > 1
1981  unsigned int pos1 = (unsigned int) ( (((double) dataSize) + 1.)*1./4. - 1. );
1982  if (pos1 > (dataSize-1)) {
1983  pos1 = 0;
1984  everythingOk = false;
1985  }
1986  unsigned int pos1inc = pos1+1;
1987  if (pos1inc > (dataSize-1)) {
1988  pos1inc = dataSize-1;
1989  everythingOk = false;
1990  }
1991 
1992  // pos3 = (dataSize+1)*3/4 - 1
1993  // pos3 >= 0 <==> dataSize >= 1/3
1994  // pos3 < (dataSize-1) <==> dataSize > 3
1995  unsigned int pos3 = (unsigned int) ( (((double) dataSize) + 1.)*3./4. - 1. );
1996  if (pos3 > (dataSize-1)) {
1997  pos3 = 0;
1998  everythingOk = false;
1999  }
2000  unsigned int pos3inc = pos3+1;
2001  if (pos3inc > (dataSize-1)) {
2002  pos3inc = dataSize-1;
2003  everythingOk = false;
2004  }
2005 
2006  double fraction1 = (((double) dataSize) + 1.)*1./4. - 1. - ((double) pos1);
2007  if (fraction1 < 0.) {
2008  fraction1 = 0.;
2009  everythingOk = false;
2010  }
2011  double fraction3 = (((double) dataSize) + 1.)*3./4. - 1. - ((double) pos3);
2012  if (fraction3 < 0.) {
2013  fraction3 = 0.;
2014  everythingOk = false;
2015  }
2016 
2017  if (everythingOk == false) {
2018  std::cerr << "In ScalarSequence<T>::subInterQuantileRange()"
2019  << ", worldRank = " << m_env.worldRank()
2020  << ": at least one adjustment was necessary"
2021  << std::endl;
2022  }
2023 
2024  //if (m_env.subDisplayFile()) {
2025  // *m_env.subDisplayFile() << "In ScalarSequence::subInterQuantileRange()"
2026  // << ", initialPos = " << initialPos
2027  // << ", this->subSequenceSize() = " << this->subSequenceSize()
2028  // << ", dataSize = " << dataSize
2029  // << ", sortedSequence.size() = " << sortedSequence.size()
2030  // << ", pos1 = " << pos1
2031  // << ", pos3 = " << pos3
2032  // << std::endl;
2033  //}
2034 
2035  T value1 = (1.-fraction1) * sortedSequence[pos1] + fraction1 * sortedSequence[pos1inc];
2036  T value3 = (1.-fraction3) * sortedSequence[pos3] + fraction3 * sortedSequence[pos3inc];
2037  T iqrValue = value3 - value1;
2038 
2039  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
2040  *m_env.subDisplayFile() << "In ScalarSequence<T>::subInterQuantileRange()"
2041  << ": iqrValue = " << iqrValue
2042  << ", dataSize = " << dataSize
2043  << ", pos1 = " << pos1
2044  << ", pos3 = " << pos3
2045  << ", value1 = " << value1
2046  << ", value3 = " << value3
2047  << std::endl;
2048 
2049  // Save data only once into a separate file
2050  //std::ofstream* ofsvar = new std::ofstream(("sort_sub"+m_env.subIdString()+".m").c_str(), std::ofstream::out | std::ofstream::in | std::ofstream::ate);
2051  //if ((ofsvar == NULL ) ||
2052  // (ofsvar->is_open() == false)) {
2053  // delete ofsvar;
2054  // ofsvar = new std::ofstream(("sort_sub"+m_env.subIdString()+".m").c_str(), std::ofstream::out | std::ofstream::trunc);
2055 
2056  // *ofsvar << "var_sort_sub" << m_env.subIdString() << " = zeros(" << 1
2057  // << "," << dataSize
2058  // << ");"
2059  // << std::endl;
2060  // for (unsigned int j = 0; j < dataSize; ++j) {
2061  // *ofsvar << "var_sort_sub" << m_env.subIdString() << "(" << 1
2062  // << "," << j+1
2063  // << ") = " << sortedSequence[j]
2064  // << ";"
2065  // << std::endl;
2066  // }
2067  //}
2068  //delete ofsvar;
2069  }
2070 
2071  return iqrValue;
2072 }
ScalarSequence(const BaseEnvironment &env, unsigned int subSequenceSize, const std::string &name)
Default constructor.
void subSort()
Sorts the sequence of scalars in the private attribute m_seq.
int worldRank() const
Returns the same thing as fullRank()
Definition: Environment.C:262
const BaseEnvironment & m_env
MonteCarloSGOptions::MonteCarloSGOptions(const BaseEnvironment &env, const char *prefix, const McOptionsValues &alternativeOptionsValues queso_require_equal_to_msg)(m_env.optionsInputFileName(), std::string(""), std::string("this constructor is incompatible with the existence of an options input file"))
unsigned int displayVerbosity() const
Definition: Environment.C:450
unsigned int subSequenceSize() const
Size of the sub-sequence of scalars.
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:320
template<class T >
const T & QUESO::ScalarSequence< T >::subMaxPlain ( ) const

Finds the maximum value of the sub-sequence of scalars.

Definition at line 369 of file ScalarSequence.C.

Referenced by QUESO::BaseVectorSequence< V, M >::subPositionsOfMaximum(), QUESO::ScalarSequence< T >::subPositionsOfMaximum(), QUESO::BaseVectorSequence< V, M >::unifiedPositionsOfMaximum(), and QUESO::ScalarSequence< T >::unifiedPositionsOfMaximum().

370 {
371  if (m_subMaxPlain == NULL) {
372  if (m_subMinPlain == NULL) m_subMinPlain = new T(0.);
373  m_subMaxPlain = new T(0.);
375  }
376 
377  return *m_subMaxPlain;
378 }
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...
unsigned int subSequenceSize() const
Size of the sub-sequence of scalars.
template<class T>
T QUESO::ScalarSequence< T >::subMeanCltStd ( unsigned int  initialPos,
unsigned int  numPos,
const T &  meanValue 
) const

Definition at line 3405 of file ScalarSequence.C.

Referenced by QUESO::SequenceOfVectors< V, M >::subMeanCltStd().

3409 {
3410  if (this->subSequenceSize() == 0) return 0.;
3411 
3412  bool bRC = ((initialPos < this->subSequenceSize()) &&
3413  (0 < numPos ) &&
3414  ((initialPos+numPos) <= this->subSequenceSize()));
3415  queso_require_msg(bRC, "invalid input data");
3416 
3417  unsigned int finalPosPlus1 = initialPos + numPos;
3418  T diff;
3419  T stdValue = 0.;
3420  for (unsigned int j = initialPos; j < finalPosPlus1; ++j) {
3421  diff = m_seq[j] - meanValue;
3422  stdValue += diff*diff;
3423  }
3424 
3425  stdValue /= (((T) numPos) - 1.);
3426  stdValue /= (((T) numPos) - 1.);
3427  stdValue = sqrt(stdValue);
3428 
3429  return stdValue;
3430 }
std::vector< T > m_seq
unsigned int subSequenceSize() const
Size of the sub-sequence of scalars.
template<class T >
T QUESO::ScalarSequence< T >::subMeanExtra ( unsigned int  initialPos,
unsigned int  numPos 
) const

Finds the mean value of the sub-sequence, considering numPos positions starting at position initialPos.

Definition at line 806 of file ScalarSequence.C.

Referenced by QUESO::ScalarSequence< T >::bmm(), QUESO::ScalarSequence< T >::geweke(), QUESO::ArrayOfSequences< V, M >::mean(), and QUESO::SequenceOfVectors< V, M >::subMeanExtra().

809 {
810  if (this->subSequenceSize() == 0) return 0.;
811 
812  bool bRC = ((initialPos < this->subSequenceSize()) &&
813  (0 < numPos ) &&
814  ((initialPos+numPos) <= this->subSequenceSize()));
815  if (bRC == false) {
816  std::cerr << "In ScalarSequence<T>::subMeanExtra()"
817  << ": ERROR at fullRank " << m_env.fullRank()
818  << ", initialPos = " << initialPos
819  << ", numPos = " << numPos
820  << ", this->subSequenceSize() = " << this->subSequenceSize()
821  << std::endl;
822  if (m_env.subDisplayFile()) {
823  *m_env.subDisplayFile() << "In ScalarSequence<T>::subMeanExtra()"
824  << ": ERROR at fullRank " << m_env.fullRank()
825  << ", initialPos = " << initialPos
826  << ", numPos = " << numPos
827  << ", this->subSequenceSize() = " << this->subSequenceSize()
828  << std::endl;
829  }
830  }
831  queso_require_msg(bRC, "invalid input data");
832 
833  unsigned int finalPosPlus1 = initialPos + numPos;
834  T tmpSum = 0.;
835  for (unsigned int j = initialPos; j < finalPosPlus1; ++j) {
836  tmpSum += m_seq[j];
837  }
838 
839  return tmpSum/(T) numPos;
840 }
int fullRank() const
Returns the rank of the MPI process in QUESO&#39;s full communicator.
Definition: Environment.C:268
std::vector< T > m_seq
const BaseEnvironment & m_env
unsigned int subSequenceSize() const
Size of the sub-sequence of scalars.
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:320
template<class T >
const T & QUESO::ScalarSequence< T >::subMeanPlain ( ) const

Finds the mean value of the sub-sequence of scalars.

Definition at line 395 of file ScalarSequence.C.

396 {
397  if (m_subMeanPlain == NULL) {
398  m_subMeanPlain = new T(0.);
400  }
401 
402  return *m_subMeanPlain;
403 }
T subMeanExtra(unsigned int initialPos, unsigned int numPos) const
Finds the mean value of the sub-sequence, considering numPos positions starting at position initialPo...
unsigned int subSequenceSize() const
Size of the sub-sequence of scalars.
template<class T >
T QUESO::ScalarSequence< T >::subMedianExtra ( unsigned int  initialPos,
unsigned int  numPos 
) const

Finds the median value of the sub-sequence, considering numPos positions starting at position initialPos.

Definition at line 922 of file ScalarSequence.C.

References QUESO::ScalarSequence< T >::resizeSequence(), and QUESO::ScalarSequence< T >::subSort().

Referenced by QUESO::SequenceOfVectors< V, M >::subMedianExtra().

925 {
926  if (this->subSequenceSize() == 0) return 0.;
927 
928  bool bRC = ((initialPos < this->subSequenceSize()) &&
929  (0 < numPos ) &&
930  ((initialPos+numPos) <= this->subSequenceSize()));
931  if (bRC == false) {
932  std::cerr << "In ScalarSequence<T>::subMedianExtra()"
933  << ": ERROR at fullRank " << m_env.fullRank()
934  << ", initialPos = " << initialPos
935  << ", numPos = " << numPos
936  << ", this->subSequenceSize() = " << this->subSequenceSize()
937  << std::endl;
938  if (m_env.subDisplayFile()) {
939  *m_env.subDisplayFile() << "In ScalarSequence<T>::subMedianExtra()"
940  << ": ERROR at fullRank " << m_env.fullRank()
941  << ", initialPos = " << initialPos
942  << ", numPos = " << numPos
943  << ", this->subSequenceSize() = " << this->subSequenceSize()
944  << std::endl;
945  }
946  }
947  queso_require_msg(bRC, "invalid input data");
948 
949  ScalarSequence sortedSequence(m_env,0,"");
950  sortedSequence.resizeSequence(numPos);
951  this->extractScalarSeq(initialPos,
952  1,
953  numPos,
954  sortedSequence);
955  sortedSequence.subSort();
956 
957  unsigned int tmpPos = (unsigned int) (0.5 * (double) numPos);
958  T resultValue = sortedSequence[tmpPos];
959 
960  return resultValue;
961 }
ScalarSequence(const BaseEnvironment &env, unsigned int subSequenceSize, const std::string &name)
Default constructor.
void extractScalarSeq(unsigned int initialPos, unsigned int spacing, unsigned int numPos, ScalarSequence< T > &scalarSeq) const
Extracts a sequence of scalars.
int fullRank() const
Returns the rank of the MPI process in QUESO&#39;s full communicator.
Definition: Environment.C:268
const BaseEnvironment & m_env
unsigned int subSequenceSize() const
Size of the sub-sequence of scalars.
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:320
template<class T >
const T & QUESO::ScalarSequence< T >::subMedianPlain ( ) const

Finds the median value of the sub-sequence of scalars.

Definition at line 419 of file ScalarSequence.C.

420 {
421  if (m_subMedianPlain == NULL) {
422  m_subMedianPlain = new T(0.);
424  }
425 
426  return *m_subMedianPlain;
427 }
T subMedianExtra(unsigned int initialPos, unsigned int numPos) const
Finds the median value of the sub-sequence, considering numPos positions starting at position initial...
unsigned int subSequenceSize() const
Size of the sub-sequence of scalars.
template<class T>
void QUESO::ScalarSequence< T >::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 at position initialPos.

Definition at line 1469 of file ScalarSequence.C.

Referenced by QUESO::MLSampling< P_V, P_M >::generateSequence(), QUESO::ArrayOfSequences< V, M >::minMax(), and QUESO::SequenceOfVectors< V, M >::subMinMaxExtra().

1474 {
1475  queso_require_less_equal_msg((initialPos+numPos), this->subSequenceSize(), "invalid input");
1476 
1478  std::advance(pos1,initialPos);
1479 
1481  std::advance(pos2,initialPos+numPos);
1482 
1483  if ((initialPos+numPos) == this->subSequenceSize()) {
1484  queso_require_msg(!(pos2 != m_seq.end()), "invalid state");
1485  }
1486 
1488  pos = std::min_element(pos1, pos2);
1489  minValue = *pos;
1490  pos = std::max_element(pos1, pos2);
1491  maxValue = *pos;
1492 
1493  return;
1494 }
std::vector< T >::const_iterator seqScalarPositionConstIteratorTypedef
std::vector< T > m_seq
unsigned int subSequenceSize() const
Size of the sub-sequence of scalars.
template<class T >
const T & QUESO::ScalarSequence< T >::subMinPlain ( ) const

Finds the minimum value of the sub-sequence of scalars.

Definition at line 343 of file ScalarSequence.C.

344 {
345  if (m_subMinPlain == NULL) {
346  m_subMinPlain = new T(0.);
347  if (m_subMaxPlain == NULL) m_subMaxPlain = new T(0.);
349  }
350 
351  return *m_subMinPlain;
352 }
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...
unsigned int subSequenceSize() const
Size of the sub-sequence of scalars.
template<class T>
T QUESO::ScalarSequence< 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 initialPos and of mean meanValue.

Output: calculated population variance of the sub-sequence of scalars. The population variance \( \sigma^2 \) is defined by \( \sigma^2 = \frac{1}{n-1} \sum_{i=1}^n \left(y_i - \mu \right)^2 \), where \( \mu \) is the sample mean and \( n \) is the sample size. This procedure lets the users choose the initial position and the number of elements of the sequence which will be used to evaluate the population variance .

Definition at line 1186 of file ScalarSequence.C.

Referenced by QUESO::SequenceOfVectors< V, M >::subPopulationVariance().

1190 {
1191  if (this->subSequenceSize() == 0) return 0.;
1192 
1193  bool bRC = ((initialPos < this->subSequenceSize()) &&
1194  (0 < numPos ) &&
1195  ((initialPos+numPos) <= this->subSequenceSize()));
1196  queso_require_msg(bRC, "invalid input data");
1197 
1198  unsigned int finalPosPlus1 = initialPos + numPos;
1199  T diff;
1200  T popValue = 0.;
1201  for (unsigned int j = initialPos; j < finalPosPlus1; ++j) {
1202  diff = m_seq[j] - meanValue;
1203  popValue += diff*diff;
1204  }
1205 
1206  popValue /= (T) numPos;
1207 
1208  return popValue;
1209 }
std::vector< T > m_seq
unsigned int subSequenceSize() const
Size of the sub-sequence of scalars.
template<class T>
T QUESO::ScalarSequence< T >::subPositionsOfMaximum ( const ScalarSequence< T > &  subCorrespondingScalarValues,
ScalarSequence< T > &  subPositionsOfMaximum 
)

Finds the positions where the maximum element occurs in the sub-sequence.

Definition at line 2477 of file ScalarSequence.C.

References QUESO::queso_require_equal_to_msg, QUESO::ScalarSequence< T >::resizeSequence(), QUESO::ScalarSequence< T >::subMaxPlain(), and QUESO::ScalarSequence< T >::subSequenceSize().

2480 {
2481  queso_require_equal_to_msg(subCorrespondingScalarValues.subSequenceSize(), this->subSequenceSize(), "invalid input");
2482 
2483  T subMaxValue = subCorrespondingScalarValues.subMaxPlain();
2484  unsigned int iMax = subCorrespondingScalarValues.subSequenceSize();
2485 
2486  unsigned int subNumPos = 0;
2487  for (unsigned int i = 0; i < iMax; ++i) {
2488  if (subCorrespondingScalarValues[i] == subMaxValue) {
2489  subNumPos++;
2490  }
2491  }
2492 
2493  subPositionsOfMaximum.resizeSequence(subNumPos);
2494  unsigned int j = 0;
2495  for (unsigned int i = 0; i < iMax; ++i) {
2496  if (subCorrespondingScalarValues[i] == subMaxValue) {
2497  subPositionsOfMaximum[j] = (*this)[i];
2498  j++;
2499  }
2500  }
2501 
2502  return subMaxValue;
2503 }
MonteCarloSGOptions::MonteCarloSGOptions(const BaseEnvironment &env, const char *prefix, const McOptionsValues &alternativeOptionsValues queso_require_equal_to_msg)(m_env.optionsInputFileName(), std::string(""), std::string("this constructor is incompatible with the existence of an options input 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.
template<class T>
T QUESO::ScalarSequence< 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 position initialPos and of mean meanValue.

Definition at line 1098 of file ScalarSequence.C.

Referenced by QUESO::SequenceOfVectors< V, M >::subSampleStd().

1102 {
1103  if (this->subSequenceSize() == 0) return 0.;
1104 
1105  bool bRC = ((initialPos < this->subSequenceSize()) &&
1106  (0 < numPos ) &&
1107  ((initialPos+numPos) <= this->subSequenceSize()));
1108  queso_require_msg(bRC, "invalid input data");
1109 
1110  unsigned int finalPosPlus1 = initialPos + numPos;
1111  T diff;
1112  T stdValue = 0.;
1113  for (unsigned int j = initialPos; j < finalPosPlus1; ++j) {
1114  diff = m_seq[j] - meanValue;
1115  stdValue += diff*diff;
1116  }
1117 
1118  stdValue /= (((T) numPos) - 1.);
1119  stdValue = sqrt(stdValue);
1120 
1121  return stdValue;
1122 }
std::vector< T > m_seq
unsigned int subSequenceSize() const
Size of the sub-sequence of scalars.
template<class T>
T QUESO::ScalarSequence< 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 initialPos and of mean meanVec.

Output: calculated sample variance of the sub-sequence of scalars. The sample variance \( \sigma_y^2 \) is the second sample central moment and is defined by \( \sigma_y^2 = \frac{1}{n} \sum_{i=1}^n \left(y_i - \mu \right)^2 \), where \( \mu \) is the sample mean and \( n \) is the sample size. This procedure lets the users choose the initial position and the number of elements of the sequence which will be used to evaluate the sample variance.

Definition at line 1012 of file ScalarSequence.C.

Referenced by QUESO::ScalarSequence< T >::bmm(), and QUESO::SequenceOfVectors< V, M >::subSampleVarianceExtra().

1016 {
1017  if (this->subSequenceSize() == 0) return 0.;
1018 
1019  bool bRC = ((initialPos < this->subSequenceSize()) &&
1020  (0 < numPos ) &&
1021  ((initialPos+numPos) <= this->subSequenceSize()));
1022  queso_require_msg(bRC, "invalid input data");
1023 
1024  unsigned int finalPosPlus1 = initialPos + numPos;
1025  T diff;
1026  T samValue = 0.;
1027  for (unsigned int j = initialPos; j < finalPosPlus1; ++j) {
1028  diff = m_seq[j] - meanValue;
1029  samValue += diff*diff;
1030  }
1031 
1032  samValue /= (((T) numPos) - 1.);
1033 
1034  return samValue;
1035 }
std::vector< T > m_seq
unsigned int subSequenceSize() const
Size of the sub-sequence of scalars.
template<class T >
const T & QUESO::ScalarSequence< T >::subSampleVariancePlain ( ) const

Finds the variance of a sample of the sub-sequence of scalars.

Definition at line 443 of file ScalarSequence.C.

444 {
445  if (m_subSampleVariancePlain == NULL) {
446  m_subSampleVariancePlain = new T(0.);
448  }
449 
450  return *m_subSampleVariancePlain;
451 }
const T & subMeanPlain() const
Finds the mean value of the sub-sequence of scalars.
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...
template<class T>
T QUESO::ScalarSequence< 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-sequence.

The bandwidth of the kernel is a free parameter which exhibits a strong influence on the resulting estimate. Silverman (1986) suggests the following normal-based estimates: S1 = 1.06 × (standard deviation) × n^{-1/5} S2 = 0.79 × (iqrValue) × n^{-1/5}, where iqrValue is the interquartile range OutputValue = 0.90 × minimum(standard deviation, iqrValue /1.34) × n^{-1/5}. These estimates are popular due to their simplicity, and are used in QUESO with the adaptation of the exponent oven the sample size n (-1/5) with -1/(4 + kdeDimension) where kdeDimension is the KDE dimension.

Definition at line 2167 of file ScalarSequence.C.

Referenced by QUESO::SequenceOfVectors< V, M >::subScalesForKde().

2171 {
2172  bool bRC = (initialPos < this->subSequenceSize());
2173  queso_require_msg(bRC, "invalid input data");
2174 
2175  unsigned int dataSize = this->subSequenceSize() - initialPos;
2176 
2177  T meanValue = this->subMeanExtra(initialPos,
2178  dataSize);
2179 
2180  T samValue = this->subSampleVarianceExtra(initialPos,
2181  dataSize,
2182  meanValue);
2183 
2184  T scaleValue;
2185  if (iqrValue <= 0.) {
2186  scaleValue = 1.06*std::sqrt(samValue)/std::pow(dataSize,1./(4. + ((double) kdeDimension)));
2187  }
2188  else {
2189  scaleValue = 1.06*std::min(std::sqrt(samValue),iqrValue/1.34)/std::pow(dataSize,1./(4. + ((double) kdeDimension)));
2190  }
2191 
2192  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
2193  *m_env.subDisplayFile() << "In ScalarSequence<T>::subScaleForKde()"
2194  << ": iqrValue = " << iqrValue
2195  << ", meanValue = " << meanValue
2196  << ", samValue = " << samValue
2197  << ", dataSize = " << dataSize
2198  << ", scaleValue = " << scaleValue
2199  << std::endl;
2200  }
2201 
2202  return scaleValue;
2203 }
T subMeanExtra(unsigned int initialPos, unsigned int numPos) const
Finds the mean value of the sub-sequence, considering numPos positions starting at position initialPo...
const BaseEnvironment & m_env
unsigned int displayVerbosity() const
Definition: Environment.C:450
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...
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:320
template<class T>
void QUESO::ScalarSequence< T >::subSort ( unsigned int  initialPos,
ScalarSequence< T > &  sortedSequence 
) const

Sorts the sub-sequence of scalars.

Definition at line 1842 of file ScalarSequence.C.

References QUESO::ScalarSequence< T >::resizeSequence(), and QUESO::ScalarSequence< T >::subSort().

Referenced by QUESO::ScalarSequence< T >::subCdfPercentageRange(), QUESO::SequenceOfVectors< V, M >::subCdfStacc(), QUESO::ScalarSequence< T >::subMedianExtra(), and QUESO::ScalarSequence< T >::subSort().

1845 {
1846  unsigned int numPos = this->subSequenceSize() - initialPos;
1847  sortedSequence.resizeSequence(numPos);
1848  this->extractScalarSeq(initialPos,
1849  1,
1850  numPos,
1851  sortedSequence);
1852  sortedSequence.subSort();
1853 
1854  return;
1855 }
void extractScalarSeq(unsigned int initialPos, unsigned int spacing, unsigned int numPos, ScalarSequence< T > &scalarSeq) const
Extracts a sequence of scalars.
unsigned int subSequenceSize() const
Size of the sub-sequence of scalars.
template<class T>
void QUESO::ScalarSequence< T >::subSort ( )
private

Sorts the sequence of scalars in the private attribute m_seq.

Definition at line 3223 of file ScalarSequence.C.

3224 {
3225  std::sort(m_seq.begin(), m_seq.end());
3226  return;
3227 }
std::vector< T > m_seq
template<class T>
void QUESO::ScalarSequence< T >::subUniformlySampledCdf ( unsigned int  numIntervals,
T &  minDomainValue,
T &  maxDomainValue,
std::vector< T > &  cdfValues 
) const

Uniformly samples from the CDF from the sub-sequence.

Definition at line 539 of file ScalarSequence.C.

Referenced by QUESO::ArrayOfSequences< V, M >::uniformlySampledCdf().

544 {
545  T tmpMinValue;
546  T tmpMaxValue;
547  std::vector<T> centers(numEvaluationPoints,0.);
548  std::vector<unsigned int> bins (numEvaluationPoints,0);
549 
550  subMinMaxExtra(0, // initialPos
551  this->subSequenceSize(),
552  tmpMinValue,
553  tmpMaxValue);
554  subHistogram(0, // initialPos,
555  tmpMinValue,
556  tmpMaxValue,
557  centers,
558  bins);
559 
560  minDomainValue = centers[0];
561  maxDomainValue = centers[centers.size()-1];
562 
563  unsigned int sumOfBins = 0;
564  for (unsigned int i = 0; i < numEvaluationPoints; ++i) {
565  sumOfBins += bins[i];
566  }
567 
568  cdfValues.clear();
569  cdfValues.resize(numEvaluationPoints);
570  unsigned int partialSum = 0;
571  for (unsigned int i = 0; i < numEvaluationPoints; ++i) {
572  partialSum += bins[i];
573  cdfValues[i] = ((T) partialSum)/((T) sumOfBins);
574  }
575 
576  return;
577 }
void subHistogram(unsigned int initialPos, const T &minHorizontalValue, const T &maxHorizontalValue, std::vector< T > &centers, std::vector< unsigned int > &bins) const
Calculates the histogram of 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...
unsigned int subSequenceSize() const
Size of the sub-sequence of scalars.
template<class T>
void QUESO::ScalarSequence< T >::subUniformlySampledMdf ( unsigned int  numIntervals,
T &  minDomainValue,
T &  maxDomainValue,
std::vector< T > &  mdfValues 
) const

Definition at line 3364 of file ScalarSequence.C.

3369 {
3370  T tmpMinValue;
3371  T tmpMaxValue;
3372  std::vector<T> centers(numEvaluationPoints,0.);
3373  std::vector<unsigned int> bins (numEvaluationPoints,0);
3374 
3375  subMinMaxExtra(0, // initialPos
3376  this->subSequenceSize(),
3377  tmpMinValue,
3378  tmpMaxValue);
3379  subHistogram(0, // initialPos,
3380  tmpMinValue,
3381  tmpMaxValue,
3382  centers,
3383  bins);
3384 
3385  minDomainValue = centers[0];
3386  maxDomainValue = centers[centers.size()-1];
3387  T binSize = (maxDomainValue - minDomainValue)/((double)(centers.size() - 1));
3388 
3389  unsigned int totalCount = 0;
3390  for (unsigned int i = 0; i < numEvaluationPoints; ++i) {
3391  totalCount += bins[i];
3392  }
3393 
3394  mdfValues.clear();
3395  mdfValues.resize(numEvaluationPoints);
3396  for (unsigned int i = 0; i < numEvaluationPoints; ++i) {
3397  mdfValues[i] = ((T) bins[i])/((T) totalCount)/binSize;
3398  }
3399 
3400  return;
3401 }
void subHistogram(unsigned int initialPos, const T &minHorizontalValue, const T &maxHorizontalValue, std::vector< T > &centers, std::vector< unsigned int > &bins) const
Calculates the histogram of 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...
unsigned int subSequenceSize() const
Size of the sub-sequence of scalars.
template<class T>
void QUESO::ScalarSequence< T >::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.

Definition at line 717 of file ScalarSequence.C.

721 {
722  T tmpMinValue;
723  T tmpMaxValue;
724  std::vector<unsigned int> bins(numEvaluationPoints,0);
725  gridValues.resize (numEvaluationPoints,0.);
726  cdfValues.resize (numEvaluationPoints,0.);
727 
728  subMinMaxExtra(0, // initialPos
729  this->subSequenceSize(),
730  tmpMinValue,
731  tmpMaxValue);
732 
733  if (tmpMinValue == tmpMaxValue) {
734  if (tmpMinValue < -1.e-12) {
735  tmpMinValue += tmpMinValue*(1.e-8);
736  }
737  else if (tmpMinValue > 1.e-12) {
738  tmpMinValue -= tmpMinValue*(1.e-8);
739  }
740  else {
741  tmpMinValue = 1.e-12;
742  }
743  }
744 
745  subWeightHistogram(0, // initialPos,
746  tmpMinValue,
747  tmpMaxValue,
748  gridValues,
749  bins);
750 
751  unsigned int sumOfBins = 0;
752  for (unsigned int i = 0; i < numEvaluationPoints; ++i) {
753  sumOfBins += bins[i];
754  }
755 
756  cdfValues.clear();
757  cdfValues.resize(numEvaluationPoints);
758  unsigned int partialSum = 0;
759  for (unsigned int i = 0; i < numEvaluationPoints; ++i) {
760  partialSum += bins[i];
761  cdfValues[i] = ((T) partialSum)/((T) sumOfBins);
762  }
763 
764  return;
765 }
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 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.
unsigned int subSequenceSize() const
Size of the sub-sequence of scalars.
template<class T>
void QUESO::ScalarSequence< T >::subWeightCdf ( unsigned int  numIntervals,
UniformOneDGrid< T > *&  gridValues,
std::vector< T > &  cdfValues 
) const

Finds the Weighted Cumulative Distribution Function (CDF) of the sub-sequence of scalars.

Definition at line 769 of file ScalarSequence.C.

773 {
774  T tmpMinValue;
775  T tmpMaxValue;
776  std::vector<unsigned int> bins(numEvaluationPoints,0);
777 
778  subMinMaxExtra(0, // initialPos
779  this->subSequenceSize(),
780  tmpMinValue,
781  tmpMaxValue);
782  subWeightHistogram(0, // initialPos,
783  tmpMinValue,
784  tmpMaxValue,
785  gridValues,
786  bins);
787 
788  unsigned int sumOfBins = 0;
789  for (unsigned int i = 0; i < numEvaluationPoints; ++i) {
790  sumOfBins += bins[i];
791  }
792 
793  cdfValues.clear();
794  cdfValues.resize(numEvaluationPoints);
795  unsigned int partialSum = 0;
796  for (unsigned int i = 0; i < numEvaluationPoints; ++i) {
797  partialSum += bins[i];
798  cdfValues[i] = ((T) partialSum)/((T) sumOfBins);
799  }
800 
801  return;
802 }
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 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.
unsigned int subSequenceSize() const
Size of the sub-sequence of scalars.
template<class T>
void QUESO::ScalarSequence< T >::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.

TODO:Note that this method is exactly the same as subBasicHistogram().

It requires the specification of the maximum (maxHorizontalValue) and the minimum (minHorizontalValue) values if the data and the initial position (initialPos) from where the data will be considered. Output: grid values that will act as the center of each bin (gridValues) and the number of data occurrences in each bin (bins).

Definition at line 1748 of file ScalarSequence.C.

1754 {
1755  queso_require_greater_equal_msg(bins.size(), 3, "number of 'bins' is too small: should be at least 3");
1756 
1757  for (unsigned int j = 0; j < bins.size(); ++j) {
1758  bins[j] = 0;
1759  }
1760 
1761  double horizontalDelta = (maxHorizontalValue - minHorizontalValue)/(((double) bins.size()) - 2.); // IMPORTANT: -2
1762  double minCenter = minHorizontalValue - horizontalDelta/2.;
1763  double maxCenter = maxHorizontalValue + horizontalDelta/2.;
1764  gridValues = new UniformOneDGrid<T>(m_env,
1765  "",
1766  bins.size(),
1767  minCenter,
1768  maxCenter);
1769 
1770  unsigned int dataSize = this->subSequenceSize();
1771  for (unsigned int j = 0; j < dataSize; ++j) {
1772  double value = m_seq[j];
1773  if (value < minHorizontalValue) {
1774  bins[0]++;
1775  }
1776  else if (value >= maxHorizontalValue) {
1777  bins[bins.size()-1]++;
1778  }
1779  else {
1780  unsigned int index = 1 + (unsigned int) ((value - minHorizontalValue)/horizontalDelta);
1781  bins[index]++;
1782  }
1783  }
1784 
1785  return;
1786 }
std::vector< T > m_seq
const BaseEnvironment & m_env
unsigned int subSequenceSize() const
Size of the sub-sequence of scalars.
template<class T>
void QUESO::ScalarSequence< T >::subWeightHistogram ( unsigned int  initialPos,
const T &  minHorizontalValue,
const T &  maxHorizontalValue,
std::vector< T > &  gridValues,
std::vector< unsigned int > &  bins 
) const

Calculates the weighted histogram of the sub-sequence.

In this method, gridValues is a std::vector<T>, but internally, it will be copied to an structure of the type UniformOneDGrid<T>.

Definition at line 1790 of file ScalarSequence.C.

1796 {
1797  queso_require_greater_equal_msg(bins.size(), 3, "number of 'bins' is too small: should be at least 3");
1798 
1799  for (unsigned int j = 0; j < bins.size(); ++j) {
1800  bins[j] = 0;
1801  }
1802 
1803  double horizontalDelta = (maxHorizontalValue - minHorizontalValue)/(((double) bins.size()) - 2.); // IMPORTANT: -2
1804  double minCenter = minHorizontalValue - horizontalDelta/2.;
1805  double maxCenter = maxHorizontalValue + horizontalDelta/2.;
1806  UniformOneDGrid<T> tmpGrid(m_env,
1807  "",
1808  bins.size(),
1809  minCenter,
1810  maxCenter);
1811  gridValues.clear();
1812  gridValues.resize(tmpGrid.size(),0.);
1813  for (unsigned int i = 0; i < tmpGrid.size(); ++i) {
1814  gridValues[i] = tmpGrid[i];
1815  }
1816 
1817  unsigned int dataSize = this->subSequenceSize();
1818  for (unsigned int j = 0; j < dataSize; ++j) {
1819  double value = m_seq[j];
1820  if (value < minHorizontalValue) {
1821  bins[0]++;
1822  }
1823  else if (value >= maxHorizontalValue) {
1824  bins[bins.size()-1]++;
1825  }
1826  else {
1827  unsigned int index = 1 + (unsigned int) ((value - minHorizontalValue)/horizontalDelta);
1828  bins[index]++;
1829  }
1830  }
1831 
1832  //std::cout << "In ScalarSequence<T>::subWeightHistogram():" << std::endl;
1833  //for (unsigned int j = 0; j < bins.size(); ++j) {
1834  // std::cout << "bins[" << j << "] = " << bins[j] << std::endl;
1835  //}
1836 
1837  return;
1838 }
std::vector< T > m_seq
const BaseEnvironment & m_env
unsigned int subSequenceSize() const
Size of the sub-sequence of scalars.
template<class T >
void QUESO::ScalarSequence< T >::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.

Given the allowed sub environments (allowedSubEnvIds) that are allowed to write to file, together with the file name and type (fileName, fileType), it writes the entire sub- sequence to the file. The sum of the initial position of the sequence (initialPos) with the number of positions that will be written (numPos) must equal the size of the sequence.

Definition at line 2537 of file ScalarSequence.C.

Referenced by QUESO::MetropolisHastingsSG< P_V, P_M >::generateFullChain(), and QUESO::MetropolisHastingsSG< P_V, P_M >::generateSequence().

2543 {
2544  queso_require_greater_equal_msg(m_env.subRank(), 0, "unexpected subRank");
2545 
2546  FilePtrSetStruct filePtrSet;
2547  if (m_env.openOutputFile(fileName,
2548  fileType,
2549  allowedSubEnvIds,
2550  false, // A 'true' causes problems when the user chooses (via options
2551  // in the input file) to use just one file for all outputs.
2552  filePtrSet)) {
2553 
2554  if (fileType == UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT ||
2555  fileType == UQ_FILE_EXTENSION_FOR_TXT_FORMAT) {
2556  this->subWriteContents(initialPos,
2557  numPos,
2558  *filePtrSet.ofsVar,
2559  fileType);
2560  }
2561 #ifdef QUESO_HAS_HDF5
2562  else if (fileType == UQ_FILE_EXTENSION_FOR_HDF_FORMAT) {
2563 
2564  // Create dataspace
2565  hsize_t dims[1] = { this->subSequenceSize() };
2566  hid_t dataspace_id = H5Screate_simple(1, dims, dims);
2567  queso_require_greater_equal_msg(
2568  dataspace_id,
2569  0,
2570  "error create dataspace with id: " << dataspace_id);
2571 
2572  // Create dataset
2573  hid_t dataset_id = H5Dcreate(filePtrSet.h5Var,
2574  "data",
2575  H5T_IEEE_F64LE,
2576  dataspace_id,
2577  H5P_DEFAULT,
2578  H5P_DEFAULT,
2579  H5P_DEFAULT);
2580 
2581  queso_require_greater_equal_msg(
2582  dataset_id,
2583  0,
2584  "error creating dataset with id: " << dataset_id);
2585 
2586  // Write the dataset
2587  herr_t status = H5Dwrite(
2588  dataset_id,
2589  H5T_NATIVE_DOUBLE, // The type in memory
2590  H5S_ALL, // The dataspace in memory
2591  dataspace_id, // The file dataspace
2592  H5P_DEFAULT, // Xfer property list
2593  &m_seq[0]);
2594 
2595  queso_require_greater_equal_msg(
2596  status,
2597  0,
2598  "error writing dataset to file with id: " << filePtrSet.h5Var);
2599 
2600  // Clean up
2601  H5Dclose(dataset_id);
2602  H5Sclose(dataspace_id);
2603  }
2604 #endif
2605 
2606  m_env.closeFile(filePtrSet,fileType);
2607  }
2608 }
void closeFile(FilePtrSetStruct &filePtrSet, const std::string &fileType) const
Closes the file.
Definition: Environment.C:1084
int subRank() const
Returns the rank of the MPI process in the sub-communicator subComm()
Definition: Environment.C:287
std::vector< T > m_seq
const BaseEnvironment & m_env
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.
unsigned int subSequenceSize() const
Size of the sub-sequence of scalars.
bool openOutputFile(const std::string &fileName, const std::string &fileType, const std::set< unsigned int > &allowedSubEnvIds, bool writeOver, FilePtrSetStruct &filePtrSet) const
Opens an output file for each sub-environment that was chosen to send data to the file...
Definition: Environment.C:521
template<class T >
void QUESO::ScalarSequence< T >::subWriteContents ( unsigned int  initialPos,
unsigned int  numPos,
std::ofstream &  ofs,
const std::string &  fileType 
) const

Writes the sub-sequence to a file.

Uses object of the type std::ofstream.

Definition at line 2612 of file ScalarSequence.C.

2617 {
2618  if (fileType == UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT) {
2619  this->writeSubMatlabHeader(ofs, this->subSequenceSize());
2620  }
2621  else if (fileType == UQ_FILE_EXTENSION_FOR_TXT_FORMAT) {
2622  this->writeTxtHeader(ofs, this->subSequenceSize());
2623  }
2624 
2625  unsigned int chainSize = this->subSequenceSize();
2626  for (unsigned int j = 0; j < chainSize; ++j) {
2627  ofs << m_seq[j]
2628  << std::endl;
2629  }
2630 
2631  if (fileType == UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT) {
2632  ofs << "];\n";
2633  }
2634 
2635  return;
2636 }
void writeSubMatlabHeader(std::ofstream &ofs, double sequenceSize) const
Helper function to write header info for matlab files from one chain.
void writeTxtHeader(std::ofstream &ofs, double sequenceSize) const
Helper function to write txt info for matlab files.
std::vector< T > m_seq
unsigned int subSequenceSize() const
Size of the sub-sequence of scalars.
template<class T>
void QUESO::ScalarSequence< T >::unifiedCdfPercentageRange ( bool  useOnlyInter0Comm,
unsigned int  initialPos,
unsigned int  numPos,
double  range,
T &  lowerValue,
T &  upperValue 
) const

Definition at line 3764 of file ScalarSequence.C.

Referenced by QUESO::SequenceOfVectors< V, M >::unifiedCdfPercentageRange().

3771 {
3772  if (m_env.numSubEnvironments() == 1) {
3773  return this->subCdfPercentageRange(initialPos,
3774  numPos,
3775  range,
3776  unifiedLowerValue,
3777  unifiedUpperValue);
3778  }
3779 
3780  // As of 07/Feb/2011, this routine does *not* require sub sequences to have equal size. Good.
3781 
3782  queso_require_less_equal_msg((initialPos+numPos), this->subSequenceSize(), "invalid input");
3783 
3784  queso_require_msg(!((range < 0) || (range > 1.)), "invalid 'range' value");
3785 
3786  if (useOnlyInter0Comm) {
3787  if (m_env.inter0Rank() >= 0) {
3788  queso_error_msg("code not implemented yet");
3789  }
3790  else {
3791  // Node not in the 'inter0' communicator
3792  this->subCdfPercentageRange(initialPos,
3793  numPos,
3794  unifiedLowerValue,
3795  unifiedUpperValue);
3796  }
3797  }
3798  else {
3799  queso_error_msg("parallel vectors not supported yet");
3800  }
3801  //m_env.fullComm().Barrier();
3802 
3803  return;
3804 }
const BaseEnvironment & m_env
void subCdfPercentageRange(unsigned int initialPos, unsigned int numPos, double range, T &lowerValue, T &upperValue) const
unsigned int numSubEnvironments() const
Access function to the number of sub-environments.
Definition: Environment.C:335
int inter0Rank() const
Returns the process inter0 rank.
Definition: Environment.C:307
unsigned int subSequenceSize() const
Size of the sub-sequence of scalars.
template<class T>
void QUESO::ScalarSequence< T >::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.

Definition at line 2308 of file ScalarSequence.C.

References QUESO::MiscGaussianDensity().

Referenced by QUESO::SequenceOfVectors< V, M >::unifiedGaussian1dKde().

2314 {
2315  if (m_env.numSubEnvironments() == 1) {
2316  return this->subGaussian1dKde(initialPos,
2317  unifiedScaleValue,
2318  unifiedEvaluationPositions,
2319  unifiedDensityValues);
2320  }
2321 
2322  // As of 14/Nov/2009, this routine needs to be checked if it requires sub sequences to have equal size. Good.
2323 
2324  if (useOnlyInter0Comm) {
2325  if (m_env.inter0Rank() >= 0) {
2326  bool bRC = ((initialPos < this->subSequenceSize() ) &&
2327  (0 < unifiedEvaluationPositions.size()) &&
2328  (unifiedEvaluationPositions.size() == unifiedDensityValues.size() ));
2329  queso_require_msg(bRC, "invalid input data");
2330 
2331  unsigned int localDataSize = this->subSequenceSize() - initialPos;
2332  unsigned int unifiedDataSize = 0;
2333  m_env.inter0Comm().template Allreduce<unsigned int>(&localDataSize, &unifiedDataSize, (int) 1, RawValue_MPI_SUM,
2334  "ScalarSequence<T>::unifiedGaussian1dKde()",
2335  "failed MPI.Allreduce() for data size");
2336 
2337  unsigned int numEvals = unifiedEvaluationPositions.size();
2338 
2339  std::vector<double> densityValues(numEvals,0.);
2340  double unifiedScaleInv = 1./unifiedScaleValue;
2341  for (unsigned int j = 0; j < numEvals; ++j) {
2342  double x = unifiedEvaluationPositions[j];
2343  double value = 0.;
2344  for (unsigned int k = 0; k < localDataSize; ++k) {
2345  double xk = m_seq[initialPos+k];
2346  value += MiscGaussianDensity((x-xk)*unifiedScaleInv,0.,1.);
2347  }
2348  densityValues[j] = value;
2349  }
2350 
2351  for (unsigned int j = 0; j < numEvals; ++j) {
2352  unifiedDensityValues[j] = 0.;
2353  }
2354  m_env.inter0Comm().template Allreduce<double>(&densityValues[0], &unifiedDensityValues[0], (int) numEvals, RawValue_MPI_SUM,
2355  "ScalarSequence<T>::unifiedGaussian1dKde()",
2356  "failed MPI.Allreduce() for density values");
2357 
2358  for (unsigned int j = 0; j < numEvals; ++j) {
2359  unifiedDensityValues[j] *= unifiedScaleInv/((double) unifiedDataSize);
2360  }
2361 
2362  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
2363  *m_env.subDisplayFile() << "In ScalarSequence<T>::unifiedGaussian1dKde()"
2364  << ": unifiedDensityValues[0] = " << unifiedDensityValues[0]
2365  << ", unifiedDensityValues[" << unifiedDensityValues.size()-1 << "] = " << unifiedDensityValues[unifiedDensityValues.size()-1]
2366  << std::endl;
2367  }
2368  }
2369  else {
2370  // Node not in the 'inter0' communicator
2371  this->subGaussian1dKde(initialPos,
2372  unifiedScaleValue,
2373  unifiedEvaluationPositions,
2374  unifiedDensityValues);
2375  }
2376  }
2377  else {
2378  queso_error_msg("parallel vectors not supported yet");
2379  }
2380 
2381  //m_env.fullComm().Barrier();
2382 
2383  return;
2384 }
const MpiComm & inter0Comm() const
Access function for MpiComm communicator for processes with subRank() 0.
Definition: Environment.C:313
double MiscGaussianDensity(double x, double mu, double sigma)
std::vector< T > m_seq
const BaseEnvironment & m_env
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.
unsigned int displayVerbosity() const
Definition: Environment.C:450
unsigned int numSubEnvironments() const
Access function to the number of sub-environments.
Definition: Environment.C:335
int inter0Rank() const
Returns the process inter0 rank.
Definition: Environment.C:307
unsigned int subSequenceSize() const
Size of the sub-sequence of scalars.
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:320
template<class T>
void QUESO::ScalarSequence< T >::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.

Definition at line 1616 of file ScalarSequence.C.

References QUESO::queso_require_equal_to_msg.

Referenced by QUESO::SequenceOfVectors< V, M >::unifiedHistogram().

1623 {
1624  if (m_env.numSubEnvironments() == 1) {
1625  return this->subHistogram(initialPos,
1626  unifiedMinHorizontalValue,
1627  unifiedMaxHorizontalValue,
1628  unifiedCenters,
1629  unifiedBins);
1630  }
1631 
1632  // As of 14/Nov/2009, this routine needs to be checked if it requires sub sequences to have equal size. Good.
1633 
1634  if (useOnlyInter0Comm) {
1635  if (m_env.inter0Rank() >= 0) {
1636  queso_require_equal_to_msg(unifiedCenters.size(), unifiedBins.size(), "vectors 'unifiedCenters' and 'unifiedBins' have different sizes");
1637 
1638  queso_require_greater_equal_msg(unifiedBins.size(), 3, "number of 'unifiedBins' is too small: should be at least 3");
1639 
1640  for (unsigned int j = 0; j < unifiedBins.size(); ++j) {
1641  unifiedCenters[j] = 0.;
1642  unifiedBins[j] = 0;
1643  }
1644 
1645  double unifiedHorizontalDelta = (unifiedMaxHorizontalValue - unifiedMinHorizontalValue)/(((double) unifiedBins.size()) - 2.); // IMPORTANT: -2
1646 
1647  double unifiedMinCenter = unifiedMinHorizontalValue - unifiedHorizontalDelta/2.;
1648  double unifiedMaxCenter = unifiedMaxHorizontalValue + unifiedHorizontalDelta/2.;
1649  for (unsigned int j = 0; j < unifiedCenters.size(); ++j) {
1650  double factor = ((double) j)/(((double) unifiedCenters.size()) - 1.);
1651  unifiedCenters[j] = (1. - factor) * unifiedMinCenter + factor * unifiedMaxCenter;
1652  }
1653 
1654  std::vector<unsigned int> localBins(unifiedBins.size(),0);
1655  unsigned int dataSize = this->subSequenceSize();
1656  for (unsigned int j = 0; j < dataSize; ++j) {
1657  double value = m_seq[j];
1658  if (value < unifiedMinHorizontalValue) {
1659  localBins[0]++;
1660  }
1661  else if (value >= unifiedMaxHorizontalValue) {
1662  localBins[localBins.size()-1]++;
1663  }
1664  else {
1665  unsigned int index = 1 + (unsigned int) ((value - unifiedMinHorizontalValue)/unifiedHorizontalDelta);
1666  localBins[index]++;
1667  }
1668  }
1669 
1670  m_env.inter0Comm().template Allreduce<unsigned int>(&localBins[0], &unifiedBins[0], (int) localBins.size(), RawValue_MPI_SUM,
1671  "ScalarSequence<T>::unifiedHistogram()",
1672  "failed MPI.Allreduce() for bins");
1673 
1674  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 10)) {
1675  for (unsigned int i = 0; i < unifiedCenters.size(); ++i) {
1676  *m_env.subDisplayFile() << "In ScalarSequence<T>::unifiedHistogram()"
1677  << ": i = " << i
1678  << ", unifiedMinHorizontalValue = " << unifiedMinHorizontalValue
1679  << ", unifiedMaxHorizontalValue = " << unifiedMaxHorizontalValue
1680  << ", unifiedCenters = " << unifiedCenters[i]
1681  << ", unifiedBins = " << unifiedBins[i]
1682  << std::endl;
1683  }
1684  }
1685  }
1686  else {
1687  // Node not in the 'inter0' communicator
1688  this->subHistogram(initialPos,
1689  unifiedMinHorizontalValue,
1690  unifiedMaxHorizontalValue,
1691  unifiedCenters,
1692  unifiedBins);
1693  }
1694  }
1695  else {
1696  queso_error_msg("parallel vectors not supported yet");
1697  }
1698 
1699  //m_env.fullComm().Barrier();
1700 
1701  return;
1702 }
const MpiComm & inter0Comm() const
Access function for MpiComm communicator for processes with subRank() 0.
Definition: Environment.C:313
void subHistogram(unsigned int initialPos, const T &minHorizontalValue, const T &maxHorizontalValue, std::vector< T > &centers, std::vector< unsigned int > &bins) const
Calculates the histogram of the sub-sequence.
std::vector< T > m_seq
const BaseEnvironment & m_env
MonteCarloSGOptions::MonteCarloSGOptions(const BaseEnvironment &env, const char *prefix, const McOptionsValues &alternativeOptionsValues queso_require_equal_to_msg)(m_env.optionsInputFileName(), std::string(""), std::string("this constructor is incompatible with the existence of an options input file"))
unsigned int displayVerbosity() const
Definition: Environment.C:450
unsigned int numSubEnvironments() const
Access function to the number of sub-environments.
Definition: Environment.C:335
int inter0Rank() const
Returns the process inter0 rank.
Definition: Environment.C:307
unsigned int subSequenceSize() const
Size of the sub-sequence of scalars.
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:320
template<class T >
T QUESO::ScalarSequence< T >::unifiedInterQuantileRange ( bool  useOnlyInter0Comm,
unsigned int  initialPos 
) const

Returns the interquartile range of the values in the unified sequence.

Definition at line 2076 of file ScalarSequence.C.

References QUESO::queso_require_equal_to_msg, and QUESO::ScalarSequence< T >::subSequenceSize().

Referenced by QUESO::SequenceOfVectors< V, M >::unifiedInterQuantileRange().

2079 {
2080  T unifiedIqrValue = 0.;
2081 
2082  if (m_env.numSubEnvironments() == 1) {
2083  return this->subInterQuantileRange(initialPos);
2084  }
2085 
2086  // As of 14/Nov/2009, this routine needs to be checked if it requires sub sequences to have equal size. Good.
2087 
2088  if (useOnlyInter0Comm) {
2089  if (m_env.inter0Rank() >= 0) {
2090  //m_env.syncPrintDebugMsg("In ScalarSequence<T>::unifiedInterQuantileRange(), beginning logic",3,3000000,m_env.inter0Comm()); // Dangerous to barrier on inter0Comm ... // KAUST
2091 
2092  ScalarSequence unifiedSortedSequence(m_env,0,"");
2093  this->unifiedSort(useOnlyInter0Comm,
2094  initialPos,
2095  unifiedSortedSequence);
2096  unsigned int unifiedDataSize = unifiedSortedSequence.subSequenceSize();
2097 
2098  unsigned int localDataSize = this->subSequenceSize() - initialPos;
2099  unsigned int sumOfLocalSizes = 0;
2100  m_env.inter0Comm().template Allreduce<unsigned int>(&localDataSize, &sumOfLocalSizes, (int) 1, RawValue_MPI_SUM,
2101  "ScalarSequence<T>::unifiedInterQuantileRange()",
2102  "failed MPI.Allreduce() for data size");
2103 
2104  queso_require_equal_to_msg(sumOfLocalSizes, unifiedDataSize, "incompatible unified sizes");
2105 
2106  unsigned int pos1 = (unsigned int) ( (((double) unifiedDataSize) + 1.)*1./4. - 1. );
2107  unsigned int pos3 = (unsigned int) ( (((double) unifiedDataSize) + 1.)*3./4. - 1. );
2108 
2109  double fraction1 = (((double) unifiedDataSize) + 1.)*1./4. - 1. - ((double) pos1);
2110  double fraction3 = (((double) unifiedDataSize) + 1.)*3./4. - 1. - ((double) pos3);
2111 
2112  T value1 = (1.-fraction1) * unifiedSortedSequence[pos1] + fraction1 * unifiedSortedSequence[pos1+1];
2113  T value3 = (1.-fraction3) * unifiedSortedSequence[pos3] + fraction3 * unifiedSortedSequence[pos3+1];
2114  unifiedIqrValue = value3 - value1;
2115 
2116  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
2117  *m_env.subDisplayFile() << "In ScalarSequence<T>::unifiedInterQuantileRange()"
2118  << ": unifiedIqrValue = " << unifiedIqrValue
2119  << ", localDataSize = " << localDataSize
2120  << ", unifiedDataSize = " << unifiedDataSize
2121  << ", pos1 = " << pos1
2122  << ", pos3 = " << pos3
2123  << ", value1 = " << value1
2124  << ", value3 = " << value3
2125  << std::endl;
2126 
2127  // Save data only once into a separate file
2128  //std::ofstream* ofsvar = new std::ofstream(("unif_sort_sub"+m_env.subIdString()+".m").c_str(), std::ofstream::out | std::ofstream::in | std::ofstream::ate);
2129  //if ((ofsvar == NULL ) ||
2130  // (ofsvar->is_open() == false)) {
2131  // delete ofsvar;
2132  // ofsvar = new std::ofstream(("unif_sort_sub"+m_env.subIdString()+".m").c_str(), std::ofstream::out | std::ofstream::trunc);
2133 
2134  // *ofsvar << "var_unif_sort_sub" << m_env.subIdString() << " = zeros(" << 1
2135  // << "," << unifiedDataSize
2136  // << ");"
2137  // << std::endl;
2138  // for (unsigned int j = 0; j < unifiedDataSize; ++j) {
2139  // *ofsvar << "var_unif_sort_sub" << m_env.subIdString() << "(" << 1
2140  // << "," << j+1
2141  // << ") = " << unifiedSortedSequence[j]
2142  // << ";"
2143  // << std::endl;
2144  // }
2145  //}
2146  //delete ofsvar;
2147  }
2148 
2149  //m_env.syncPrintDebugMsg("In ScalarSequence<T>::unifiedInterQuantileRange(), ending logic",3,3000000,m_env.inter0Comm()); // Dangerous to barrier on inter0Comm ... // KAUST
2150  }
2151  else {
2152  // Node not in the 'inter0' communicator
2153  unifiedIqrValue = this->subInterQuantileRange(initialPos);
2154  }
2155  }
2156  else {
2157  queso_error_msg("parallel vectors not supported yet");
2158  }
2159 
2160  //m_env.fullComm().Barrier();
2161 
2162  return unifiedIqrValue;
2163 }
T subInterQuantileRange(unsigned int initialPos) const
Returns the interquartile range of the values in the sub-sequence.
ScalarSequence(const BaseEnvironment &env, unsigned int subSequenceSize, const std::string &name)
Default constructor.
const MpiComm & inter0Comm() const
Access function for MpiComm communicator for processes with subRank() 0.
Definition: Environment.C:313
void unifiedSort(bool useOnlyInter0Comm, unsigned int initialPos, ScalarSequence< T > &unifiedSortedSequence) const
Sorts the unified sequence of scalars.
const BaseEnvironment & m_env
MonteCarloSGOptions::MonteCarloSGOptions(const BaseEnvironment &env, const char *prefix, const McOptionsValues &alternativeOptionsValues queso_require_equal_to_msg)(m_env.optionsInputFileName(), std::string(""), std::string("this constructor is incompatible with the existence of an options input file"))
unsigned int displayVerbosity() const
Definition: Environment.C:450
unsigned int numSubEnvironments() const
Access function to the number of sub-environments.
Definition: Environment.C:335
int inter0Rank() const
Returns the process inter0 rank.
Definition: Environment.C:307
unsigned int subSequenceSize() const
Size of the sub-sequence of scalars.
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:320
template<class T >
const T & QUESO::ScalarSequence< T >::unifiedMaxPlain ( bool  useOnlyInter0Comm) const

Finds the maximum value of the unified sequence of scalars.

Definition at line 382 of file ScalarSequence.C.

Referenced by QUESO::MLSampling< P_V, P_M >::generateSequence_Step03_inter0().

383 {
384  if (m_unifiedMaxPlain == NULL) {
385  if (m_unifiedMinPlain == NULL) m_unifiedMinPlain = new T(0.);
386  m_unifiedMaxPlain = new T(0.);
388  }
389 
390  return *m_unifiedMaxPlain;
391 }
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...
unsigned int subSequenceSize() const
Size of the sub-sequence of scalars.
template<class T>
T QUESO::ScalarSequence< T >::unifiedMeanCltStd ( bool  useOnlyInter0Comm,
unsigned int  initialPos,
unsigned int  localNumPos,
const T &  unifiedMeanValue 
) const

Definition at line 3434 of file ScalarSequence.C.

Referenced by QUESO::SequenceOfVectors< V, M >::unifiedMeanCltStd().

3439 {
3440  if (m_env.numSubEnvironments() == 1) {
3441  return this->subMeanCltStd(initialPos,
3442  numPos,
3443  unifiedMeanValue);
3444  }
3445 
3446  // As of 14/Nov/2009, this routine does *not* require sub sequences to have equal size. Good.
3447 
3448  T unifiedStdValue = 0.;
3449  if (useOnlyInter0Comm) {
3450  if (m_env.inter0Rank() >= 0) {
3451  bool bRC = ((initialPos < this->subSequenceSize()) &&
3452  (0 < numPos ) &&
3453  ((initialPos+numPos) <= this->subSequenceSize()));
3454  queso_require_msg(bRC, "invalid input data");
3455 
3456  unsigned int finalPosPlus1 = initialPos + numPos;
3457  T diff;
3458  T localStdValue = 0.;
3459  for (unsigned int j = initialPos; j < finalPosPlus1; ++j) {
3460  diff = m_seq[j] - unifiedMeanValue;
3461  localStdValue += diff*diff;
3462  }
3463 
3464  unsigned int unifiedNumPos = 0;
3465  m_env.inter0Comm().template Allreduce<unsigned int>(&numPos, &unifiedNumPos, (int) 1, RawValue_MPI_SUM,
3466  "ScalarSequence<T>::unifiedMeanCltStd()",
3467  "failed MPI.Allreduce() for numPos");
3468 
3469  m_env.inter0Comm().template Allreduce<double>(&localStdValue, &unifiedStdValue, (int) 1, RawValue_MPI_SUM,
3470  "ScalarSequence<T>::unifiedMeanCltStd()",
3471  "failed MPI.Allreduce() for stdValue");
3472 
3473  unifiedStdValue /= (((T) unifiedNumPos) - 1.);
3474  unifiedStdValue /= (((T) unifiedNumPos) - 1.);
3475  unifiedStdValue /= sqrt(unifiedStdValue);
3476  }
3477  else {
3478  // Node not in the 'inter0' communicator
3479  this->subMeanCltStd(initialPos,
3480  numPos,
3481  unifiedMeanValue);
3482  }
3483  }
3484  else {
3485  queso_error_msg("parallel vectors not supported yet");
3486  }
3487  //m_env.fullComm().Barrier();
3488 
3489  return unifiedStdValue;
3490 }
const MpiComm & inter0Comm() const
Access function for MpiComm communicator for processes with subRank() 0.
Definition: Environment.C:313
std::vector< T > m_seq
const BaseEnvironment & m_env
T subMeanCltStd(unsigned int initialPos, unsigned int numPos, const T &meanValue) const
unsigned int numSubEnvironments() const
Access function to the number of sub-environments.
Definition: Environment.C:335
int inter0Rank() const
Returns the process inter0 rank.
Definition: Environment.C:307
unsigned int subSequenceSize() const
Size of the sub-sequence of scalars.
template<class T >
T QUESO::ScalarSequence< 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.

Definition at line 844 of file ScalarSequence.C.

Referenced by QUESO::ComputeCovCorrBetweenScalarSequences(), QUESO::MLSampling< P_V, P_M >::generateSequence(), and QUESO::SequenceOfVectors< V, M >::unifiedMeanExtra().

848 {
849  if (m_env.numSubEnvironments() == 1) {
850  return this->subMeanExtra(initialPos,
851  numPos);
852  }
853 
854  // As of 14/Nov/2009, this routine does *not* require sub sequences to have equal size. Good.
855 
856  T unifiedMeanValue = 0.;
857  if (useOnlyInter0Comm) {
858  if (m_env.inter0Rank() >= 0) {
859  bool bRC = ((initialPos < this->subSequenceSize()) &&
860  (0 < numPos ) &&
861  ((initialPos+numPos) <= this->subSequenceSize()));
862  queso_require_msg(bRC, "invalid input data");
863 
864  unsigned int finalPosPlus1 = initialPos + numPos;
865  T localSum = 0.;
866  for (unsigned int j = initialPos; j < finalPosPlus1; ++j) {
867  localSum += m_seq[j];
868  }
869 
870  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 10)) {
871  *m_env.subDisplayFile() << "In ScalarSequence<T>::unifiedMeanExtra()"
872  << ": initialPos = " << initialPos
873  << ", numPos = " << numPos
874  << ", before MPI.Allreduce"
875  << std::endl;
876  }
877  //std::cout << m_env.inter0Comm().MyPID()
878  // << std::endl;
879  //sleep(1);
880  unsigned int unifiedNumPos = 0;
881  m_env.inter0Comm().template Allreduce<unsigned int>(&numPos, &unifiedNumPos, (int) 1, RawValue_MPI_SUM,
882  "ScalarSequence<T>::unifiedMeanExtra()",
883  "failed MPI.Allreduce() for numPos");
884 
885  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 10)) {
886  *m_env.subDisplayFile() << "In ScalarSequence<T>::unifiedMeanExtra()"
887  << ": numPos = " << numPos
888  << ", unifiedNumPos = " << unifiedNumPos
889  << std::endl;
890  }
891 
892  m_env.inter0Comm().template Allreduce<double>(&localSum, &unifiedMeanValue, (int) 1, RawValue_MPI_SUM,
893  "ScalarSequence<T>::unifiedMeanExtra()",
894  "failed MPI.Allreduce() for sum");
895 
896  unifiedMeanValue /= ((T) unifiedNumPos);
897 
898  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 10)) {
899  *m_env.subDisplayFile() << "In ScalarSequence<T>::unifiedMeanExtra()"
900  << ": localSum = " << localSum
901  << ", unifiedMeanValue = " << unifiedMeanValue
902  << std::endl;
903  }
904  }
905  else {
906  // Node not in the 'inter0' communicator
907  this->subMeanExtra(initialPos,
908  numPos);
909  }
910  }
911  else {
912  queso_error_msg("parallel vectors not supported yet");
913  }
914 
915  //m_env.fullComm().Barrier();
916 
917  return unifiedMeanValue;
918 }
T subMeanExtra(unsigned int initialPos, unsigned int numPos) const
Finds the mean value of the sub-sequence, considering numPos positions starting at position initialPo...
const MpiComm & inter0Comm() const
Access function for MpiComm communicator for processes with subRank() 0.
Definition: Environment.C:313
std::vector< T > m_seq
const BaseEnvironment & m_env
unsigned int displayVerbosity() const
Definition: Environment.C:450
unsigned int numSubEnvironments() const
Access function to the number of sub-environments.
Definition: Environment.C:335
int inter0Rank() const
Returns the process inter0 rank.
Definition: Environment.C:307
unsigned int subSequenceSize() const
Size of the sub-sequence of scalars.
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:320
template<class T >
const T & QUESO::ScalarSequence< T >::unifiedMeanPlain ( bool  useOnlyInter0Comm) const

Finds the mean value of the unified sequence of scalars.

Definition at line 407 of file ScalarSequence.C.

Referenced by QUESO::MLSampling< P_V, P_M >::generateSequence().

408 {
409  if (m_unifiedMeanPlain == NULL) {
410  m_unifiedMeanPlain = new T(0.);
411  *m_unifiedMeanPlain = unifiedMeanExtra(useOnlyInter0Comm,0,subSequenceSize());
412  }
413 
414  return *m_unifiedMeanPlain;
415 }
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...
unsigned int subSequenceSize() const
Size of the sub-sequence of scalars.
template<class T >
T QUESO::ScalarSequence< 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 initialPos.

Definition at line 965 of file ScalarSequence.C.

Referenced by QUESO::SequenceOfVectors< V, M >::unifiedMedianExtra().

969 {
970  if (m_env.numSubEnvironments() == 1) {
971  return this->subMedianExtra(initialPos,
972  numPos);
973  }
974 
975  // As of 07/Jul/2012, this routine does *not* require sub sequences to have equal size. Good.
976 
977  T unifiedMedianValue = 0.;
978  if (useOnlyInter0Comm) {
979  if (m_env.inter0Rank() >= 0) {
980  bool bRC = ((initialPos < this->subSequenceSize()) &&
981  (0 < numPos ) &&
982  ((initialPos+numPos) <= this->subSequenceSize()));
983  queso_require_msg(bRC, "invalid input data");
984 
985  ScalarSequence unifiedSortedSequence(m_env,0,"");
986  this->unifiedSort(useOnlyInter0Comm,
987  initialPos,
988  unifiedSortedSequence);
989  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 10)) {
990  *m_env.subDisplayFile() << "In ScalarSequence<T>::unifiedMedianExtra()"
991  << ", unifiedMedianValue = " << unifiedMedianValue
992  << std::endl;
993  }
994  }
995  else {
996  // Node not in the 'inter0' communicator
997  this->subMedianExtra(initialPos,
998  numPos);
999  }
1000  }
1001  else {
1002  queso_error_msg("parallel vectors not supported yet");
1003  }
1004 
1005  //m_env.fullComm().Barrier();
1006 
1007  return unifiedMedianValue;
1008 }
ScalarSequence(const BaseEnvironment &env, unsigned int subSequenceSize, const std::string &name)
Default constructor.
void unifiedSort(bool useOnlyInter0Comm, unsigned int initialPos, ScalarSequence< T > &unifiedSortedSequence) const
Sorts the unified sequence of scalars.
const BaseEnvironment & m_env
T subMedianExtra(unsigned int initialPos, unsigned int numPos) const
Finds the median value of the sub-sequence, considering numPos positions starting at position initial...
unsigned int displayVerbosity() const
Definition: Environment.C:450
unsigned int numSubEnvironments() const
Access function to the number of sub-environments.
Definition: Environment.C:335
int inter0Rank() const
Returns the process inter0 rank.
Definition: Environment.C:307
unsigned int subSequenceSize() const
Size of the sub-sequence of scalars.
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:320
template<class T >
const T & QUESO::ScalarSequence< T >::unifiedMedianPlain ( bool  useOnlyInter0Comm) const

Finds the median value of the unified sequence of scalars.

Definition at line 431 of file ScalarSequence.C.

432 {
433  if (m_unifiedMedianPlain == NULL) {
434  m_unifiedMedianPlain = new T(0.);
435  *m_unifiedMedianPlain = unifiedMedianExtra(useOnlyInter0Comm,0,subSequenceSize());
436  }
437 
438  return *m_unifiedMedianPlain;
439 }
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...
unsigned int subSequenceSize() const
Size of the sub-sequence of scalars.
template<class T>
void QUESO::ScalarSequence< T >::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 starting at position initialPos.

Definition at line 1498 of file ScalarSequence.C.

Referenced by QUESO::MLSampling< P_V, P_M >::generateSequence(), and QUESO::SequenceOfVectors< V, M >::unifiedMinMaxExtra().

1504 {
1505  if (m_env.numSubEnvironments() == 1) {
1506  return this->subMinMaxExtra(initialPos,
1507  numPos,
1508  unifiedMinValue,
1509  unifiedMaxValue);
1510  }
1511 
1512  // As of 14/Nov/2009, this routine does *not* require sub sequences to have equal size. Good.
1513 
1514  if (useOnlyInter0Comm) {
1515  if (m_env.inter0Rank() >= 0) {
1516  // Find local min and max
1517  T minValue;
1518  T maxValue;
1519  this->subMinMaxExtra(initialPos,
1520  numPos,
1521  minValue,
1522  maxValue);
1523 
1524  // Get overall min
1525  std::vector<double> sendBuf(1,0.);
1526  for (unsigned int i = 0; i < sendBuf.size(); ++i) {
1527  sendBuf[i] = minValue;
1528  }
1529  m_env.inter0Comm().template Allreduce<double>(&sendBuf[0], &unifiedMinValue, (int) sendBuf.size(), RawValue_MPI_MIN,
1530  "ScalarSequence<T>::unifiedMinMaxExtra()",
1531  "failed MPI.Allreduce() for min");
1532 
1533  // Get overall max
1534  for (unsigned int i = 0; i < sendBuf.size(); ++i) {
1535  sendBuf[i] = maxValue;
1536  }
1537  m_env.inter0Comm().template Allreduce<double>(&sendBuf[0], &unifiedMaxValue, (int) sendBuf.size(), RawValue_MPI_MAX,
1538  "ScalarSequence<T>::unifiedMinMaxExtra()",
1539  "failed MPI.Allreduce() for max");
1540 
1541  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 10)) {
1542  *m_env.subDisplayFile() << "In ScalarSequence<T>::unifiedMinMaxExtra()"
1543  << ": localMinValue = " << minValue
1544  << ", localMaxValue = " << maxValue
1545  << ", unifiedMinValue = " << unifiedMinValue
1546  << ", unifiedMaxValue = " << unifiedMaxValue
1547  << std::endl;
1548  }
1549  }
1550  else {
1551  // Node not in the 'inter0' communicator
1552  this->subMinMaxExtra(initialPos,
1553  numPos,
1554  unifiedMinValue,
1555  unifiedMaxValue);
1556  }
1557  }
1558  else {
1559  queso_error_msg("parallel vectors not supported yet");
1560  }
1561 
1562  //m_env.fullComm().Barrier();
1563 
1564  return;
1565 }
const MpiComm & inter0Comm() const
Access function for MpiComm communicator for processes with subRank() 0.
Definition: Environment.C:313
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...
const BaseEnvironment & m_env
unsigned int displayVerbosity() const
Definition: Environment.C:450
unsigned int numSubEnvironments() const
Access function to the number of sub-environments.
Definition: Environment.C:335
int inter0Rank() const
Returns the process inter0 rank.
Definition: Environment.C:307
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:320
template<class T >
const T & QUESO::ScalarSequence< T >::unifiedMinPlain ( bool  useOnlyInter0Comm) const

Finds the minimum value of the unified sequence of scalars.

Definition at line 356 of file ScalarSequence.C.

357 {
358  if (m_unifiedMinPlain == NULL) {
359  m_unifiedMinPlain = new T(0.);
360  if (m_unifiedMaxPlain == NULL) m_unifiedMaxPlain = new T(0.);
362  }
363 
364  return *m_unifiedMinPlain;
365 }
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...
unsigned int subSequenceSize() const
Size of the sub-sequence of scalars.
template<class T>
T QUESO::ScalarSequence< 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 position initialPos and of mean meanValue.

Output: calculated population variance of the unified sequence of scalars.

Definition at line 1213 of file ScalarSequence.C.

Referenced by QUESO::SequenceOfVectors< V, M >::unifiedPopulationVariance().

1218 {
1219  if (m_env.numSubEnvironments() == 1) {
1220  return this->subPopulationVariance(initialPos,
1221  numPos,
1222  unifiedMeanValue);
1223  }
1224 
1225  // As of 14/Nov/2009, this routine does *not* require sub sequences to have equal size. Good.
1226 
1227  T unifiedPopValue = 0.;
1228  if (useOnlyInter0Comm) {
1229  if (m_env.inter0Rank() >= 0) {
1230  bool bRC = ((initialPos < this->subSequenceSize()) &&
1231  (0 < numPos ) &&
1232  ((initialPos+numPos) <= this->subSequenceSize()));
1233  queso_require_msg(bRC, "invalid input data");
1234 
1235  unsigned int finalPosPlus1 = initialPos + numPos;
1236  T diff;
1237  T localPopValue = 0.;
1238  for (unsigned int j = initialPos; j < finalPosPlus1; ++j) {
1239  diff = m_seq[j] - unifiedMeanValue;
1240  localPopValue += diff*diff;
1241  }
1242 
1243  unsigned int unifiedNumPos = 0;
1244  m_env.inter0Comm().template Allreduce<unsigned int>(&numPos, &unifiedNumPos, (int) 1, RawValue_MPI_SUM,
1245  "ScalarSequence<T>::unifiedPopulationVariance()",
1246  "failed MPI.Allreduce() for numPos");
1247 
1248  m_env.inter0Comm().template Allreduce<double>(&localPopValue, &unifiedPopValue, (int) 1, RawValue_MPI_SUM,
1249  "ScalarSequence<T>::unifiedPopulationVariance()",
1250  "failed MPI.Allreduce() for popValue");
1251 
1252  unifiedPopValue /= ((T) unifiedNumPos);
1253  }
1254  else {
1255  // Node not in the 'inter0' communicator
1256  this->subPopulationVariance(initialPos,
1257  numPos,
1258  unifiedMeanValue);
1259  }
1260  }
1261  else {
1262  queso_error_msg("parallel vectors not supported yet");
1263  }
1264 
1265  //m_env.fullComm().Barrier();
1266 
1267  return unifiedPopValue;
1268 }
const MpiComm & inter0Comm() const
Access function for MpiComm communicator for processes with subRank() 0.
Definition: Environment.C:313
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 ...
std::vector< T > m_seq
const BaseEnvironment & m_env
unsigned int numSubEnvironments() const
Access function to the number of sub-environments.
Definition: Environment.C:335
int inter0Rank() const
Returns the process inter0 rank.
Definition: Environment.C:307
unsigned int subSequenceSize() const
Size of the sub-sequence of scalars.
template<class T>
T QUESO::ScalarSequence< T >::unifiedPositionsOfMaximum ( const ScalarSequence< T > &  subCorrespondingScalarValues,
ScalarSequence< T > &  unifiedPositionsOfMaximum 
)

Finds the positions where the maximum element occurs in the unified sequence.

Definition at line 2507 of file ScalarSequence.C.

References QUESO::queso_require_equal_to_msg, QUESO::ScalarSequence< T >::resizeSequence(), QUESO::ScalarSequence< T >::subMaxPlain(), and QUESO::ScalarSequence< T >::subSequenceSize().

2510 {
2511  queso_require_equal_to_msg(subCorrespondingScalarValues.subSequenceSize(), this->subSequenceSize(), "invalid input");
2512 
2513  T maxValue = subCorrespondingScalarValues.subMaxPlain();
2514  unsigned int iMax = subCorrespondingScalarValues.subSequenceSize();
2515 
2516  unsigned int numPos = 0;
2517  for (unsigned int i = 0; i < iMax; ++i) {
2518  if (subCorrespondingScalarValues[i] == maxValue) {
2519  numPos++;
2520  }
2521  }
2522 
2523  unifiedPositionsOfMaximum.resizeSequence(numPos);
2524  unsigned int j = 0;
2525  for (unsigned int i = 0; i < iMax; ++i) {
2526  if (subCorrespondingScalarValues[i] == maxValue) {
2527  unifiedPositionsOfMaximum[j] = (*this)[i];
2528  j++;
2529  }
2530  }
2531 
2532  return maxValue;
2533 }
T unifiedPositionsOfMaximum(const ScalarSequence< T > &subCorrespondingScalarValues, ScalarSequence< T > &unifiedPositionsOfMaximum)
Finds the positions where the maximum element occurs in the unified sequence.
MonteCarloSGOptions::MonteCarloSGOptions(const BaseEnvironment &env, const char *prefix, const McOptionsValues &alternativeOptionsValues queso_require_equal_to_msg)(m_env.optionsInputFileName(), std::string(""), std::string("this constructor is incompatible with the existence of an options input file"))
unsigned int subSequenceSize() const
Size of the sub-sequence of scalars.
template<class T >
void QUESO::ScalarSequence< T >::unifiedReadContents ( const std::string &  fileName,
const std::string &  fileType,
const unsigned int  subSequenceSize 
)

Reads the unified sequence from a file.

Definition at line 2865 of file ScalarSequence.C.

References QUESO::FilePtrSetStruct::h5Var, QUESO::FilePtrSetStruct::ifsVar, QUESO::MiscGetEllapsedSeconds(), QUESO::queso_require_equal_to_msg, QUESO::queso_require_not_equal_to_msg, and QUESO::UQ_OK_RC.

Referenced by QUESO::MLSampling< P_V, P_M >::restartML().

2869 {
2870  queso_require_not_equal_to_msg(inputFileType, std::string(UQ_FILE_EXTENSION_FOR_TXT_FORMAT), std::string("reading txt files is not yet supported"));
2871  std::string fileType(inputFileType);
2872 #ifdef QUESO_HAS_HDF5
2873  // Do nothing
2874 #else
2875  if (fileType == UQ_FILE_EXTENSION_FOR_HDF_FORMAT) {
2876  if (m_env.subDisplayFile()) {
2877  *m_env.subDisplayFile() << "WARNING in ScalarSequence<T>::unifiedReadContents()"
2878  << ": file format '" << UQ_FILE_EXTENSION_FOR_HDF_FORMAT
2879  << "' has been requested, but this QUESO library has not been built with 'hdf5'"
2880  << ". Code will therefore process the file format '" << UQ_FILE_EXTENSION_FOR_HDF_FORMAT
2881  << "' instead..."
2882  << std::endl;
2883  }
2884  if (m_env.subRank() == 0) {
2885  std::cerr << "WARNING in ScalarSequence<T>::unifiedReadContents()"
2886  << ": file format '" << UQ_FILE_EXTENSION_FOR_HDF_FORMAT
2887  << "' has been requested, but this QUESO library has not been built with 'hdf5'"
2888  << ". Code will therefore process the file format '" << UQ_FILE_EXTENSION_FOR_HDF_FORMAT
2889  << "' instead..."
2890  << std::endl;
2891  }
2892  fileType = UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT;
2893  }
2894 #endif
2895 
2896  //m_env.fullComm().Barrier(); // Dangerous to barrier on fullComm ...
2897  if (m_env.subDisplayFile()) {
2898  *m_env.subDisplayFile() << "Entering ScalarSequence<T>::unifiedReadContents()"
2899  << ": worldRank " << m_env.worldRank()
2900  << ", fullRank " << m_env.fullRank()
2901  << ", subEnvironment " << m_env.subId()
2902  << ", subRank " << m_env.subRank()
2903  << ", inter0Rank " << m_env.inter0Rank()
2904  //<< ", m_env.inter0Comm().NumProc() = " << m_env.inter0Comm().NumProc()
2905  << ", fileName = " << fileName
2906  << ", subReadSize = " << subReadSize
2907  //<< ", unifiedReadSize = " << unifiedReadSize
2908  << std::endl;
2909  }
2910 
2911  this->resizeSequence(subReadSize);
2912 
2913  if (m_env.inter0Rank() >= 0) {
2914  double unifiedReadSize = subReadSize*m_env.inter0Comm().NumProc();
2915 
2916  // In the logic below, the id of a line' begins with value 0 (zero)
2917  unsigned int idOfMyFirstLine = 1 + m_env.inter0Rank()*subReadSize;
2918  unsigned int idOfMyLastLine = (1 + m_env.inter0Rank())*subReadSize;
2919  unsigned int numParams = 1; // this->vectorSizeLocal();
2920 
2921  for (unsigned int r = 0; r < (unsigned int) m_env.inter0Comm().NumProc(); ++r) { // "m or hdf"
2922  if (m_env.inter0Rank() == (int) r) {
2923  // My turn
2924  FilePtrSetStruct unifiedFilePtrSet;
2925  if (m_env.openUnifiedInputFile(fileName,
2926  fileType,
2927  unifiedFilePtrSet)) {
2928  if ((fileType == UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT) ||
2929  (fileType == UQ_FILE_EXTENSION_FOR_TXT_FORMAT)) {
2930  if (r == 0) {
2931  // Read number of chain positions in the file by taking care of the first line,
2932  // which resembles something like 'variable_name = zeros(n_positions,m_params);'
2933  std::string tmpString;
2934 
2935  // Read 'variable name' string
2936  *unifiedFilePtrSet.ifsVar >> tmpString;
2937  //std::cout << "Just read '" << tmpString << "'" << std::endl;
2938 
2939  // Read '=' sign
2940  *unifiedFilePtrSet.ifsVar >> tmpString;
2941  //std::cout << "Just read '" << tmpString << "'" << std::endl;
2942  queso_require_equal_to_msg(tmpString, std::string("="), std::string("string should be the '=' sign"));
2943 
2944  // Read 'zeros(n_positions,n_params)' string
2945  *unifiedFilePtrSet.ifsVar >> tmpString;
2946  //std::cout << "Just read '" << tmpString << "'" << std::endl;
2947  unsigned int posInTmpString = 6;
2948 
2949  // Isolate 'n_positions' in a string
2950  //char nPositionsString[tmpString.size()-posInTmpString+1]; // avoid compiler warning
2951  std::string nPositionsString((size_t) (tmpString.size()-posInTmpString+1),' ');
2952  unsigned int posInPositionsString = 0;
2953  do {
2954  queso_require_less_msg(posInTmpString, tmpString.size(), "symbol ',' not found in first line of file");
2955  nPositionsString[posInPositionsString++] = tmpString[posInTmpString++];
2956  } while (tmpString[posInTmpString] != ',');
2957  nPositionsString[posInPositionsString] = '\0';
2958 
2959  // Isolate 'n_params' in a string
2960  posInTmpString++; // Avoid reading ',' char
2961  //char nParamsString[tmpString.size()-posInTmpString+1]; // avoid compiler warning
2962  std::string nParamsString((size_t) (tmpString.size()-posInTmpString+1),' ');
2963  unsigned int posInParamsString = 0;
2964  do {
2965  queso_require_less_msg(posInTmpString, tmpString.size(), "symbol ')' not found in first line of file");
2966  nParamsString[posInParamsString++] = tmpString[posInTmpString++];
2967  } while (tmpString[posInTmpString] != ')');
2968  nParamsString[posInParamsString] = '\0';
2969 
2970  // Convert 'n_positions' and 'n_params' strings to numbers
2971  unsigned int sizeOfChainInFile = (unsigned int) strtod(nPositionsString.c_str(),NULL);
2972  unsigned int numParamsInFile = (unsigned int) strtod(nParamsString.c_str(), NULL);
2973  if (m_env.subDisplayFile()) {
2974  *m_env.subDisplayFile() << "In ScalarSequence<T>::unifiedReadContents()"
2975  << ": worldRank " << m_env.worldRank()
2976  << ", fullRank " << m_env.fullRank()
2977  << ", sizeOfChainInFile = " << sizeOfChainInFile
2978  << ", numParamsInFile = " << numParamsInFile
2979  << std::endl;
2980  }
2981 
2982  // Check if [size of chain in file] >= [requested unified sequence size]
2983  queso_require_greater_equal_msg(sizeOfChainInFile, unifiedReadSize, "size of chain in file is not big enough");
2984 
2985  // Check if [num params in file] == [num params in current chain]
2986  queso_require_equal_to_msg(numParamsInFile, numParams, "number of parameters of chain in file is different than number of parameters in this chain object");
2987  } // if (r == 0)
2988 
2989  // Code common to any core in 'inter0Comm', including core of rank 0
2990  unsigned int maxCharsPerLine = 64*numParams; // Up to about 60 characters to represent each parameter value
2991 
2992  unsigned int lineId = 0;
2993  while (lineId < idOfMyFirstLine) {
2994  unifiedFilePtrSet.ifsVar->ignore(maxCharsPerLine,'\n');
2995  lineId++;
2996  };
2997 
2998  if (r == 0) {
2999  // Take care of initial part of the first data line,
3000  // which resembles something like 'variable_name = [value1 value2 ...'
3001  std::string tmpString;
3002 
3003  // Read 'variable name' string
3004  *unifiedFilePtrSet.ifsVar >> tmpString;
3005  //std::cout << "Core 0 just read '" << tmpString << "'" << std::endl;
3006 
3007  // Read '=' sign
3008  *unifiedFilePtrSet.ifsVar >> tmpString;
3009  //std::cout << "Core 0 just read '" << tmpString << "'" << std::endl;
3010  queso_require_equal_to_msg(tmpString, std::string("="), std::string("in core 0, string should be the '=' sign"));
3011 
3012  // Take into account the ' [' portion
3013  std::streampos tmpPos = unifiedFilePtrSet.ifsVar->tellg();
3014  unifiedFilePtrSet.ifsVar->seekg(tmpPos+(std::streampos)2);
3015  }
3016 
3017  T tmpScalar(0.); // V tmpVec(m_vectorSpace.zeroVector());
3018  while (lineId <= idOfMyLastLine) {
3019  for (unsigned int i = 0; i < numParams; ++i) {
3020  *unifiedFilePtrSet.ifsVar >> tmpScalar;
3021  }
3022  m_seq[lineId - idOfMyFirstLine] = tmpScalar;
3023  lineId++;
3024  };
3025  }
3026 #ifdef QUESO_HAS_HDF5
3027  else if (fileType == UQ_FILE_EXTENSION_FOR_HDF_FORMAT) {
3028  if (r == 0) {
3029  hid_t dataset = H5Dopen2(unifiedFilePtrSet.h5Var,
3030  "data",
3031  H5P_DEFAULT); // Dataset access property list
3032  hid_t datatype = H5Dget_type(dataset);
3033  H5T_class_t t_class = H5Tget_class(datatype);
3034  queso_require_equal_to_msg(t_class, H5T_FLOAT, "t_class is not H5T_DOUBLE");
3035  hid_t dataspace = H5Dget_space(dataset);
3036  int rank = H5Sget_simple_extent_ndims(dataspace);
3037  queso_require_equal_to_msg(rank, 2, "hdf rank is not 2");
3038  hsize_t dims_in[2];
3039  int status_n;
3040  status_n = H5Sget_simple_extent_dims(dataspace, dims_in, NULL);
3041  if (status_n) {}; // just to remove compiler warning
3042  //std::cout << "In ScalarSequence<T>::unifiedReadContents()"
3043  // << ": dims_in[0] = " << dims_in[0]
3044  // << ", dims_in[1] = " << dims_in[1]
3045  // << std::endl;
3046  queso_require_equal_to_msg(dims_in[0], numParams, "dims_in[0] is not equal to 'numParams'");
3047  queso_require_greater_equal_msg(dims_in[1], subReadSize, "dims_in[1] is smaller that requested 'subReadSize'");
3048 
3049  struct timeval timevalBegin;
3050  int iRC = UQ_OK_RC;
3051  iRC = gettimeofday(&timevalBegin,NULL);
3052  if (iRC) {}; // just to remove compiler warning
3053 
3054  unsigned int chainSizeIn = (unsigned int) dims_in[1];
3055  //double* dataIn[numParams]; // avoid compiler warning
3056  std::vector<double*> dataIn((size_t) numParams,NULL);
3057  dataIn[0] = (double*) malloc(numParams*chainSizeIn*sizeof(double));
3058  for (unsigned int i = 1; i < numParams; ++i) { // Yes, from '1'
3059  dataIn[i] = dataIn[i-1] + chainSizeIn; // Yes, just 'chainSizeIn', not 'chainSizeIn*sizeof(double)'
3060  }
3061  //std::cout << "In ScalarSequence<T>::unifiedReadContents(): h5 case, memory allocated" << std::endl;
3062  herr_t status;
3063  status = H5Dread(dataset,
3064  H5T_NATIVE_DOUBLE,
3065  H5S_ALL,
3066  dataspace,
3067  H5P_DEFAULT,
3068  dataIn[0]);
3069  if (status) {}; // just to remove compiler warning
3070  //std::cout << "In ScalarSequence<T>::unifiedReadContents(): h5 case, data read" << std::endl;
3071  T tmpScalar(0.); // V tmpVec(m_vectorSpace.zeroVector());
3072  for (unsigned int j = 0; j < subReadSize; ++j) { // Yes, 'subReadSize', not 'chainSizeIn'
3073  for (unsigned int i = 0; i < numParams; ++i) {
3074  tmpScalar = dataIn[i][j];
3075  }
3076  m_seq[j] = tmpScalar;
3077  }
3078 
3079  double readTime = MiscGetEllapsedSeconds(&timevalBegin);
3080  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
3081  *m_env.subDisplayFile() << "In ScalarSequence<T>::unifiedReadContents()"
3082  << ": worldRank " << m_env.worldRank()
3083  << ", fullRank " << m_env.fullRank()
3084  << ", subEnvironment " << m_env.subId()
3085  << ", subRank " << m_env.subRank()
3086  << ", inter0Rank " << m_env.inter0Rank()
3087  << ", fileName = " << fileName
3088  << ", numParams = " << numParams
3089  << ", chainSizeIn = " << chainSizeIn
3090  << ", subReadSize = " << subReadSize
3091  << ", readTime = " << readTime << " seconds"
3092  << std::endl;
3093  }
3094 
3095  H5Sclose(dataspace);
3096  H5Tclose(datatype);
3097  H5Dclose(dataset);
3098  //free(dataIn[0]); // related to the changes above for compiler warning
3099  for (unsigned int tmpIndex = 0; tmpIndex < dataIn.size(); tmpIndex++) {
3100  free (dataIn[tmpIndex]);
3101  }
3102  }
3103  else {
3104  queso_error_msg("hdf file type not supported for multiple sub-environments yet");
3105  }
3106  }
3107 #endif
3108  else {
3109  queso_error_msg("invalid file type");
3110  }
3111  m_env.closeFile(unifiedFilePtrSet,fileType);
3112  } // if (m_env.openUnifiedInputFile())
3113  } // if (m_env.inter0Rank() == (int) r)
3114  m_env.inter0Comm().Barrier();
3115  } // for r
3116  } // if (m_env.inter0Rank() >= 0)
3117  else {
3118  T tmpScalar(0.); // V tmpVec(m_vectorSpace.zeroVector());
3119  for (unsigned int i = 1; i < subReadSize; ++i) {
3120  m_seq[i] = tmpScalar;
3121  }
3122  }
3123 
3124  if (m_env.subDisplayFile()) {
3125  *m_env.subDisplayFile() << "Leaving ScalarSequence<T>::unifiedReadContents()"
3126  << ", fileName = " << fileName
3127  << std::endl;
3128  }
3129  //m_env.fullComm().Barrier(); // Dangerous to barrier on fullComm ...
3130 
3131  return;
3132 }
unsigned int subId() const
Access function to the number of each sub-environment Id: m_subId.
Definition: Environment.C:342
void resizeSequence(unsigned int newSequenceSize)
Resizes the size of the sequence of scalars.
void Barrier() const
Pause every process in *this communicator until all the processes reach this point.
Definition: MpiComm.C:174
const int UQ_OK_RC
Definition: Defines.h:92
void closeFile(FilePtrSetStruct &filePtrSet, const std::string &fileType) const
Closes the file.
Definition: Environment.C:1084
MonteCarloSGOptions::MonteCarloSGOptions(const BaseEnvironment &env, const char *prefix queso_require_not_equal_to_msg)(m_env.optionsInputFileName(), std::string(""), std::string("this constructor is incompatible with the absence of an options input file"))
const MpiComm & inter0Comm() const
Access function for MpiComm communicator for processes with subRank() 0.
Definition: Environment.C:313
int subRank() const
Returns the rank of the MPI process in the sub-communicator subComm()
Definition: Environment.C:287
int worldRank() const
Returns the same thing as fullRank()
Definition: Environment.C:262
int fullRank() const
Returns the rank of the MPI process in QUESO&#39;s full communicator.
Definition: Environment.C:268
bool openUnifiedInputFile(const std::string &fileName, const std::string &fileType, FilePtrSetStruct &filePtrSet) const
Opens the unified input file.
Definition: Environment.C:991
std::vector< T > m_seq
const BaseEnvironment & m_env
MonteCarloSGOptions::MonteCarloSGOptions(const BaseEnvironment &env, const char *prefix, const McOptionsValues &alternativeOptionsValues queso_require_equal_to_msg)(m_env.optionsInputFileName(), std::string(""), std::string("this constructor is incompatible with the existence of an options input file"))
int NumProc() const
Returns total number of processes.
Definition: MpiComm.C:133
unsigned int displayVerbosity() const
Definition: Environment.C:450
double MiscGetEllapsedSeconds(struct timeval *timeval0)
int inter0Rank() const
Returns the process inter0 rank.
Definition: Environment.C:307
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:320
template<class T>
T QUESO::ScalarSequence< 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 starting at position initialPos and of mean unifiedMeanValue.

Definition at line 1126 of file ScalarSequence.C.

Referenced by QUESO::SequenceOfVectors< V, M >::unifiedSampleStd().

1131 {
1132  if (m_env.numSubEnvironments() == 1) {
1133  return this->subSampleStd(initialPos,
1134  numPos,
1135  unifiedMeanValue);
1136  }
1137 
1138  // As of 14/Nov/2009, this routine does *not* require sub sequences to have equal size. Good.
1139 
1140  T unifiedStdValue = 0.;
1141  if (useOnlyInter0Comm) {
1142  if (m_env.inter0Rank() >= 0) {
1143  bool bRC = ((initialPos < this->subSequenceSize()) &&
1144  (0 < numPos ) &&
1145  ((initialPos+numPos) <= this->subSequenceSize()));
1146  queso_require_msg(bRC, "invalid input data");
1147 
1148  unsigned int finalPosPlus1 = initialPos + numPos;
1149  T diff;
1150  T localStdValue = 0.;
1151  for (unsigned int j = initialPos; j < finalPosPlus1; ++j) {
1152  diff = m_seq[j] - unifiedMeanValue;
1153  localStdValue += diff*diff;
1154  }
1155 
1156  unsigned int unifiedNumPos = 0;
1157  m_env.inter0Comm().template Allreduce<unsigned int>(&numPos, &unifiedNumPos, (int) 1, RawValue_MPI_SUM,
1158  "ScalarSequence<T>::unifiedSampleStd()",
1159  "failed MPI.Allreduce() for numPos");
1160 
1161  m_env.inter0Comm().template Allreduce<double>(&localStdValue, &unifiedStdValue, (int) 1, RawValue_MPI_SUM,
1162  "ScalarSequence<T>::unifiedSampleStd()",
1163  "failed MPI.Allreduce() for stdValue");
1164 
1165  unifiedStdValue /= (((T) unifiedNumPos) - 1.);
1166  unifiedStdValue = sqrt(unifiedStdValue);
1167  }
1168  else {
1169  // Node not in the 'inter0' communicator
1170  this->subSampleStd(initialPos,
1171  numPos,
1172  unifiedMeanValue);
1173  }
1174  }
1175  else {
1176  queso_error_msg("parallel vectors not supported yet");
1177  }
1178 
1179  //m_env.fullComm().Barrier();
1180 
1181  return unifiedStdValue;
1182 }
const MpiComm & inter0Comm() const
Access function for MpiComm communicator for processes with subRank() 0.
Definition: Environment.C:313
std::vector< T > m_seq
const BaseEnvironment & m_env
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...
unsigned int numSubEnvironments() const
Access function to the number of sub-environments.
Definition: Environment.C:335
int inter0Rank() const
Returns the process inter0 rank.
Definition: Environment.C:307
unsigned int subSequenceSize() const
Size of the sub-sequence of scalars.
template<class T>
T QUESO::ScalarSequence< 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 initialPos and of mean meanVec.

Output:

Parameters
samVecis the vector of the calculated sample variance of the unified sequence of scalars.

Definition at line 1039 of file ScalarSequence.C.

Referenced by QUESO::ComputeCovCorrBetweenScalarSequences(), and QUESO::SequenceOfVectors< V, M >::unifiedSampleVarianceExtra().

1044 {
1045  if (m_env.numSubEnvironments() == 1) {
1046  return this->subSampleVarianceExtra(initialPos,
1047  numPos,
1048  unifiedMeanValue);
1049  }
1050 
1051  // As of 14/Nov/2009, this routine does *not* require sub sequences to have equal size. Good.
1052 
1053  T unifiedSamValue = 0.;
1054  if (useOnlyInter0Comm) {
1055  if (m_env.inter0Rank() >= 0) {
1056  bool bRC = ((initialPos < this->subSequenceSize()) &&
1057  (0 < numPos ) &&
1058  ((initialPos+numPos) <= this->subSequenceSize()));
1059  queso_require_msg(bRC, "invalid input data");
1060 
1061  unsigned int finalPosPlus1 = initialPos + numPos;
1062  T diff;
1063  T localSamValue = 0.;
1064  for (unsigned int j = initialPos; j < finalPosPlus1; ++j) {
1065  diff = m_seq[j] - unifiedMeanValue;
1066  localSamValue += diff*diff;
1067  }
1068 
1069  unsigned int unifiedNumPos = 0;
1070  m_env.inter0Comm().template Allreduce<unsigned int>(&numPos, &unifiedNumPos, (int) 1, RawValue_MPI_SUM,
1071  "ScalarSequence<T>::unifiedSampleVarianceExtra()",
1072  "failed MPI.Allreduce() for numPos");
1073 
1074  m_env.inter0Comm().template Allreduce<double>(&localSamValue, &unifiedSamValue, (int) 1, RawValue_MPI_SUM,
1075  "ScalarSequence<T>::unifiedSampleVarianceExtra()",
1076  "failed MPI.Allreduce() for samValue");
1077 
1078  unifiedSamValue /= (((T) unifiedNumPos) - 1.);
1079  }
1080  else {
1081  // Node not in the 'inter0' communicator
1082  this->subSampleVarianceExtra(initialPos,
1083  numPos,
1084  unifiedMeanValue);
1085  }
1086  }
1087  else {
1088  queso_error_msg("parallel vectors not supported yet");
1089  }
1090 
1091  //m_env.fullComm().Barrier();
1092 
1093  return unifiedSamValue;
1094 }
const MpiComm & inter0Comm() const
Access function for MpiComm communicator for processes with subRank() 0.
Definition: Environment.C:313
std::vector< T > m_seq
const BaseEnvironment & m_env
unsigned int numSubEnvironments() const
Access function to the number of sub-environments.
Definition: Environment.C:335
int inter0Rank() const
Returns the process inter0 rank.
Definition: Environment.C:307
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...
template<class T >
const T & QUESO::ScalarSequence< T >::unifiedSampleVariancePlain ( bool  useOnlyInter0Comm) const

Finds the variance of a sample of the unified sequence of scalars.

Definition at line 455 of file ScalarSequence.C.

456 {
457  if (m_unifiedSampleVariancePlain == NULL) {
458  m_unifiedSampleVariancePlain = new T(0.);
460  }
461 
463 }
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 ...
const T & unifiedMeanPlain(bool useOnlyInter0Comm) const
Finds the mean value of the unified sequence of scalars.
unsigned int subSequenceSize() const
Size of the sub-sequence of scalars.
template<class T>
T QUESO::ScalarSequence< 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.

Definition at line 2207 of file ScalarSequence.C.

Referenced by QUESO::SequenceOfVectors< V, M >::unifiedScalesForKde().

2212 {
2213  if (m_env.numSubEnvironments() == 1) {
2214  return this->subScaleForKde(initialPos,
2215  unifiedIqrValue,
2216  kdeDimension);
2217  }
2218 
2219  // As of 14/Nov/2009, this routine needs to be checked if it requires sub sequences to have equal size. Good.
2220 
2221  T unifiedScaleValue = 0.;
2222  if (useOnlyInter0Comm) {
2223  if (m_env.inter0Rank() >= 0) {
2224  bool bRC = (initialPos < this->subSequenceSize());
2225  queso_require_msg(bRC, "invalid input data");
2226 
2227  unsigned int localDataSize = this->subSequenceSize() - initialPos;
2228 
2229  T unifiedMeanValue = this->unifiedMeanExtra(useOnlyInter0Comm,
2230  initialPos,
2231  localDataSize);
2232 
2233  T unifiedSamValue = this->unifiedSampleVarianceExtra(useOnlyInter0Comm,
2234  initialPos,
2235  localDataSize,
2236  unifiedMeanValue);
2237 
2238  unsigned int unifiedDataSize = 0;
2239  m_env.inter0Comm().template Allreduce<unsigned int>(&localDataSize, &unifiedDataSize, (int) 1, RawValue_MPI_SUM,
2240  "ScalarSequence<T>::unifiedScaleForKde()",
2241  "failed MPI.Allreduce() for data size");
2242 
2243  if (unifiedIqrValue <= 0.) {
2244  unifiedScaleValue = 1.06*std::sqrt(unifiedSamValue)/std::pow(unifiedDataSize,1./(4. + ((double) kdeDimension)));
2245  }
2246  else {
2247  unifiedScaleValue = 1.06*std::min(std::sqrt(unifiedSamValue),unifiedIqrValue/1.34)/std::pow(unifiedDataSize,1./(4. + ((double) kdeDimension)));
2248  }
2249 
2250  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
2251  *m_env.subDisplayFile() << "In ScalarSequence<T>::unifiedScaleForKde()"
2252  << ": unifiedIqrValue = " << unifiedIqrValue
2253  << ", unifiedMeanValue = " << unifiedMeanValue
2254  << ", unifiedSamValue = " << unifiedSamValue
2255  << ", unifiedDataSize = " << unifiedDataSize
2256  << ", unifiedScaleValue = " << unifiedScaleValue
2257  << std::endl;
2258  }
2259  }
2260  else {
2261  // Node not in the 'inter0' communicator
2262  unifiedScaleValue = this->subScaleForKde(initialPos,
2263  unifiedIqrValue,
2264  kdeDimension);
2265  }
2266  }
2267  else {
2268  queso_error_msg("parallel vectors not supported yet");
2269  }
2270 
2271  //m_env.fullComm().Barrier();
2272 
2273  return unifiedScaleValue;
2274 }
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...
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 ...
const MpiComm & inter0Comm() const
Access function for MpiComm communicator for processes with subRank() 0.
Definition: Environment.C:313
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 BaseEnvironment & m_env
unsigned int displayVerbosity() const
Definition: Environment.C:450
unsigned int numSubEnvironments() const
Access function to the number of sub-environments.
Definition: Environment.C:335
int inter0Rank() const
Returns the process inter0 rank.
Definition: Environment.C:307
unsigned int subSequenceSize() const
Size of the sub-sequence of scalars.
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:320
template<class T >
unsigned int QUESO::ScalarSequence< T >::unifiedSequenceSize ( bool  useOnlyInter0Comm) const

Size of the unified sequence of scalars.

Definition at line 143 of file ScalarSequence.C.

Referenced by QUESO::MLSampling< P_V, P_M >::checkpointML(), QUESO::MLSampling< P_V, P_M >::generateSequence_Step02_inter0(), QUESO::MLSampling< P_V, P_M >::generateSequence_Step03_inter0(), QUESO::MLSampling< P_V, P_M >::generateSequence_Step05_inter0(), and QUESO::MLSampling< P_V, P_M >::generateSequence_Step09_all().

144 {
145  if (m_env.numSubEnvironments() == 1) {
146  return this->subSequenceSize();
147  }
148 
149  // As of 14/Nov/2009, this routine does *not* require sub sequences to have equal size. Good.
150 
151  unsigned int unifiedNumSamples = 0;
152  if (useOnlyInter0Comm) {
153  if (m_env.inter0Rank() >= 0) {
154  unsigned int subNumSamples = this->subSequenceSize();
155  m_env.inter0Comm().template Allreduce<unsigned int>(&subNumSamples, &unifiedNumSamples, (int) 1, RawValue_MPI_SUM,
156  "ScalarSequence<T>::unifiedSequenceSize()",
157  "failed MPI.Allreduce() for unifiedSequenceSize()");
158  }
159  else {
160  // Node not in the 'inter0' communicator
161  unifiedNumSamples = this->subSequenceSize();
162  }
163  }
164  else {
165  queso_error_msg("parallel vectors not supported yet");
166  }
167 
168  return unifiedNumSamples;
169 }
const MpiComm & inter0Comm() const
Access function for MpiComm communicator for processes with subRank() 0.
Definition: Environment.C:313
const BaseEnvironment & m_env
unsigned int numSubEnvironments() const
Access function to the number of sub-environments.
Definition: Environment.C:335
int inter0Rank() const
Returns the process inter0 rank.
Definition: Environment.C:307
unsigned int subSequenceSize() const
Size of the sub-sequence of scalars.
template<class T>
void QUESO::ScalarSequence< T >::unifiedSort ( bool  useOnlyInter0Comm,
unsigned int  initialPos,
ScalarSequence< T > &  unifiedSortedSequence 
) const

Sorts the unified sequence of scalars.

Definition at line 1859 of file ScalarSequence.C.

References QUESO::queso_require_equal_to_msg, QUESO::ScalarSequence< T >::rawData(), QUESO::ScalarSequence< T >::resizeSequence(), and QUESO::ScalarSequence< T >::subSequenceSize().

1863 {
1864  if (m_env.numSubEnvironments() == 1) {
1865  return this->subSort(initialPos,unifiedSortedSequence);
1866  }
1867 
1868  // As of 14/Nov/2009, this routine needs to be checked if it requires sub sequences to have equal size. Good.
1869 
1870  if (useOnlyInter0Comm) {
1871  if (m_env.inter0Rank() >= 0) {
1872  //m_env.syncPrintDebugMsg("In ScalarSequence<T>::unifiedSort(), beginning logic",3,3000000,m_env.inter0Comm()); // Dangerous to barrier on inter0Comm ... // KAUST
1873 
1874  unsigned int localNumPos = this->subSequenceSize() - initialPos;
1875 
1876  std::vector<T> leafData(localNumPos,0.);
1877  this->extractRawData(0,
1878  1,
1879  localNumPos,
1880  leafData);
1881 
1882  if (m_env.inter0Rank() == 0) {
1883  int minus1NumTreeLevels = 0;
1884  int power2NumTreeNodes = 1;
1885 
1886  while (power2NumTreeNodes < m_env.inter0Comm().NumProc()) {
1887  power2NumTreeNodes += power2NumTreeNodes;
1888  minus1NumTreeLevels++;
1889  }
1890 
1891  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 10)) {
1892  *m_env.subDisplayFile() << "In ScalarSequence<T>::unifiedSort()"
1893  << ": sorting tree has " << m_env.inter0Comm().NumProc()
1894  << " nodes and " << minus1NumTreeLevels+1
1895  << " levels"
1896  << std::endl;
1897  }
1898 
1899  this->parallelMerge(unifiedSortedSequence.rawData(),
1900  leafData,
1901  minus1NumTreeLevels);
1902  }
1903  else if (m_env.inter0Rank() > 0) { // KAUST
1904  unsigned int uintBuffer[1];
1905  RawType_MPI_Status status;
1906  m_env.inter0Comm().Recv((void *) uintBuffer, 1, RawValue_MPI_UNSIGNED, RawValue_MPI_ANY_SOURCE, SCALAR_SEQUENCE_INIT_MPI_MSG, &status,
1907  "ScalarSequence<T>::unifiedSort()",
1908  "failed MPI.Recv() for init");
1909  //if (status) {}; // just to remove compiler warning
1910 
1911  unsigned int treeLevel = uintBuffer[0];
1912  this->parallelMerge(unifiedSortedSequence.rawData(),
1913  leafData,
1914  treeLevel);
1915  }
1916 
1917  //m_env.syncPrintDebugMsg("In ScalarSequence<T>::unifiedSort(), returned from parallelMerge()",3,3000000,m_env.inter0Comm()); // Dangerous to barrier on inter0Comm ... // KAUST
1918 
1919  // Broadcast
1920  unsigned int unifiedDataSize = unifiedSortedSequence.subSequenceSize();
1921  m_env.inter0Comm().Bcast((void *) &unifiedDataSize, (int) 1, RawValue_MPI_UNSIGNED, 0,
1922  "ScalarSequence<T>::unifiedSort()",
1923  "failed MPI.Bcast() for unified data size");
1924 
1925  unsigned int sumOfNumPos = 0;
1926  m_env.inter0Comm().template Allreduce<unsigned int>(&localNumPos, &sumOfNumPos, (int) 1, RawValue_MPI_SUM,
1927  "ScalarSequence<T>::unifiedSort()",
1928  "failed MPI.Allreduce() for data size");
1929 
1930  queso_require_equal_to_msg(sumOfNumPos, unifiedDataSize, "incompatible unified sizes");
1931 
1932  unifiedSortedSequence.resizeSequence(unifiedDataSize);
1933  m_env.inter0Comm().Bcast((void *) &unifiedSortedSequence.rawData()[0], (int) unifiedDataSize, RawValue_MPI_DOUBLE, 0,
1934  "ScalarSequence<T>::unifiedSort()",
1935  "failed MPI.Bcast() for unified data");
1936 
1937  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
1938  *m_env.subDisplayFile() << "In ScalarSequence<T>::parallelMerge()"
1939  << ": tree node " << m_env.inter0Rank()
1940  << ", unifiedSortedSequence[0] = " << unifiedSortedSequence[0]
1941  << ", unifiedSortedSequence[" << unifiedSortedSequence.subSequenceSize()-1 << "] = " << unifiedSortedSequence[unifiedSortedSequence.subSequenceSize()-1]
1942  << std::endl;
1943  }
1944 
1945  //m_env.syncPrintDebugMsg("In ScalarSequence<T>::unifiedSort(), ending logic",3,3000000,m_env.inter0Comm()); // Dangerous to barrier on inter0Comm ... // KAUST
1946  }
1947  else {
1948  // Node not in the 'inter0' communicator
1949  this->subSort(initialPos,unifiedSortedSequence);
1950  }
1951  }
1952  else {
1953  queso_error_msg("parallel vectors not supported yet");
1954  }
1955 
1956  //m_env.fullComm().Barrier();
1957 
1958  return;
1959 }
const MpiComm & inter0Comm() const
Access function for MpiComm communicator for processes with subRank() 0.
Definition: Environment.C:313
void subSort()
Sorts the sequence of scalars in the private attribute m_seq.
void Recv(void *buf, int count, RawType_MPI_Datatype datatype, int source, int tag, RawType_MPI_Status *status, const char *whereMsg, const char *whatMsg) const
Blocking receive of data from this process to another process.
Definition: MpiComm.C:307
void extractRawData(unsigned int initialPos, unsigned int spacing, unsigned int numPos, std::vector< double > &rawData) const
Extracts the raw data.
const BaseEnvironment & m_env
MonteCarloSGOptions::MonteCarloSGOptions(const BaseEnvironment &env, const char *prefix, const McOptionsValues &alternativeOptionsValues queso_require_equal_to_msg)(m_env.optionsInputFileName(), std::string(""), std::string("this constructor is incompatible with the existence of an options input file"))
void parallelMerge(std::vector< T > &sortedBuffer, const std::vector< T > &leafData, unsigned int treeLevel) const
Sorts/merges data in parallel using MPI.
int NumProc() const
Returns total number of processes.
Definition: MpiComm.C:133
unsigned int displayVerbosity() const
Definition: Environment.C:450
unsigned int numSubEnvironments() const
Access function to the number of sub-environments.
Definition: Environment.C:335
MPI_Status RawType_MPI_Status
Definition: MpiComm.h:46
int inter0Rank() const
Returns the process inter0 rank.
Definition: Environment.C:307
unsigned int subSequenceSize() const
Size of the sub-sequence of scalars.
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:320
void Bcast(void *buffer, int count, RawType_MPI_Datatype datatype, int root, const char *whereMsg, const char *whatMsg) const
Broadcast values from the root process to the slave processes.
Definition: MpiComm.C:191
template<class T>
void QUESO::ScalarSequence< T >::unifiedUniformlySampledCdf ( bool  useOnlyInter0Comm,
unsigned int  numIntervals,
T &  unifiedMinDomainValue,
T &  unifiedMaxDomainValue,
std::vector< T > &  unifiedCdfValues 
) const

Uniformly samples from the CDF from the unified sequence.

Definition at line 581 of file ScalarSequence.C.

587 {
588  if (m_env.numSubEnvironments() == 1) {
589  return this->subUniformlySampledCdf(numEvaluationPoints,
590  unifiedMinDomainValue,
591  unifiedMaxDomainValue,
592  unifiedCdfValues);
593  }
594 
595  // KAUST2
596  // As of 14/Nov/2009, this routine needs to be checked if it requires sub sequences to have equal size. Good.
597 
598  if (useOnlyInter0Comm) {
599  if (m_env.inter0Rank() >= 0) {
600  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 10)) {
601  *m_env.subDisplayFile() << "Entering ScalarSequence<T>::unifiedUniformlySampledCdf()"
602  << std::endl;
603  }
604 
605  T unifiedTmpMinValue;
606  T unifiedTmpMaxValue;
607  std::vector<T> unifiedCenters(numEvaluationPoints,0.);
608  std::vector<unsigned int> unifiedBins (numEvaluationPoints,0);
609 
610  this->unifiedMinMaxExtra(useOnlyInter0Comm,
611  0, // initialPos
612  this->subSequenceSize(),
613  unifiedTmpMinValue,
614  unifiedTmpMaxValue);
615  this->unifiedHistogram(useOnlyInter0Comm,
616  0, // initialPos
617  unifiedTmpMinValue,
618  unifiedTmpMaxValue,
619  unifiedCenters,
620  unifiedBins);
621 
622  unifiedMinDomainValue = unifiedCenters[0];
623  unifiedMaxDomainValue = unifiedCenters[unifiedCenters.size()-1];
624 
625  unsigned int unifiedTotalSumOfBins = 0;
626  for (unsigned int i = 0; i < numEvaluationPoints; ++i) {
627  unifiedTotalSumOfBins += unifiedBins[i];
628  }
629 
630  std::vector<unsigned int> unifiedPartialSumsOfBins(numEvaluationPoints,0);
631  unifiedPartialSumsOfBins[0] = unifiedBins[0];
632  for (unsigned int i = 1; i < numEvaluationPoints; ++i) { // Yes, from '1'
633  unifiedPartialSumsOfBins[i] = unifiedPartialSumsOfBins[i-1] + unifiedBins[i];
634  }
635 
636  unifiedCdfValues.clear();
637  unifiedCdfValues.resize(numEvaluationPoints);
638  for (unsigned int i = 0; i < numEvaluationPoints; ++i) {
639  unifiedCdfValues[i] = ((T) unifiedPartialSumsOfBins[i])/((T) unifiedTotalSumOfBins);
640  }
641 
642  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 10)) {
643  for (unsigned int i = 0; i < numEvaluationPoints; ++i) {
644  *m_env.subDisplayFile() << "In ScalarSequence<T>::unifiedUniformlySampledCdf()"
645  << ": i = " << i
646  << ", unifiedTmpMinValue = " << unifiedTmpMinValue
647  << ", unifiedTmpMaxValue = " << unifiedTmpMaxValue
648  << ", unifiedBins = " << unifiedBins[i]
649  << ", unifiedCdfValue = " << unifiedCdfValues[i]
650  << ", unifiedPartialSumsOfBins = " << unifiedPartialSumsOfBins[i]
651  << ", unifiedTotalSumOfBins = " << unifiedTotalSumOfBins
652  << std::endl;
653  }
654  }
655 
656  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 10)) {
657  *m_env.subDisplayFile() << "Leaving ScalarSequence<T>::unifiedUniformlySampledCdf()"
658  << std::endl;
659  }
660  }
661  else {
662  // Node not in the 'inter0' communicator
663  this->subUniformlySampledCdf(numEvaluationPoints,
664  unifiedMinDomainValue,
665  unifiedMaxDomainValue,
666  unifiedCdfValues);
667  }
668  }
669  else {
670  queso_error_msg("parallel vectors not supported yet");
671  }
672 
673  //m_env.fullComm().Barrier();
674 
675  return;
676 }
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 BaseEnvironment & m_env
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...
unsigned int displayVerbosity() const
Definition: Environment.C:450
void subUniformlySampledCdf(unsigned int numIntervals, T &minDomainValue, T &maxDomainValue, std::vector< T > &cdfValues) const
Uniformly samples from the CDF from the sub-sequence.
unsigned int numSubEnvironments() const
Access function to the number of sub-environments.
Definition: Environment.C:335
int inter0Rank() const
Returns the process inter0 rank.
Definition: Environment.C:307
unsigned int subSequenceSize() const
Size of the sub-sequence of scalars.
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:320
template<class T >
void QUESO::ScalarSequence< T >::unifiedWriteContents ( const std::string &  fileName,
const std::string &  fileType 
) const

Writes the unified sequence to a file.

Writes the unified sequence in Matlab/Octave format or, if enabled, in HDF5 format.

Definition at line 2640 of file ScalarSequence.C.

References QUESO::FilePtrSetStruct::h5Var, QUESO::MiscGetEllapsedSeconds(), QUESO::FilePtrSetStruct::ofsVar, and QUESO::UQ_OK_RC.

Referenced by QUESO::MLSampling< P_V, P_M >::checkpointML(), QUESO::MLSampling< P_V, P_M >::generateSequence(), QUESO::MetropolisHastingsSG< P_V, P_M >::generateSequence(), QUESO::MLSampling< P_V, P_M >::generateSequence_Level0_all(), and QUESO::MLSampling< P_V, P_M >::generateSequence_Step11_inter0().

2643 {
2644  std::string fileType(inputFileType);
2645 #ifdef QUESO_HAS_HDF5
2646  // Do nothing
2647 #else
2648  if (fileType == UQ_FILE_EXTENSION_FOR_HDF_FORMAT) {
2649  if (m_env.subDisplayFile()) {
2650  *m_env.subDisplayFile() << "WARNING in ScalarSequence<T>::unifiedWriteContents()"
2651  << ": file format '" << UQ_FILE_EXTENSION_FOR_HDF_FORMAT
2652  << "' has been requested, but this QUESO library has not been built with 'hdf5'"
2653  << ". Code will therefore process the file format '" << UQ_FILE_EXTENSION_FOR_HDF_FORMAT
2654  << "' instead..."
2655  << std::endl;
2656  }
2657  if (m_env.subRank() == 0) {
2658  std::cerr << "WARNING in ScalarSequence<T>::unifiedWriteContents()"
2659  << ": file format '" << UQ_FILE_EXTENSION_FOR_HDF_FORMAT
2660  << "' has been requested, but this QUESO library has not been built with 'hdf5'"
2661  << ". Code will therefore process the file format '" << UQ_FILE_EXTENSION_FOR_HDF_FORMAT
2662  << "' instead..."
2663  << std::endl;
2664  }
2665  fileType = UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT;
2666  }
2667 #endif
2668 
2669  // All processors in 'fullComm' should call this routine...
2670 
2671  //m_env.fullComm().Barrier(); // Dangerous to barrier on fullComm ...
2672  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 10)) {
2673  *m_env.subDisplayFile() << "Entering ScalarSequence<T>::unifiedWriteContents()"
2674  << ": worldRank " << m_env.worldRank()
2675  << ", subEnvironment " << m_env.subId()
2676  << ", subRank " << m_env.subRank()
2677  << ", inter0Rank " << m_env.inter0Rank()
2678  //<< ", m_env.inter0Comm().NumProc() = " << m_env.inter0Comm().NumProc()
2679  << ", fileName = " << fileName
2680  << ", fileType = " << fileType
2681  << std::endl;
2682  }
2683 
2684  // As of 14/Nov/2009, this routine does *not* require sub sequences to have equal size. Good.
2685 
2686  if (m_env.inter0Rank() >= 0) {
2687  for (unsigned int r = 0; r < (unsigned int) m_env.inter0Comm().NumProc(); ++r) {
2688  if (m_env.inter0Rank() == (int) r) {
2689  // My turn
2690  FilePtrSetStruct unifiedFilePtrSet;
2691  // bool writeOver = (r == 0);
2692  bool writeOver = false; // A 'true' causes problems when the user chooses (via options
2693  // in the input file) to use just one file for all outputs.
2694  //std::cout << "\n In ScalarSequence<T>::unifiedWriteContents(), pos 000 \n" << std::endl;
2695  if (m_env.openUnifiedOutputFile(fileName,
2696  fileType, // "m or hdf"
2697  writeOver,
2698  unifiedFilePtrSet)) {
2699  //std::cout << "\n In ScalarSequence<T>::unifiedWriteContents(), pos 001 \n" << std::endl;
2700 
2701  unsigned int chainSize = this->subSequenceSize();
2702  if ((fileType == UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT) ||
2703  (fileType == UQ_FILE_EXTENSION_FOR_TXT_FORMAT)) {
2704 
2705  // Write header info
2706  if (r == 0) {
2707  if (fileType == UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT) {
2708  this->writeUnifiedMatlabHeader(*unifiedFilePtrSet.ofsVar,
2709  this->subSequenceSize()*m_env.inter0Comm().NumProc());
2710  }
2711  else { // It's definitely txt if we get in here
2712  this->writeTxtHeader(*unifiedFilePtrSet.ofsVar,
2713  this->subSequenceSize()*m_env.inter0Comm().NumProc());
2714  }
2715  }
2716 
2717  for (unsigned int j = 0; j < chainSize; ++j) {
2718  *unifiedFilePtrSet.ofsVar << m_seq[j]
2719  << std::endl;
2720  }
2721 
2722  m_env.closeFile(unifiedFilePtrSet,fileType);
2723  }
2724 #ifdef QUESO_HAS_HDF5
2725  else if (fileType == UQ_FILE_EXTENSION_FOR_HDF_FORMAT) {
2726  unsigned int numParams = 1; // m_vectorSpace.dimLocal();
2727  if (r == 0) {
2728  hid_t datatype = H5Tcopy(H5T_NATIVE_DOUBLE);
2729  //std::cout << "In ScalarSequence<T>::unifiedWriteContents(): h5 case, data type created" << std::endl;
2730  hsize_t dimsf[1];
2731  dimsf[0] = chainSize;
2732  hid_t dataspace = H5Screate_simple(1, dimsf, NULL); // HDF5_rank = 2
2733  //std::cout << "In ScalarSequence<T>::unifiedWriteContents(): h5 case, data space created" << std::endl;
2734  hid_t dataset = H5Dcreate2(unifiedFilePtrSet.h5Var,
2735  "data",
2736  datatype,
2737  dataspace,
2738  H5P_DEFAULT, // Link creation property list
2739  H5P_DEFAULT, // Dataset creation property list
2740  H5P_DEFAULT); // Dataset access property list
2741  //std::cout << "In ScalarSequence<T>::unifiedWriteContents(): h5 case, data set created" << std::endl;
2742 
2743  struct timeval timevalBegin;
2744  int iRC = UQ_OK_RC;
2745  iRC = gettimeofday(&timevalBegin,NULL);
2746  if (iRC) {}; // just to remove compiler warning
2747 
2748  herr_t status;
2749  //std::cout << "\n In ScalarSequence<T>::unifiedWriteContents(), pos 002 \n" << std::endl;
2750  status = H5Dwrite(dataset,
2751  H5T_NATIVE_DOUBLE,
2752  H5S_ALL,
2753  H5S_ALL,
2754  H5P_DEFAULT,
2755  &m_seq[0]);
2756  if (status) {}; // just to remove compiler warning
2757 
2758  //std::cout << "\n In ScalarSequence<T>::unifiedWriteContents(), pos 003 \n" << std::endl;
2759  //std::cout << "In ScalarSequence<T>::unifiedWriteContents(): h5 case, data written" << std::endl;
2760 
2761  double writeTime = MiscGetEllapsedSeconds(&timevalBegin);
2762  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
2763  *m_env.subDisplayFile() << "In ScalarSequence<T>::unifiedWriteContents()"
2764  << ": worldRank " << m_env.worldRank()
2765  << ", fullRank " << m_env.fullRank()
2766  << ", subEnvironment " << m_env.subId()
2767  << ", subRank " << m_env.subRank()
2768  << ", inter0Rank " << m_env.inter0Rank()
2769  << ", fileName = " << fileName
2770  << ", numParams = " << numParams
2771  << ", chainSize = " << chainSize
2772  << ", writeTime = " << writeTime << " seconds"
2773  << std::endl;
2774  }
2775 
2776  H5Dclose(dataset);
2777  //std::cout << "In ScalarSequence<T>::unifiedWriteContents(): h5 case, data set closed" << std::endl;
2778  H5Sclose(dataspace);
2779  //std::cout << "In ScalarSequence<T>::unifiedWriteContents(): h5 case, data space closed" << std::endl;
2780  H5Tclose(datatype);
2781  //std::cout << "In ScalarSequence<T>::unifiedWriteContents(): h5 case, data type closed" << std::endl;
2782  }
2783  else {
2784  queso_error_msg("hdf file type not supported for multiple sub-environments yet");
2785  }
2786  }
2787 #endif
2788  } // if (m_env.openUnifiedOutputFile())
2789  //std::cout << "\n In ScalarSequence<T>::unifiedWriteContents(), pos 004 \n" << std::endl;
2790  } // if (m_env.inter0Rank() == (int) r)
2791  m_env.inter0Comm().Barrier();
2792  } // for r
2793 
2794  if (m_env.inter0Rank() == 0) {
2795  if ((fileType == UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT) ||
2796  (fileType == UQ_FILE_EXTENSION_FOR_TXT_FORMAT)) {
2797  FilePtrSetStruct unifiedFilePtrSet;
2798  if (m_env.openUnifiedOutputFile(fileName,
2799  fileType,
2800  false, // Yes, 'writeOver = false' in order to close the array for matlab
2801  unifiedFilePtrSet)) {
2802 
2803  if (fileType == UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT) {
2804  *unifiedFilePtrSet.ofsVar << "];\n";
2805  }
2806 
2807  m_env.closeFile(unifiedFilePtrSet,fileType);
2808  }
2809  }
2810  else if (fileType == UQ_FILE_EXTENSION_FOR_HDF_FORMAT) {
2811  // Do nothing
2812  }
2813  else {
2814  queso_error_msg("invalid file type");
2815  }
2816  }
2817  } // if (m_env.inter0Rank() >= 0)
2818 
2819  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 10)) {
2820  *m_env.subDisplayFile() << "Leaving ScalarSequence<T>::unifiedWriteContents()"
2821  << ", fileName = " << fileName
2822  << ", fileType = " << fileType
2823  << std::endl;
2824  }
2825  //m_env.fullComm().Barrier(); // Dangerous to barrier on fullComm ...
2826 
2827  return;
2828 }
unsigned int subId() const
Access function to the number of each sub-environment Id: m_subId.
Definition: Environment.C:342
void Barrier() const
Pause every process in *this communicator until all the processes reach this point.
Definition: MpiComm.C:174
void writeUnifiedMatlabHeader(std::ofstream &ofs, double sequenceSize) const
Helper function to write header info for matlab files from all chains.
const int UQ_OK_RC
Definition: Defines.h:92
void closeFile(FilePtrSetStruct &filePtrSet, const std::string &fileType) const
Closes the file.
Definition: Environment.C:1084
const MpiComm & inter0Comm() const
Access function for MpiComm communicator for processes with subRank() 0.
Definition: Environment.C:313
int subRank() const
Returns the rank of the MPI process in the sub-communicator subComm()
Definition: Environment.C:287
int worldRank() const
Returns the same thing as fullRank()
Definition: Environment.C:262
int fullRank() const
Returns the rank of the MPI process in QUESO&#39;s full communicator.
Definition: Environment.C:268
void writeTxtHeader(std::ofstream &ofs, double sequenceSize) const
Helper function to write txt info for matlab files.
std::vector< T > m_seq
const BaseEnvironment & m_env
bool openUnifiedOutputFile(const std::string &fileName, const std::string &fileType, bool writeOver, FilePtrSetStruct &filePtrSet) const
Opens a unified output file, that will contain data from all sub-environments.
Definition: Environment.C:726
int NumProc() const
Returns total number of processes.
Definition: MpiComm.C:133
unsigned int displayVerbosity() const
Definition: Environment.C:450
double MiscGetEllapsedSeconds(struct timeval *timeval0)
int inter0Rank() const
Returns the process inter0 rank.
Definition: Environment.C:307
unsigned int subSequenceSize() const
Size of the sub-sequence of scalars.
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:320
template<class T >
void QUESO::ScalarSequence< T >::writeSubMatlabHeader ( std::ofstream &  ofs,
double  sequenceSize 
) const
private

Helper function to write header info for matlab files from one chain.

Definition at line 2844 of file ScalarSequence.C.

2846 {
2847  ofs << m_name << "_sub" << m_env.subIdString() << " = zeros(" << sequenceSize
2848  << "," << 1
2849  << ");"
2850  << std::endl;
2851  ofs << m_name << "_sub" << m_env.subIdString() << " = [";
2852 }
const BaseEnvironment & m_env
const std::string & subIdString() const
Access to the attribute m_subIdString; which stores the string for the sub-environment, and it will be used, for instance, to create the output files for each sub-environment.
Definition: Environment.C:348
template<class T >
void QUESO::ScalarSequence< T >::writeTxtHeader ( std::ofstream &  ofs,
double  sequenceSize 
) const
private

Helper function to write txt info for matlab files.

Definition at line 2856 of file ScalarSequence.C.

2858 {
2859  ofs << sequenceSize << " " << 1 << std::endl;
2860 }
template<class T >
void QUESO::ScalarSequence< T >::writeUnifiedMatlabHeader ( std::ofstream &  ofs,
double  sequenceSize 
) const
private

Helper function to write header info for matlab files from all chains.

Definition at line 2832 of file ScalarSequence.C.

2834 {
2835  ofs << m_name << "_unified" << " = zeros(" << sequenceSize
2836  << "," << 1
2837  << ");"
2838  << std::endl;
2839  ofs << m_name << "_unified" << " = [";
2840 }

Member Data Documentation

template<class T = double>
const BaseEnvironment& QUESO::ScalarSequence< T >::m_env
private

Definition at line 525 of file ScalarSequence.h.

template<class T = double>
std::string QUESO::ScalarSequence< T >::m_name
private

Definition at line 526 of file ScalarSequence.h.

Referenced by QUESO::ScalarSequence< T >::copy().

template<class T = double>
std::vector<T> QUESO::ScalarSequence< T >::m_seq
private
template<class T = double>
T* QUESO::ScalarSequence< T >::m_subMaxPlain
mutableprivate

Definition at line 531 of file ScalarSequence.h.

template<class T = double>
T* QUESO::ScalarSequence< T >::m_subMeanPlain
mutableprivate

Definition at line 533 of file ScalarSequence.h.

template<class T = double>
T* QUESO::ScalarSequence< T >::m_subMedianPlain
mutableprivate

Definition at line 535 of file ScalarSequence.h.

template<class T = double>
T* QUESO::ScalarSequence< T >::m_subMinPlain
mutableprivate

Definition at line 529 of file ScalarSequence.h.

template<class T = double>
T* QUESO::ScalarSequence< T >::m_subSampleVariancePlain
mutableprivate

Definition at line 537 of file ScalarSequence.h.

template<class T = double>
T* QUESO::ScalarSequence< T >::m_unifiedMaxPlain
mutableprivate

Definition at line 532 of file ScalarSequence.h.

template<class T = double>
T* QUESO::ScalarSequence< T >::m_unifiedMeanPlain
mutableprivate

Definition at line 534 of file ScalarSequence.h.

template<class T = double>
T* QUESO::ScalarSequence< T >::m_unifiedMedianPlain
mutableprivate

Definition at line 536 of file ScalarSequence.h.

template<class T = double>
T* QUESO::ScalarSequence< T >::m_unifiedMinPlain
mutableprivate

Definition at line 530 of file ScalarSequence.h.

template<class T = double>
T* QUESO::ScalarSequence< T >::m_unifiedSampleVariancePlain
mutableprivate

Definition at line 538 of file ScalarSequence.h.


The documentation for this class was generated from the following files:

Generated on Tue Jun 5 2018 19:49:01 for queso-0.57.1 by  doxygen 1.8.5