26 #include <queso/ScalarSequence.h>
34 unsigned int subSequenceSize,
35 const std::string& name)
39 m_seq (subSequenceSize,0.),
41 m_unifiedMinPlain (NULL),
43 m_unifiedMaxPlain (NULL),
44 m_subMeanPlain (NULL),
45 m_unifiedMeanPlain (NULL),
46 m_subMedianPlain (NULL),
47 m_unifiedMedianPlain (NULL),
48 m_subSampleVariancePlain (NULL),
49 m_unifiedSampleVariancePlain(NULL)
56 deleteStoredScalars();
71 if (posId >= this->subSequenceSize()) {
72 std::cerr <<
"In ScalarSequence<T>::operator[]() const"
73 <<
": posId = " << posId
74 <<
", this->subSequenceSize() = " << this->subSequenceSize()
86 if (posId >= this->subSequenceSize()) {
87 std::cerr <<
"In ScalarSequence<T>::operator[]()"
88 <<
": posId = " << posId
89 <<
", this->subSequenceSize() = " << this->subSequenceSize()
94 deleteStoredScalars();
125 unsigned int numPos = this->subSequenceSize();
127 this->resetValues(0,numPos);
128 this->resizeSequence(0);
145 if (m_env.numSubEnvironments() == 1) {
146 return this->subSequenceSize();
151 unsigned int unifiedNumSamples = 0;
152 if (useOnlyInter0Comm) {
153 if (m_env.inter0Rank() >= 0) {
154 unsigned int subNumSamples = this->subSequenceSize();
156 "ScalarSequence<T>::unifiedSequenceSize()",
157 "failed MPI.Allreduce() for unifiedSequenceSize()");
161 unifiedNumSamples = this->subSequenceSize();
168 return unifiedNumSamples;
175 if (newSequenceSize != this->subSequenceSize()) {
176 m_seq.resize(newSequenceSize,0.);
177 std::vector<T>(m_seq).swap(m_seq);
178 deleteStoredScalars();
188 if (this->subSequenceSize() == 0)
return;
190 bool bRC = ((initialPos < this->subSequenceSize()) &&
192 ((initialPos+numPos) <= this->subSequenceSize()));
195 for (
unsigned int j = 0; j < numPos; ++j) {
196 m_seq[initialPos+j] = 0.;
199 deleteStoredScalars();
208 if (this->subSequenceSize() == 0)
return;
210 bool bRC = ((initialPos < this->subSequenceSize()) &&
212 ((initialPos+numPos) <= this->subSequenceSize()));
216 if (initialPos < this->subSequenceSize()) std::advance(posIteratorBegin,initialPos);
217 else posIteratorBegin = m_seq.end();
219 unsigned int posEnd = initialPos + numPos - 1;
221 if (posEnd < this->subSequenceSize()) std::advance(posIteratorEnd,posEnd);
222 else posIteratorEnd = m_seq.end();
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()");
228 deleteStoredScalars();
236 bool useOnlyInter0Comm,
237 std::vector<T>& outputVec)
const
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.);
254 std::vector<int> recvcnts(m_env.inter0Comm().NumProc(),0);
256 "ScalarSequence<T>::getUnifiedContentsAtProc0Only()",
257 "failed MPI.Gather()");
258 if (m_env.inter0Rank() == 0) {
263 std::vector<int> displs(m_env.inter0Comm().NumProc(),0);
264 for (
unsigned int r = 1; r < (
unsigned int) m_env.inter0Comm().NumProc(); ++r) {
265 displs[r] = displs[r-1] + recvcnts[r-1];
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()
278 for (
unsigned int i = 0; i < m_seq.size(); ++i) {
279 *m_env.subDisplayFile() <<
" (before gatherv) m_seq[" << i <<
"]= " << m_seq[i]
285 "ScalarSequence<T>::getUnifiedContentsAtProc0Only()",
286 "failed MPI.Gatherv()");
288 #if 0 // for debug only
289 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
290 for (
unsigned int i = 0; i < m_seq.size(); ++i) {
291 *m_env.subDisplayFile() <<
" (after gatherv) m_seq[" << i <<
"]= " << m_seq[i]
294 for (
unsigned int i = 0; i < outputVec.size(); ++i) {
295 *m_env.subDisplayFile() <<
" (after gatherv) outputVec[" << i <<
"]= " << outputVec[i]
301 #if 0 // for debug only
302 if (m_env.inter0Rank() == 0) {
303 for (
unsigned int i = 0; i < auxSubSize; ++i) {
304 outputVec[i] = m_seq[i];
307 "ScalarSequence<T>::getUnifiedContentsAtProc0Only(1)",
308 "failed MPI.Gatherv()");
312 "ScalarSequence<T>::getUnifiedContentsAtProc0Only(2)",
313 "failed MPI.Gatherv()");
315 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
316 for (
unsigned int i = 0; i < m_seq.size(); ++i) {
317 *m_env.subDisplayFile() <<
" (after 2nd gatherv) m_seq[" << i <<
"]= " << m_seq[i]
320 for (
unsigned int i = 0; i < outputVec.size(); ++i) {
321 *m_env.subDisplayFile() <<
" (after 2nd gatherv) outputVec[" << i <<
"]= " << outputVec[i]
343 if (m_subMinPlain == NULL) {
344 m_subMinPlain =
new T(0.);
345 if (m_subMaxPlain == NULL) m_subMaxPlain =
new T(0.);
346 subMinMaxExtra(0,this->subSequenceSize(),*m_subMinPlain,*m_subMaxPlain);
349 return *m_subMinPlain;
356 if (m_unifiedMinPlain == NULL) {
357 m_unifiedMinPlain =
new T(0.);
358 if (m_unifiedMaxPlain == NULL) m_unifiedMaxPlain =
new T(0.);
359 unifiedMinMaxExtra(useOnlyInter0Comm,0,this->subSequenceSize(),*m_unifiedMinPlain,*m_unifiedMaxPlain);
362 return *m_unifiedMinPlain;
369 if (m_subMaxPlain == NULL) {
370 if (m_subMinPlain == NULL) m_subMinPlain =
new T(0.);
371 m_subMaxPlain =
new T(0.);
372 subMinMaxExtra(0,this->subSequenceSize(),*m_subMinPlain,*m_subMaxPlain);
375 return *m_subMaxPlain;
382 if (m_unifiedMaxPlain == NULL) {
383 if (m_unifiedMinPlain == NULL) m_unifiedMinPlain =
new T(0.);
384 m_unifiedMaxPlain =
new T(0.);
385 unifiedMinMaxExtra(useOnlyInter0Comm,0,this->subSequenceSize(),*m_unifiedMinPlain,*m_unifiedMaxPlain);
388 return *m_unifiedMaxPlain;
395 if (m_subMeanPlain == NULL) {
396 m_subMeanPlain =
new T(0.);
397 *m_subMeanPlain = subMeanExtra(0,subSequenceSize());
400 return *m_subMeanPlain;
407 if (m_unifiedMeanPlain == NULL) {
408 m_unifiedMeanPlain =
new T(0.);
409 *m_unifiedMeanPlain = unifiedMeanExtra(useOnlyInter0Comm,0,subSequenceSize());
412 return *m_unifiedMeanPlain;
419 if (m_subMedianPlain == NULL) {
420 m_subMedianPlain =
new T(0.);
421 *m_subMedianPlain = subMedianExtra(0,subSequenceSize());
424 return *m_subMedianPlain;
431 if (m_unifiedMedianPlain == NULL) {
432 m_unifiedMedianPlain =
new T(0.);
433 *m_unifiedMedianPlain = unifiedMedianExtra(useOnlyInter0Comm,0,subSequenceSize());
436 return *m_unifiedMedianPlain;
443 if (m_subSampleVariancePlain == NULL) {
444 m_subSampleVariancePlain =
new T(0.);
445 *m_subSampleVariancePlain = subSampleVarianceExtra(0,subSequenceSize(),subMeanPlain());
448 return *m_subSampleVariancePlain;
455 if (m_unifiedSampleVariancePlain == NULL) {
456 m_unifiedSampleVariancePlain =
new T(0.);
457 *m_unifiedSampleVariancePlain = unifiedSampleVarianceExtra(useOnlyInter0Comm,0,subSequenceSize(),unifiedMeanPlain(useOnlyInter0Comm));
460 return *m_unifiedSampleVariancePlain;
468 delete m_subMinPlain;
469 m_subMinPlain = NULL;
471 if (m_unifiedMinPlain) {
472 delete m_unifiedMinPlain;
473 m_unifiedMinPlain = NULL;
476 delete m_subMaxPlain;
477 m_subMaxPlain = NULL;
479 if (m_unifiedMaxPlain) {
480 delete m_unifiedMaxPlain;
481 m_unifiedMaxPlain = NULL;
483 if (m_subMeanPlain) {
484 delete m_subMeanPlain;
485 m_subMeanPlain = NULL;
487 if (m_unifiedMeanPlain) {
488 delete m_unifiedMeanPlain;
489 m_unifiedMeanPlain = NULL;
491 if (m_subMedianPlain) {
492 delete m_subMedianPlain;
493 m_subMedianPlain = NULL;
495 if (m_unifiedMedianPlain) {
496 delete m_unifiedMedianPlain;
497 m_unifiedMedianPlain = NULL;
499 if (m_subSampleVariancePlain) {
500 delete m_subSampleVariancePlain;
501 m_subSampleVariancePlain = NULL;
503 if (m_unifiedSampleVariancePlain) {
504 delete m_unifiedSampleVariancePlain;
505 m_unifiedSampleVariancePlain = NULL;
515 unsigned int maxJ = this->subSequenceSize();
516 if (meanValue == 0.) {
517 for (
unsigned int j = 0; j < maxJ; ++j) {
518 m_seq[j] = m_env.rngObject()->gaussianSample(stdDev);
522 for (
unsigned int j = 0; j < maxJ; ++j) {
523 m_seq[j] = meanValue + m_env.rngObject()->gaussianSample(stdDev);
527 deleteStoredScalars();
536 unsigned int maxJ = this->subSequenceSize();
539 for (
unsigned int j = 0; j < maxJ; ++j) {
540 m_seq[j] = m_env.rngObject()->uniformSample();
544 for (
unsigned int j = 0; j < maxJ; ++j) {
545 m_seq[j] = b*m_env.rngObject()->uniformSample();
551 for (
unsigned int j = 0; j < maxJ; ++j) {
552 m_seq[j] = a + m_env.rngObject()->uniformSample();
556 for (
unsigned int j = 0; j < maxJ; ++j) {
557 m_seq[j] = a + (b-a)*m_env.rngObject()->uniformSample();
562 deleteStoredScalars();
570 unsigned int numEvaluationPoints,
573 std::vector<T>& cdfValues)
const
577 std::vector<T> centers(numEvaluationPoints,0.);
578 std::vector<unsigned int> bins (numEvaluationPoints,0);
581 this->subSequenceSize(),
590 minDomainValue = centers[0];
591 maxDomainValue = centers[centers.size()-1];
593 unsigned int sumOfBins = 0;
594 for (
unsigned int i = 0; i < numEvaluationPoints; ++i) {
595 sumOfBins += bins[i];
599 cdfValues.resize(numEvaluationPoints);
600 unsigned int partialSum = 0;
601 for (
unsigned int i = 0; i < numEvaluationPoints; ++i) {
602 partialSum += bins[i];
603 cdfValues[i] = ((T) partialSum)/((T) sumOfBins);
612 bool useOnlyInter0Comm,
613 unsigned int numEvaluationPoints,
614 T& unifiedMinDomainValue,
615 T& unifiedMaxDomainValue,
616 std::vector<T>& unifiedCdfValues)
const
618 if (m_env.numSubEnvironments() == 1) {
619 return this->subUniformlySampledCdf(numEvaluationPoints,
620 unifiedMinDomainValue,
621 unifiedMaxDomainValue,
628 if (useOnlyInter0Comm) {
629 if (m_env.inter0Rank() >= 0) {
630 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 10)) {
631 *m_env.subDisplayFile() <<
"Entering ScalarSequence<T>::unifiedUniformlySampledCdf()"
635 T unifiedTmpMinValue;
636 T unifiedTmpMaxValue;
637 std::vector<T> unifiedCenters(numEvaluationPoints,0.);
638 std::vector<unsigned int> unifiedBins (numEvaluationPoints,0);
640 this->unifiedMinMaxExtra(useOnlyInter0Comm,
642 this->subSequenceSize(),
645 this->unifiedHistogram(useOnlyInter0Comm,
652 unifiedMinDomainValue = unifiedCenters[0];
653 unifiedMaxDomainValue = unifiedCenters[unifiedCenters.size()-1];
655 unsigned int unifiedTotalSumOfBins = 0;
656 for (
unsigned int i = 0; i < numEvaluationPoints; ++i) {
657 unifiedTotalSumOfBins += unifiedBins[i];
660 std::vector<unsigned int> unifiedPartialSumsOfBins(numEvaluationPoints,0);
661 unifiedPartialSumsOfBins[0] = unifiedBins[0];
662 for (
unsigned int i = 1; i < numEvaluationPoints; ++i) {
663 unifiedPartialSumsOfBins[i] = unifiedPartialSumsOfBins[i-1] + unifiedBins[i];
666 unifiedCdfValues.clear();
667 unifiedCdfValues.resize(numEvaluationPoints);
668 for (
unsigned int i = 0; i < numEvaluationPoints; ++i) {
669 unifiedCdfValues[i] = ((T) unifiedPartialSumsOfBins[i])/((T) unifiedTotalSumOfBins);
672 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 10)) {
673 for (
unsigned int i = 0; i < numEvaluationPoints; ++i) {
674 *m_env.subDisplayFile() <<
"In ScalarSequence<T>::unifiedUniformlySampledCdf()"
676 <<
", unifiedTmpMinValue = " << unifiedTmpMinValue
677 <<
", unifiedTmpMaxValue = " << unifiedTmpMaxValue
678 <<
", unifiedBins = " << unifiedBins[i]
679 <<
", unifiedCdfValue = " << unifiedCdfValues[i]
680 <<
", unifiedPartialSumsOfBins = " << unifiedPartialSumsOfBins[i]
681 <<
", unifiedTotalSumOfBins = " << unifiedTotalSumOfBins
686 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 10)) {
687 *m_env.subDisplayFile() <<
"Leaving ScalarSequence<T>::unifiedUniformlySampledCdf()"
693 this->subUniformlySampledCdf(numEvaluationPoints,
694 unifiedMinDomainValue,
695 unifiedMaxDomainValue,
711 unsigned int numEvaluationPoints,
713 std::vector<T>& cdfValues)
const
717 std::vector<unsigned int> bins(numEvaluationPoints,0);
720 this->subSequenceSize(),
729 unsigned int sumOfBins = 0;
730 for (
unsigned int i = 0; i < numEvaluationPoints; ++i) {
731 sumOfBins += bins[i];
735 cdfValues.resize(numEvaluationPoints);
736 unsigned int partialSum = 0;
737 for (
unsigned int i = 0; i < numEvaluationPoints; ++i) {
738 partialSum += bins[i];
739 cdfValues[i] = ((T) partialSum)/((T) sumOfBins);
748 unsigned int numEvaluationPoints,
749 std::vector<T>& gridValues,
750 std::vector<T>& cdfValues)
const
754 std::vector<unsigned int> bins(numEvaluationPoints,0);
755 gridValues.resize (numEvaluationPoints,0.);
756 cdfValues.resize (numEvaluationPoints,0.);
759 this->subSequenceSize(),
763 if (tmpMinValue == tmpMaxValue) {
764 if (tmpMinValue < -1.e-12) {
765 tmpMinValue += tmpMinValue*(1.e-8);
767 else if (tmpMinValue > 1.e-12) {
768 tmpMinValue -= tmpMinValue*(1.e-8);
771 tmpMinValue = 1.e-12;
775 subWeightHistogram(0,
781 unsigned int sumOfBins = 0;
782 for (
unsigned int i = 0; i < numEvaluationPoints; ++i) {
783 sumOfBins += bins[i];
787 cdfValues.resize(numEvaluationPoints);
788 unsigned int partialSum = 0;
789 for (
unsigned int i = 0; i < numEvaluationPoints; ++i) {
790 partialSum += bins[i];
791 cdfValues[i] = ((T) partialSum)/((T) sumOfBins);
800 unsigned int numEvaluationPoints,
802 std::vector<T>& cdfValues)
const
806 std::vector<unsigned int> bins(numEvaluationPoints,0);
809 this->subSequenceSize(),
812 subWeightHistogram(0,
818 unsigned int sumOfBins = 0;
819 for (
unsigned int i = 0; i < numEvaluationPoints; ++i) {
820 sumOfBins += bins[i];
824 cdfValues.resize(numEvaluationPoints);
825 unsigned int partialSum = 0;
826 for (
unsigned int i = 0; i < numEvaluationPoints; ++i) {
827 partialSum += bins[i];
828 cdfValues[i] = ((T) partialSum)/((T) sumOfBins);
837 unsigned int initialPos,
838 unsigned int numPos)
const
840 if (this->subSequenceSize() == 0)
return 0.;
842 bool bRC = ((initialPos < this->subSequenceSize()) &&
844 ((initialPos+numPos) <= this->subSequenceSize()));
846 std::cerr <<
"In ScalarSequence<T>::subMeanExtra()"
847 <<
": ERROR at fullRank " << m_env.fullRank()
848 <<
", initialPos = " << initialPos
849 <<
", numPos = " << numPos
850 <<
", this->subSequenceSize() = " << this->subSequenceSize()
852 if (m_env.subDisplayFile()) {
853 *m_env.subDisplayFile() <<
"In ScalarSequence<T>::subMeanExtra()"
854 <<
": ERROR at fullRank " << m_env.fullRank()
855 <<
", initialPos = " << initialPos
856 <<
", numPos = " << numPos
857 <<
", this->subSequenceSize() = " << this->subSequenceSize()
863 unsigned int finalPosPlus1 = initialPos + numPos;
865 for (
unsigned int j = initialPos; j < finalPosPlus1; ++j) {
869 return tmpSum/(T) numPos;
875 bool useOnlyInter0Comm,
876 unsigned int initialPos,
877 unsigned int numPos)
const
879 if (m_env.numSubEnvironments() == 1) {
880 return this->subMeanExtra(initialPos,
886 T unifiedMeanValue = 0.;
887 if (useOnlyInter0Comm) {
888 if (m_env.inter0Rank() >= 0) {
889 bool bRC = ((initialPos < this->subSequenceSize()) &&
891 ((initialPos+numPos) <= this->subSequenceSize()));
894 unsigned int finalPosPlus1 = initialPos + numPos;
896 for (
unsigned int j = initialPos; j < finalPosPlus1; ++j) {
897 localSum += m_seq[j];
900 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 10)) {
901 *m_env.subDisplayFile() <<
"In ScalarSequence<T>::unifiedMeanExtra()"
902 <<
": initialPos = " << initialPos
903 <<
", numPos = " << numPos
904 <<
", before MPI.Allreduce"
910 unsigned int unifiedNumPos = 0;
912 "ScalarSequence<T>::unifiedMeanExtra()",
913 "failed MPI.Allreduce() for numPos");
915 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 10)) {
916 *m_env.subDisplayFile() <<
"In ScalarSequence<T>::unifiedMeanExtra()"
917 <<
": numPos = " << numPos
918 <<
", unifiedNumPos = " << unifiedNumPos
923 "ScalarSequence<T>::unifiedMeanExtra()",
924 "failed MPI.Allreduce() for sum");
926 unifiedMeanValue /= ((T) unifiedNumPos);
928 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 10)) {
929 *m_env.subDisplayFile() <<
"In ScalarSequence<T>::unifiedMeanExtra()"
930 <<
": localSum = " << localSum
931 <<
", unifiedMeanValue = " << unifiedMeanValue
937 this->subMeanExtra(initialPos,
947 return unifiedMeanValue;
953 unsigned int initialPos,
954 unsigned int numPos)
const
956 if (this->subSequenceSize() == 0)
return 0.;
958 bool bRC = ((initialPos < this->subSequenceSize()) &&
960 ((initialPos+numPos) <= this->subSequenceSize()));
962 std::cerr <<
"In ScalarSequence<T>::subMedianExtra()"
963 <<
": ERROR at fullRank " << m_env.fullRank()
964 <<
", initialPos = " << initialPos
965 <<
", numPos = " << numPos
966 <<
", this->subSequenceSize() = " << this->subSequenceSize()
968 if (m_env.subDisplayFile()) {
969 *m_env.subDisplayFile() <<
"In ScalarSequence<T>::subMedianExtra()"
970 <<
": ERROR at fullRank " << m_env.fullRank()
971 <<
", initialPos = " << initialPos
972 <<
", numPos = " << numPos
973 <<
", this->subSequenceSize() = " << this->subSequenceSize()
981 this->extractScalarSeq(initialPos,
987 unsigned int tmpPos = (
unsigned int) (0.5 * (
double) numPos);
988 T resultValue = sortedSequence[tmpPos];
996 bool useOnlyInter0Comm,
997 unsigned int initialPos,
998 unsigned int numPos)
const
1000 if (m_env.numSubEnvironments() == 1) {
1001 return this->subMedianExtra(initialPos,
1007 T unifiedMedianValue = 0.;
1008 if (useOnlyInter0Comm) {
1009 if (m_env.inter0Rank() >= 0) {
1010 bool bRC = ((initialPos < this->subSequenceSize()) &&
1012 ((initialPos+numPos) <= this->subSequenceSize()));
1016 this->unifiedSort(useOnlyInter0Comm,
1018 unifiedSortedSequence);
1019 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 10)) {
1020 *m_env.subDisplayFile() <<
"In ScalarSequence<T>::unifiedMedianExtra()"
1021 <<
", unifiedMedianValue = " << unifiedMedianValue
1027 this->subMedianExtra(initialPos,
1037 return unifiedMedianValue;
1043 unsigned int initialPos,
1044 unsigned int numPos,
1045 const T& meanValue)
const
1047 if (this->subSequenceSize() == 0)
return 0.;
1049 bool bRC = ((initialPos < this->subSequenceSize()) &&
1051 ((initialPos+numPos) <= this->subSequenceSize()));
1054 unsigned int finalPosPlus1 = initialPos + numPos;
1057 for (
unsigned int j = initialPos; j < finalPosPlus1; ++j) {
1058 diff = m_seq[j] - meanValue;
1059 samValue += diff*diff;
1062 samValue /= (((T) numPos) - 1.);
1070 bool useOnlyInter0Comm,
1071 unsigned int initialPos,
1072 unsigned int numPos,
1073 const T& unifiedMeanValue)
const
1075 if (m_env.numSubEnvironments() == 1) {
1076 return this->subSampleVarianceExtra(initialPos,
1083 T unifiedSamValue = 0.;
1084 if (useOnlyInter0Comm) {
1085 if (m_env.inter0Rank() >= 0) {
1086 bool bRC = ((initialPos < this->subSequenceSize()) &&
1088 ((initialPos+numPos) <= this->subSequenceSize()));
1091 unsigned int finalPosPlus1 = initialPos + numPos;
1093 T localSamValue = 0.;
1094 for (
unsigned int j = initialPos; j < finalPosPlus1; ++j) {
1095 diff = m_seq[j] - unifiedMeanValue;
1096 localSamValue += diff*diff;
1099 unsigned int unifiedNumPos = 0;
1101 "ScalarSequence<T>::unifiedSampleVarianceExtra()",
1102 "failed MPI.Allreduce() for numPos");
1105 "ScalarSequence<T>::unifiedSampleVarianceExtra()",
1106 "failed MPI.Allreduce() for samValue");
1108 unifiedSamValue /= (((T) unifiedNumPos) - 1.);
1112 this->subSampleVarianceExtra(initialPos,
1123 return unifiedSamValue;
1129 unsigned int initialPos,
1130 unsigned int numPos,
1131 const T& meanValue)
const
1133 if (this->subSequenceSize() == 0)
return 0.;
1135 bool bRC = ((initialPos < this->subSequenceSize()) &&
1137 ((initialPos+numPos) <= this->subSequenceSize()));
1140 unsigned int finalPosPlus1 = initialPos + numPos;
1143 for (
unsigned int j = initialPos; j < finalPosPlus1; ++j) {
1144 diff = m_seq[j] - meanValue;
1145 stdValue += diff*diff;
1148 stdValue /= (((T) numPos) - 1.);
1149 stdValue = sqrt(stdValue);
1157 bool useOnlyInter0Comm,
1158 unsigned int initialPos,
1159 unsigned int numPos,
1160 const T& unifiedMeanValue)
const
1162 if (m_env.numSubEnvironments() == 1) {
1163 return this->subSampleStd(initialPos,
1170 T unifiedStdValue = 0.;
1171 if (useOnlyInter0Comm) {
1172 if (m_env.inter0Rank() >= 0) {
1173 bool bRC = ((initialPos < this->subSequenceSize()) &&
1175 ((initialPos+numPos) <= this->subSequenceSize()));
1178 unsigned int finalPosPlus1 = initialPos + numPos;
1180 T localStdValue = 0.;
1181 for (
unsigned int j = initialPos; j < finalPosPlus1; ++j) {
1182 diff = m_seq[j] - unifiedMeanValue;
1183 localStdValue += diff*diff;
1186 unsigned int unifiedNumPos = 0;
1188 "ScalarSequence<T>::unifiedSampleStd()",
1189 "failed MPI.Allreduce() for numPos");
1192 "ScalarSequence<T>::unifiedSampleStd()",
1193 "failed MPI.Allreduce() for stdValue");
1195 unifiedStdValue /= (((T) unifiedNumPos) - 1.);
1196 unifiedStdValue = sqrt(unifiedStdValue);
1200 this->subSampleStd(initialPos,
1211 return unifiedStdValue;
1217 unsigned int initialPos,
1218 unsigned int numPos,
1219 const T& meanValue)
const
1221 if (this->subSequenceSize() == 0)
return 0.;
1223 bool bRC = ((initialPos < this->subSequenceSize()) &&
1225 ((initialPos+numPos) <= this->subSequenceSize()));
1228 unsigned int finalPosPlus1 = initialPos + numPos;
1231 for (
unsigned int j = initialPos; j < finalPosPlus1; ++j) {
1232 diff = m_seq[j] - meanValue;
1233 popValue += diff*diff;
1236 popValue /= (T) numPos;
1244 bool useOnlyInter0Comm,
1245 unsigned int initialPos,
1246 unsigned int numPos,
1247 const T& unifiedMeanValue)
const
1249 if (m_env.numSubEnvironments() == 1) {
1250 return this->subPopulationVariance(initialPos,
1257 T unifiedPopValue = 0.;
1258 if (useOnlyInter0Comm) {
1259 if (m_env.inter0Rank() >= 0) {
1260 bool bRC = ((initialPos < this->subSequenceSize()) &&
1262 ((initialPos+numPos) <= this->subSequenceSize()));
1265 unsigned int finalPosPlus1 = initialPos + numPos;
1267 T localPopValue = 0.;
1268 for (
unsigned int j = initialPos; j < finalPosPlus1; ++j) {
1269 diff = m_seq[j] - unifiedMeanValue;
1270 localPopValue += diff*diff;
1273 unsigned int unifiedNumPos = 0;
1275 "ScalarSequence<T>::unifiedPopulationVariance()",
1276 "failed MPI.Allreduce() for numPos");
1279 "ScalarSequence<T>::unifiedPopulationVariance()",
1280 "failed MPI.Allreduce() for popValue");
1282 unifiedPopValue /= ((T) unifiedNumPos);
1286 this->subPopulationVariance(initialPos,
1297 return unifiedPopValue;
1303 unsigned int initialPos,
1304 unsigned int numPos,
1306 unsigned int lag)
const
1308 bool bRC = ((initialPos < this->subSequenceSize()) &&
1310 ((initialPos+numPos) <= this->subSequenceSize()) &&
1314 unsigned int loopSize = numPos - lag;
1315 unsigned int finalPosPlus1 = initialPos + loopSize;
1319 for (
unsigned int j = initialPos; j < finalPosPlus1; ++j) {
1320 diff1 = m_seq[j ] - meanValue;
1321 diff2 = m_seq[j+lag] - meanValue;
1322 covValue += diff1*diff2;
1325 covValue /= (T) loopSize;
1333 unsigned int initialPos,
1334 unsigned int numPos,
1335 unsigned int lag)
const
1337 bool bRC = ((initialPos < this->subSequenceSize()) &&
1339 ((initialPos+numPos) <= this->subSequenceSize()) &&
1343 T meanValue = this->subMeanExtra(initialPos,
1346 T covValueZero = this->autoCovariance(initialPos,
1351 T corrValue = this->autoCovariance(initialPos,
1356 return corrValue/covValueZero;
1362 unsigned int initialPos,
1363 unsigned int numPos,
1364 unsigned int maxLag,
1365 std::vector<T>& autoCorrs)
const
1367 unsigned int fftSize = 0;
1369 double tmp = log((
double) maxLag)/log(2.);
1370 double fractionalPart = tmp - ((double) ((
unsigned int) tmp));
1371 if (fractionalPart > 0.) tmp += (1. - fractionalPart);
1372 unsigned int fftSize1 = (
unsigned int) std::pow(2.,tmp+1.);
1373 fftSize1 = fftSize1;
1375 tmp = log((
double) numPos)/log(2.);
1376 fractionalPart = tmp - ((double) ((
unsigned int) tmp));
1377 if (fractionalPart > 0.) tmp += (1. - fractionalPart);
1378 unsigned int fftSize2 = (
unsigned int) std::pow(2.,tmp+1);
1383 std::vector<double> rawDataVec(numPos,0.);
1384 std::vector<std::complex<double> > resultData(0,std::complex<double>(0.,0.));
1388 this->extractRawData(initialPos,
1392 T meanValue = this->subMeanExtra(initialPos,
1394 for (
unsigned int j = 0; j < numPos; ++j) {
1395 rawDataVec[j] -= meanValue;
1398 rawDataVec.resize(fftSize,0.);
1408 fftObj.
forward(rawDataVec,fftSize,resultData);
1411 for (
unsigned int j = 0; j < fftSize; ++j) {
1412 rawDataVec[j] = std::norm(resultData[j]);
1422 fftObj.
inverse(rawDataVec,fftSize,resultData);
1430 autoCorrs.resize(maxLag+1,0.);
1431 for (
unsigned int j = 0; j < autoCorrs.size(); ++j) {
1432 double ratio = ((double) j)/((double) (numPos-1));
1433 autoCorrs[j] = ( resultData[j].real()/resultData[0].real() )*(1.-ratio);
1442 unsigned int initialPos,
1443 unsigned int numPos,
1444 unsigned int numSum,
1445 T& autoCorrsSum)
const
1454 double tmp = log((
double) numPos)/log(2.);
1455 double fractionalPart = tmp - ((double) ((
unsigned int) tmp));
1456 if (fractionalPart > 0.) tmp += (1. - fractionalPart);
1457 unsigned int fftSize = (
unsigned int) std::pow(2.,tmp+1);
1459 std::vector<double> rawDataVec(numPos,0.);
1460 std::vector<std::complex<double> > resultData(0,std::complex<double>(0.,0.));
1464 this->extractRawData(initialPos,
1468 T meanValue = this->subMeanExtra(initialPos,
1470 for (
unsigned int j = 0; j < numPos; ++j) {
1471 rawDataVec[j] -= meanValue;
1473 rawDataVec.resize(fftSize,0.);
1483 fftObj.
forward(rawDataVec,fftSize,resultData);
1486 for (
unsigned int j = 0; j < fftSize; ++j) {
1487 rawDataVec[j] = std::norm(resultData[j]);
1489 fftObj.
inverse(rawDataVec,fftSize,resultData);
1500 for (
unsigned int j = 0; j < numSum; ++j) {
1501 double ratio = ((double) j)/((double) (numPos-1));
1502 autoCorrsSum += ( resultData[j].real()/resultData[0].real() )*(1.-ratio);
1511 unsigned int initialPos,
1512 unsigned int numPos,
1519 std::advance(pos1,initialPos);
1522 std::advance(pos2,initialPos+numPos);
1524 if ((initialPos+numPos) == this->subSequenceSize()) {
1529 pos = std::min_element(pos1, pos2);
1531 pos = std::max_element(pos1, pos2);
1540 bool useOnlyInter0Comm,
1541 unsigned int initialPos,
1542 unsigned int numPos,
1544 T& unifiedMaxValue)
const
1546 if (m_env.numSubEnvironments() == 1) {
1547 return this->subMinMaxExtra(initialPos,
1555 if (useOnlyInter0Comm) {
1556 if (m_env.inter0Rank() >= 0) {
1560 this->subMinMaxExtra(initialPos,
1566 std::vector<double> sendBuf(1,0.);
1567 for (
unsigned int i = 0; i < sendBuf.size(); ++i) {
1568 sendBuf[i] = minValue;
1571 "ScalarSequence<T>::unifiedMinMaxExtra()",
1572 "failed MPI.Allreduce() for min");
1575 for (
unsigned int i = 0; i < sendBuf.size(); ++i) {
1576 sendBuf[i] = maxValue;
1579 "ScalarSequence<T>::unifiedMinMaxExtra()",
1580 "failed MPI.Allreduce() for max");
1582 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 10)) {
1583 *m_env.subDisplayFile() <<
"In ScalarSequence<T>::unifiedMinMaxExtra()"
1584 <<
": localMinValue = " << minValue
1585 <<
", localMaxValue = " << maxValue
1586 <<
", unifiedMinValue = " << unifiedMinValue
1587 <<
", unifiedMaxValue = " << unifiedMaxValue
1593 this->subMinMaxExtra(initialPos,
1611 unsigned int initialPos,
1612 const T& minHorizontalValue,
1613 const T& maxHorizontalValue,
1614 std::vector<T>& centers,
1615 std::vector<unsigned int>& bins)
const
1623 for (
unsigned int j = 0; j < bins.size(); ++j) {
1628 double horizontalDelta = (maxHorizontalValue - minHorizontalValue)/(((
double) bins.size()) - 2.);
1630 double minCenter = minHorizontalValue - horizontalDelta/2.;
1631 double maxCenter = maxHorizontalValue + horizontalDelta/2.;
1632 for (
unsigned int j = 0; j < centers.size(); ++j) {
1633 double factor = ((double) j)/(((double) centers.size()) - 1.);
1634 centers[j] = (1. - factor) * minCenter + factor * maxCenter;
1637 unsigned int dataSize = this->subSequenceSize();
1638 for (
unsigned int j = 0; j < dataSize; ++j) {
1639 double value = m_seq[j];
1640 if (value < minHorizontalValue) {
1643 else if (value >= maxHorizontalValue) {
1644 bins[bins.size()-1]++;
1647 unsigned int index = 1 + (
unsigned int) ((value - minHorizontalValue)/horizontalDelta);
1658 bool useOnlyInter0Comm,
1659 unsigned int initialPos,
1660 const T& unifiedMinHorizontalValue,
1661 const T& unifiedMaxHorizontalValue,
1662 std::vector<T>& unifiedCenters,
1663 std::vector<unsigned int>& unifiedBins)
const
1665 if (m_env.numSubEnvironments() == 1) {
1666 return this->subHistogram(initialPos,
1667 unifiedMinHorizontalValue,
1668 unifiedMaxHorizontalValue,
1675 if (useOnlyInter0Comm) {
1676 if (m_env.inter0Rank() >= 0) {
1677 queso_require_equal_to_msg(unifiedCenters.size(), unifiedBins.size(),
"vectors 'unifiedCenters' and 'unifiedBins' have different sizes");
1681 for (
unsigned int j = 0; j < unifiedBins.size(); ++j) {
1682 unifiedCenters[j] = 0.;
1686 double unifiedHorizontalDelta = (unifiedMaxHorizontalValue - unifiedMinHorizontalValue)/(((
double) unifiedBins.size()) - 2.);
1688 double unifiedMinCenter = unifiedMinHorizontalValue - unifiedHorizontalDelta/2.;
1689 double unifiedMaxCenter = unifiedMaxHorizontalValue + unifiedHorizontalDelta/2.;
1690 for (
unsigned int j = 0; j < unifiedCenters.size(); ++j) {
1691 double factor = ((double) j)/(((double) unifiedCenters.size()) - 1.);
1692 unifiedCenters[j] = (1. - factor) * unifiedMinCenter + factor * unifiedMaxCenter;
1695 std::vector<unsigned int> localBins(unifiedBins.size(),0);
1696 unsigned int dataSize = this->subSequenceSize();
1697 for (
unsigned int j = 0; j < dataSize; ++j) {
1698 double value = m_seq[j];
1699 if (value < unifiedMinHorizontalValue) {
1702 else if (value >= unifiedMaxHorizontalValue) {
1703 localBins[localBins.size()-1]++;
1706 unsigned int index = 1 + (
unsigned int) ((value - unifiedMinHorizontalValue)/unifiedHorizontalDelta);
1712 "ScalarSequence<T>::unifiedHistogram()",
1713 "failed MPI.Allreduce() for bins");
1715 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 10)) {
1716 for (
unsigned int i = 0; i < unifiedCenters.size(); ++i) {
1717 *m_env.subDisplayFile() <<
"In ScalarSequence<T>::unifiedHistogram()"
1719 <<
", unifiedMinHorizontalValue = " << unifiedMinHorizontalValue
1720 <<
", unifiedMaxHorizontalValue = " << unifiedMaxHorizontalValue
1721 <<
", unifiedCenters = " << unifiedCenters[i]
1722 <<
", unifiedBins = " << unifiedBins[i]
1729 this->subHistogram(initialPos,
1730 unifiedMinHorizontalValue,
1731 unifiedMaxHorizontalValue,
1748 unsigned int initialPos,
1749 const T& minHorizontalValue,
1750 const T& maxHorizontalValue,
1752 std::vector<unsigned int>& bins)
const
1756 for (
unsigned int j = 0; j < bins.size(); ++j) {
1760 double horizontalDelta = (maxHorizontalValue - minHorizontalValue)/(((
double) bins.size()) - 2.);
1761 double minCenter = minHorizontalValue - horizontalDelta/2.;
1762 double maxCenter = maxHorizontalValue + horizontalDelta/2.;
1769 unsigned int dataSize = this->subSequenceSize();
1770 for (
unsigned int j = 0; j < dataSize; ++j) {
1771 double value = m_seq[j];
1772 if (value < minHorizontalValue) {
1775 else if (value >= maxHorizontalValue) {
1776 bins[bins.size()-1] += value;
1779 unsigned int index = 1 + (
unsigned int) ((value - minHorizontalValue)/horizontalDelta);
1780 bins[index] += value;
1790 unsigned int initialPos,
1791 const T& minHorizontalValue,
1792 const T& maxHorizontalValue,
1794 std::vector<unsigned int>& bins)
const
1798 for (
unsigned int j = 0; j < bins.size(); ++j) {
1802 double horizontalDelta = (maxHorizontalValue - minHorizontalValue)/(((
double) bins.size()) - 2.);
1803 double minCenter = minHorizontalValue - horizontalDelta/2.;
1804 double maxCenter = maxHorizontalValue + horizontalDelta/2.;
1811 unsigned int dataSize = this->subSequenceSize();
1812 for (
unsigned int j = 0; j < dataSize; ++j) {
1813 double value = m_seq[j];
1814 if (value < minHorizontalValue) {
1817 else if (value >= maxHorizontalValue) {
1818 bins[bins.size()-1] += value;
1821 unsigned int index = 1 + (
unsigned int) ((value - minHorizontalValue)/horizontalDelta);
1822 bins[index] += value;
1832 unsigned int initialPos,
1833 const T& minHorizontalValue,
1834 const T& maxHorizontalValue,
1835 std::vector<T>& gridValues,
1836 std::vector<unsigned int>& bins)
const
1840 for (
unsigned int j = 0; j < bins.size(); ++j) {
1844 double horizontalDelta = (maxHorizontalValue - minHorizontalValue)/(((
double) bins.size()) - 2.);
1845 double minCenter = minHorizontalValue - horizontalDelta/2.;
1846 double maxCenter = maxHorizontalValue + horizontalDelta/2.;
1853 gridValues.resize(tmpGrid.size(),0.);
1854 for (
unsigned int i = 0; i < tmpGrid.size(); ++i) {
1855 gridValues[i] = tmpGrid[i];
1858 unsigned int dataSize = this->subSequenceSize();
1859 for (
unsigned int j = 0; j < dataSize; ++j) {
1860 double value = m_seq[j];
1861 if (value < minHorizontalValue) {
1864 else if (value >= maxHorizontalValue) {
1865 bins[bins.size()-1] += value;
1868 unsigned int index = 1 + (
unsigned int) ((value - minHorizontalValue)/horizontalDelta);
1869 bins[index] += value;
1884 unsigned int initialPos,
1887 unsigned int numPos = this->subSequenceSize() - initialPos;
1889 this->extractScalarSeq(initialPos,
1901 bool useOnlyInter0Comm,
1902 unsigned int initialPos,
1905 if (m_env.numSubEnvironments() == 1) {
1906 return this->subSort(initialPos,unifiedSortedSequence);
1911 if (useOnlyInter0Comm) {
1912 if (m_env.inter0Rank() >= 0) {
1915 unsigned int localNumPos = this->subSequenceSize() - initialPos;
1917 std::vector<T> leafData(localNumPos,0.);
1918 this->extractRawData(0,
1923 if (m_env.inter0Rank() == 0) {
1924 int minus1NumTreeLevels = 0;
1925 int power2NumTreeNodes = 1;
1927 while (power2NumTreeNodes < m_env.inter0Comm().NumProc()) {
1928 power2NumTreeNodes += power2NumTreeNodes;
1929 minus1NumTreeLevels++;
1932 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 10)) {
1933 *m_env.subDisplayFile() <<
"In ScalarSequence<T>::unifiedSort()"
1934 <<
": sorting tree has " << m_env.inter0Comm().NumProc()
1935 <<
" nodes and " << minus1NumTreeLevels+1
1940 this->parallelMerge(unifiedSortedSequence.
rawData(),
1942 minus1NumTreeLevels);
1944 else if (m_env.inter0Rank() > 0) {
1945 unsigned int uintBuffer[1];
1948 "ScalarSequence<T>::unifiedSort()",
1949 "failed MPI.Recv() for init");
1952 unsigned int treeLevel = uintBuffer[0];
1953 this->parallelMerge(unifiedSortedSequence.
rawData(),
1961 unsigned int unifiedDataSize = unifiedSortedSequence.
subSequenceSize();
1963 "ScalarSequence<T>::unifiedSort()",
1964 "failed MPI.Bcast() for unified data size");
1966 unsigned int sumOfNumPos = 0;
1968 "ScalarSequence<T>::unifiedSort()",
1969 "failed MPI.Allreduce() for data size");
1975 "ScalarSequence<T>::unifiedSort()",
1976 "failed MPI.Bcast() for unified data");
1978 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
1979 *m_env.subDisplayFile() <<
"In ScalarSequence<T>::parallelMerge()"
1980 <<
": tree node " << m_env.inter0Rank()
1981 <<
", unifiedSortedSequence[0] = " << unifiedSortedSequence[0]
1982 <<
", unifiedSortedSequence[" << unifiedSortedSequence.
subSequenceSize()-1 <<
"] = " << unifiedSortedSequence[unifiedSortedSequence.
subSequenceSize()-1]
1990 this->subSort(initialPos,unifiedSortedSequence);
2009 this->subSort(initialPos,
2013 unsigned int dataSize = this->subSequenceSize() - initialPos;
2017 bool everythingOk =
true;
2022 unsigned int pos1 = (
unsigned int) ( (((
double) dataSize) + 1.)*1./4. - 1. );
2023 if (pos1 > (dataSize-1)) {
2025 everythingOk =
false;
2027 unsigned int pos1inc = pos1+1;
2028 if (pos1inc > (dataSize-1)) {
2029 pos1inc = dataSize-1;
2030 everythingOk =
false;
2036 unsigned int pos3 = (
unsigned int) ( (((
double) dataSize) + 1.)*3./4. - 1. );
2037 if (pos3 > (dataSize-1)) {
2039 everythingOk =
false;
2041 unsigned int pos3inc = pos3+1;
2042 if (pos3inc > (dataSize-1)) {
2043 pos3inc = dataSize-1;
2044 everythingOk =
false;
2047 double fraction1 = (((double) dataSize) + 1.)*1./4. - 1. - ((double) pos1);
2048 if (fraction1 < 0.) {
2050 everythingOk =
false;
2052 double fraction3 = (((double) dataSize) + 1.)*3./4. - 1. - ((double) pos3);
2053 if (fraction3 < 0.) {
2055 everythingOk =
false;
2058 if (everythingOk ==
false) {
2059 std::cerr <<
"In ScalarSequence<T>::subInterQuantileRange()"
2060 <<
", worldRank = " << m_env.worldRank()
2061 <<
": at least one adjustment was necessary"
2076 T value1 = (1.-fraction1) * sortedSequence[pos1] + fraction1 * sortedSequence[pos1inc];
2077 T value3 = (1.-fraction3) * sortedSequence[pos3] + fraction3 * sortedSequence[pos3inc];
2078 T iqrValue = value3 - value1;
2080 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
2081 *m_env.subDisplayFile() <<
"In ScalarSequence<T>::subInterQuantileRange()"
2082 <<
": iqrValue = " << iqrValue
2083 <<
", dataSize = " << dataSize
2084 <<
", pos1 = " << pos1
2085 <<
", pos3 = " << pos3
2086 <<
", value1 = " << value1
2087 <<
", value3 = " << value3
2118 bool useOnlyInter0Comm,
2119 unsigned int initialPos)
const
2121 T unifiedIqrValue = 0.;
2123 if (m_env.numSubEnvironments() == 1) {
2124 return this->subInterQuantileRange(initialPos);
2129 if (useOnlyInter0Comm) {
2130 if (m_env.inter0Rank() >= 0) {
2134 this->unifiedSort(useOnlyInter0Comm,
2136 unifiedSortedSequence);
2137 unsigned int unifiedDataSize = unifiedSortedSequence.
subSequenceSize();
2139 unsigned int localDataSize = this->subSequenceSize() - initialPos;
2140 unsigned int sumOfLocalSizes = 0;
2142 "ScalarSequence<T>::unifiedInterQuantileRange()",
2143 "failed MPI.Allreduce() for data size");
2147 unsigned int pos1 = (
unsigned int) ( (((
double) unifiedDataSize) + 1.)*1./4. - 1. );
2148 unsigned int pos3 = (
unsigned int) ( (((
double) unifiedDataSize) + 1.)*3./4. - 1. );
2150 double fraction1 = (((double) unifiedDataSize) + 1.)*1./4. - 1. - ((double) pos1);
2151 double fraction3 = (((double) unifiedDataSize) + 1.)*3./4. - 1. - ((double) pos3);
2153 T value1 = (1.-fraction1) * unifiedSortedSequence[pos1] + fraction1 * unifiedSortedSequence[pos1+1];
2154 T value3 = (1.-fraction3) * unifiedSortedSequence[pos3] + fraction3 * unifiedSortedSequence[pos3+1];
2155 unifiedIqrValue = value3 - value1;
2157 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
2158 *m_env.subDisplayFile() <<
"In ScalarSequence<T>::unifiedInterQuantileRange()"
2159 <<
": unifiedIqrValue = " << unifiedIqrValue
2160 <<
", localDataSize = " << localDataSize
2161 <<
", unifiedDataSize = " << unifiedDataSize
2162 <<
", pos1 = " << pos1
2163 <<
", pos3 = " << pos3
2164 <<
", value1 = " << value1
2165 <<
", value3 = " << value3
2194 unifiedIqrValue = this->subInterQuantileRange(initialPos);
2203 return unifiedIqrValue;
2209 unsigned int initialPos,
2211 unsigned int kdeDimension)
const
2213 bool bRC = (initialPos < this->subSequenceSize());
2216 unsigned int dataSize = this->subSequenceSize() - initialPos;
2218 T meanValue = this->subMeanExtra(initialPos,
2221 T samValue = this->subSampleVarianceExtra(initialPos,
2226 if (iqrValue <= 0.) {
2227 scaleValue = 1.06*std::sqrt(samValue)/std::pow(dataSize,1./(4. + ((
double) kdeDimension)));
2230 scaleValue = 1.06*std::min(std::sqrt(samValue),iqrValue/1.34)/std::pow(dataSize,1./(4. + ((
double) kdeDimension)));
2233 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
2234 *m_env.subDisplayFile() <<
"In ScalarSequence<T>::subScaleForKde()"
2235 <<
": iqrValue = " << iqrValue
2236 <<
", meanValue = " << meanValue
2237 <<
", samValue = " << samValue
2238 <<
", dataSize = " << dataSize
2239 <<
", scaleValue = " << scaleValue
2249 bool useOnlyInter0Comm,
2250 unsigned int initialPos,
2251 const T& unifiedIqrValue,
2252 unsigned int kdeDimension)
const
2254 if (m_env.numSubEnvironments() == 1) {
2255 return this->subScaleForKde(initialPos,
2262 T unifiedScaleValue = 0.;
2263 if (useOnlyInter0Comm) {
2264 if (m_env.inter0Rank() >= 0) {
2265 bool bRC = (initialPos < this->subSequenceSize());
2268 unsigned int localDataSize = this->subSequenceSize() - initialPos;
2270 T unifiedMeanValue = this->unifiedMeanExtra(useOnlyInter0Comm,
2274 T unifiedSamValue = this->unifiedSampleVarianceExtra(useOnlyInter0Comm,
2279 unsigned int unifiedDataSize = 0;
2281 "ScalarSequence<T>::unifiedScaleForKde()",
2282 "failed MPI.Allreduce() for data size");
2284 if (unifiedIqrValue <= 0.) {
2285 unifiedScaleValue = 1.06*std::sqrt(unifiedSamValue)/std::pow(unifiedDataSize,1./(4. + ((
double) kdeDimension)));
2288 unifiedScaleValue = 1.06*std::min(std::sqrt(unifiedSamValue),unifiedIqrValue/1.34)/std::pow(unifiedDataSize,1./(4. + ((
double) kdeDimension)));
2291 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
2292 *m_env.subDisplayFile() <<
"In ScalarSequence<T>::unifiedScaleForKde()"
2293 <<
": unifiedIqrValue = " << unifiedIqrValue
2294 <<
", unifiedMeanValue = " << unifiedMeanValue
2295 <<
", unifiedSamValue = " << unifiedSamValue
2296 <<
", unifiedDataSize = " << unifiedDataSize
2297 <<
", unifiedScaleValue = " << unifiedScaleValue
2303 unifiedScaleValue = this->subScaleForKde(initialPos,
2314 return unifiedScaleValue;
2320 unsigned int initialPos,
2322 const std::vector<T>& evaluationPositions,
2323 std::vector<double>& densityValues)
const
2325 bool bRC = ((initialPos < this->subSequenceSize() ) &&
2326 (0 < evaluationPositions.size()) &&
2327 (evaluationPositions.size() == densityValues.size() ));
2330 unsigned int dataSize = this->subSequenceSize() - initialPos;
2331 unsigned int numEvals = evaluationPositions.size();
2333 double scaleInv = 1./scaleValue;
2334 for (
unsigned int j = 0; j < numEvals; ++j) {
2335 double x = evaluationPositions[j];
2337 for (
unsigned int k = 0;
k < dataSize; ++
k) {
2338 double xk = m_seq[initialPos+
k];
2341 densityValues[j] = scaleInv * (value/(double) dataSize);
2350 bool useOnlyInter0Comm,
2351 unsigned int initialPos,
2352 double unifiedScaleValue,
2353 const std::vector<T>& unifiedEvaluationPositions,
2354 std::vector<double>& unifiedDensityValues)
const
2356 if (m_env.numSubEnvironments() == 1) {
2357 return this->subGaussian1dKde(initialPos,
2359 unifiedEvaluationPositions,
2360 unifiedDensityValues);
2365 if (useOnlyInter0Comm) {
2366 if (m_env.inter0Rank() >= 0) {
2367 bool bRC = ((initialPos < this->subSequenceSize() ) &&
2368 (0 < unifiedEvaluationPositions.size()) &&
2369 (unifiedEvaluationPositions.size() == unifiedDensityValues.size() ));
2372 unsigned int localDataSize = this->subSequenceSize() - initialPos;
2373 unsigned int unifiedDataSize = 0;
2375 "ScalarSequence<T>::unifiedGaussian1dKde()",
2376 "failed MPI.Allreduce() for data size");
2378 unsigned int numEvals = unifiedEvaluationPositions.size();
2380 std::vector<double> densityValues(numEvals,0.);
2381 double unifiedScaleInv = 1./unifiedScaleValue;
2382 for (
unsigned int j = 0; j < numEvals; ++j) {
2383 double x = unifiedEvaluationPositions[j];
2385 for (
unsigned int k = 0;
k < localDataSize; ++
k) {
2386 double xk = m_seq[initialPos+
k];
2389 densityValues[j] = value;
2392 for (
unsigned int j = 0; j < numEvals; ++j) {
2393 unifiedDensityValues[j] = 0.;
2396 "ScalarSequence<T>::unifiedGaussian1dKde()",
2397 "failed MPI.Allreduce() for density values");
2399 for (
unsigned int j = 0; j < numEvals; ++j) {
2400 unifiedDensityValues[j] *= unifiedScaleInv/((double) unifiedDataSize);
2403 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
2404 *m_env.subDisplayFile() <<
"In ScalarSequence<T>::unifiedGaussian1dKde()"
2405 <<
": unifiedDensityValues[0] = " << unifiedDensityValues[0]
2406 <<
", unifiedDensityValues[" << unifiedDensityValues.size()-1 <<
"] = " << unifiedDensityValues[unifiedDensityValues.size()-1]
2412 this->subGaussian1dKde(initialPos,
2414 unifiedEvaluationPositions,
2415 unifiedDensityValues);
2430 unsigned int initialPos,
2431 unsigned int spacing)
2433 if (m_env.subDisplayFile()) {
2434 *m_env.subDisplayFile() <<
"Entering ScalarSequence<V,M>::filter()"
2435 <<
": initialPos = " << initialPos
2436 <<
", spacing = " << spacing
2437 <<
", subSequenceSize = " << this->subSequenceSize()
2442 unsigned int j = initialPos;
2443 unsigned int originalSubSequenceSize = this->subSequenceSize();
2444 while (j < originalSubSequenceSize) {
2447 m_seq[i] = m_seq[j];
2453 this->resizeSequence(i);
2455 if (m_env.subDisplayFile()) {
2456 *m_env.subDisplayFile() <<
"Leaving ScalarSequence<V,M>::filter()"
2457 <<
": initialPos = " << initialPos
2458 <<
", spacing = " << spacing
2459 <<
", subSequenceSize = " << this->subSequenceSize()
2469 bool useOnlyInter0Comm,
2470 unsigned int initialPos,
2471 unsigned int spacing)
const
2473 double resultValue = 0.;
2477 if (useOnlyInter0Comm) {
2478 if (m_env.inter0Rank() >= 0) {
2499 unsigned int srcInitialPos,
2500 unsigned int srcNumPos)
2506 deleteStoredScalars();
2507 unsigned int currentSize = this->subSequenceSize();
2508 m_seq.resize(currentSize+srcNumPos,0.);
2509 for (
unsigned int i = 0; i < srcNumPos; ++i) {
2510 m_seq[currentSize+i] = src.
m_seq[srcInitialPos+i];
2524 T subMaxValue = subCorrespondingScalarValues.
subMaxPlain();
2527 unsigned int subNumPos = 0;
2528 for (
unsigned int i = 0; i < iMax; ++i) {
2529 if (subCorrespondingScalarValues[i] == subMaxValue) {
2536 for (
unsigned int i = 0; i < iMax; ++i) {
2537 if (subCorrespondingScalarValues[i] == subMaxValue) {
2538 subPositionsOfMaximum[j] = (*this)[i];
2554 T maxValue = subCorrespondingScalarValues.
subMaxPlain();
2557 unsigned int numPos = 0;
2558 for (
unsigned int i = 0; i < iMax; ++i) {
2559 if (subCorrespondingScalarValues[i] == maxValue) {
2566 for (
unsigned int i = 0; i < iMax; ++i) {
2567 if (subCorrespondingScalarValues[i] == maxValue) {
2568 unifiedPositionsOfMaximum[j] = (*this)[i];
2579 unsigned int initialPos,
2580 unsigned int numPos,
2581 const std::string& fileName,
2582 const std::string& fileType,
2583 const std::set<unsigned int>& allowedSubEnvIds)
const
2588 if (m_env.openOutputFile(fileName,
2594 this->subWriteContents(initialPos,
2598 m_env.closeFile(filePtrSet,fileType);
2607 unsigned int initialPos,
2608 unsigned int numPos,
2610 const std::string& fileType)
const
2615 ofs << m_name <<
"_sub" << m_env.subIdString() <<
" = zeros(" << this->subSequenceSize()
2619 ofs << m_name <<
"_sub" << m_env.subIdString() <<
" = [";
2620 unsigned int chainSize = this->subSequenceSize();
2621 for (
unsigned int j = 0; j < chainSize; ++j) {
2633 const std::string& fileName,
2634 const std::string& inputFileType)
const
2636 std::string fileType(inputFileType);
2637 #ifdef QUESO_HAS_HDF5
2641 if (m_env.subDisplayFile()) {
2642 *m_env.subDisplayFile() <<
"WARNING in ScalarSequence<T>::unifiedWriteContents()"
2644 <<
"' has been requested, but this QUESO library has not been built with 'hdf5'"
2649 if (m_env.subRank() == 0) {
2650 std::cerr <<
"WARNING in ScalarSequence<T>::unifiedWriteContents()"
2652 <<
"' has been requested, but this QUESO library has not been built with 'hdf5'"
2664 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 10)) {
2665 *m_env.subDisplayFile() <<
"Entering ScalarSequence<T>::unifiedWriteContents()"
2666 <<
": worldRank " << m_env.worldRank()
2667 <<
", subEnvironment " << m_env.subId()
2668 <<
", subRank " << m_env.subRank()
2669 <<
", inter0Rank " << m_env.inter0Rank()
2671 <<
", fileName = " << fileName
2672 <<
", fileType = " << fileType
2678 if (m_env.inter0Rank() >= 0) {
2679 for (
unsigned int r = 0; r < (
unsigned int) m_env.inter0Comm().NumProc(); ++r) {
2680 if (m_env.inter0Rank() == (int) r) {
2684 bool writeOver =
false;
2687 if (m_env.openUnifiedOutputFile(fileName,
2690 unifiedFilePtrSet)) {
2693 unsigned int chainSize = this->subSequenceSize();
2696 *unifiedFilePtrSet.
ofsVar << m_name <<
"_unified" <<
" = zeros(" << this->subSequenceSize()*m_env.inter0Comm().NumProc()
2700 *unifiedFilePtrSet.
ofsVar << m_name <<
"_unified" <<
" = [";
2703 for (
unsigned int j = 0; j < chainSize; ++j) {
2704 *unifiedFilePtrSet.
ofsVar << m_seq[j]
2708 m_env.closeFile(unifiedFilePtrSet,fileType);
2710 #ifdef QUESO_HAS_HDF5
2712 unsigned int numParams = 1;
2714 hid_t datatype = H5Tcopy(H5T_NATIVE_DOUBLE);
2717 dimsf[0] = numParams;
2718 dimsf[1] = chainSize;
2719 hid_t dataspace = H5Screate_simple(2, dimsf, NULL);
2721 hid_t dataset = H5Dcreate2(unifiedFilePtrSet.h5Var,
2730 struct timeval timevalBegin;
2732 iRC = gettimeofday(&timevalBegin,NULL);
2736 std::vector<double*> dataOut((
size_t) numParams,NULL);
2737 dataOut[0] = (
double*) malloc(numParams*chainSize*
sizeof(
double));
2738 for (
unsigned int i = 1; i < numParams; ++i) {
2739 dataOut[i] = dataOut[i-1] + chainSize;
2742 for (
unsigned int j = 0; j < chainSize; ++j) {
2743 T tmpScalar = m_seq[j];
2744 for (
unsigned int i = 0; i < numParams; ++i) {
2745 dataOut[i][j] = tmpScalar;
2752 status = H5Dwrite(dataset,
2757 (
void*) dataOut[0]);
2764 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
2765 *m_env.subDisplayFile() <<
"In ScalarSequence<T>::unifiedWriteContents()"
2766 <<
": worldRank " << m_env.worldRank()
2767 <<
", fullRank " << m_env.fullRank()
2768 <<
", subEnvironment " << m_env.subId()
2769 <<
", subRank " << m_env.subRank()
2770 <<
", inter0Rank " << m_env.inter0Rank()
2771 <<
", fileName = " << fileName
2772 <<
", numParams = " << numParams
2773 <<
", chainSize = " << chainSize
2774 <<
", writeTime = " << writeTime <<
" seconds"
2780 H5Sclose(dataspace);
2785 for (
unsigned int tmpIndex = 0; tmpIndex < dataOut.size(); tmpIndex++) {
2786 free (dataOut[tmpIndex]);
2790 queso_error_msg(
"hdf file type not supported for multiple sub-environments yet");
2797 m_env.inter0Comm().Barrier();
2800 if (m_env.inter0Rank() == 0) {
2803 if (m_env.openUnifiedOutputFile(fileName,
2806 unifiedFilePtrSet)) {
2807 *unifiedFilePtrSet.
ofsVar <<
"];\n";
2808 m_env.closeFile(unifiedFilePtrSet,fileType);
2820 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 10)) {
2821 *m_env.subDisplayFile() <<
"Leaving ScalarSequence<T>::unifiedWriteContents()"
2822 <<
", fileName = " << fileName
2823 <<
", fileType = " << fileType
2834 const std::string& fileName,
2835 const std::string& inputFileType,
2836 const unsigned int subReadSize)
2838 std::string fileType(inputFileType);
2839 #ifdef QUESO_HAS_HDF5
2843 if (m_env.subDisplayFile()) {
2844 *m_env.subDisplayFile() <<
"WARNING in ScalarSequence<T>::unifiedReadContents()"
2846 <<
"' has been requested, but this QUESO library has not been built with 'hdf5'"
2851 if (m_env.subRank() == 0) {
2852 std::cerr <<
"WARNING in ScalarSequence<T>::unifiedReadContents()"
2854 <<
"' has been requested, but this QUESO library has not been built with 'hdf5'"
2864 if (m_env.subDisplayFile()) {
2865 *m_env.subDisplayFile() <<
"Entering ScalarSequence<T>::unifiedReadContents()"
2866 <<
": worldRank " << m_env.worldRank()
2867 <<
", fullRank " << m_env.fullRank()
2868 <<
", subEnvironment " << m_env.subId()
2869 <<
", subRank " << m_env.subRank()
2870 <<
", inter0Rank " << m_env.inter0Rank()
2872 <<
", fileName = " << fileName
2873 <<
", subReadSize = " << subReadSize
2878 this->resizeSequence(subReadSize);
2880 if (m_env.inter0Rank() >= 0) {
2881 double unifiedReadSize = subReadSize*m_env.inter0Comm().NumProc();
2884 unsigned int idOfMyFirstLine = 1 + m_env.inter0Rank()*subReadSize;
2885 unsigned int idOfMyLastLine = (1 + m_env.inter0Rank())*subReadSize;
2886 unsigned int numParams = 1;
2888 for (
unsigned int r = 0; r < (
unsigned int) m_env.inter0Comm().NumProc(); ++r) {
2889 if (m_env.inter0Rank() == (int) r) {
2892 if (m_env.openUnifiedInputFile(fileName,
2894 unifiedFilePtrSet)) {
2899 std::string tmpString;
2902 *unifiedFilePtrSet.
ifsVar >> tmpString;
2906 *unifiedFilePtrSet.
ifsVar >> tmpString;
2911 *unifiedFilePtrSet.
ifsVar >> tmpString;
2913 unsigned int posInTmpString = 6;
2917 std::string nPositionsString((
size_t) (tmpString.size()-posInTmpString+1),
' ');
2918 unsigned int posInPositionsString = 0;
2921 nPositionsString[posInPositionsString++] = tmpString[posInTmpString++];
2922 }
while (tmpString[posInTmpString] !=
',');
2923 nPositionsString[posInPositionsString] =
'\0';
2928 std::string nParamsString((
size_t) (tmpString.size()-posInTmpString+1),
' ');
2929 unsigned int posInParamsString = 0;
2932 nParamsString[posInParamsString++] = tmpString[posInTmpString++];
2933 }
while (tmpString[posInTmpString] !=
')');
2934 nParamsString[posInParamsString] =
'\0';
2937 unsigned int sizeOfChainInFile = (
unsigned int) strtod(nPositionsString.c_str(),NULL);
2938 unsigned int numParamsInFile = (
unsigned int) strtod(nParamsString.c_str(), NULL);
2939 if (m_env.subDisplayFile()) {
2940 *m_env.subDisplayFile() <<
"In ScalarSequence<T>::unifiedReadContents()"
2941 <<
": worldRank " << m_env.worldRank()
2942 <<
", fullRank " << m_env.fullRank()
2943 <<
", sizeOfChainInFile = " << sizeOfChainInFile
2944 <<
", numParamsInFile = " << numParamsInFile
2952 queso_require_equal_to_msg(numParamsInFile, numParams,
"number of parameters of chain in file is different than number of parameters in this chain object");
2956 unsigned int maxCharsPerLine = 64*numParams;
2958 unsigned int lineId = 0;
2959 while (lineId < idOfMyFirstLine) {
2960 unifiedFilePtrSet.
ifsVar->ignore(maxCharsPerLine,
'\n');
2967 std::string tmpString;
2970 *unifiedFilePtrSet.
ifsVar >> tmpString;
2974 *unifiedFilePtrSet.
ifsVar >> tmpString;
2979 std::streampos tmpPos = unifiedFilePtrSet.
ifsVar->tellg();
2980 unifiedFilePtrSet.
ifsVar->seekg(tmpPos+(std::streampos)2);
2984 while (lineId <= idOfMyLastLine) {
2985 for (
unsigned int i = 0; i < numParams; ++i) {
2986 *unifiedFilePtrSet.
ifsVar >> tmpScalar;
2988 m_seq[lineId - idOfMyFirstLine] = tmpScalar;
2992 #ifdef QUESO_HAS_HDF5
2995 hid_t dataset = H5Dopen2(unifiedFilePtrSet.h5Var,
2998 hid_t datatype = H5Dget_type(dataset);
2999 H5T_class_t t_class = H5Tget_class(datatype);
3001 hid_t dataspace = H5Dget_space(dataset);
3002 int rank = H5Sget_simple_extent_ndims(dataspace);
3006 status_n = H5Sget_simple_extent_dims(dataspace, dims_in, NULL);
3015 struct timeval timevalBegin;
3017 iRC = gettimeofday(&timevalBegin,NULL);
3020 unsigned int chainSizeIn = (
unsigned int) dims_in[1];
3022 std::vector<double*>
dataIn((
size_t) numParams,NULL);
3023 dataIn[0] = (
double*) malloc(numParams*chainSizeIn*
sizeof(
double));
3024 for (
unsigned int i = 1; i < numParams; ++i) {
3025 dataIn[i] = dataIn[i-1] + chainSizeIn;
3029 status = H5Dread(dataset,
3038 for (
unsigned int j = 0; j < subReadSize; ++j) {
3039 for (
unsigned int i = 0; i < numParams; ++i) {
3040 tmpScalar = dataIn[i][j];
3042 m_seq[j] = tmpScalar;
3046 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
3047 *m_env.subDisplayFile() <<
"In ScalarSequence<T>::unifiedReadContents()"
3048 <<
": worldRank " << m_env.worldRank()
3049 <<
", fullRank " << m_env.fullRank()
3050 <<
", subEnvironment " << m_env.subId()
3051 <<
", subRank " << m_env.subRank()
3052 <<
", inter0Rank " << m_env.inter0Rank()
3053 <<
", fileName = " << fileName
3054 <<
", numParams = " << numParams
3055 <<
", chainSizeIn = " << chainSizeIn
3056 <<
", subReadSize = " << subReadSize
3057 <<
", readTime = " << readTime <<
" seconds"
3061 H5Sclose(dataspace);
3065 for (
unsigned int tmpIndex = 0; tmpIndex < dataIn.size(); tmpIndex++) {
3066 free (dataIn[tmpIndex]);
3070 queso_error_msg(
"hdf file type not supported for multiple sub-environments yet");
3077 m_env.closeFile(unifiedFilePtrSet,fileType);
3080 m_env.inter0Comm().Barrier();
3085 for (
unsigned int i = 1; i < subReadSize; ++i) {
3086 m_seq[i] = tmpScalar;
3090 if (m_env.subDisplayFile()) {
3091 *m_env.subDisplayFile() <<
"Leaving ScalarSequence<T>::unifiedReadContents()"
3092 <<
", fileName = " << fileName
3107 for (
unsigned int i = 0; i < m_seq.size(); ++i) {
3108 m_seq[i] = src.
m_seq[i];
3110 deleteStoredScalars();
3118 unsigned int initialPos,
3119 unsigned int spacing,
3120 unsigned int numPos,
3125 for (
unsigned int j = 0; j < numPos; ++j) {
3135 scalarSeq[j] = m_seq[initialPos+j ];
3139 for (
unsigned int j = 0; j < numPos; ++j) {
3149 scalarSeq[j] = m_seq[initialPos+j*spacing];
3159 unsigned int initialPos,
3160 unsigned int spacing,
3161 unsigned int numPos,
3162 std::vector<double>& rawDataVec)
const
3164 rawDataVec.resize(numPos);
3166 for (
unsigned int j = 0; j < numPos; ++j) {
3167 rawDataVec[j] = m_seq[initialPos+j ];
3171 for (
unsigned int j = 0; j < numPos; ++j) {
3172 rawDataVec[j] = m_seq[initialPos+j*spacing];
3191 std::sort(m_seq.begin(), m_seq.end());
3200 std::vector<T>& sortedBuffer,
3201 const std::vector<T>& leafData,
3202 unsigned int currentTreeLevel)
const
3204 int parentNode = m_env.inter0Rank() & ~(1 << currentTreeLevel);
3206 if (m_env.inter0Rank() >= 0) {
3207 if (currentTreeLevel == 0) {
3209 unsigned int leafDataSize = leafData.size();
3210 sortedBuffer.resize(leafDataSize,0.);
3211 for (
unsigned int i = 0; i < leafDataSize; ++i) {
3212 sortedBuffer[i] = leafData[i];
3214 std::sort(sortedBuffer.begin(), sortedBuffer.end());
3215 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
3216 *m_env.subDisplayFile() <<
"In ScalarSequence<T>::parallelMerge()"
3217 <<
": tree node " << m_env.inter0Rank()
3218 <<
", leaf sortedBuffer[0] = " << sortedBuffer[0]
3219 <<
", leaf sortedBuffer[" << sortedBuffer.size()-1 <<
"] = " << sortedBuffer[sortedBuffer.size()-1]
3224 int nextTreeLevel = currentTreeLevel - 1;
3225 int rightChildNode = m_env.inter0Rank() | (1 << nextTreeLevel);
3227 if (rightChildNode >= m_env.inter0Comm().NumProc()) {
3228 this->parallelMerge(sortedBuffer,
3233 unsigned int uintBuffer[1];
3234 uintBuffer[0] = nextTreeLevel;
3236 "ScalarSequence<T>::parallelMerge()",
3237 "failed MPI.Send() for init");
3239 this->parallelMerge(sortedBuffer,
3244 unsigned int leftSize = sortedBuffer.size();
3245 std::vector<T> leftSortedBuffer(leftSize,0.);
3246 for (
unsigned int i = 0; i < leftSize; ++i) {
3247 leftSortedBuffer[i] = sortedBuffer[i];
3253 "ScalarSequence<T>::parallelMerge()",
3254 "failed MPI.Recv() for size");
3257 unsigned int rightSize = uintBuffer[0];
3258 std::vector<T> rightSortedBuffer(rightSize,0.);
3260 "ScalarSequence<T>::parallelMerge()",
3261 "failed MPI.Recv() for data");
3264 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
3265 *m_env.subDisplayFile() <<
"In ScalarSequence<T>::parallelMerge()"
3266 <<
": tree node " << m_env.inter0Rank()
3267 <<
" is combining " << leftSortedBuffer.size()
3268 <<
" left doubles with " << rightSortedBuffer.size()
3273 sortedBuffer.clear();
3274 sortedBuffer.resize(leftSortedBuffer.size()+rightSortedBuffer.size(),0.);
3278 while ((i < leftSize ) &&
3280 if (leftSortedBuffer[i] > rightSortedBuffer[j]) sortedBuffer[k++] = rightSortedBuffer[j++];
3281 else sortedBuffer[k++] = leftSortedBuffer [i++];
3283 while (i < leftSize ) sortedBuffer[k++] = leftSortedBuffer [i++];
3284 while (j < rightSize) sortedBuffer[k++] = rightSortedBuffer[j++];
3285 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
3286 *m_env.subDisplayFile() <<
"In ScalarSequence<T>::parallelMerge()"
3287 <<
": tree node " << m_env.inter0Rank()
3288 <<
", merged sortedBuffer[0] = " << sortedBuffer[0]
3289 <<
", merged sortedBuffer[" << sortedBuffer.size()-1 <<
"] = " << sortedBuffer[sortedBuffer.size()-1]
3295 if (parentNode != m_env.inter0Rank()) {
3297 unsigned int uintBuffer[1];
3298 uintBuffer[0] = sortedBuffer.size();
3300 "ScalarSequence<T>::parallelMerge()",
3301 "failed MPI.Send() for size");
3303 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 10)) {
3304 *m_env.subDisplayFile() <<
"In ScalarSequence<T>::parallelMerge()"
3305 <<
": tree node " << m_env.inter0Rank()
3306 <<
" is sending " << sortedBuffer.size()
3307 <<
" doubles to tree node " << parentNode
3308 <<
", with sortedBuffer[0] = " << sortedBuffer[0]
3309 <<
" and sortedBuffer[" << sortedBuffer.size()-1 <<
"] = " << sortedBuffer[sortedBuffer.size()-1]
3314 "ScalarSequence<T>::parallelMerge()",
3315 "failed MPI.Send() for data");
3327 #ifdef QUESO_COMPUTES_EXTRA_POST_PROCESSING_STATISTICS
3331 unsigned int numEvaluationPoints,
3334 std::vector<T>& mdfValues)
const
3338 std::vector<T> centers(numEvaluationPoints,0.);
3339 std::vector<unsigned int> bins (numEvaluationPoints,0);
3342 this->subSequenceSize(),
3351 minDomainValue = centers[0];
3352 maxDomainValue = centers[centers.size()-1];
3353 T binSize = (maxDomainValue - minDomainValue)/((
double)(centers.size() - 1));
3355 unsigned int totalCount = 0;
3356 for (
unsigned int i = 0; i < numEvaluationPoints; ++i) {
3357 totalCount += bins[i];
3361 mdfValues.resize(numEvaluationPoints);
3362 for (
unsigned int i = 0; i < numEvaluationPoints; ++i) {
3363 mdfValues[i] = ((T) bins[i])/((T) totalCount)/binSize;
3371 ScalarSequence<T>::subMeanCltStd(
3372 unsigned int initialPos,
3373 unsigned int numPos,
3374 const T& meanValue)
const
3376 if (this->subSequenceSize() == 0)
return 0.;
3378 bool bRC = ((initialPos < this->subSequenceSize()) &&
3380 ((initialPos+numPos) <= this->subSequenceSize()));
3383 unsigned int finalPosPlus1 = initialPos + numPos;
3386 for (
unsigned int j = initialPos; j < finalPosPlus1; ++j) {
3387 diff = m_seq[j] - meanValue;
3388 stdValue += diff*diff;
3391 stdValue /= (((T) numPos) - 1.);
3392 stdValue /= (((T) numPos) - 1.);
3393 stdValue = sqrt(stdValue);
3400 ScalarSequence<T>::unifiedMeanCltStd(
3401 bool useOnlyInter0Comm,
3402 unsigned int initialPos,
3403 unsigned int numPos,
3404 const T& unifiedMeanValue)
const
3406 if (m_env.numSubEnvironments() == 1) {
3407 return this->subMeanCltStd(initialPos,
3414 T unifiedStdValue = 0.;
3415 if (useOnlyInter0Comm) {
3416 if (m_env.inter0Rank() >= 0) {
3417 bool bRC = ((initialPos < this->subSequenceSize()) &&
3419 ((initialPos+numPos) <= this->subSequenceSize()));
3422 unsigned int finalPosPlus1 = initialPos + numPos;
3424 T localStdValue = 0.;
3425 for (
unsigned int j = initialPos; j < finalPosPlus1; ++j) {
3426 diff = m_seq[j] - unifiedMeanValue;
3427 localStdValue += diff*diff;
3430 unsigned int unifiedNumPos = 0;
3432 "ScalarSequence<T>::unifiedMeanCltStd()",
3433 "failed MPI.Allreduce() for numPos");
3436 "ScalarSequence<T>::unifiedMeanCltStd()",
3437 "failed MPI.Allreduce() for stdValue");
3439 unifiedStdValue /= (((T) unifiedNumPos) - 1.);
3440 unifiedStdValue /= (((T) unifiedNumPos) - 1.);
3441 unifiedStdValue /= sqrt(unifiedStdValue);
3445 this->subMeanCltStd(initialPos,
3455 return unifiedStdValue;
3460 ScalarSequence<T>::bmm(
3461 unsigned int initialPos,
3462 unsigned int batchLength)
const
3464 bool bRC = ((initialPos < this->subSequenceSize() ) &&
3465 (batchLength < (this->subSequenceSize()-initialPos)));
3468 unsigned int numberOfBatches = (this->subSequenceSize() - initialPos)/batchLength;
3469 ScalarSequence<T> batchMeans(m_env,numberOfBatches,
"");
3471 for (
unsigned int batchId = 0; batchId < numberOfBatches; batchId++) {
3472 batchMeans[batchId] = this->subMeanExtra(initialPos + batchId*batchLength,
3476 T meanOfBatchMeans = batchMeans.subMeanExtra(0,
3477 batchMeans.subSequenceSize());
3484 T bmmValue = batchMeans.subSampleVarianceExtra(0,
3485 batchMeans.subSequenceSize(),
3488 bmmValue /= (T) batchMeans.subSequenceSize();
3496 ScalarSequence<T>::psd(
3497 unsigned int initialPos,
3498 unsigned int numBlocks,
3499 double hopSizeRatio,
3500 std::vector<double>& psdResult)
const
3502 bool bRC = ((initialPos < this->subSequenceSize() ) &&
3503 (hopSizeRatio != 0. ) &&
3504 (numBlocks < (this->subSequenceSize() - initialPos)) &&
3505 (fabs(hopSizeRatio) < (double) (this->subSequenceSize() - initialPos)));
3508 unsigned int dataSize = this->subSequenceSize() - initialPos;
3510 T meanValue = this->subMeanExtra(initialPos,
3514 unsigned int hopSize = 0;
3515 unsigned int blockSize = 0;
3516 if (hopSizeRatio <= -1.) {
3517 double overlapSize = -hopSizeRatio;
3518 double tmp = ((double) (dataSize + (numBlocks - 1)*overlapSize))/((double) numBlocks);
3519 blockSize = (
unsigned int) tmp;
3521 else if (hopSizeRatio < 0.) {
3522 double tmp = ((double) dataSize)/(( ((double) numBlocks) - 1. )*(-hopSizeRatio) + 1.);
3523 blockSize = (
unsigned int) tmp;
3524 hopSize = (
unsigned int) ( ((
double) blockSize) * (-hopSizeRatio) );
3526 else if (hopSizeRatio == 0.) {
3529 else if (hopSizeRatio < 1.) {
3530 double tmp = ((double) dataSize)/(( ((double) numBlocks) - 1. )*hopSizeRatio + 1.);
3531 blockSize = (
unsigned int) tmp;
3532 hopSize = (
unsigned int) ( ((
double) blockSize) * hopSizeRatio );
3535 hopSize = (
unsigned int) hopSizeRatio;
3536 blockSize = dataSize - (numBlocks - 1)*hopSize;
3539 int numberOfDiscardedDataElements = dataSize - (numBlocks-1)*hopSize - blockSize;
3553 double tmp = log((
double) blockSize)/log(2.);
3554 double fractionalPart = tmp - ((double) ((
unsigned int) tmp));
3555 if (fractionalPart > 0.) tmp += (1. - fractionalPart);
3556 unsigned int fftSize = (
unsigned int) std::pow(2.,tmp);
3564 double modificationScale = 0.;
3565 for (
unsigned int j = 0; j < blockSize; ++j) {
3567 modificationScale += tmpValue*tmpValue;
3569 modificationScale = 1./modificationScale;
3571 std::vector<double> blockData(blockSize,0.);
3572 Fft<T> fftObj(m_env);
3573 std::vector<std::complex<double> > fftResult(0,std::complex<double>(0.,0.));
3576 unsigned int halfFFTSize = fftSize/2;
3578 psdResult.resize(1+halfFFTSize,0.);
3579 double factor = 1./M_PI/((double) numBlocks);
3582 psdResult.resize(fftSize,0.);
3583 double factor = 1./2./M_PI/((double) numBlocks);
3586 for (
unsigned int blockId = 0; blockId < numBlocks; blockId++) {
3588 unsigned int initialDataPos = initialPos + blockId*hopSize;
3589 for (
unsigned int j = 0; j < blockSize; ++j) {
3590 unsigned int dataPos = initialDataPos + j;
3592 blockData[j] =
MiscHammingWindow(blockSize-1,j) * ( m_seq[dataPos] - meanValue );
3595 fftObj.forward(blockData,fftSize,fftResult);
3605 for (
unsigned int j = 0; j < psdResult.size(); ++j) {
3606 psdResult[j] += norm(fftResult[j])*modificationScale;
3610 for (
unsigned int j = 0; j < psdResult.size(); ++j) {
3611 psdResult[j] *= factor;
3619 ScalarSequence<T>::geweke(
3620 unsigned int initialPos,
3622 double ratioNb)
const
3624 double doubleFullDataSize = (double) (this->subSequenceSize() - initialPos);
3625 ScalarSequence<T> tmpSeq(m_env,0,
"");
3626 std::vector<double> psdResult(0,0.);
3628 unsigned int dataSizeA = (
unsigned int) (doubleFullDataSize * ratioNa);
3629 double doubleDataSizeA = (double) dataSizeA;
3630 unsigned int initialPosA = initialPos;
3631 this->extractScalarSeq(initialPosA,
3635 double meanA = tmpSeq.subMeanExtra(0,
3638 (
unsigned int) std::sqrt((
double) dataSizeA),
3641 double psdA = psdResult[0];
3642 double varOfMeanA = 2.*M_PI*psdA/doubleDataSizeA;
3644 unsigned int dataSizeB = (
unsigned int) (doubleFullDataSize * ratioNb);
3645 double doubleDataSizeB = (double) dataSizeB;
3646 unsigned int initialPosB = this->subSequenceSize() - dataSizeB;
3647 this->extractScalarSeq(initialPosB,
3651 double meanB = tmpSeq.subMeanExtra(0,
3654 (
unsigned int) std::sqrt((
double) dataSizeB),
3657 double psdB = psdResult[0];
3658 double varOfMeanB = 2.*M_PI*psdB/doubleDataSizeB;
3660 if (m_env.subDisplayFile()) {
3661 *m_env.subDisplayFile() <<
"In ScalarSequence<T>::geweke()"
3662 <<
", before computation of gewCoef"
3664 <<
", dataSizeA = " << dataSizeA
3665 <<
", numBlocksA = " << (
unsigned int) std::sqrt((
double) dataSizeA)
3666 << ", meanA = " << meanA
3667 << ", psdA = " << psdA
3668 << ", varOfMeanA = " << varOfMeanA
3670 << ", dataSizeB = " << dataSizeB
3671 << ", numBlocksB = " << (
unsigned int) std::sqrt((
double) dataSizeB)
3672 << ", meanB = " << meanB
3673 << ", psdB = " << psdB
3674 << ", varOfMeanB = " << varOfMeanB
3677 double gewCoef = (meanA - meanB)/std::sqrt(varOfMeanA + varOfMeanB);
3684 ScalarSequence<T>::meanStacc(
3685 unsigned int initialPos)
const
3696 ScalarSequence<T>::subCdfPercentageRange(
3697 unsigned int initialPos,
3698 unsigned int numPos,
3701 T& upperValue)
const
3707 ScalarSequence<T> sortedSequence(m_env,0,
"");;
3708 sortedSequence.resizeSequence(numPos);
3709 this->extractScalarSeq(initialPos,
3713 sortedSequence.subSort();
3715 unsigned int lowerId = (
unsigned int) round( 0.5*(1.-range)*((double) numPos) );
3716 lowerValue = sortedSequence[lowerId];
3718 unsigned int upperId = (
unsigned int) round( 0.5*(1.+range)*((double) numPos) );
3719 if (upperId == numPos) {
3720 upperId = upperId-1;
3723 upperValue = sortedSequence[upperId];
3730 ScalarSequence<T>::unifiedCdfPercentageRange(
3731 bool useOnlyInter0Comm,
3732 unsigned int initialPos,
3733 unsigned int numPos,
3735 T& unifiedLowerValue,
3736 T& unifiedUpperValue)
const
3738 if (m_env.numSubEnvironments() == 1) {
3739 return this->subCdfPercentageRange(initialPos,
3752 if (useOnlyInter0Comm) {
3753 if (m_env.inter0Rank() >= 0) {
3758 this->subCdfPercentageRange(initialPos,
3774 ScalarSequence<T>::subCdfStacc(
3775 unsigned int initialPos,
3776 std::vector<double>& cdfStaccValues,
3777 std::vector<double>& cdfStaccValuesUp,
3778 std::vector<double>& cdfStaccValuesLow,
3779 const ScalarSequence<T>& sortedDataValues)
const
3782 bool bRC = (initialPos < this->subSequenceSize() );
3785 unsigned int numPoints = subSequenceSize()-initialPos;
3786 double auxNumPoints = numPoints;
3787 double maxLamb = 0.;
3788 std::vector<double> ro (numPoints,0.);
3789 std::vector<double> Isam_mat(numPoints,0.);
3791 for (
unsigned int pointId = 0; pointId < numPoints; pointId++) {
3792 double p = ( ((double) pointId) + 1.0 )/auxNumPoints;
3793 double ro0 = p*(1.0-p);
3794 cdfStaccValues[pointId] = p;
3799 for (
unsigned int k = 0;
k < numPoints;
k++) {
3800 if (m_seq[
k] <= sortedDataValues[pointId]) {
3808 for (
unsigned int tau = 0; tau < (numPoints-1); tau++) {
3810 for (
unsigned int kk = 0; kk < numPoints-(tau+1); kk++) {
3811 ro[tau] += (Isam_mat[kk+tau+1]-p)*(Isam_mat[kk]-p);
3813 ro[tau] *= 1.0/auxNumPoints;
3816 for (
unsigned int tau = 0; tau < (numPoints-1); tau++) {
3817 double auxTau = tau;
3818 lamb += (1.-(auxTau+1.)/auxNumPoints)*ro[tau]/ro0;
3819 if (lamb > maxLamb) maxLamb = lamb;
3824 cdfStaccValuesUp [pointId] = cdfStaccValues[pointId]+1.96*sqrt(ro0/auxNumPoints*(1.+lamb));
3825 cdfStaccValuesLow[pointId] = cdfStaccValues[pointId]-1.96*sqrt(ro0/auxNumPoints*(1.+lamb));
3826 if (cdfStaccValuesLow[pointId] < 0.) cdfStaccValuesLow[pointId] = 0.;
3827 if (cdfStaccValuesUp [pointId] > 1.) cdfStaccValuesUp [pointId] = 1.;
3835 unsigned int dataSize = this->subSequenceSize() - initialPos;
3836 unsigned int numEvals = evaluationPositions.size();
3838 for (
unsigned int j = 0; j < numEvals; ++j) {
3839 double x = evaluationPositions[j];
3841 for (
unsigned int k = 0;
k < dataSize; ++
k) {
3842 double xk = m_seq[initialPos+
k];
3845 cdfStaccValues[j] = value/(double) dataSize;
3854 ScalarSequence<T>::subCdfStacc(
3855 unsigned int initialPos,
3856 const std::vector<T>& evaluationPositions,
3857 std::vector<double>& cdfStaccValues)
const
3861 bool bRC = ((initialPos < this->subSequenceSize() ) &&
3862 (0 < evaluationPositions.size()) &&
3863 (evaluationPositions.size() == cdfStaccValues.size() ));
3873 unsigned int dataSize = this->subSequenceSize() - initialPos;
3874 unsigned int numEvals = evaluationPositions.size();
3876 for (
unsigned int j = 0; j < numEvals; ++j) {
3879 for (
unsigned int k = 0;
k < dataSize; ++
k) {
3883 cdfStaccValues[j] = value/(double) dataSize;
3889 #endif // #ifdef QUESO_COMPUTES_EXTRA_POST_PROCESSING_STATISTICS
3899 unsigned int initialPos,
3902 const std::vector<T>& evaluationPositions1,
3903 const std::vector<T>& evaluationPositions2,
3904 std::vector<double>& densityValues)
3908 double covValue = 0.;
3909 double corrValue = 0.;
3918 (0 < evaluationPositions1.size() ) &&
3919 (evaluationPositions1.size() == evaluationPositions2.size() ) &&
3920 (evaluationPositions1.size() == densityValues.size() ));
3924 unsigned int numEvals = evaluationPositions1.size();
3926 double scale1Inv = 1./scaleValue1;
3927 double scale2Inv = 1./scaleValue2;
3929 double r = 1. - corrValue*corrValue;
3931 std::cerr <<
"In ComputeSubGaussian2dKde()"
3932 <<
": WARNING, r = " << r
3939 for (
unsigned int j = 0; j < numEvals; ++j) {
3940 double x1 = evaluationPositions1[j];
3941 double x2 = evaluationPositions2[j];
3943 for (
unsigned int k = 0;
k < dataSize; ++
k) {
3944 double d1k = scale1Inv*(x1 - scalarSeq1[initialPos+
k]);
3945 double d2k = scale2Inv*(x2 - scalarSeq2[initialPos+
k]);
3946 value += exp(-.5*( d1k*d1k + 2*corrValue*d1k*d2k + d2k*d2k )/r);
3948 densityValues[j] = scale1Inv * scale2Inv * (value/(double) dataSize) / 2. / M_PI / sqrt(r);
3959 unsigned int initialPos,
3960 double unifiedScaleValue1,
3961 double unifiedScaleValue2,
3962 const std::vector<T>& unifiedEvaluationPositions1,
3963 const std::vector<T>& unifiedEvaluationPositions2,
3964 std::vector<double>& unifiedDensityValues)
3972 unifiedEvaluationPositions1,
3973 unifiedEvaluationPositions2,
3974 unifiedDensityValues);
3979 if (useOnlyInter0Comm) {
3990 unifiedEvaluationPositions1,
3991 unifiedEvaluationPositions2,
3992 unifiedDensityValues);
4009 unsigned int subNumSamples,
4028 for (
unsigned k = 0;
k < subNumSamples; ++
k) {
4030 tmpP = subPSeq[
k] - unifiedMeanP;
4031 tmpQ = subQSeq[
k] - unifiedMeanQ;
4032 covValue += tmpP*tmpQ;
4048 unsigned int unifiedNumSamples = 0;
4050 "ComputeCovCorrBetweenScalarSequences()",
4051 "failed MPI.Allreduce() for subNumSamples");
4055 "ComputeCovCorrBetweenScalarSequences()",
4056 "failed MPI.Allreduce() for a matrix position");
4057 covValue = aux/((double) (unifiedNumSamples-1));
4059 corrValue = covValue/std::sqrt(unifiedSampleVarianceP)/std::sqrt(unifiedSampleVarianceQ);
4061 if ((corrValue < -1.) || (corrValue > 1.)) {
4062 std::cerr <<
"In ComputeCovCorrBetweenScalarSequences()"
4063 <<
": computed correlation is out of range, corrValue = " << corrValue
void ComputeUnifiedGaussian2dKde(bool useOnlyInter0Comm, const ScalarSequence< T > &scalarSeq1, const ScalarSequence< T > &scalarSeq2, unsigned int initialPos, double unifiedScaleValue1, double unifiedScaleValue2, const std::vector< T > &unifiedEvaluationPositions1, const std::vector< T > &unifiedEvaluationPositions2, std::vector< double > &unifiedDensityValues)
#define SCALAR_SEQUENCE_INIT_MPI_MSG
T autoCorrViaDef(unsigned int initialPos, unsigned int numPos, unsigned int lag) const
Calculates the autocorrelation via definition.
void subUniformlySampledCdf(unsigned int numIntervals, T &minDomainValue, T &maxDomainValue, std::vector< T > &cdfValues) const
Uniformly samples from the CDF from the sub-sequence.
void copy(const ScalarSequence< T > &src)
Copies the scalar sequence src to this.
const T & subMeanPlain() const
Finds the mean value of the sub-sequence of scalars.
#define RawValue_MPI_IN_PLACE
double MiscGaussianDensity(double x, double mu, double sigma)
void ComputeSubGaussian2dKde(const ScalarSequence< T > &scalarSeq1, const ScalarSequence< T > &scalarSeq2, unsigned int initialPos, double scaleValue1, double scaleValue2, const std::vector< T > &evaluationPositions1, const std::vector< T > &evaluationPositions2, std::vector< double > &densityValues)
void setName(const std::string &newName)
Sets a new name to the sequence of scalars.
const T & operator[](unsigned int posId) const
Access position posId of the sequence of scalars (const).
T subInterQuantileRange(unsigned int initialPos) const
Returns the interquartile range of the values in the sub-sequence.
const std::string & name() const
Access to the name of the sequence of scalars.
std::vector< T > & rawData()
The sequence of scalars. Access to private attribute m_seq.
void subBasicCdf(unsigned int numIntervals, UniformOneDGrid< T > *&gridValues, std::vector< T > &cdfValues) const
Finds the Cumulative Distribution Function (CDF) of the sub-sequence of scalars.
void clear()
Clears the sequence of scalars.
std::vector< T >::const_iterator seqScalarPositionConstIteratorTypedef
const T & unifiedMaxPlain(bool useOnlyInter0Comm) const
Finds the maximum value of the unified sequence of scalars.
ScalarSequence< T > & operator=(const ScalarSequence< T > &rhs)
Assignment operator; it copies rhs to this.
T unifiedMeanExtra(bool useOnlyInter0Comm, unsigned int initialPos, unsigned int localNumPos) const
Finds the mean value of the unified sequence of numPos positions starting at position initialPos...
void subHistogram(unsigned int initialPos, const T &minHorizontalValue, const T &maxHorizontalValue, std::vector< T > ¢ers, std::vector< unsigned int > &bins) const
Calculates the histogram of the sub-sequence.
void parallelMerge(std::vector< T > &sortedBuffer, const std::vector< T > &leafData, unsigned int treeLevel) const
Sorts/merges data in parallel using MPI.
MPI_Status RawType_MPI_Status
T autoCovariance(unsigned int initialPos, unsigned int numPos, const T &meanValue, unsigned int lag) const
Calculates the autocovariance.
#define UQ_FILE_EXTENSION_FOR_HDF_FORMAT
const T & unifiedMeanPlain(bool useOnlyInter0Comm) const
Finds the mean value of the unified sequence of scalars.
T subMeanExtra(unsigned int initialPos, unsigned int numPos) const
Finds the mean value of the sub-sequence, considering numPos positions starting at position initialPo...
void resizeSequence(unsigned int newSequenceSize)
Resizes the size of the sequence of scalars.
void ComputeCovCorrBetweenScalarSequences(const ScalarSequence< T > &subPSeq, const ScalarSequence< T > &subQSeq, unsigned int subNumSamples, T &covValue, T &corrValue)
#define RawValue_MPI_ANY_SOURCE
double MiscHammingWindow(unsigned int N, unsigned int j)
const T & unifiedSampleVariancePlain(bool useOnlyInter0Comm) const
Finds the variance of a sample of the unified sequence of scalars.
const T & subMinPlain() const
Finds the minimum value of the sub-sequence of scalars.
std::ofstream * ofsVar
Provides a stream interface to write data to files.
Struct for handling data input and output from files.
T subPositionsOfMaximum(const ScalarSequence< T > &subCorrespondingScalarValues, ScalarSequence< T > &subPositionsOfMaximum)
Finds the positions where the maximum element occurs in the sub-sequence.
void inverse(const std::vector< T > &data, unsigned int fftSize, std::vector< std::complex< double > > &result)
Calculates the inverse Fourier transform for real and complex data.
void subMinMaxExtra(unsigned int initialPos, unsigned int numPos, T &minValue, T &maxValue) const
Finds the minimum and the maximum values of the sub-sequence, considering numPos positions starting a...
void setGaussian(const T &mean, const T &stdDev)
Sets the values of the sequence as a Gaussian distribution of mean given by meanVec and standard devi...
#define queso_require_less_equal_msg(expr1, expr2, msg)
ScalarSequence(const BaseEnvironment &env, unsigned int subSequenceSize, const std::string &name)
Default constructor.
T unifiedPopulationVariance(bool useOnlyInter0Comm, unsigned int initialPos, unsigned int numPos, const T &unifiedMeanValue) const
Finds the population variance of the unified sequence, considering numPos positions starting at posit...
#define queso_error_msg(msg)
unsigned int unifiedSequenceSize(bool useOnlyInter0Comm) const
Size of the unified sequence of scalars.
T subMedianExtra(unsigned int initialPos, unsigned int numPos) const
Finds the median value of the sub-sequence, considering numPos positions starting at position initial...
T unifiedScaleForKde(bool useOnlyInter0Comm, unsigned int initialPos, const T &unifiedIqrValue, unsigned int kdeDimension) const
Selects the scales (bandwidth) for the kernel density estimation, considering the unified sequence...
void append(const ScalarSequence< T > &src, unsigned int srcInitialPos, unsigned int srcNumPos)
Appends the scalar sequence src to this sequence.
unsigned int numSubEnvironments() const
Access function to the number of sub-environments.
void autoCorrViaFft(unsigned int initialPos, unsigned int numPos, unsigned int maxLag, std::vector< T > &autoCorrs) const
Calculates the autocorrelation via Fast Fourier transforms (FFT).
const T & subMaxPlain() const
Finds the maximum value of the sub-sequence of scalars.
int inter0Rank() const
Returns the process inter0 rank.
#define SCALAR_SEQUENCE_DATA_MPI_MSG
T subSampleStd(unsigned int initialPos, unsigned int numPos, const T &meanValue) const
Finds the sample standard deviation of the unified sequence, considering numPos positions starting at...
T subScaleForKde(unsigned int initialPos, const T &iqrValue, unsigned int kdeDimension) const
Selects the scales (output value) for the kernel density estimation, considering only the sub-sequenc...
const T & unifiedMinPlain(bool useOnlyInter0Comm) const
Finds the minimum value of the unified sequence of scalars.
#define queso_require_equal_to_msg(expr1, expr2, msg)
void setUniform(const T &a, const T &b)
Sets the values of the sequence as a uniform distribution between the values given by vectors aVec an...
#define SCALAR_SEQUENCE_SIZE_MPI_MSG
T unifiedPositionsOfMaximum(const ScalarSequence< T > &subCorrespondingScalarValues, ScalarSequence< T > &unifiedPositionsOfMaximum)
Finds the positions where the maximum element occurs in the unified sequence.
double MiscGetEllapsedSeconds(struct timeval *timeval0)
#define queso_require_msg(asserted, msg)
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...
#define queso_require_less_msg(expr1, expr2, msg)
T unifiedInterQuantileRange(bool useOnlyInter0Comm, unsigned int initialPos) const
Returns the interquartile range of the values in the unified sequence.
void unifiedHistogram(bool useOnlyInter0Comm, unsigned int initialPos, const T &unifiedMinHorizontalValue, const T &unifiedMaxHorizontalValue, std::vector< T > &unifiedCenters, std::vector< unsigned int > &unifiedBins) const
Calculates the histogram of the unified sequence.
void extractScalarSeq(unsigned int initialPos, unsigned int spacing, unsigned int numPos, ScalarSequence< T > &scalarSeq) const
Extracts a sequence of scalars.
T unifiedSampleStd(bool useOnlyInter0Comm, unsigned int initialPos, unsigned int localNumPos, const T &unifiedMeanValue) const
Finds the sample standard deviation of the unified sequence, considering localnumPos positions starti...
void erasePositions(unsigned int initialPos, unsigned int numPos)
Erases numPos values of the sequence, starting at position initialPos.
This (virtual) class sets up the environment underlying the use of the QUESO library by an executable...
void unifiedWriteContents(const std::string &fileName, const std::string &fileType) const
Writes the unified sequence to a file.
void extractRawData(unsigned int initialPos, unsigned int spacing, unsigned int numPos, std::vector< double > &rawData) const
Extracts the raw data.
void unifiedGaussian1dKde(bool useOnlyInter0Comm, unsigned int initialPos, double unifiedScaleValue, const std::vector< T > &unifiedEvaluationPositions, std::vector< double > &unifiedDensityValues) const
Gaussian kernel for the KDE estimate of the unified sequence.
#define UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT
T unifiedSampleVarianceExtra(bool useOnlyInter0Comm, unsigned int initialPos, unsigned int localNumPos, const T &unifiedMeanValue) const
Finds the sample variance of the unified sequence, considering numPos positions starting at position ...
Class for accommodating uniform one-dimensional grids.
#define queso_not_implemented()
void unifiedSort(bool useOnlyInter0Comm, unsigned int initialPos, ScalarSequence< T > &unifiedSortedSequence) const
Sorts the unified sequence of scalars.
void deleteStoredScalars()
Deletes all stored scalars.
std::vector< T >::iterator seqScalarPositionIteratorTypedef
T brooksGelmanConvMeasure(bool useOnlyInter0Comm, unsigned int initialPos, unsigned int spacing) const
Estimates convergence rate using Brooks & Gelman method.
~ScalarSequence()
Destructor.
void subSort()
Sorts the sequence of scalars in the private attribute m_seq.
const MpiComm & inter0Comm() const
Access function for MpiComm inter0-communicator.
void subWeightCdf(unsigned int numIntervals, std::vector< T > &gridValues, std::vector< T > &cdfValues) const
Finds the Weighted Cumulative Distribution Function (CDF) of the sub-sequence of scalars.
void unifiedUniformlySampledCdf(bool useOnlyInter0Comm, unsigned int numIntervals, T &unifiedMinDomainValue, T &unifiedMaxDomainValue, std::vector< T > &unifiedCdfValues) const
Uniformly samples from the CDF from the unified sequence.
void subSort(unsigned int initialPos, ScalarSequence< T > &sortedSequence) const
Sorts the sub-sequence of scalars.
void forward(const std::vector< T > &data, unsigned int fftSize, std::vector< std::complex< double > > &result)
Calculates the forward Fourier transform (for real data. TODO: complex data).
#define queso_require_greater_equal_msg(expr1, expr2, msg)
std::ifstream * ifsVar
Provides a stream interface to read data from files.
const BaseEnvironment & env() const
Access to QUESO environment.
Class for a Fast Fourier Transform (FFT) algorithm.
const T & subSampleVariancePlain() const
Finds the variance of a sample of the sub-sequence of scalars.
void subWriteContents(unsigned int initialPos, unsigned int numPos, const std::string &fileName, const std::string &fileType, const std::set< unsigned int > &allowedSubEnvIds) const
Writes the sub-sequence to a file.
void subGaussian1dKde(unsigned int initialPos, double scaleValue, const std::vector< T > &evaluationPositions, std::vector< double > &densityValues) const
Gaussian kernel for the KDE estimate of the sub-sequence.
void getUnifiedContentsAtProc0Only(bool useOnlyInter0Comm, std::vector< T > &outputVec) const
Gets the unified contents of processor of rank equals to 0.
T subPopulationVariance(unsigned int initialPos, unsigned int numPos, const T &meanValue) const
Finds the population variance of the sub-sequence, considering numPos positions starting at position ...
Class for handling scalar samples.
void subBasicHistogram(unsigned int initialPos, const T &minHorizontalValue, const T &maxHorizontalValue, UniformOneDGrid< T > *&gridValues, std::vector< unsigned int > &bins) const
Calculates the histogram of the sub-sequence.
unsigned int subSequenceSize() const
Size of the sub-sequence of scalars.
#define RawValue_MPI_DOUBLE
const T & subMedianPlain() const
Finds the median value of the sub-sequence of scalars.
void resetValues(unsigned int initialPos, unsigned int)
Sets numPos values of the sequence to zero, starting at position initialPos.
void Allreduce(void *sendbuf, void *recvbuf, int count, RawType_MPI_Datatype datatype, RawType_MPI_Op op, const char *whereMsg, const char *whatMsg) const
Combines values from all processes and distributes the result back to all processes.
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...
and that you are informed that you can do these things To protect your we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it For if you distribute copies of the whether gratis or for a you must give the recipients all the rights that we gave you You must make sure that receive or can get the source code If you link other code with the you must provide complete object files to the so that they can relink them with the library after making changes to the library and recompiling it And you must show them these terms so they know their rights We protect your rights with a two step which gives you legal permission to copy
#define RawValue_MPI_UNSIGNED
void subWeightHistogram(unsigned int initialPos, const T &minHorizontalValue, const T &maxHorizontalValue, UniformOneDGrid< T > *&gridValues, std::vector< unsigned int > &bins) const
Calculates the weighted histogram of the sub-sequence.
void filter(unsigned int initialPos, unsigned int spacing)
Filters positions in the sequence of vectors.
const T & unifiedMedianPlain(bool useOnlyInter0Comm) const
Finds the median value of the unified sequence of scalars.
T unifiedMedianExtra(bool useOnlyInter0Comm, unsigned int initialPos, unsigned int localNumPos) const
Finds the median value of the unified sequence, considering numPos positions starting at position ini...
void unifiedReadContents(const std::string &fileName, const std::string &fileType, const unsigned int subSequenceSize)
Reads the unified sequence from a file.