25 #include <queso/MLSampling.h>
26 #include <queso/InstantiateIntersection.h>
27 #include <queso/GslVector.h>
28 #include <queso/GslMatrix.h>
34 void BIP_routine(glp_tree *tree,
void *info)
36 const BaseEnvironment& env = *(((BIP_routine_struct *) info)->env);
37 unsigned int currLevel = ((BIP_routine_struct *) info)->currLevel;
39 int reason = glp_ios_reason(tree);
41 if ((env.subDisplayFile()) && (env.displayVerbosity() >= 1)) {
42 *env.subDisplayFile() <<
"In BIP_routine()"
44 <<
": glp_ios_reason() = " << reason
47 std::cout <<
"In BIP_routine: reason = " << reason << std::endl;
86 #endif // QUESO_HAS_GLPK
88 template <
class P_V,
class P_M>
91 unsigned int unifiedRequestedNumSamples,
92 const std::vector<double>& unifiedWeightStdVectorAtProc0Only,
93 std::vector<unsigned int>& unifiedIndexCountersAtProc0Only)
95 if (m_env.inter0Rank() != 0)
return;
97 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
98 *m_env.subDisplayFile() <<
"Entering MLSampling<P_V,P_M>::sampleIndexes_proc0()"
100 <<
", step " << m_currStep
101 <<
": unifiedRequestedNumSamples = " << unifiedRequestedNumSamples
102 <<
", unifiedWeightStdVectorAtProc0Only.size() = " << unifiedWeightStdVectorAtProc0Only.size()
106 #if 0 // For debug only
107 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
108 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::sampleIndexes_proc0()"
110 <<
", step " << m_currStep
113 unsigned int numZeros = 0;
114 for (
unsigned int i = 0; i < unifiedWeightStdVectorAtProc0Only.size(); ++i) {
115 *m_env.subDisplayFile() <<
" unifiedWeightStdVectorAtProc0Only[" << i
116 <<
"] = " << unifiedWeightStdVectorAtProc0Only[i]
118 if (unifiedWeightStdVectorAtProc0Only[i] == 0.) numZeros++;
120 *m_env.subDisplayFile() <<
"Number of zeros in unifiedWeightStdVectorAtProc0Only = " << numZeros
125 if (m_env.inter0Rank() == 0) {
126 unsigned int resizeSize = unifiedWeightStdVectorAtProc0Only.size();
127 unifiedIndexCountersAtProc0Only.resize(resizeSize,0);
132 unifiedWeightStdVectorAtProc0Only);
133 for (
unsigned int i = 0; i < unifiedRequestedNumSamples; ++i) {
134 unsigned int index = tmpFd.
sample();
135 unifiedIndexCountersAtProc0Only[index] += 1;
142 template <
class P_V,
class P_M>
146 unsigned int indexOfFirstWeight,
147 unsigned int indexOfLastWeight,
148 const std::vector<unsigned int>& unifiedIndexCountersAtProc0Only,
149 std::vector<ExchangeInfoStruct>& exchangeStdVec)
153 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
154 *m_env.subDisplayFile() <<
"Entering MLSampling<P_V,P_M>::decideOnBalancedChains_all()"
156 <<
", step " << m_currStep
157 <<
": indexOfFirstWeight = " << indexOfFirstWeight
158 <<
", indexOfLastWeight = " << indexOfLastWeight
164 if (m_env.inter0Rank() >= 0) {
165 Np = (
unsigned int) m_env.inter0Comm().NumProc();
167 std::vector<unsigned int> allFirstIndexes(Np,0);
168 std::vector<unsigned int> allLastIndexes(Np,0);
170 if (m_env.inter0Rank() >= 0) {
174 unsigned int auxUInt = indexOfFirstWeight;
176 "MLSampling<P_V,P_M>::decideOnBalancedChains_all()",
177 "failed MPI.Gather() for first indexes");
179 if (m_env.inter0Rank() == 0) {
180 queso_require_equal_to_msg(allFirstIndexes[0], indexOfFirstWeight,
"failed MPI.Gather() result for first indexes, at proc 0");
183 auxUInt = indexOfLastWeight;
185 "MLSampling<P_V,P_M>::decideOnBalancedChains_all()",
186 "failed MPI.Gather() for last indexes");
188 if (m_env.inter0Rank() == 0) {
197 if (m_env.inter0Rank() == 0) {
198 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
199 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::decideOnBalancedChains_all()"
201 <<
", step " << m_currStep
202 <<
": original distribution of unified indexes in 'inter0Comm' is as follows"
204 for (
unsigned int r = 0; r < Np; ++r) {
205 *m_env.subDisplayFile() <<
" allFirstIndexes[" << r <<
"] = " << allFirstIndexes[r]
206 <<
" allLastIndexes[" << r <<
"] = " << allLastIndexes[r]
210 for (
unsigned int r = 0; r < (Np-1); ++r) {
214 for (
unsigned int r = 0; r < (Np-1); ++r) {
218 std::vector<unsigned int> origNumChainsPerNode (Np,0);
219 std::vector<unsigned int> origNumPositionsPerNode(Np,0);
221 for (
unsigned int i = 0; i < unifiedIndexCountersAtProc0Only.size(); ++i) {
222 if ((allFirstIndexes[r] <= i) &&
223 (i <= allLastIndexes[r] )) {
228 if ((r < (
int) Np ) &&
229 (allFirstIndexes[r] <= i) &&
230 (i <= allLastIndexes[r] )) {
234 std::cerr <<
"In MLSampling<P_V,P_M>::decideOnBalancedChains_all()"
237 <<
", allFirstIndexes[r] = " << allFirstIndexes[r]
238 <<
", allLastIndexes[r] = " << allLastIndexes[r]
243 if (unifiedIndexCountersAtProc0Only[i] != 0) {
244 origNumChainsPerNode [r] += 1;
245 origNumPositionsPerNode[r] += unifiedIndexCountersAtProc0Only[i];
252 exchangeStdVec.push_back(auxInfo);
258 unsigned int totalNumberOfChains = 0;
259 for (
unsigned int r = 0; r < Np; ++r) {
260 totalNumberOfChains += origNumChainsPerNode[r];
262 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
263 *m_env.subDisplayFile() <<
" KEY"
265 <<
", step " << m_currStep
267 <<
", totalNumberOfChains = " << totalNumberOfChains
272 unsigned int origMinPosPerNode = *std::min_element(origNumPositionsPerNode.begin(), origNumPositionsPerNode.end());
273 unsigned int origMaxPosPerNode = *std::max_element(origNumPositionsPerNode.begin(), origNumPositionsPerNode.end());
274 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
275 for (
unsigned int nodeId = 0; nodeId < Np; ++nodeId) {
276 *m_env.subDisplayFile() <<
" KEY"
278 <<
", step " << m_currStep
279 <<
", origNumChainsPerNode[" << nodeId <<
"] = " << origNumChainsPerNode[nodeId]
280 <<
", origNumPositionsPerNode[" << nodeId <<
"] = " << origNumPositionsPerNode[nodeId]
284 double origRatioOfPosPerNode = ((double) origMaxPosPerNode ) / ((double) origMinPosPerNode);
285 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
286 *m_env.subDisplayFile() <<
" KEY"
288 <<
", step " << m_currStep
289 <<
", origRatioOfPosPerNode = " << origRatioOfPosPerNode
297 (m_env.numSubEnvironments() > 1 ) &&
298 (Np < totalNumberOfChains ) &&
305 m_env.fullComm().Barrier();
306 unsigned int tmpValue = result;
308 "MLSampling<P_V,P_M>::decideOnBalancedChains_all()",
309 "failed MPI.Bcast() for 'result'");
310 if (m_env.inter0Rank() != 0) result = tmpValue;
312 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
313 *m_env.subDisplayFile() <<
"Leaving MLSampling<P_V,P_M>::decideOnBalancedChains_all()"
315 <<
", step " << m_currStep
316 <<
": result = " << result
323 template <
class P_V,
class P_M>
332 std::vector<ExchangeInfoStruct>& exchangeStdVec,
335 if (m_env.inter0Rank() < 0)
return;
337 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
338 *m_env.subDisplayFile() <<
"Entering MLSampling<P_V,P_M>::prepareBalLinkedChains_inter0()"
340 <<
", step " << m_currStep
344 unsigned int Np = (
unsigned int) m_env.inter0Comm().NumProc();
345 if (m_env.inter0Rank() == 0) {
348 justBalance_proc0(currOptions,
354 #ifdef QUESO_HAS_GLPK
356 solveBIP_proc0(exchangeStdVec);
358 if (m_env.subDisplayFile()) {
359 *m_env.subDisplayFile() <<
"WARNING in MLSampling<P_V,P_M>::prepareBalLinkedChains_inter0()"
361 <<
"' has been requested, but this QUESO library has not been built with 'hdf5'"
362 <<
". Code will therefore process the algorithm id '" << 2
366 if (m_env.subRank() == 0) {
367 std::cerr <<
"WARNING in MLSampling<P_V,P_M>::prepareBalLinkedChains_inter0()"
369 <<
"' has been requested, but this QUESO library has not been built with 'hdf5'"
370 <<
". Code will therefore process the algorithm id '" << 2
374 justBalance_proc0(currOptions,
381 m_env.inter0Comm().Barrier();
386 unsigned int exchangeStdVecSize = exchangeStdVec.size();
388 "MLSampling<P_V,P_M>::prepareBalLinkedChains_inter0()",
389 "failed MPI.Bcast() for exchangeStdVec size");
390 if (m_env.inter0Rank() > 0) exchangeStdVec.resize(exchangeStdVecSize);
393 "MLSampling<P_V,P_M>::prepareBalLinkedChains_inter0()",
394 "failed MPI.Bcast() for exchangeStdVec data");
399 std::vector<unsigned int> finalNumChainsPerNode (Np,0);
400 std::vector<unsigned int> finalNumPositionsPerNode(Np,0);
401 unsigned int Nc = exchangeStdVec.size();
402 for (
unsigned int chainId = 0; chainId < Nc; ++chainId) {
403 unsigned int nodeId = exchangeStdVec[chainId].finalNodeOfInitialPosition;
404 finalNumChainsPerNode [nodeId] += 1;
405 finalNumPositionsPerNode[nodeId] += exchangeStdVec[chainId].numberOfPositions;
411 unsigned int finalMinPosPerNode = *std::min_element(finalNumPositionsPerNode.begin(), finalNumPositionsPerNode.end());
412 unsigned int finalMaxPosPerNode = *std::max_element(finalNumPositionsPerNode.begin(), finalNumPositionsPerNode.end());
413 double finalRatioOfPosPerNode = ((double) finalMaxPosPerNode) / ((double)finalMinPosPerNode);
416 std::vector<double> auxBuf(1,0.);
417 double minRatio = 0.;
418 auxBuf[0] = finalRatioOfPosPerNode;
420 "MLSampling<P_V,P_M>::prepareBalLinkedChains_inter0()",
421 "failed MPI.Allreduce() for min");
425 double maxRatio = 0.;
426 auxBuf[0] = finalRatioOfPosPerNode;
428 "MLSampling<P_V,P_M>::prepareBalLinkedChains_inter0()",
429 "failed MPI.Allreduce() for max");
436 unsigned int finalNumChainsPerNodeSize = finalNumChainsPerNode.size();
438 "MLSampling<P_V,P_M>::prepareBalLinkedChains_inter0()",
439 "failed MPI.Bcast() for finalNumChainsPerNode size");
440 if (m_env.inter0Rank() > 0) finalNumChainsPerNode.resize(finalNumChainsPerNodeSize);
442 m_env.inter0Comm().Bcast((
void *) &finalNumChainsPerNode[0], (
int) finalNumChainsPerNodeSize,
RawValue_MPI_UNSIGNED, 0,
443 "MLSampling<P_V,P_M>::prepareBalLinkedChains_inter0()",
444 "failed MPI.Bcast() for finalNumChainsPerNode data");
450 mpiExchangePositions_inter0(prevChain,
453 prevLogLikelihoodValues,
456 finalNumChainsPerNode,
457 finalNumPositionsPerNode,
458 balancedLinkControl);
463 template <
class P_V,
class P_M>
466 unsigned int indexOfFirstWeight,
467 unsigned int indexOfLastWeight,
468 const std::vector<unsigned int>& unifiedIndexCountersAtProc0Only,
471 if (m_env.inter0Rank() < 0)
return;
473 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
474 *m_env.subDisplayFile() <<
"Entering MLSampling<P_V,P_M>::prepareUnbLinkedChains_inter0()"
476 <<
", step " << m_currStep
477 <<
": indexOfFirstWeight = " << indexOfFirstWeight
478 <<
", indexOfLastWeight = " << indexOfLastWeight
482 unsigned int subNumSamples = 0;
483 std::vector<unsigned int> unifiedIndexCountersAtAllProcs(0);
486 unsigned int resizeSize = unifiedIndexCountersAtProc0Only.size();
488 "MLSampling<P_V,P_M>::prepareUnbLinkedChains_inter0()",
489 "failed MPI.Bcast() for resizeSize");
490 unifiedIndexCountersAtAllProcs.resize(resizeSize,0);
492 if (m_env.inter0Rank() == 0) unifiedIndexCountersAtAllProcs = unifiedIndexCountersAtProc0Only;
495 m_env.inter0Comm().Bcast((
void *) &unifiedIndexCountersAtAllProcs[0], (
int) unifiedIndexCountersAtAllProcs.size(),
RawValue_MPI_UNSIGNED, 0,
496 "MLSampling<P_V,P_M>::prepareUnbLinkedChains_inter0()",
497 "failed MPI.Bcast() for unified index counters");
498 #if 0 // Use allgatherv ??? for subNumSamples instead
499 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
500 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::prepareUnbLinkedChains_inter0()"
502 <<
", step " << m_currStep
505 for (
int r = 0; r < m_env.inter0Comm().NumProc(); ++r) {
506 *m_env.subDisplayFile() <<
" unifiedIndexCountersAtAllProcs[" << r <<
"] = " << unifiedIndexCountersAtAllProcs[r]
518 queso_require_less_msg(indexOfFirstWeight, unifiedIndexCountersAtAllProcs.size(),
"invalid indexOfFirstWeight");
519 queso_require_less_msg(indexOfLastWeight, unifiedIndexCountersAtAllProcs.size(),
"invalid indexOfLastWeight");
521 for (
unsigned int i = indexOfFirstWeight; i <= indexOfLastWeight; ++i) {
522 subNumSamples += unifiedIndexCountersAtAllProcs[i];
525 std::vector<unsigned int> auxBuf(1,0);
527 unsigned int minModifiedSubNumSamples = 0;
528 auxBuf[0] = subNumSamples;
530 "MLSampling<P_V,P_M>::prepareUnbLinkedChains_inter0()",
531 "failed MPI.Allreduce() for min");
533 unsigned int maxModifiedSubNumSamples = 0;
534 auxBuf[0] = subNumSamples;
536 "MLSampling<P_V,P_M>::prepareUnbLinkedChains_inter0()",
537 "failed MPI.Allreduce() for max");
539 unsigned int sumModifiedSubNumSamples = 0;
540 auxBuf[0] = subNumSamples;
542 "MLSampling<P_V,P_M>::prepareUnbLinkedChains_inter0()",
543 "failed MPI.Allreduce() for sum");
550 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
551 *m_env.subDisplayFile() <<
"KEY Leaving MLSampling<P_V,P_M>::prepareUnbLinkedChains_inter0()"
553 <<
", step " << m_currStep
554 <<
": subNumSamples = " << subNumSamples
555 <<
", unifiedIndexCountersAtAllProcs.size() = " << unifiedIndexCountersAtAllProcs.size()
557 *m_env.subDisplayFile() <<
"KEY Leaving MLSampling<P_V,P_M>::prepareUnbLinkedChains_inter0()"
559 <<
", step " << m_currStep
560 <<
": minModifiedSubNumSamples = " << minModifiedSubNumSamples
561 <<
", avgModifiedSubNumSamples = " << ((double) sumModifiedSubNumSamples)/((double) m_env.inter0Comm().NumProc())
562 <<
", maxModifiedSubNumSamples = " << maxModifiedSubNumSamples
566 unsigned int numberOfPositionsToGuaranteeForNode = subNumSamples;
567 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
568 *m_env.subDisplayFile() <<
"KEY In MLSampling<P_V,P_M>::prepareUnbLinkedChains_inter0()"
570 <<
", step " << m_currStep
571 <<
": numberOfPositionsToGuaranteeForNode = " << numberOfPositionsToGuaranteeForNode
574 for (
unsigned int i = indexOfFirstWeight; i <= indexOfLastWeight; ++i) {
576 while (unifiedIndexCountersAtAllProcs[i] != 0) {
577 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 30)) {
578 *m_env.subDisplayFile() <<
", numberOfPositionsToGuaranteeForNode = " << numberOfPositionsToGuaranteeForNode
579 <<
", unifiedIndexCountersAtAllProcs[" << i
580 <<
"] = " << unifiedIndexCountersAtAllProcs[i]
583 if (unifiedIndexCountersAtAllProcs[i] < numberOfPositionsToGuaranteeForNode) {
589 numberOfPositionsToGuaranteeForNode -= unifiedIndexCountersAtAllProcs[i];
590 unifiedIndexCountersAtAllProcs[i] = 0;
592 else if ((unifiedIndexCountersAtAllProcs[i] == numberOfPositionsToGuaranteeForNode) &&
593 (unifiedIndexCountersAtAllProcs[i] > 0 )) {
600 unifiedIndexCountersAtAllProcs[i] -= numberOfPositionsToGuaranteeForNode;
601 numberOfPositionsToGuaranteeForNode = 0;
603 else if ((unifiedIndexCountersAtAllProcs[i] == numberOfPositionsToGuaranteeForNode) &&
604 (unifiedIndexCountersAtAllProcs[i] == 0 )) {
612 queso_require_equal_to_msg(numberOfPositionsToGuaranteeForNode, 0,
"numberOfPositionsToGuaranteeForNode exited loop with wrong value");
615 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
616 *m_env.subDisplayFile() <<
"KEY Leaving MLSampling<P_V,P_M>::prepareUnbLinkedChains_inter0()"
618 <<
", step " << m_currStep
619 <<
": unbalancedLinkControl.unbLinkedChains.size() = " << unbalancedLinkControl.
unbLinkedChains.size()
626 template <
class P_V,
class P_M>
630 const P_M& unifiedCovMatrix,
634 double& cumulativeRunTime,
635 unsigned int& cumulativeRejections,
639 m_env.fullComm().Barrier();
641 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
642 *m_env.subDisplayFile() <<
"Entering MLSampling<P_V,P_M>::generateBalLinkedChains_all()"
643 <<
": balancedLinkControl.balLinkedChains.size() = " << balancedLinkControl.
balLinkedChains.size()
647 P_V auxInitialPosition(m_vectorSpace.zeroVector());
648 double auxInitialLogPrior;
649 double auxInitialLogLikelihood;
651 unsigned int chainIdMax = 0;
652 if (m_env.inter0Rank() >= 0) {
657 "MLSampling<P_V,P_M>::generateBalLinkedChains_all()",
658 "failed MPI.Bcast() for chainIdMax");
660 struct timeval timevalEntering;
662 iRC = gettimeofday(&timevalEntering, NULL);
665 if (m_env.inter0Rank() >= 0) {
666 unsigned int numberOfPositions = 0;
667 for (
unsigned int chainId = 0; chainId < chainIdMax; ++chainId) {
668 numberOfPositions += balancedLinkControl.
balLinkedChains[chainId].numberOfPositions;
671 std::vector<unsigned int> auxBuf(1,0);
673 unsigned int minNumberOfPositions = 0;
674 auxBuf[0] = numberOfPositions;
676 "MLSampling<P_V,P_M>::generateBalLinkedChains_all()",
677 "failed MPI.Allreduce() for min");
679 unsigned int maxNumberOfPositions = 0;
680 auxBuf[0] = numberOfPositions;
682 "MLSampling<P_V,P_M>::generateBalLinkedChains_all()",
683 "failed MPI.Allreduce() for max");
685 unsigned int sumNumberOfPositions = 0;
686 auxBuf[0] = numberOfPositions;
688 "MLSampling<P_V,P_M>::generateBalLinkedChains_all()",
689 "failed MPI.Allreduce() for sum");
691 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
692 *m_env.subDisplayFile() <<
"KEY In MLSampling<P_V,P_M>::generateBalLinkedChains_all()"
694 <<
", step " << m_currStep
695 <<
": chainIdMax = " << chainIdMax
696 <<
", numberOfPositions = " << numberOfPositions
697 <<
", at " << ctime(&timevalEntering.tv_sec)
699 *m_env.subDisplayFile() <<
"KEY In MLSampling<P_V,P_M>::generateBalLinkedChains_all()"
701 <<
", step " << m_currStep
702 <<
": minNumberOfPositions = " << minNumberOfPositions
703 <<
", avgNumberOfPositions = " << ((double) sumNumberOfPositions)/((double) m_env.inter0Comm().NumProc())
704 <<
", maxNumberOfPositions = " << maxNumberOfPositions
710 if ((m_debugExponent == 1.) &&
711 (m_currStep == 10)) {
714 unsigned int cumulativeNumPositions = 0;
715 for (
unsigned int chainId = 0; chainId < chainIdMax; ++chainId) {
716 unsigned int tmpChainSize = 0;
717 if (m_env.inter0Rank() >= 0) {
719 auxInitialPosition = *(balancedLinkControl.
balLinkedChains[chainId].initialPosition);
720 auxInitialLogPrior = balancedLinkControl.
balLinkedChains[chainId].initialLogPrior;
721 auxInitialLogLikelihood = balancedLinkControl.
balLinkedChains[chainId].initialLogLikelihood;
722 tmpChainSize = balancedLinkControl.
balLinkedChains[chainId].numberOfPositions+1;
723 if ((m_env.subDisplayFile() ) &&
724 (m_env.displayVerbosity() >= 3)) {
725 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateBalLinkedChains_all()"
727 <<
", step " << m_currStep
728 <<
", chainId = " << chainId
729 <<
" < " << chainIdMax
730 <<
": begin generating " << tmpChainSize
731 <<
" chain positions"
735 auxInitialPosition.mpiBcast(0, m_env.subComm());
737 #if 0 // For debug only
738 for (
int r = 0; r < m_env.subComm().NumProc(); ++r) {
739 if (r == m_env.subComm().MyPID()) {
740 std::cout <<
"Vector 'auxInitialPosition at rank " << r
741 <<
" has contents " << auxInitialPosition
744 m_env.subComm().Barrier();
751 "MLSampling<P_V,P_M>::generateBalLinkedChains_all()",
752 "failed MPI.Bcast() for tmpChainSize");
757 m_options.m_prefix+
"tmp_chain");
764 "MLSamplingClass<P_V,P_M>::generateBalLinkedChains_all()",
765 "failed MPI.Bcast() for auxInitialLogPrior");
767 "MLSamplingClass<P_V,P_M>::generateBalLinkedChains_all()",
768 "failed MPI.Bcast() for auxInitialLogLikelihood");
774 auxInitialLogLikelihood,
777 &tmpLogLikelihoodValues,
778 &tmpLogTargetValues);
787 &tmpLogLikelihoodValues,
788 &tmpLogTargetValues);
792 cumulativeRunTime += mcRawInfo.
runTime;
795 if (m_env.inter0Rank() >= 0) {
796 if (m_env.exceptionalCircumstance()) {
797 if ((m_env.subDisplayFile() ) &&
798 (m_env.displayVerbosity() >= 0)) {
799 P_V tmpVec(m_vectorSpace.zeroVector());
800 for (
unsigned int i = 0; i < tmpLogLikelihoodValues.
subSequenceSize(); ++i) {
802 *m_env.subDisplayFile() <<
"DEBUG finalChain[" << cumulativeNumPositions+i <<
"] "
803 <<
"= tmpChain[" << i <<
"] = " << tmpVec
804 <<
", tmpLogLikelihoodValues[" << i <<
"] = " << tmpLogLikelihoodValues[i]
805 <<
", tmpLogTargetValues[" << i <<
"] = " << tmpLogTargetValues[i]
811 cumulativeNumPositions += tmpChainSize;
812 if (cumulativeNumPositions > 100) m_env.setExceptionalCircumstance(
false);
814 if ((m_env.subDisplayFile() ) &&
815 (m_env.displayVerbosity() >= 3)) {
816 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateBalLinkedChains_all()"
818 <<
", step " << m_currStep
819 <<
", chainId = " << chainId
820 <<
" < " << chainIdMax
822 <<
" chain positions"
828 if (currLogLikelihoodValues) {
829 currLogLikelihoodValues->
append(tmpLogLikelihoodValues,1,tmpLogLikelihoodValues.
subSequenceSize()-1);
830 if ((m_env.subDisplayFile() ) &&
831 (m_env.displayVerbosity() >= 99) &&
833 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateBalLinkedChains_all()"
835 <<
", step " << m_currStep
836 <<
", chainId = " << chainId
837 <<
", tmpLogLikelihoodValues.subSequenceSize() = " << tmpLogLikelihoodValues.
subSequenceSize()
838 <<
", tmpLogLikelihoodValues[0] = " << tmpLogLikelihoodValues[0]
839 <<
", tmpLogLikelihoodValues[1] = " << tmpLogLikelihoodValues[1]
840 <<
", currLogLikelihoodValues[0] = " << (*currLogLikelihoodValues)[0]
844 if (currLogTargetValues) {
853 struct timeval timevalBarrier;
854 iRC = gettimeofday(&timevalBarrier, NULL);
857 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
858 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateBalLinkedChains_all()"
860 <<
", step " << m_currStep
861 <<
": ended chain loop after " << loopTime <<
" seconds"
862 <<
", calling fullComm().Barrier() at " << ctime(&timevalBarrier.tv_sec)
866 m_env.fullComm().Barrier();
868 struct timeval timevalLeaving;
869 iRC = gettimeofday(&timevalLeaving, NULL);
872 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
873 *m_env.subDisplayFile() <<
"Leaving MLSampling<P_V,P_M>::generateBalLinkedChains_all()"
875 <<
", step " << m_currStep
876 <<
": after " << barrierTime <<
" seconds in fullComm().Barrier()"
877 <<
", at " << ctime(&timevalLeaving.tv_sec)
884 template <
class P_V,
class P_M>
888 const P_M& unifiedCovMatrix,
891 unsigned int indexOfFirstWeight,
898 double& cumulativeRunTime,
899 unsigned int& cumulativeRejections,
903 m_env.fullComm().Barrier();
905 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
906 *m_env.subDisplayFile() <<
"Entering MLSampling<P_V,P_M>::generateUnbLinkedChains_all()"
907 <<
": unbalancedLinkControl.unbLinkedChains.size() = " << unbalancedLinkControl.
unbLinkedChains.size()
908 <<
", indexOfFirstWeight = " << indexOfFirstWeight
912 P_V auxInitialPosition(m_vectorSpace.zeroVector());
913 double auxInitialLogPrior;
914 double auxInitialLogLikelihood;
916 unsigned int chainIdMax = 0;
917 if (m_env.inter0Rank() >= 0) {
922 "MLSampling<P_V,P_M>::generateUnbLinkedChains_all()",
923 "failed MPI.Bcast() for chainIdMax");
925 struct timeval timevalEntering;
927 iRC = gettimeofday(&timevalEntering, NULL);
930 if (m_env.inter0Rank() >= 0) {
931 unsigned int numberOfPositions = 0;
932 for (
unsigned int chainId = 0; chainId < chainIdMax; ++chainId) {
933 numberOfPositions += unbalancedLinkControl.
unbLinkedChains[chainId].numberOfPositions;
936 std::vector<unsigned int> auxBuf(1,0);
938 unsigned int minNumberOfPositions = 0;
939 auxBuf[0] = numberOfPositions;
941 "MLSampling<P_V,P_M>::generateUnbLinkedChains_all()",
942 "failed MPI.Allreduce() for min");
944 unsigned int maxNumberOfPositions = 0;
945 auxBuf[0] = numberOfPositions;
947 "MLSampling<P_V,P_M>::generateUnbLinkedChains_all()",
948 "failed MPI.Allreduce() for max");
950 unsigned int sumNumberOfPositions = 0;
951 auxBuf[0] = numberOfPositions;
953 "MLSampling<P_V,P_M>::generateUnbLinkedChains_all()",
954 "failed MPI.Allreduce() for sum");
956 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
957 *m_env.subDisplayFile() <<
"KEY In MLSampling<P_V,P_M>::generateUnbLinkedChains_all()"
959 <<
", step " << m_currStep
960 <<
": chainIdMax = " << chainIdMax
961 <<
", numberOfPositions = " << numberOfPositions
962 <<
", at " << ctime(&timevalEntering.tv_sec)
964 *m_env.subDisplayFile() <<
"KEY In MLSampling<P_V,P_M>::generateUnbLinkedChains_all()"
966 <<
", step " << m_currStep
967 <<
": minNumberOfPositions = " << minNumberOfPositions
968 <<
", avgNumberOfPositions = " << ((double) sumNumberOfPositions)/((double) m_env.inter0Comm().NumProc())
969 <<
", maxNumberOfPositions = " << maxNumberOfPositions
973 if ((m_debugExponent == 1.) &&
974 (m_currStep == 10)) {
977 double expRatio = currExponent;
978 if (prevExponent > 0.0) {
979 expRatio /= prevExponent;
981 unsigned int cumulativeNumPositions = 0;
982 for (
unsigned int chainId = 0; chainId < chainIdMax; ++chainId) {
983 unsigned int tmpChainSize = 0;
984 if (m_env.inter0Rank() >= 0) {
985 unsigned int auxIndex = unbalancedLinkControl.
unbLinkedChains[chainId].initialPositionIndexInPreviousChain - indexOfFirstWeight;
987 auxInitialLogPrior = prevLogTargetValues[auxIndex] - prevLogLikelihoodValues[auxIndex];
988 auxInitialLogLikelihood = expRatio * prevLogLikelihoodValues[auxIndex];
989 tmpChainSize = unbalancedLinkControl.
unbLinkedChains[chainId].numberOfPositions+1;
990 if ((m_env.subDisplayFile() ) &&
991 (m_env.displayVerbosity() >= 3)) {
992 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateUnbLinkedChains_all()"
994 <<
", step " << m_currStep
995 <<
", chainId = " << chainId
996 <<
" < " << chainIdMax
997 <<
": begin generating " << tmpChainSize
998 <<
" chain positions"
1002 auxInitialPosition.mpiBcast(0, m_env.subComm());
1004 #if 0 // For debug only
1005 for (
int r = 0; r < m_env.subComm().NumProc(); ++r) {
1006 if (r == m_env.subComm().MyPID()) {
1007 std::cout <<
"Vector 'auxInitialPosition at rank " << r
1008 <<
" has contents " << auxInitialPosition
1011 m_env.subComm().Barrier();
1018 "MLSampling<P_V,P_M>::generateUnbLinkedChains_all()",
1019 "failed MPI.Bcast() for tmpChainSize");
1024 m_options.m_prefix+
"tmp_chain");
1032 "MLSamplingClass<P_V,P_M>::generateUnbLinkedChains_all()",
1033 "failed MPI.Bcast() for auxInitialLogPrior");
1035 "MLSamplingClass<P_V,P_M>::generateUnbLinkedChains_all",
1036 "failed MPI.Bcast() for auxInitialLogLikelihood");
1041 auxInitialLogLikelihood,
1044 &tmpLogLikelihoodValues,
1045 &tmpLogTargetValues);
1054 &tmpLogLikelihoodValues,
1055 &tmpLogTargetValues);
1059 cumulativeRunTime += mcRawInfo.
runTime;
1062 if (m_env.inter0Rank() >= 0) {
1063 if (m_env.exceptionalCircumstance()) {
1064 if ((m_env.subDisplayFile() ) &&
1065 (m_env.displayVerbosity() >= 0)) {
1066 P_V tmpVec(m_vectorSpace.zeroVector());
1067 for (
unsigned int i = 0; i < tmpLogLikelihoodValues.
subSequenceSize(); ++i) {
1069 *m_env.subDisplayFile() <<
"DEBUG finalChain[" << cumulativeNumPositions+i <<
"] "
1070 <<
"= tmpChain[" << i <<
"] = " << tmpVec
1071 <<
", tmpLogLikelihoodValues[" << i <<
"] = " << tmpLogLikelihoodValues[i]
1072 <<
", tmpLogTargetValues[" << i <<
"] = " << tmpLogTargetValues[i]
1078 cumulativeNumPositions += tmpChainSize;
1079 if (cumulativeNumPositions > 100) m_env.setExceptionalCircumstance(
false);
1081 if ((m_env.subDisplayFile() ) &&
1082 (m_env.displayVerbosity() >= 3)) {
1083 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateUnbLinkedChains_all()"
1085 <<
", step " << m_currStep
1086 <<
", chainId = " << chainId
1087 <<
" < " << chainIdMax
1089 <<
" chain positions"
1095 if (currLogLikelihoodValues) {
1096 currLogLikelihoodValues->
append(tmpLogLikelihoodValues,1,tmpLogLikelihoodValues.
subSequenceSize()-1);
1097 if ((m_env.subDisplayFile() ) &&
1098 (m_env.displayVerbosity() >= 99) &&
1100 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateUnbLinkedChains_all()"
1102 <<
", step " << m_currStep
1103 <<
", chainId = " << chainId
1104 <<
", tmpLogLikelihoodValues.subSequenceSize() = " << tmpLogLikelihoodValues.
subSequenceSize()
1105 <<
", tmpLogLikelihoodValues[0] = " << tmpLogLikelihoodValues[0]
1106 <<
", tmpLogLikelihoodValues[1] = " << tmpLogLikelihoodValues[1]
1107 <<
", currLogLikelihoodValues[0] = " << (*currLogLikelihoodValues)[0]
1111 if (currLogTargetValues) {
1117 struct timeval timevalBarrier;
1118 iRC = gettimeofday(&timevalBarrier, NULL);
1121 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
1122 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateUnbLinkedChains_all()"
1124 <<
", step " << m_currStep
1125 <<
": ended chain loop after " << loopTime <<
" seconds"
1126 <<
", calling fullComm().Barrier() at " << ctime(&timevalBarrier.tv_sec)
1130 m_env.fullComm().Barrier();
1132 struct timeval timevalLeaving;
1133 iRC = gettimeofday(&timevalLeaving, NULL);
1136 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
1137 *m_env.subDisplayFile() <<
"Leaving MLSampling<P_V,P_M>::generateUnbLinkedChains_all()"
1139 <<
", step " << m_currStep
1140 <<
": after " << barrierTime <<
" seconds in fullComm().Barrier()"
1141 <<
", at " << ctime(&timevalLeaving.tv_sec)
1148 #ifdef QUESO_HAS_GLPK
1149 template <
class P_V,
class P_M>
1152 std::vector<ExchangeInfoStruct>& exchangeStdVec)
1154 if (m_env.inter0Rank() != 0)
return;
1157 struct timeval timevalBIP;
1158 iRC = gettimeofday(&timevalBIP, NULL);
1161 unsigned int Np = (
unsigned int) m_env.inter0Comm().NumProc();
1162 unsigned int Nc = exchangeStdVec.size();
1164 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
1165 *m_env.subDisplayFile() <<
"Entering MLSampling<P_V,P_M>::solveBIP_proc0()"
1167 <<
", step " << m_currStep
1177 lp = glp_create_prob();
1178 glp_set_prob_name(lp,
"sample");
1183 unsigned int m = Nc+Np-1;
1184 unsigned int n = Nc*Np;
1185 unsigned int ne = Nc*Np + 2*Nc*(Np -1);
1187 glp_add_rows(lp, m);
1188 for (
int i = 1; i <= (int) Nc; ++i) {
1189 glp_set_row_bnds(lp, i, GLP_FX, 1.0, 1.0);
1190 glp_set_row_name(lp, i,
"");
1192 for (
int i = (Nc+1); i <= (int) (Nc+Np-1); ++i) {
1193 glp_set_row_bnds(lp, i, GLP_UP, 0.0, 0.0);
1194 glp_set_row_name(lp, i,
"");
1197 glp_add_cols(lp, n);
1198 for (
int j = 1; j <= (int) n; ++j) {
1200 glp_set_col_kind(lp, j, GLP_IV);
1201 glp_set_col_bnds(lp, j, GLP_DB, 0.0, 1.0);
1202 glp_set_col_name(lp, j,
"");
1205 glp_set_obj_dir(lp, GLP_MIN);
1206 for (
int chainId = 0; chainId <= (int) (Nc-1); ++chainId) {
1207 glp_set_obj_coef(lp, (chainId*Np)+1, exchangeStdVec[chainId].numberOfPositions);
1210 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
1211 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::solveBIP_proc0()"
1213 <<
", step " << m_currStep
1214 <<
": finished setting BIP rows and cols"
1224 std::vector<int > iVec(ne+1,0);
1225 std::vector<int > jVec(ne+1,0);
1226 std::vector<double> aVec(ne+1,0.);
1228 for (
int i = 1; i <= (int) Nc; ++i) {
1229 for (
int j = 1; j <= (int) Np; ++j) {
1231 jVec[coefId] = (i-1)*Np + j;
1236 for (
int i = 1; i <= (int) (Np-1); ++i) {
1237 for (
int j = 1; j <= (int) Nc; ++j) {
1238 iVec[coefId] = Nc+i;
1239 jVec[coefId] = (j-1)*Np + i;
1240 aVec[coefId] = -((double) exchangeStdVec[j-1].numberOfPositions);
1243 iVec[coefId] = Nc+i;
1244 jVec[coefId] = (j-1)*Np + i + 1;
1245 aVec[coefId] = exchangeStdVec[j-1].numberOfPositions;
1249 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
1250 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::solveBIP_proc0()"
1252 <<
", step " << m_currStep
1253 <<
": finished setting BIP constraint matrix"
1255 <<
", coefId = " << coefId
1261 glp_load_matrix(lp, ne, &iVec[0], &jVec[0], &aVec[0]);
1263 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
1264 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::solveBIP_proc0()"
1266 <<
", step " << m_currStep
1267 <<
": finished loading BIP constraint matrix"
1268 <<
", glp_get_num_rows(lp) = " << glp_get_num_rows(lp)
1269 <<
", glp_get_num_cols(lp) = " << glp_get_num_cols(lp)
1270 <<
", glp_get_num_nz(lp) = " << glp_get_num_nz(lp)
1271 <<
", glp_get_num_int(lp) = " << glp_get_num_int(lp)
1272 <<
", glp_get_num_bin(lp) = " << glp_get_num_bin(lp)
1292 for (
unsigned int chainId = 0; chainId < Nc; ++chainId) {
1293 for (
unsigned int nodeId = 0; nodeId < Np; ++nodeId) {
1294 int j = chainId*Np + nodeId + 1;
1296 glp_set_col_stat(lp, j, GLP_BS);
1299 glp_set_col_stat(lp, j, GLP_BS);
1304 for (
unsigned int chainId = 0; chainId < Nc; ++chainId) {
1305 for (
unsigned int nodeId = 0; nodeId < Np; ++nodeId) {
1306 int j = chainId*Np + nodeId + 1;
1307 int initialState = glp_mip_col_val(lp, j);
1317 for (
int i = 1; i <= (int) Nc; ++i) {
1318 glp_set_row_stat(lp, i, GLP_NS);
1320 for (
int i = (Nc+1); i <= (int) (Nc+Np-1); ++i) {
1321 glp_set_row_stat(lp, i, GLP_BS);
1331 BIP_routine_struct BIP_routine_info;
1332 BIP_routine_info.env = &m_env;
1333 BIP_routine_info.currLevel = m_currLevel;
1335 glp_iocp BIP_params;
1336 glp_init_iocp(&BIP_params);
1337 BIP_params.presolve = GLP_ON;
1342 int BIP_rc = glp_intopt(lp, &BIP_params);
1344 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
1345 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::solveBIP_proc0()"
1347 <<
", step " << m_currStep
1348 <<
": finished solving BIP"
1349 <<
", BIP_rc = " << BIP_rc
1358 int BIP_Status = glp_mip_status(lp);
1359 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
1360 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::solveBIP_proc0()"
1362 <<
", step " << m_currStep
1363 <<
": BIP_Status = " << BIP_Status
1367 switch (BIP_Status) {
1370 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
1371 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::solveBIP_proc0()"
1373 <<
", step " << m_currStep
1374 <<
": BIP solution is optimal"
1381 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
1382 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::solveBIP_proc0()"
1384 <<
", step " << m_currStep
1385 <<
": BIP solution is guaranteed to be 'only' feasible"
1395 for (
int i = 1; i <= (int) Nc; ++i) {
1398 for (
int i = (Nc+1); i <= (int) (Nc+Np-1); ++i) {
1405 std::vector<unsigned int> finalNumChainsPerNode (Np,0);
1406 std::vector<unsigned int> finalNumPositionsPerNode(Np,0);
1407 for (
unsigned int chainId = 0; chainId < Nc; ++chainId) {
1408 for (
unsigned int nodeId = 0; nodeId < Np; ++nodeId) {
1409 int j = chainId*Np + nodeId + 1;
1410 if (glp_mip_col_val(lp, j) == 0) {
1413 else if (glp_mip_col_val(lp, j) == 1) {
1415 exchangeStdVec[chainId].finalNodeOfInitialPosition = nodeId;
1416 finalNumChainsPerNode [nodeId] += 1;
1417 finalNumPositionsPerNode[nodeId] += exchangeStdVec[chainId].numberOfPositions;
1425 unsigned int finalMinPosPerNode = *std::min_element(finalNumPositionsPerNode.begin(), finalNumPositionsPerNode.end());
1426 unsigned int finalMaxPosPerNode = *std::max_element(finalNumPositionsPerNode.begin(), finalNumPositionsPerNode.end());
1428 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
1429 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::solveBIP_proc0()"
1431 <<
", step " << m_currStep
1432 <<
": finished preparing output information"
1439 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
1440 *m_env.subDisplayFile() <<
"KEY In MLSampling<P_V,P_M>::solveBIP_proc0()"
1442 <<
", step " << m_currStep
1443 <<
": solution gives the following redistribution"
1445 for (
unsigned int nodeId = 0; nodeId < Np; ++nodeId) {
1446 *m_env.subDisplayFile() <<
" KEY In MLSampling<P_V,P_M>::solveBIP_proc0()"
1448 <<
", step " << m_currStep
1449 <<
", finalNumChainsPerNode[" << nodeId <<
"] = " << finalNumChainsPerNode[nodeId]
1450 <<
", finalNumPositionsPerNode[" << nodeId <<
"] = " << finalNumPositionsPerNode[nodeId]
1453 *m_env.subDisplayFile() <<
" KEY In MLSampling<P_V,P_M>::solveBIP_proc0()"
1455 <<
", step " << m_currStep
1456 <<
", finalRatioOfPosPerNode = " << ((double) finalMaxPosPerNode) / ((double)finalMinPosPerNode)
1465 for (
unsigned int nodeId = 1; nodeId < Np; ++nodeId) {
1466 queso_require_greater_equal_msg(finalNumPositionsPerNode[nodeId-1], finalNumPositionsPerNode[nodeId],
"Next node should have a number of positions equal or less than the current node");
1469 for (
int i = (
int) (Nc+1); i <= (int) (Nc+Np-1); ++i) {
1470 unsigned int nodeId = i - Nc;
1471 int diff = ((int) finalNumPositionsPerNode[nodeId]) - ((int) finalNumPositionsPerNode[nodeId-1]);
1478 glp_delete_prob(lp);
1481 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
1482 *m_env.subDisplayFile() <<
"Leaving MLSampling<P_V,P_M>::solveBIP_proc0()"
1484 <<
", step " << m_currStep
1485 <<
", after " << bipRunTime <<
" seconds"
1491 #endif // QUESO_HAS_GLPK
1493 template <
class P_V,
class P_M>
1497 std::vector<ExchangeInfoStruct>& exchangeStdVec)
1499 if (m_env.inter0Rank() != 0)
return;
1502 struct timeval timevalBal;
1503 iRC = gettimeofday(&timevalBal, NULL);
1506 unsigned int Np = m_env.numSubEnvironments();
1507 unsigned int Nc = exchangeStdVec.size();
1509 std::vector<ExchangeInfoStruct> currExchangeStdVec(Nc);
1510 for (
unsigned int chainId = 0; chainId < Nc; ++chainId) {
1511 currExchangeStdVec[chainId] = exchangeStdVec[chainId];
1512 currExchangeStdVec[chainId].finalNodeOfInitialPosition = currExchangeStdVec[chainId].originalNodeOfInitialPosition;
1518 unsigned int iterIdMax = 0;
1519 std::vector<unsigned int> currNumChainsPerNode (Np,0);
1520 std::vector<unsigned int> currNumPositionsPerNode(Np,0);
1521 for (
unsigned int chainId = 0; chainId < Nc; ++chainId) {
1522 unsigned int nodeId = currExchangeStdVec[chainId].finalNodeOfInitialPosition;
1523 currNumChainsPerNode [nodeId] += 1;
1524 currNumPositionsPerNode[nodeId] += currExchangeStdVec[chainId].numberOfPositions;
1525 iterIdMax += currExchangeStdVec[chainId].numberOfPositions;
1527 unsigned int currMinPosPerNode = *std::min_element(currNumPositionsPerNode.begin(), currNumPositionsPerNode.end());
1528 unsigned int currMaxPosPerNode = *std::max_element(currNumPositionsPerNode.begin(), currNumPositionsPerNode.end());
1529 double currRatioOfPosPerNode = ((double) currMaxPosPerNode ) / ((double) currMinPosPerNode);
1536 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
1537 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::justBalance_proc0()"
1539 <<
", step " << m_currStep
1540 <<
", iter " << iterId
1541 <<
", currRatioOfPosPerNode = " << currRatioOfPosPerNode
1543 for (
unsigned int nodeId = 0; nodeId < Np; ++nodeId) {
1544 *m_env.subDisplayFile() <<
" KEY In MLSampling<P_V,P_M>::justBalance_proc0()"
1546 <<
", step " << m_currStep
1547 <<
", iter " << iterId
1548 <<
", currNumChainsPerNode[" << nodeId <<
"] = " << currNumChainsPerNode[nodeId]
1549 <<
", currNumPositionsPerNode[" << nodeId <<
"] = " << currNumPositionsPerNode[nodeId]
1554 std::vector<std::vector<double> > vectorOfChainSizesPerNode(Np);
1555 while ((iterId < (
int) iterIdMax ) &&
1562 for (
unsigned int nodeId = 0; nodeId < Np; ++nodeId) {
1563 vectorOfChainSizesPerNode[nodeId].clear();
1565 for (
unsigned int chainId = 0; chainId < Nc; ++chainId) {
1566 unsigned int nodeId = currExchangeStdVec[chainId].finalNodeOfInitialPosition;
1567 vectorOfChainSizesPerNode[nodeId].push_back(currExchangeStdVec[chainId].numberOfPositions);
1570 for (
unsigned int nodeId = 0; nodeId < Np; ++nodeId) {
1571 std::sort(vectorOfChainSizesPerNode[nodeId].begin(), vectorOfChainSizesPerNode[nodeId].end());
1572 queso_require_equal_to_msg(vectorOfChainSizesPerNode[nodeId].size(), currNumChainsPerNode[nodeId],
"inconsistent number of chains in node");
1578 unsigned int currBiggestAmountOfPositionsPerNode = currNumPositionsPerNode[0];
1579 unsigned int currSmallestAmountOfPositionsPerNode = currNumPositionsPerNode[0];
1580 unsigned int currNodeWithMostPositions = 0;
1581 unsigned int currNodeWithLeastPositions = 0;
1582 for (
unsigned int nodeId = 0; nodeId < Np; ++nodeId) {
1583 if (currNumPositionsPerNode[nodeId] > currBiggestAmountOfPositionsPerNode) {
1584 currBiggestAmountOfPositionsPerNode = currNumPositionsPerNode[nodeId];
1585 currNodeWithMostPositions = nodeId;
1587 if (currNumPositionsPerNode[nodeId] < currSmallestAmountOfPositionsPerNode) {
1588 currSmallestAmountOfPositionsPerNode = currNumPositionsPerNode[nodeId];
1589 currNodeWithLeastPositions = nodeId;
1593 queso_require_equal_to_msg(currMinPosPerNode, currNumPositionsPerNode[currNodeWithLeastPositions],
"inconsistent currMinPosPerNode");
1595 queso_require_equal_to_msg(currMaxPosPerNode, currNumPositionsPerNode[currNodeWithMostPositions],
"inconsistent currMaxPosPerNode");
1597 unsigned int numberOfPositionsToMove = vectorOfChainSizesPerNode[currNodeWithMostPositions][0];
1599 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 3)) {
1600 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::justBalance_proc0()"
1602 <<
", step " << m_currStep
1603 <<
", iter " << iterId
1604 <<
", before update"
1605 <<
", node w/ most pos is "
1606 << currNodeWithMostPositions <<
"(cs=" << currNumChainsPerNode[currNodeWithMostPositions ] <<
", ps=" << currNumPositionsPerNode[currNodeWithMostPositions ] <<
")"
1607 <<
", node w/ least pos is "
1608 << currNodeWithLeastPositions <<
"(cs=" << currNumChainsPerNode[currNodeWithLeastPositions] <<
", ps=" << currNumPositionsPerNode[currNodeWithLeastPositions] <<
")"
1609 <<
", number of pos to move = " << numberOfPositionsToMove
1616 std::vector<ExchangeInfoStruct> newExchangeStdVec(Nc);
1617 for (
unsigned int chainId = 0; chainId < Nc; ++chainId) {
1618 newExchangeStdVec[chainId] = currExchangeStdVec[chainId];
1621 for (
unsigned int chainId = 0; chainId < Nc; ++chainId) {
1622 if ((newExchangeStdVec[chainId].finalNodeOfInitialPosition == (
int) currNodeWithMostPositions) &&
1623 (newExchangeStdVec[chainId].numberOfPositions == numberOfPositionsToMove )) {
1624 newExchangeStdVec[chainId].finalNodeOfInitialPosition = currNodeWithLeastPositions;
1632 std::vector<unsigned int> newNumChainsPerNode (Np,0);
1633 std::vector<unsigned int> newNumPositionsPerNode(Np,0);
1634 for (
unsigned int chainId = 0; chainId < Nc; ++chainId) {
1635 unsigned int nodeId = newExchangeStdVec[chainId].finalNodeOfInitialPosition;
1636 newNumChainsPerNode [nodeId] += 1;
1637 newNumPositionsPerNode[nodeId] += newExchangeStdVec[chainId].numberOfPositions;
1640 unsigned int newBiggestAmountOfPositionsPerNode = newNumPositionsPerNode[0];
1641 unsigned int newSmallestAmountOfPositionsPerNode = newNumPositionsPerNode[0];
1642 unsigned int newNodeWithMostPositions = 0;
1643 unsigned int newNodeWithLeastPositions = 0;
1644 for (
unsigned int nodeId = 0; nodeId < Np; ++nodeId) {
1645 if (newNumPositionsPerNode[nodeId] > newBiggestAmountOfPositionsPerNode) {
1646 newBiggestAmountOfPositionsPerNode = newNumPositionsPerNode[nodeId];
1647 newNodeWithMostPositions = nodeId;
1649 if (newNumPositionsPerNode[nodeId] < newSmallestAmountOfPositionsPerNode) {
1650 newSmallestAmountOfPositionsPerNode = newNumPositionsPerNode[nodeId];
1651 newNodeWithLeastPositions = nodeId;
1655 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 3)) {
1656 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::justBalance_proc0()"
1658 <<
", step " << m_currStep
1659 <<
", iter " << iterId
1661 <<
", node w/ most pos is "
1662 << newNodeWithMostPositions <<
"(cs=" << newNumChainsPerNode[newNodeWithMostPositions ] <<
", ps=" << newNumPositionsPerNode[newNodeWithMostPositions ] <<
")"
1663 <<
", node w/ least pos is "
1664 << newNodeWithLeastPositions <<
"(cs=" << newNumChainsPerNode[newNodeWithLeastPositions] <<
", ps=" << newNumPositionsPerNode[newNodeWithLeastPositions] <<
")"
1668 unsigned int newMinPosPerNode = *std::min_element(newNumPositionsPerNode.begin(), newNumPositionsPerNode.end());
1669 unsigned int newMaxPosPerNode = *std::max_element(newNumPositionsPerNode.begin(), newNumPositionsPerNode.end());
1670 double newRatioOfPosPerNode = ((double) newMaxPosPerNode ) / ((double) newMinPosPerNode);
1672 queso_require_equal_to_msg(newMinPosPerNode, newNumPositionsPerNode[newNodeWithLeastPositions],
"inconsistent newMinPosPerNode");
1674 queso_require_equal_to_msg(newMaxPosPerNode, newNumPositionsPerNode[newNodeWithMostPositions],
"inconsistent newMaxPosPerNode");
1676 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 3)) {
1677 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::justBalance_proc0()"
1679 <<
", step " << m_currStep
1680 <<
", iter " << iterId
1681 <<
", newMaxPosPerNode = " << newMaxPosPerNode
1682 <<
", newMinPosPerNode = " << newMinPosPerNode
1683 <<
", newRatioOfPosPerNode = " << newRatioOfPosPerNode
1685 for (
unsigned int nodeId = 0; nodeId < Np; ++nodeId) {
1686 *m_env.subDisplayFile() <<
" KEY In MLSampling<P_V,P_M>::justBalance_proc0()"
1688 <<
", step " << m_currStep
1689 <<
", iter " << iterId
1690 <<
", newNumChainsPerNode[" << nodeId <<
"] = " << newNumChainsPerNode [nodeId]
1691 <<
", newNumPositionsPerNode[" << nodeId <<
"] = " << newNumPositionsPerNode[nodeId]
1699 if (newRatioOfPosPerNode > currRatioOfPosPerNode) {
1706 for (
unsigned int nodeId = 0; nodeId < Np; ++nodeId) {
1707 currNumChainsPerNode [nodeId] = 0;
1708 currNumPositionsPerNode[nodeId] = 0;
1710 currRatioOfPosPerNode = newRatioOfPosPerNode;
1711 for (
unsigned int chainId = 0; chainId < Nc; ++chainId) {
1712 currExchangeStdVec[chainId] = newExchangeStdVec[chainId];
1713 unsigned int nodeId = currExchangeStdVec[chainId].finalNodeOfInitialPosition;
1714 currNumChainsPerNode [nodeId] += 1;
1715 currNumPositionsPerNode[nodeId] += currExchangeStdVec[chainId].numberOfPositions;
1717 currMinPosPerNode = *std::min_element(currNumPositionsPerNode.begin(), currNumPositionsPerNode.end());
1718 currMaxPosPerNode = *std::max_element(currNumPositionsPerNode.begin(), currNumPositionsPerNode.end());
1719 currRatioOfPosPerNode = ((double) currMaxPosPerNode ) / ((double) currMinPosPerNode);
1725 for (
unsigned int chainId = 0; chainId < Nc; ++chainId) {
1726 exchangeStdVec[chainId].finalNodeOfInitialPosition = currExchangeStdVec[chainId].finalNodeOfInitialPosition;
1732 std::vector<unsigned int> finalNumChainsPerNode (Np,0);
1733 std::vector<unsigned int> finalNumPositionsPerNode(Np,0);
1734 for (
unsigned int chainId = 0; chainId < Nc; ++chainId) {
1735 unsigned int nodeId = exchangeStdVec[chainId].finalNodeOfInitialPosition;
1736 finalNumChainsPerNode [nodeId] += 1;
1737 finalNumPositionsPerNode[nodeId] += exchangeStdVec[chainId].numberOfPositions;
1739 unsigned int finalMinPosPerNode = *std::min_element(finalNumPositionsPerNode.begin(), finalNumPositionsPerNode.end());
1740 unsigned int finalMaxPosPerNode = *std::max_element(finalNumPositionsPerNode.begin(), finalNumPositionsPerNode.end());
1741 double finalRatioOfPosPerNode = ((double) finalMaxPosPerNode ) / ((double) finalMinPosPerNode);
1743 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
1744 *m_env.subDisplayFile() <<
"KEY In MLSampling<P_V,P_M>::justBalance_proc0()"
1746 <<
", step " << m_currStep
1747 <<
": solution gives the following redistribution"
1749 for (
unsigned int nodeId = 0; nodeId < Np; ++nodeId) {
1750 *m_env.subDisplayFile() <<
" KEY In MLSampling<P_V,P_M>::justBalance_proc0()"
1752 <<
", step " << m_currStep
1753 <<
", finalNumChainsPerNode[" << nodeId <<
"] = " << finalNumChainsPerNode[nodeId]
1754 <<
", finalNumPositionsPerNode[" << nodeId <<
"] = " << finalNumPositionsPerNode[nodeId]
1757 *m_env.subDisplayFile() <<
" KEY In MLSampling<P_V,P_M>::justBalance_proc0()"
1759 <<
", step " << m_currStep
1760 <<
", finalRatioOfPosPerNode = " << finalRatioOfPosPerNode
1768 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
1769 *m_env.subDisplayFile() <<
"Leaving MLSampling<P_V,P_M>::justBalance_proc0()"
1771 <<
", step " << m_currStep
1772 <<
", iterId = " << iterId
1773 <<
", currRatioOfPosPerNode = " << currRatioOfPosPerNode
1774 <<
", after " << balRunTime <<
" seconds"
1781 template <
class P_V,
class P_M>
1785 double prevExponent,
1786 double currExponent,
1789 const std::vector<ExchangeInfoStruct>& exchangeStdVec,
1790 const std::vector<unsigned int>& finalNumChainsPerNode,
1791 const std::vector<unsigned int>& finalNumPositionsPerNode,
1794 if (m_env.inter0Rank() < 0) {
1798 unsigned int Np = (
unsigned int) m_env.inter0Comm().NumProc();
1799 unsigned int Nc = exchangeStdVec.size();
1801 double expRatio = currExponent;
1802 if (prevExponent > 0.0) {
1803 expRatio /= prevExponent;
1806 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
1807 *m_env.subDisplayFile() <<
"Entering MLSampling<P_V,P_M>::mpiExchangePositions_inter0()"
1809 <<
", step " << m_currStep
1820 for (
unsigned int r = 0; r < Np; ++r) {
1824 unsigned int numberOfInitialPositionsNodeRAlreadyHas = 0;
1825 std::vector<unsigned int> numberOfInitialPositionsNodeRHasToReceiveFromNode(Np,0);
1826 std::vector<unsigned int> indexesOfInitialPositionsNodeRHasToReceiveFromMe(0);
1828 unsigned int sumOfChainLenghtsNodeRAlreadyHas = 0;
1829 std::vector<unsigned int> chainLenghtsNodeRHasToInherit(0);
1831 for (
unsigned int i = 0; i < Nc; ++i) {
1832 if (exchangeStdVec[i].finalNodeOfInitialPosition == (
int) r) {
1833 if (exchangeStdVec[i].originalNodeOfInitialPosition == (
int) r) {
1834 numberOfInitialPositionsNodeRAlreadyHas++;
1835 sumOfChainLenghtsNodeRAlreadyHas += exchangeStdVec[i].numberOfPositions;
1838 numberOfInitialPositionsNodeRHasToReceiveFromNode[exchangeStdVec[i].originalNodeOfInitialPosition]++;
1839 chainLenghtsNodeRHasToInherit.push_back(exchangeStdVec[i].numberOfPositions);
1840 if (m_env.inter0Rank() == exchangeStdVec[i].originalNodeOfInitialPosition) {
1841 indexesOfInitialPositionsNodeRHasToReceiveFromMe.push_back(exchangeStdVec[i].originalIndexOfInitialPosition);
1847 unsigned int totalNumberOfInitialPositionsNodeRHasToReceive = 0;
1848 for (
unsigned int nodeId = 0; nodeId < Np; ++nodeId) {
1849 totalNumberOfInitialPositionsNodeRHasToReceive += numberOfInitialPositionsNodeRHasToReceiveFromNode[nodeId];
1852 unsigned int totalNumberOfChainLenghtsNodeRHasToInherit = chainLenghtsNodeRHasToInherit.size();
1853 unsigned int totalSumOfChainLenghtsNodeRHasToInherit = 0;
1854 for (
unsigned int i = 0; i < totalNumberOfChainLenghtsNodeRHasToInherit; ++i) {
1855 totalSumOfChainLenghtsNodeRHasToInherit += chainLenghtsNodeRHasToInherit[i];
1861 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
1862 *m_env.subDisplayFile() <<
"KEY In MLSampling<P_V,P_M>::mpiExchangePositions_inter0()"
1864 <<
", step " << m_currStep
1866 <<
", finalNumChainsPerNode[r] = " << finalNumChainsPerNode[r]
1867 <<
", totalNumberOfInitialPositionsNodeRHasToReceive = " << totalNumberOfInitialPositionsNodeRHasToReceive
1868 <<
", numberOfInitialPositionsNodeRAlreadyHas = " << numberOfInitialPositionsNodeRAlreadyHas
1870 *m_env.subDisplayFile() <<
"KEY In MLSampling<P_V,P_M>::mpiExchangePositions_inter0()"
1872 <<
", step " << m_currStep
1874 <<
", finalNumPositionsPerNode[r] = " << finalNumPositionsPerNode[r]
1875 <<
", totalSumOfChainLenghtsNodeRHasToInherit = " << totalSumOfChainLenghtsNodeRHasToInherit
1876 <<
", sumOfChainLenghtsNodeRAlreadyHas = " << sumOfChainLenghtsNodeRAlreadyHas
1883 queso_require_equal_to_msg(indexesOfInitialPositionsNodeRHasToReceiveFromMe.size(), numberOfInitialPositionsNodeRHasToReceiveFromNode[m_env.inter0Rank()],
"inconsistent number of initial positions to send to node 'r'");
1885 queso_require_equal_to_msg(finalNumChainsPerNode[r], (totalNumberOfInitialPositionsNodeRHasToReceive + numberOfInitialPositionsNodeRAlreadyHas),
"inconsistent number of chains in node 'r'");
1887 queso_require_equal_to_msg(finalNumPositionsPerNode[r], (totalSumOfChainLenghtsNodeRHasToInherit + sumOfChainLenghtsNodeRAlreadyHas),
"inconsistent sum of chain lenghts in node 'r'");
1889 queso_require_equal_to_msg(totalNumberOfInitialPositionsNodeRHasToReceive, totalNumberOfChainLenghtsNodeRHasToInherit,
"inconsistent on total number of initial positions to receive in node 'r'");
1892 indexesOfInitialPositionsNodeRHasToReceiveFromMe.resize(numberOfInitialPositionsNodeRHasToReceiveFromNode[m_env.inter0Rank()]);
1893 chainLenghtsNodeRHasToInherit.resize (totalSumOfChainLenghtsNodeRHasToInherit);
1898 unsigned int dimSize = m_vectorSpace.dimLocal();
1899 unsigned int nValuesPerInitialPosition = dimSize + 2;
1900 P_V auxInitialPosition(m_vectorSpace.zeroVector());
1901 std::vector<double> sendbuf(0);
1902 unsigned int sendcnt = 0;
1903 if (m_env.inter0Rank() != (int) r) {
1904 sendcnt = numberOfInitialPositionsNodeRHasToReceiveFromNode[m_env.inter0Rank()] * nValuesPerInitialPosition;
1905 sendbuf.resize(sendcnt);
1906 for (
unsigned int i = 0; i < numberOfInitialPositionsNodeRHasToReceiveFromNode[m_env.inter0Rank()]; ++i) {
1907 unsigned int auxIndex = indexesOfInitialPositionsNodeRHasToReceiveFromMe[i];
1909 for (
unsigned int j = 0; j < dimSize; ++j) {
1910 sendbuf[i*nValuesPerInitialPosition + j] = auxInitialPosition[j];
1912 sendbuf[i*nValuesPerInitialPosition + dimSize] = prevLogLikelihoodValues[auxIndex];
1913 sendbuf[i*nValuesPerInitialPosition + dimSize + 1] = prevLogTargetValues[auxIndex];
1917 std::vector<double> recvbuf(0);
1918 std::vector<int> recvcnts(Np,0);
1919 if (m_env.inter0Rank() == (int) r) {
1920 recvbuf.resize(totalNumberOfInitialPositionsNodeRHasToReceive * nValuesPerInitialPosition);
1921 for (
unsigned int nodeId = 0; nodeId < Np; ++nodeId) {
1922 recvcnts[nodeId] = numberOfInitialPositionsNodeRHasToReceiveFromNode[nodeId] * nValuesPerInitialPosition;
1926 std::vector<int> displs(Np,0);
1927 for (
unsigned int nodeId = 1; nodeId < Np; ++nodeId) {
1928 displs[nodeId] = displs[nodeId-1] + recvcnts[nodeId-1];
1932 if (m_env.inter0Rank() == r) {
1934 "MLSampling<P_V,P_M>::mpiExchangePositions_inter0(1)",
1935 "failed MPI.Gatherv()");
1939 "MLSampling<P_V,P_M>::mpiExchangePositions_inter0(2)",
1940 "failed MPI.Gatherv()");
1944 "MLSampling<P_V,P_M>::mpiExchangePositions_inter0()",
1945 "failed MPI.Gatherv()");
1957 if (m_env.inter0Rank() == (int) r) {
1959 unsigned int auxIndex = 0;
1961 for (
unsigned int i = 0; i < Nc; ++i) {
1962 if ((exchangeStdVec[i].finalNodeOfInitialPosition == (
int) r) &&
1963 (exchangeStdVec[i].originalNodeOfInitialPosition == (
int) r)) {
1964 unsigned int originalIndex = exchangeStdVec[i].originalIndexOfInitialPosition;
1966 balancedLinkControl.
balLinkedChains[auxIndex].initialPosition =
new P_V(auxInitialPosition);
1967 balancedLinkControl.
balLinkedChains[auxIndex].initialLogPrior = prevLogTargetValues[originalIndex] - prevLogLikelihoodValues[originalIndex];
1968 balancedLinkControl.
balLinkedChains[auxIndex].initialLogLikelihood = expRatio*prevLogLikelihoodValues[originalIndex];
1969 balancedLinkControl.
balLinkedChains[auxIndex].numberOfPositions = exchangeStdVec[i].numberOfPositions;
1974 for (
unsigned int i = 0; i < totalNumberOfInitialPositionsNodeRHasToReceive; ++i) {
1975 for (
unsigned int j = 0; j < dimSize; ++j) {
1976 auxInitialPosition[j] = recvbuf[i*nValuesPerInitialPosition + j];
1978 balancedLinkControl.
balLinkedChains[auxIndex].initialPosition =
new P_V(auxInitialPosition);
1979 double prevLogLikelihood = recvbuf[i*nValuesPerInitialPosition + dimSize];
1980 double prevLogTarget = recvbuf[i*nValuesPerInitialPosition + dimSize + 1];
1981 balancedLinkControl.
balLinkedChains[auxIndex].initialLogPrior = prevLogTarget - prevLogLikelihood;
1982 balancedLinkControl.
balLinkedChains[auxIndex].initialLogLikelihood = expRatio*prevLogLikelihood;
1983 balancedLinkControl.
balLinkedChains[auxIndex].numberOfPositions = chainLenghtsNodeRHasToInherit[i];
1988 m_env.inter0Comm().Barrier();
1991 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
1992 *m_env.subDisplayFile() <<
"Leaving MLSampling<P_V,P_M>::mpiExchangePositions_inter0()"
1994 <<
", step " << m_currStep
2002 template <
class P_V,
class P_M>
2005 double currExponent,
2011 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
2012 *m_env.subDisplayFile() <<
"\n CHECKPOINTING initiating at level " << m_currLevel
2013 <<
"\n" << std::endl;
2020 unsigned int quantity2 = currLogLikelihoodValues.
unifiedSequenceSize(m_vectorSpace.numOfProcsForStorage() == 1);
2021 unsigned int quantity3 = currLogTargetValues.
unifiedSequenceSize(m_vectorSpace.numOfProcsForStorage() == 1);
2022 if (m_env.inter0Rank() >= 0) {
2028 if (m_env.fullRank() == 0) {
2029 std::ofstream* ofsVar =
new std::ofstream((m_options.m_restartOutput_baseNameForFiles +
"Control.txt").c_str(),
2030 std::ofstream::out | std::ofstream::trunc);
2031 *ofsVar << m_currLevel << std::endl
2032 << m_vectorSpace.dimGlobal() << std::endl
2033 << currExponent << std::endl
2034 << currEta << std::endl
2035 << quantity1 << std::endl;
2036 unsigned int savedPrecision = ofsVar->precision();
2037 ofsVar->precision(16);
2038 for (
unsigned int i = 0; i < m_logEvidenceFactors.size(); ++i) {
2039 *ofsVar << m_logEvidenceFactors[i] << std::endl;
2041 ofsVar->precision(savedPrecision);
2042 *ofsVar <<
"COMPLETE" << std::endl;
2046 m_env.fullComm().Barrier();
2051 char levelSufix[256];
2054 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
2055 *m_env.subDisplayFile() <<
"\n CHECKPOINTING chain at level " << m_currLevel
2056 <<
"\n" << std::endl;
2058 currChain.
unifiedWriteContents(m_options.m_restartOutput_baseNameForFiles +
"Chain_l" + levelSufix,
2059 m_options.m_restartOutput_fileType);
2060 m_env.fullComm().Barrier();
2062 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
2063 *m_env.subDisplayFile() <<
"\n CHECKPOINTING like at level " << m_currLevel
2064 <<
"\n" << std::endl;
2066 currLogLikelihoodValues.
unifiedWriteContents(m_options.m_restartOutput_baseNameForFiles +
"LogLike_l" + levelSufix,
2067 m_options.m_restartOutput_fileType);
2068 m_env.fullComm().Barrier();
2070 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
2071 *m_env.subDisplayFile() <<
"\n CHECKPOINTING target at level " << m_currLevel
2072 <<
"\n" << std::endl;
2074 currLogTargetValues.
unifiedWriteContents(m_options.m_restartOutput_baseNameForFiles +
"LogTarget_l" + levelSufix,
2075 m_options.m_restartOutput_fileType);
2076 m_env.fullComm().Barrier();
2081 if (m_env.fullRank() == 0) {
2082 std::ofstream* ofsVar =
new std::ofstream((m_options.m_restartOutput_baseNameForFiles +
"Control_l" + levelSufix +
".txt").c_str(),
2083 std::ofstream::out | std::ofstream::trunc);
2084 *ofsVar << m_currLevel << std::endl
2085 << m_vectorSpace.dimGlobal() << std::endl
2086 << currExponent << std::endl
2087 << currEta << std::endl
2088 << quantity1 << std::endl;
2089 unsigned int savedPrecision = ofsVar->precision();
2090 ofsVar->precision(16);
2091 for (
unsigned int i = 0; i < m_logEvidenceFactors.size(); ++i) {
2092 *ofsVar << m_logEvidenceFactors[i] << std::endl;
2094 ofsVar->precision(savedPrecision);
2095 *ofsVar <<
"COMPLETE" << std::endl;
2099 m_env.fullComm().Barrier();
2101 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
2102 *m_env.subDisplayFile() <<
"\n CHECKPOINTING done at level " << m_currLevel
2103 <<
"\n" << std::endl;
2109 template <
class P_V,
class P_M>
2112 double& currExponent,
2118 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
2119 *m_env.subDisplayFile() <<
"\n RESTARTING initiating at level " << m_currLevel
2120 <<
"\n" << std::endl;
2126 unsigned int vectorSpaceDim = 0;
2127 unsigned int quantity1 = 0;
2128 std::string checkingString(
"");
2129 if (m_env.fullRank() == 0) {
2130 std::ifstream* ifsVar =
new std::ifstream((m_options.m_restartInput_baseNameForFiles +
"Control.txt").c_str(),
2136 unsigned int numLines = std::count(std::istreambuf_iterator<char>(*ifsVar),
2137 std::istreambuf_iterator<char>(),
2139 ifsVar->seekg(0,std::ios_base::beg);
2140 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
2141 *m_env.subDisplayFile() <<
"Restart input file has " << numLines
2149 *ifsVar >> m_currLevel;
2152 m_logEvidenceFactors.clear();
2153 m_logEvidenceFactors.resize(m_currLevel,0.);
2154 *ifsVar >> vectorSpaceDim
2158 for (
unsigned int i = 0; i < m_logEvidenceFactors.size(); ++i) {
2159 *ifsVar >> m_logEvidenceFactors[i];
2161 *ifsVar >> checkingString;
2164 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
2165 *m_env.subDisplayFile() <<
"Restart input file has the following information:"
2166 <<
"\n m_currLevel = " << m_currLevel
2167 <<
"\n vectorSpaceDim = " << vectorSpaceDim
2168 <<
"\n currExponent = " << currExponent
2169 <<
"\n currEta = " << currEta
2170 <<
"\n quantity1 = " << quantity1;
2171 for (
unsigned int i = 0; i < m_logEvidenceFactors.size(); ++i) {
2172 *m_env.subDisplayFile() <<
"\n [" << i <<
"] = " << m_logEvidenceFactors[i];
2174 *m_env.subDisplayFile() << std::endl;
2177 #if 0 // For debug only
2178 std::string tmpString;
2179 for (
unsigned int i = 0; i < 2; ++i) {
2180 *ifsVar >> tmpString;
2181 std::cout <<
"Just read '" << tmpString <<
"'" << std::endl;
2183 while ((lineId < numLines) && (ifsVar->eof() ==
false)) {
2185 ifsVar->ignore(maxCharsPerLine,
'\n');
2190 m_env.fullComm().Barrier();
2195 unsigned int tmpUint = (
unsigned int) m_currLevel;
2197 "MLSampling<P_V,P_M>::restartML()",
2198 "failed MPI.Bcast() for m_currLevel");
2199 if (m_env.fullRank() != 0) {
2200 m_currLevel = tmpUint;
2207 if (m_env.fullRank() == 0) {
2208 tmpData[0] = vectorSpaceDim;
2209 tmpData[1] = currExponent;
2210 tmpData[2] = currEta;
2211 tmpData[3] = quantity1;
2212 for (
unsigned int i = 0; i < m_logEvidenceFactors.size(); ++i) {
2213 tmpData[4+i] = m_logEvidenceFactors[i];
2217 m_logEvidenceFactors.clear();
2218 m_logEvidenceFactors.resize(m_currLevel,0.);
2220 m_env.fullComm().Bcast((
void *) &tmpData[0], (
int) tmpData.size(),
RawValue_MPI_DOUBLE, 0,
2221 "MLSampling<P_V,P_M>::restartML()",
2222 "failed MPI.Bcast() for rest of information read from input file");
2223 if (m_env.fullRank() != 0) {
2224 vectorSpaceDim = tmpData[0];
2225 currExponent = tmpData[1];
2226 currEta = tmpData[2];
2227 quantity1 = tmpData[3];
2228 for (
unsigned int i = 0; i < m_logEvidenceFactors.size(); ++i) {
2229 m_logEvidenceFactors[i] = tmpData[4+i];
2237 queso_require_msg(!((currExponent < 0.) || (currExponent > 1.)),
"read currExponent is not consistent");
2238 queso_require_equal_to_msg((quantity1 % m_env.numSubEnvironments()), 0,
"read size of chain should be a multiple of the number of subenvironments");
2239 unsigned int subSequenceSize = 0;
2240 subSequenceSize = ((double) quantity1) / ((double) m_env.numSubEnvironments());
2242 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
2243 *m_env.subDisplayFile() <<
"Restart input file has the following information"
2244 <<
": subSequenceSize = " << subSequenceSize
2251 char levelSufix[256];
2254 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
2255 *m_env.subDisplayFile() <<
"\n RESTARTING chain at level " << m_currLevel
2256 <<
"\n" << std::endl;
2258 currChain.
unifiedReadContents(m_options.m_restartInput_baseNameForFiles +
"Chain_l" + levelSufix,
2259 m_options.m_restartInput_fileType,
2261 m_env.fullComm().Barrier();
2263 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
2264 *m_env.subDisplayFile() <<
"\n RESTARTING like at level " << m_currLevel
2265 <<
"\n" << std::endl;
2267 currLogLikelihoodValues.
unifiedReadContents(m_options.m_restartInput_baseNameForFiles +
"LogLike_l" + levelSufix,
2268 m_options.m_restartInput_fileType,
2270 m_env.fullComm().Barrier();
2272 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
2273 *m_env.subDisplayFile() <<
"\n RESTARTING target at level " << m_currLevel
2274 <<
"\n" << std::endl;
2276 currLogTargetValues.
unifiedReadContents(m_options.m_restartInput_baseNameForFiles +
"LogTarget_l" + levelSufix,
2277 m_options.m_restartInput_fileType,
2279 m_env.fullComm().Barrier();
2281 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
2282 *m_env.subDisplayFile() <<
"\n RESTARTING done at level " << m_currLevel
2283 <<
"\n" << std::endl;
2289 template <
class P_V,
class P_M>
2293 unsigned int& unifiedRequestedNumSamples,
2298 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
2299 *m_env.subDisplayFile() <<
"KEY In MLSampling<P_V,P_M>::generateSequence()"
2301 <<
", currOptions.m_rawChainSize = " << currOptions.
m_rawChainSize
2306 struct timeval timevalLevel;
2307 iRC = gettimeofday(&timevalLevel, NULL);
2310 if (m_env.inter0Rank() >= 0) {
2313 "MLSampling<P_V,P_M>::generateSequence()",
2314 "failed MPI.Allreduce() for requested num samples in level 0");
2321 currLogLikelihoodValues.
setName(currOptions.
m_prefix +
"rawLogLikelihood");
2328 P_V auxVec(m_vectorSpace.zeroVector());
2332 bool outOfSupport =
true;
2335 m_priorRv.realizer().realization(auxVec);
2336 if (m_numDisabledParameters > 0) {
2337 unsigned int disabledCounter = 0;
2338 for (
unsigned int paramId = 0; paramId < m_vectorSpace.dimLocal(); ++paramId) {
2339 if (m_parameterEnabledStatus[paramId] ==
false) {
2345 auxVec.mpiBcast(0, m_env.subComm());
2347 outOfSupport = !(m_targetDomain->contains(auxVec));
2348 }
while (outOfSupport);
2352 #if 1 // prudencio 2010-08-01
2353 currLogLikelihoodValues[i] = likelihoodSynchronizer.callFunction(&auxVec,NULL,NULL,NULL,NULL,NULL,NULL);
2355 currLogLikelihoodValues[i] = m_likelihoodFunction.lnValue(auxVec,NULL,NULL,NULL,NULL);
2357 currLogTargetValues[i] = m_priorRv.pdf().lnValue(auxVec,NULL,NULL,NULL,NULL) + currLogLikelihoodValues[i];
2361 if (m_env.inter0Rank() >= 0) {
2362 #ifdef QUESO_USES_SEQUENCE_STATISTICAL_OPTIONS
2363 if (currOptions.m_rawChainComputeStats) {
2372 currChain.computeStatistics(*currOptions.m_rawChainStatisticalOptionsObj,
2389 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
2390 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence()"
2393 <<
" chain positions"
2409 #ifdef QUESO_USES_SEQUENCE_STATISTICAL_OPTIONS
2410 if (currOptions.m_filteredChainComputeStats) {
2426 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
2427 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence()"
2429 <<
", total level time = " << levelRunTime <<
" seconds"
2436 template <
class P_V,
class P_M>
2440 unsigned int& unifiedRequestedNumSamples)
2443 struct timeval timevalStep;
2444 iRC = gettimeofday(&timevalStep, NULL);
2447 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
2448 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence()"
2450 <<
", step " << m_currStep
2451 <<
": beginning step 1 of 11"
2459 "MLSampling<P_V,P_M>::generateSequence()",
2460 "failed MPI.Allreduce() for requested num samples in step 1");
2462 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
2463 *m_env.subDisplayFile() <<
"KEY In MLSampling<P_V,P_M>::generateSequence()"
2465 <<
", step " << m_currStep
2466 <<
", currOptions->m_rawChainSize = " << currOptions->
m_rawChainSize
2471 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
2472 *m_env.subDisplayFile() <<
"Leaving MLSampling<P_V,P_M>::generateSequence_Step()"
2474 <<
", step " << m_currStep
2475 <<
", after " << stepRunTime <<
" seconds"
2482 template <
class P_V,
class P_M>
2492 unsigned int& indexOfFirstWeight,
2493 unsigned int& indexOfLastWeight)
2496 struct timeval timevalStep;
2497 iRC = gettimeofday(&timevalStep, NULL);
2500 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
2501 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence()"
2503 <<
", step " << m_currStep
2504 <<
": beginning step 2 of 11"
2508 prevChain = currChain;
2512 prevLogLikelihoodValues = currLogLikelihoodValues;
2513 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
2514 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence_Step()"
2516 <<
", step " << m_currStep
2517 <<
", prevLogLikelihoodValues[0] = " << prevLogLikelihoodValues[0]
2520 prevLogTargetValues = currLogTargetValues;
2522 currLogLikelihoodValues.
clear();
2523 currLogLikelihoodValues.
setName(currOptions->
m_prefix +
"rawLogLikelihood");
2525 currLogTargetValues.
clear();
2528 #if 0 // For debug only
2529 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
2530 P_V prevPosition(m_vectorSpace.zeroVector());
2531 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence()"
2533 <<
", step " << m_currStep
2538 *m_env.subDisplayFile() <<
" prevChain[" << i
2539 <<
"] = " << prevPosition
2540 <<
", prevLogLikelihoodValues[" << i
2541 <<
"] = " << prevLogLikelihoodValues[i]
2542 <<
", prevLogTargetValues[" << i
2543 <<
"] = " << prevLogTargetValues[i]
2551 unsigned int quantity3 = prevLogLikelihoodValues.
unifiedSequenceSize(m_vectorSpace.numOfProcsForStorage() == 1);
2552 unsigned int quantity4 = currLogLikelihoodValues.
unifiedSequenceSize(m_vectorSpace.numOfProcsForStorage() == 1);
2553 unsigned int quantity5 = prevLogTargetValues.
unifiedSequenceSize(m_vectorSpace.numOfProcsForStorage() == 1);
2554 unsigned int quantity6 = currLogTargetValues.
unifiedSequenceSize(m_vectorSpace.numOfProcsForStorage() == 1);
2555 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
2556 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence()"
2558 <<
", step " << m_currStep
2559 <<
": prevChain.unifiedSequenceSize() = " << quantity1
2560 <<
", currChain.unifiedSequenceSize() = " << quantity2
2561 <<
", prevLogLikelihoodValues.unifiedSequenceSize() = " << quantity3
2562 <<
", currLogLikelihoodValues.unifiedSequenceSize() = " << quantity4
2563 <<
", prevLogTargetValues.unifiedSequenceSize() = " << quantity5
2564 <<
", currLogTargetValues.unifiedSequenceSize() = " << quantity6
2573 indexOfFirstWeight = 0;
2574 indexOfLastWeight = indexOfFirstWeight + prevChain.
subSequenceSize()-1;
2577 int r = m_env.inter0Rank();
2579 m_env.inter0Comm().Barrier();
2580 unsigned int auxUint = 0;
2585 "MLSampling<P_V,P_M>::generateSequence()",
2586 "failed MPI.Recv()");
2588 indexOfFirstWeight = auxUint;
2589 indexOfLastWeight = indexOfFirstWeight + prevChain.
subSequenceSize()-1;
2591 if (r < (m_env.inter0Comm().NumProc()-1)) {
2592 auxUint = indexOfLastWeight + 1;
2595 "MLSampling<P_V,P_M>::generateSequence()",
2596 "failed MPI.Send()");
2599 m_env.inter0Comm().Barrier();
2603 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
2604 *m_env.subDisplayFile() <<
"Leaving MLSampling<P_V,P_M>::generateSequence_Step()"
2606 <<
", step " << m_currStep
2607 <<
", after " << stepRunTime <<
" seconds"
2614 template <
class P_V,
class P_M>
2619 double prevExponent,
2620 double failedExponent,
2621 double& currExponent,
2625 struct timeval timevalStep;
2626 iRC = gettimeofday(&timevalStep, NULL);
2629 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
2630 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence()"
2632 <<
", step " << m_currStep
2633 <<
", failedExponent = " << failedExponent
2634 <<
": beginning step 3 of 11"
2638 std::vector<double> exponents(2,0.);
2639 exponents[0] = prevExponent;
2642 double nowExponent = 1.;
2643 double nowEffectiveSizeRatio = 0.;
2645 unsigned int nowAttempt = 0;
2646 bool testResult =
false;
2650 double nowUnifiedEvidenceLnFactor = 0.;
2652 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
2653 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence()"
2655 <<
", step " << m_currStep
2656 <<
", failedExponent = " << failedExponent
2657 <<
": entering loop for computing next exponent"
2658 <<
", with nowAttempt = " << nowAttempt
2662 if (failedExponent > 0.) {
2663 nowExponent = .5*(prevExponent+failedExponent);
2666 if (nowAttempt > 0) {
2667 if (nowEffectiveSizeRatio > meanEffectiveSizeRatio) {
2668 exponents[0] = nowExponent;
2671 exponents[1] = nowExponent;
2673 nowExponent = .5*(exponents[0] + exponents[1]);
2676 double auxExponent = nowExponent;
2677 if (prevExponent != 0.) {
2678 auxExponent /= prevExponent;
2681 double subWeightRatioSum = 0.;
2682 double unifiedWeightRatioSum = 0.;
2685 omegaLnDiffSequence[i] = prevLogLikelihoodValues[i]*auxExponent;
2688 #if 1 // prudenci-2012-07-06
2690 double unifiedOmegaLnMax = omegaLnDiffSequence.
unifiedMaxPlain(m_vectorSpace.numOfProcsForStorage() == 1);
2692 double unifiedOmegaLnMin = 0.;
2693 double unifiedOmegaLnMax = 0.;
2694 omegaLnDiffSequence.unifiedMinMaxExtra(m_vectorSpace.numOfProcsForStorage() == 1,
2696 omegaLnDiffSequence.subSequenceSize(),
2701 omegaLnDiffSequence[i] -= unifiedOmegaLnMax;
2702 weightSequence[i] = exp(omegaLnDiffSequence[i]);
2703 subWeightRatioSum += weightSequence[i];
2704 #if 0 // For debug only
2705 if ((m_currLevel == 1) && (nowAttempt == 6)) {
2706 if (m_env.subDisplayFile() && (m_env.displayVerbosity() >= 99)) {
2707 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence()"
2709 <<
", step " << m_currStep
2711 <<
", prevLogLikelihoodValues[i] = " << prevLogLikelihoodValues[i]
2712 <<
", omegaLnDiffSequence[i] = " << omegaLnDiffSequence[i]
2713 <<
", weightSequence[i] = " << weightSequence[i]
2721 "MLSampling<P_V,P_M>::generateSequence()",
2722 "failed MPI.Allreduce() for weight ratio sum");
2724 unsigned int auxQuantity = weightSequence.
unifiedSequenceSize(m_vectorSpace.numOfProcsForStorage() == 1);
2725 nowUnifiedEvidenceLnFactor = log(unifiedWeightRatioSum) + unifiedOmegaLnMax - log(auxQuantity);
2727 double effectiveSampleSize = 0.;
2729 weightSequence[i] /= unifiedWeightRatioSum;
2730 effectiveSampleSize += weightSequence[i]*weightSequence[i];
2741 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
2742 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence()"
2744 <<
", step " << m_currStep
2745 <<
": nowAttempt = " << nowAttempt
2746 <<
", prevExponent = " << prevExponent
2747 <<
", exponents[0] = " << exponents[0]
2748 <<
", nowExponent = " << nowExponent
2749 <<
", exponents[1] = " << exponents[1]
2750 <<
", subWeightRatioSum = " << subWeightRatioSum
2751 <<
", unifiedWeightRatioSum = " << unifiedWeightRatioSum
2752 <<
", unifiedOmegaLnMax = " << unifiedOmegaLnMax
2753 <<
", weightSequence.unifiedSequenceSize() = " << auxQuantity
2754 <<
", nowUnifiedEvidenceLnFactor = " << nowUnifiedEvidenceLnFactor
2755 <<
", effectiveSampleSize = " << effectiveSampleSize
2759 #if 0 // For debug only
2760 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
2761 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence()"
2763 <<
", step " << m_currStep
2768 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
2769 *m_env.subDisplayFile() <<
" weightSequence[" << i
2770 <<
"] = " << weightSequence[i]
2776 double subQuantity = effectiveSampleSize;
2777 effectiveSampleSize = 0.;
2779 "MLSampling<P_V,P_M>::generateSequence()",
2780 "failed MPI.Allreduce() for effective sample size");
2782 effectiveSampleSize = 1./effectiveSampleSize;
2783 nowEffectiveSizeRatio = effectiveSampleSize/((double) weightSequence.
unifiedSequenceSize(m_vectorSpace.numOfProcsForStorage() == 1));
2790 if (failedExponent > 0.) {
2795 bool aux2 = (nowExponent == 1. )
2797 (nowEffectiveSizeRatio > meanEffectiveSizeRatio);
2800 (nowEffectiveSizeRatio <= currOptions->m_maxEffectiveSizeRatio);
2801 testResult = aux2 || aux3;
2804 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
2805 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence()"
2807 <<
", step " << m_currStep
2808 <<
": nowAttempt = " << nowAttempt
2809 <<
", prevExponent = " << prevExponent
2810 <<
", failedExponent = " << failedExponent
2811 <<
", exponents[0] = " << exponents[0]
2812 <<
", nowExponent = " << nowExponent
2813 <<
", exponents[1] = " << exponents[1]
2814 <<
", effectiveSampleSize = " << effectiveSampleSize
2817 <<
", nowEffectiveSizeRatio = " << nowEffectiveSizeRatio
2821 <<
", testResult = " << testResult
2830 "MLSampling<P_V,P_M>::generateSequence(), step 3, nowExponent") ==
false) {
2831 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
2832 *m_env.subDisplayFile() <<
"WARNING, In MLSampling<P_V,P_M>::generateSequence()"
2834 <<
", step " << m_currStep
2835 <<
": nowAttempt = " << nowAttempt
2836 <<
", MiscCheck for 'nowExponent' detected a problem"
2845 "MLSampling<P_V,P_M>::generateSequence(), step 3, testResult") ==
false) {
2846 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
2847 *m_env.subDisplayFile() <<
"WARNING, In MLSampling<P_V,P_M>::generateSequence()"
2849 <<
", step " << m_currStep
2850 <<
": nowAttempt = " << nowAttempt
2851 <<
", MiscCheck for 'testResult' detected a problem"
2855 }
while (testResult ==
false);
2856 currExponent = nowExponent;
2857 if (failedExponent > 0.) {
2858 m_logEvidenceFactors[m_logEvidenceFactors.size()-1] = nowUnifiedEvidenceLnFactor;
2861 m_logEvidenceFactors.push_back(nowUnifiedEvidenceLnFactor);
2864 unsigned int quantity1 = weightSequence.
unifiedSequenceSize(m_vectorSpace.numOfProcsForStorage() == 1);
2865 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
2866 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence()"
2868 <<
", step " << m_currStep
2869 <<
": weightSequence.subSequenceSize() = " << weightSequence.
subSequenceSize()
2870 <<
", weightSequence.unifiedSequenceSize() = " << quantity1
2871 <<
", failedExponent = " << failedExponent
2872 <<
", currExponent = " << currExponent
2873 <<
", effective ratio = " << nowEffectiveSizeRatio
2874 <<
", log(evidence factor) = " << m_logEvidenceFactors[m_logEvidenceFactors.size()-1]
2875 <<
", evidence factor = " << exp(m_logEvidenceFactors[m_logEvidenceFactors.size()-1])
2893 "MLSampling<P_V,P_M>::generateSequence(), step 3, logEvidenceFactor") ==
false) {
2894 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
2895 *m_env.subDisplayFile() <<
"WARNING, In MLSampling<P_V,P_M>::generateSequence()"
2897 <<
", step " << m_currStep
2898 <<
", failedExponent = " << failedExponent
2899 <<
": nowAttempt = " << nowAttempt
2900 <<
", MiscCheck for 'logEvidenceFactor' detected a problem"
2906 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
2907 *m_env.subDisplayFile() <<
"Leaving MLSampling<P_V,P_M>::generateSequence_Step()"
2909 <<
", step " << m_currStep
2910 <<
", failedExponent = " << failedExponent
2911 <<
", after " << stepRunTime <<
" seconds"
2918 template <
class P_V,
class P_M>
2923 P_M& unifiedCovMatrix)
2926 struct timeval timevalStep;
2927 iRC = gettimeofday(&timevalStep, NULL);
2930 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
2931 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence()"
2933 <<
", step " << m_currStep
2934 <<
": beginning step 4 of 11"
2938 P_V auxVec(m_vectorSpace.zeroVector());
2939 P_V subWeightedMeanVec(m_vectorSpace.zeroVector());
2942 subWeightedMeanVec += weightSequence[i]*auxVec;
2946 P_V unifiedWeightedMeanVec(m_vectorSpace.zeroVector());
2947 if (m_env.inter0Rank() >= 0) {
2948 subWeightedMeanVec.mpiAllReduce(
RawValue_MPI_SUM,m_env.inter0Comm(),unifiedWeightedMeanVec);
2951 unifiedWeightedMeanVec = subWeightedMeanVec;
2954 P_V diffVec(m_vectorSpace.zeroVector());
2955 P_M subCovMatrix(m_vectorSpace.zeroVector());
2958 diffVec = auxVec - unifiedWeightedMeanVec;
2959 subCovMatrix += weightSequence[i]*
matrixProduct(diffVec,diffVec);
2962 for (
unsigned int i = 0; i < unifiedCovMatrix.numRowsLocal(); ++i) {
2963 for (
unsigned int j = 0; j < unifiedCovMatrix.numCols(); ++j) {
2964 double localValue = subCovMatrix(i,j);
2965 double sumValue = 0.;
2966 if (m_env.inter0Rank() >= 0) {
2968 "MLSampling<P_V,P_M>::generateSequence()",
2969 "failed MPI.Allreduce() for cov matrix");
2972 sumValue = localValue;
2974 unifiedCovMatrix(i,j) = sumValue;
2978 if (m_numDisabledParameters > 0) {
2979 for (
unsigned int paramId = 0; paramId < m_vectorSpace.dimLocal(); ++paramId) {
2980 if (m_parameterEnabledStatus[paramId] ==
false) {
2981 for (
unsigned int i = 0; i < m_vectorSpace.dimLocal(); ++i) {
2982 unifiedCovMatrix(i,paramId) = 0.;
2984 for (
unsigned int j = 0; j < m_vectorSpace.dimLocal(); ++j) {
2985 unifiedCovMatrix(paramId,j) = 0.;
2987 unifiedCovMatrix(paramId,paramId) = 1.;
2992 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
2993 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence()"
2995 <<
", step " << m_currStep
2996 <<
": unifiedCovMatrix = " << unifiedCovMatrix
3001 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
3002 *m_env.subDisplayFile() <<
"Leaving MLSampling<P_V,P_M>::generateSequence_Step()"
3004 <<
", step " << m_currStep
3005 <<
", after " << stepRunTime <<
" seconds"
3012 template <
class P_V,
class P_M>
3015 unsigned int unifiedRequestedNumSamples,
3017 std::vector<unsigned int>& unifiedIndexCountersAtProc0Only,
3018 std::vector<double>& unifiedWeightStdVectorAtProc0Only)
3021 struct timeval timevalStep;
3022 iRC = gettimeofday(&timevalStep, NULL);
3025 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
3026 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence()"
3028 <<
", step " << m_currStep
3029 <<
": beginning step 5 of 11"
3033 #if 0 // For debug only
3034 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
3035 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence()"
3037 <<
", step " << m_currStep
3038 <<
", before weightSequence.getUnifiedContentsAtProc0Only()"
3043 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
3044 *m_env.subDisplayFile() <<
", weightSequence[" << i
3045 <<
"] = " << weightSequence[i]
3052 unifiedWeightStdVectorAtProc0Only);
3054 #if 0 // For debug only
3055 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
3056 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence()"
3058 <<
", step " << m_currStep
3059 <<
", after weightSequence.getUnifiedContentsAtProc0Only()"
3063 for (
unsigned int i = 0; i < unifiedWeightStdVectorAtProc0Only.size(); ++i) {
3064 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
3065 *m_env.subDisplayFile() <<
" unifiedWeightStdVectorAtProc0Only[" << i
3066 <<
"] = " << unifiedWeightStdVectorAtProc0Only[i]
3071 sampleIndexes_proc0(unifiedRequestedNumSamples,
3072 unifiedWeightStdVectorAtProc0Only,
3073 unifiedIndexCountersAtProc0Only);
3075 unsigned int auxUnifiedSize = weightSequence.
unifiedSequenceSize(m_vectorSpace.numOfProcsForStorage() == 1);
3076 if (m_env.inter0Rank() == 0) {
3077 queso_require_equal_to_msg(unifiedIndexCountersAtProc0Only.size(), auxUnifiedSize,
"wrong output from sampleIndexesAtProc0() in step 5");
3081 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
3082 *m_env.subDisplayFile() <<
"Leaving MLSampling<P_V,P_M>::generateSequence_Step()"
3084 <<
", step " << m_currStep
3085 <<
", after " << stepRunTime <<
" seconds"
3092 template <
class P_V,
class P_M>
3096 unsigned int indexOfFirstWeight,
3097 unsigned int indexOfLastWeight,
3098 const std::vector<unsigned int>& unifiedIndexCountersAtProc0Only,
3099 bool& useBalancedChains,
3100 std::vector<ExchangeInfoStruct>& exchangeStdVec)
3103 struct timeval timevalStep;
3104 iRC = gettimeofday(&timevalStep, NULL);
3107 useBalancedChains = decideOnBalancedChains_all(currOptions,
3110 unifiedIndexCountersAtProc0Only,
3114 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
3115 *m_env.subDisplayFile() <<
"Leaving MLSampling<P_V,P_M>::generateSequence_Step()"
3117 <<
", step " << m_currStep
3118 <<
", after " << stepRunTime <<
" seconds"
3125 template <
class P_V,
class P_M>
3128 bool useBalancedChains,
3129 unsigned int indexOfFirstWeight,
3130 unsigned int indexOfLastWeight,
3131 const std::vector<unsigned int>& unifiedIndexCountersAtProc0Only,
3135 double prevExponent,
3136 double currExponent,
3139 std::vector<ExchangeInfoStruct>& exchangeStdVec,
3143 struct timeval timevalStep;
3144 iRC = gettimeofday(&timevalStep, NULL);
3147 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
3148 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence()"
3150 <<
", step " << m_currStep
3151 <<
": beginning step 7 of 11"
3155 if (useBalancedChains) {
3156 prepareBalLinkedChains_inter0(currOptions,
3160 prevLogLikelihoodValues,
3161 prevLogTargetValues,
3163 balancedLinkControl);
3166 prepareUnbLinkedChains_inter0(indexOfFirstWeight,
3168 unifiedIndexCountersAtProc0Only,
3169 unbalancedLinkControl);
3172 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
3173 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence()"
3175 <<
", step " << m_currStep
3176 <<
": balancedLinkControl.balLinkedChains.size() = " << balancedLinkControl.
balLinkedChains.size()
3177 <<
", unbalancedLinkControl.unbLinkedChains.size() = " << unbalancedLinkControl.
unbLinkedChains.size()
3182 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
3183 *m_env.subDisplayFile() <<
"Leaving MLSampling<P_V,P_M>::generateSequence_Step()"
3185 <<
", step " << m_currStep
3186 <<
", after " << stepRunTime <<
" seconds"
3193 template <
class P_V,
class P_M>
3200 struct timeval timevalStep;
3201 iRC = gettimeofday(&timevalStep, NULL);
3204 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
3205 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence()"
3207 <<
", step " << m_currStep
3208 <<
": beginning step 8 of 11"
3215 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
3216 *m_env.subDisplayFile() <<
"Leaving MLSampling<P_V,P_M>::generateSequence_Step()"
3218 <<
", step " << m_currStep
3219 <<
", after " << stepRunTime <<
" seconds"
3226 template <
class P_V,
class P_M>
3230 double prevExponent,
3231 double currExponent,
3234 unsigned int indexOfFirstWeight,
3235 unsigned int indexOfLastWeight,
3236 const std::vector<double>& unifiedWeightStdVectorAtProc0Only,
3241 P_M& unifiedCovMatrix,
3245 struct timeval timevalStep;
3246 iRC = gettimeofday(&timevalStep, NULL);
3250 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
3251 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence()"
3253 <<
", step " << m_currStep
3254 <<
": skipping step 9 of 11"
3259 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
3260 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence_Step09_all()"
3262 <<
", step " << m_currStep
3263 <<
": beginning step 9 of 11"
3267 double beforeEta = prevEta;
3268 double beforeRejectionRate = 0.;
3269 bool beforeRejectionRateIsBelowRange =
true;
3271 double nowEta = prevEta;
3272 double nowRejectionRate = 0.;
3273 bool nowRejectionRateIsBelowRange =
true;
3275 std::vector<double> etas(2,0.);
3276 etas[0] = beforeEta;
3279 std::vector<double> rejs(2,0.);
3283 unsigned int nowAttempt = 0;
3284 bool testResult =
false;
3286 bool useMiddlePointLogicForEta =
false;
3287 P_M nowCovMatrix(unifiedCovMatrix);
3288 #if 0 // KAUST, to check
3289 std::vector<double> unifiedWeightStdVectorAtProc0Only(0);
3291 unifiedWeightStdVectorAtProc0Only);
3294 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
3295 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence_Step09_all()"
3297 <<
", step " << m_currStep
3298 <<
": entering loop for assessing rejection rate"
3299 <<
", with nowAttempt = " << nowAttempt
3300 <<
", nowRejectionRate = " << nowRejectionRate
3303 nowCovMatrix = unifiedCovMatrix;
3305 if (nowRejectionRate < currOptions->m_minRejectionRate) {
3306 nowRejectionRateIsBelowRange =
true;
3309 nowRejectionRateIsBelowRange =
false;
3312 queso_error_msg(
"nowRejectionRate should be out of the requested range at this point of the logic");
3315 if (m_env.inter0Rank() >= 0) {
3316 if (nowAttempt > 0) {
3317 if (useMiddlePointLogicForEta ==
false) {
3318 if (nowAttempt == 1) {
3321 else if ((beforeRejectionRateIsBelowRange ==
true) &&
3322 (nowRejectionRateIsBelowRange ==
true)) {
3325 else if ((beforeRejectionRateIsBelowRange ==
false) &&
3326 (nowRejectionRateIsBelowRange ==
false)) {
3329 else if ((beforeRejectionRateIsBelowRange ==
true ) &&
3330 (nowRejectionRateIsBelowRange ==
false)) {
3331 useMiddlePointLogicForEta =
true;
3334 etas[0] = std::min(beforeEta,nowEta);
3335 etas[1] = std::max(beforeEta,nowEta);
3337 if (etas[0] == beforeEta) {
3338 rejs[0] = beforeRejectionRate;
3339 rejs[1] = nowRejectionRate;
3342 rejs[0] = nowRejectionRate;
3343 rejs[1] = beforeRejectionRate;
3346 else if ((beforeRejectionRateIsBelowRange ==
false) &&
3347 (nowRejectionRateIsBelowRange ==
true )) {
3348 useMiddlePointLogicForEta =
true;
3351 etas[0] = std::min(beforeEta,nowEta);
3352 etas[1] = std::max(beforeEta,nowEta);
3360 beforeRejectionRate = nowRejectionRate;
3361 beforeRejectionRateIsBelowRange = nowRejectionRateIsBelowRange;
3362 if (useMiddlePointLogicForEta ==
false) {
3363 if (beforeRejectionRateIsBelowRange) nowEta *= 4.;
3365 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
3366 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence_Step09_all()"
3368 <<
", step " << m_currStep
3369 <<
": in loop for assessing rejection rate"
3370 <<
", with nowAttempt = " << nowAttempt
3371 <<
", useMiddlePointLogicForEta = false"
3372 <<
", nowEta just updated to value (to be tested) " << nowEta
3377 if (nowRejectionRate > meanRejectionRate) {
3378 if (rejs[0] > meanRejectionRate) {
3388 if (rejs[0] < meanRejectionRate) {
3397 nowEta = .5*(etas[0] + etas[1]);
3398 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
3399 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence_Step09_all()"
3401 <<
", step " << m_currStep
3402 <<
": in loop for assessing rejection rate"
3403 <<
", with nowAttempt = " << nowAttempt
3404 <<
", useMiddlePointLogicForEta = true"
3405 <<
", nowEta just updated to value (to be tested) " << nowEta
3406 <<
", etas[0] = " << etas[0]
3407 <<
", etas[1] = " << etas[1]
3414 nowCovMatrix *= nowEta;
3418 unsigned int originalSubNumSamples = 1 + (
unsigned int) (doubSubNumSamples);
3419 double auxDouble = (double) originalSubNumSamples;
3420 if ((auxDouble - doubSubNumSamples) < 1.e-8) {
3421 originalSubNumSamples += 1;
3424 if (m_env.inter0Rank() >= 0) {
3425 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
3426 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence_Step09_all()"
3428 <<
", step " << m_currStep
3429 <<
": in loop for assessing rejection rate"
3430 <<
", about to sample " << originalSubNumSamples <<
" indexes"
3431 <<
", meanRejectionRate = " << meanRejectionRate
3437 std::vector<unsigned int> nowUnifiedIndexCountersAtProc0Only(0);
3438 if (m_env.inter0Rank() >= 0) {
3439 unsigned int tmpUnifiedNumSamples = originalSubNumSamples*m_env.inter0Comm().NumProc();
3440 sampleIndexes_proc0(tmpUnifiedNumSamples,
3441 unifiedWeightStdVectorAtProc0Only,
3442 nowUnifiedIndexCountersAtProc0Only);
3444 unsigned int auxUnifiedSize = weightSequence.
unifiedSequenceSize(m_vectorSpace.numOfProcsForStorage() == 1);
3445 if (m_env.inter0Rank() == 0) {
3446 queso_require_equal_to_msg(nowUnifiedIndexCountersAtProc0Only.size(), auxUnifiedSize,
"wrong output from sampleIndexesAtProc0() in step 9");
3449 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
3450 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence_Step09_all()"
3452 <<
", step " << m_currStep
3453 <<
": in loop for assessing rejection rate"
3454 <<
", about to distribute sampled assessment indexes"
3459 std::vector<ExchangeInfoStruct> exchangeStdVec(0);
3464 bool useBalancedChains = decideOnBalancedChains_all(currOptions,
3467 nowUnifiedIndexCountersAtProc0Only,
3470 if (m_env.inter0Rank() >= 0) {
3471 if (useBalancedChains) {
3472 prepareBalLinkedChains_inter0(currOptions,
3476 prevLogLikelihoodValues,
3477 prevLogTargetValues,
3482 prepareUnbLinkedChains_inter0(indexOfFirstWeight,
3484 nowUnifiedIndexCountersAtProc0Only,
3489 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
3490 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence_Step09_all()"
3492 <<
", step " << m_currStep
3493 <<
": in loop for assessing rejection rate"
3494 <<
", about to generate assessment chain"
3500 m_options.m_prefix+
"now_chain");
3501 double nowRunTime = 0.;
3502 unsigned int nowRejections = 0;
3507 #ifdef QUESO_USES_SEQUENCE_STATISTICAL_OPTIONS
3508 bool savedRawChainComputeStats = currOptions->m_rawChainComputeStats;
3515 if (m_env.displayVerbosity() >= 999999) {
3519 #ifdef QUESO_USES_SEQUENCE_STATISTICAL_OPTIONS
3520 currOptions->m_rawChainComputeStats =
false;
3527 if (useBalancedChains) {
3528 generateBalLinkedChains_all(*currOptions,
3539 generateUnbLinkedChains_all(*currOptions,
3547 prevLogLikelihoodValues,
3548 prevLogTargetValues,
3559 #ifdef QUESO_USES_SEQUENCE_STATISTICAL_OPTIONS
3560 currOptions->m_rawChainComputeStats = savedRawChainComputeStats;
3566 for (
unsigned int i = 0; i < nowBalLinkControl.
balLinkedChains.size(); ++i) {
3573 if (m_env.inter0Rank() >= 0) {
3575 unsigned int nowUnifiedRejections = 0;
3577 "MLSampling<P_V,P_M>::generateSequence_Step09_all()",
3578 "failed MPI.Allreduce() for now rejections");
3580 #if 0 // Round Rock 2009 12 29
3581 unsigned int tmpUnifiedNumSamples = 0;
3583 "MLSampling<P_V,P_M>::generateSequence_Step09_all()",
3584 "failed MPI.Allreduce() for num samples in step 9");
3587 unsigned int tmpUnifiedNumSamples = originalSubNumSamples*m_env.inter0Comm().NumProc();
3588 nowRejectionRate = ((double) nowUnifiedRejections) / ((double) tmpUnifiedNumSamples);
3593 (nowRejectionRate <= currOptions->m_maxRejectionRate);
3600 "MLSampling<P_V,P_M>::generateSequence_Step09_all(), step 9, testResult") ==
false) {
3601 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
3602 *m_env.subDisplayFile() <<
"WARNING, In MLSampling<P_V,P_M>::generateSequence()"
3604 <<
", step " << m_currStep
3605 <<
": nowAttempt = " << nowAttempt
3606 <<
", MiscCheck for 'testResult' detected a problem"
3613 unsigned int tmpUint = (
unsigned int) testResult;
3615 "MLSampling<P_V,P_M>::generateSequence_Step09_all()",
3616 "failed MPI.Bcast() for testResult");
3617 testResult = (bool) tmpUint;
3619 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
3620 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence_Step09_all()"
3622 <<
", step " << m_currStep
3623 <<
": in loop for assessing rejection rate"
3624 <<
", nowAttempt = " << nowAttempt
3625 <<
", beforeEta = " << beforeEta
3626 <<
", etas[0] = " << etas[0]
3627 <<
", nowEta = " << nowEta
3628 <<
", etas[1] = " << etas[1]
3630 <<
", nowRejectionRate = " << nowRejectionRate
3636 if (m_env.inter0Rank() >= 0) {
3641 "MLSampling<P_V,P_M>::generateSequence_Step09_all(), step 9, nowEta") ==
false) {
3642 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
3643 *m_env.subDisplayFile() <<
"WARNING, In MLSampling<P_V,P_M>::generateSequence()"
3645 <<
", step " << m_currStep
3646 <<
": nowAttempt = " << nowAttempt
3647 <<
", MiscCheck for 'nowEta' detected a problem"
3652 }
while (testResult ==
false);
3654 if (currEta != 1.) {
3655 unifiedCovMatrix *= currEta;
3656 if (m_numDisabledParameters > 0) {
3657 for (
unsigned int paramId = 0; paramId < m_vectorSpace.dimLocal(); ++paramId) {
3658 if (m_parameterEnabledStatus[paramId] ==
false) {
3659 for (
unsigned int i = 0; i < m_vectorSpace.dimLocal(); ++i) {
3660 unifiedCovMatrix(i,paramId) = 0.;
3662 for (
unsigned int j = 0; j < m_vectorSpace.dimLocal(); ++j) {
3663 unifiedCovMatrix(paramId,j) = 0.;
3665 unifiedCovMatrix(paramId,paramId) = 1.;
3671 unsigned int quantity1 = weightSequence.
unifiedSequenceSize(m_vectorSpace.numOfProcsForStorage() == 1);
3672 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
3673 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence_Step09_all()"
3675 <<
", step " << m_currStep
3676 <<
": weightSequence.subSequenceSize() = " << weightSequence.
subSequenceSize()
3677 <<
", weightSequence.unifiedSequenceSize() = " << quantity1
3678 <<
", currEta = " << currEta
3679 <<
", assessed rejection rate = " << nowRejectionRate
3685 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
3686 *m_env.subDisplayFile() <<
"Leaving MLSampling<P_V,P_M>::generateSequence_Step()"
3688 <<
", step " << m_currStep
3689 <<
", after " << stepRunTime <<
" seconds"
3696 template <
class P_V,
class P_M>
3700 const P_M& unifiedCovMatrix,
3702 bool useBalancedChains,
3704 unsigned int indexOfFirstWeight,
3706 double prevExponent,
3707 double currExponent,
3712 double& cumulativeRawChainRunTime,
3713 unsigned int& cumulativeRawChainRejections,
3718 struct timeval timevalStep;
3719 iRC = gettimeofday(&timevalStep, NULL);
3722 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
3723 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence()"
3725 <<
", step " << m_currStep
3726 <<
": beginning step 10 of 11"
3727 <<
", currLogLikelihoodValues = " << currLogLikelihoodValues
3734 #ifdef QUESO_USES_SEQUENCE_STATISTICAL_OPTIONS
3735 bool savedRawChainComputeStats = currOptions.m_rawChainComputeStats;
3740 if (m_env.displayVerbosity() >= 999999) {
3744 #ifdef QUESO_USES_SEQUENCE_STATISTICAL_OPTIONS
3745 currOptions.m_rawChainComputeStats =
false;
3750 if (useBalancedChains) {
3751 generateBalLinkedChains_all(currOptions,
3754 balancedLinkControl,
3756 cumulativeRawChainRunTime,
3757 cumulativeRawChainRejections,
3758 currLogLikelihoodValues,
3759 currLogTargetValues);
3762 generateUnbLinkedChains_all(currOptions,
3765 unbalancedLinkControl,
3770 prevLogLikelihoodValues,
3771 prevLogTargetValues,
3773 cumulativeRawChainRunTime,
3774 cumulativeRawChainRejections,
3775 currLogLikelihoodValues,
3776 currLogTargetValues);
3779 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
3780 double tmpValue = INFINITY;
3781 if (currLogLikelihoodValues) tmpValue = (*currLogLikelihoodValues)[0];
3782 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence_Step()"
3784 <<
", step " << m_currStep
3785 <<
", after chain generatrion"
3786 <<
", currLogLikelihoodValues[0] = " << tmpValue
3793 #ifdef QUESO_USES_SEQUENCE_STATISTICAL_OPTIONS
3794 currOptions.m_rawChainComputeStats = savedRawChainComputeStats;
3799 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
3800 *m_env.subDisplayFile() <<
"Leaving MLSampling<P_V,P_M>::generateSequence_Step()"
3802 <<
", step " << m_currStep
3803 <<
", after " << stepRunTime <<
" seconds"
3810 template <
class P_V,
class P_M>
3814 unsigned int unifiedRequestedNumSamples,
3815 unsigned int cumulativeRawChainRejections,
3819 unsigned int& unifiedNumberOfRejections)
3822 struct timeval timevalStep;
3823 iRC = gettimeofday(&timevalStep, NULL);
3826 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
3827 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence()"
3829 <<
", step " << m_currStep
3830 <<
": beginning step 11 of 11"
3836 #ifdef QUESO_USES_SEQUENCE_STATISTICAL_OPTIONS
3837 if (currOptions->m_rawChainComputeStats) {
3845 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 10)) {
3846 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence_Step()"
3848 <<
", step " << m_currStep
3849 <<
", calling computeStatistics for raw chain"
3850 <<
". Ofstream pointer value = " << filePtrSet.
ofsVar
3851 <<
", statistical options are"
3852 <<
"\n" << *currOptions->m_rawChainStatisticalOptionsObj
3856 currChain.computeStatistics(*currOptions->m_rawChainStatisticalOptionsObj,
3867 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
3868 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence_Step()"
3870 <<
", step " << m_currStep
3871 <<
", before calling currLogLikelihoodValues.unifiedWriteContents()"
3872 <<
", currLogLikelihoodValues[0] = " << currLogLikelihoodValues[0]
3891 if (filterSpacing == 0) {
3898 currChain.
filter(filterInitialPos,
3902 currLogLikelihoodValues.
filter(filterInitialPos,
3904 currLogLikelihoodValues.
setName(currOptions->
m_prefix +
"filtLogLikelihood");
3906 currLogTargetValues.
filter(filterInitialPos,
3910 #ifdef QUESO_USES_SEQUENCE_STATISTICAL_OPTIONS
3911 if (currOptions->m_filteredChainComputeStats) {
3912 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 10)) {
3913 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence_Step()"
3915 <<
", step " << m_currStep
3916 <<
", calling computeStatistics for filtered chain"
3917 <<
". Ofstream pointer value = " << filePtrSet.
ofsVar
3918 <<
", statistical options are"
3919 <<
"\n" << *currOptions->m_rawChainStatisticalOptionsObj
3924 currChain.computeStatistics(*currOptions->m_filteredChainStatisticalOptionsObj,
3949 unsigned int unifiedGeneratedNumSamples = 0;
3951 "MLSampling<P_V,P_M>::generateSequence()",
3952 "failed MPI.Allreduce() for generated num samples in step 11");
3956 queso_require_equal_to_msg(unifiedGeneratedNumSamples, unifiedRequestedNumSamples,
"currChain (linked one) has been generated with invalid size");
3961 "MLSampling<P_V,P_M>::generateSequence()",
3962 "failed MPI.Allreduce() for number of rejections");
3965 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
3966 *m_env.subDisplayFile() <<
"Leaving MLSampling<P_V,P_M>::generateSequence_Step()"
3968 <<
", step " << m_currStep
3969 <<
", after " << stepRunTime <<
" seconds"
3977 template<
class P_V,
class P_M>
3983 m_env (priorRv.env()),
3984 m_priorRv (priorRv),
3985 m_likelihoodFunction(likelihoodFunction),
3986 m_vectorSpace (m_priorRv.imageSet().vectorSpace()),
3988 m_numDisabledParameters (0),
3989 m_parameterEnabledStatus(m_vectorSpace.dimLocal(),true),
3990 m_options (m_env,prefix),
3993 m_debugExponent (0.),
3994 m_logEvidenceFactors(0),
3996 m_meanLogLikelihood (0.),
4010 template<
class P_V,
class P_M>
4013 m_numDisabledParameters = 0;
4014 m_parameterEnabledStatus.clear();
4015 if (m_targetDomain)
delete m_targetDomain;
4021 template <
class P_V,
class P_M>
4028 struct timeval timevalRoutineBegin;
4030 iRC = gettimeofday(&timevalRoutineBegin, NULL);
4033 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
4034 *m_env.subDisplayFile() <<
"Entering MLSampling<P_V,P_M>::generateSequence()"
4035 <<
", at " << ctime(&timevalRoutineBegin.tv_sec)
4036 <<
", after " << timevalRoutineBegin.tv_sec - m_env.timevalBegin().tv_sec
4037 <<
" seconds from queso environment instatiation..."
4044 double currExponent = 0.;
4045 double currEta = 1.;
4046 unsigned int currUnifiedRequestedNumSamples = 0;
4049 m_options.m_prefix+
"curr_chain");
4057 bool stopAtEndOfLevel =
false;
4058 char levelPrefix[256];
4069 if (m_options.m_restartInput_baseNameForFiles !=
".") {
4070 restartML(currExponent,
4073 currLogLikelihoodValues,
4074 currLogTargetValues);
4076 if (currExponent == 1.) {
4077 if (lastLevelOptions.m_parameterDisabledSet.size() > 0) {
4078 for (std::set<unsigned int>::iterator setIt = lastLevelOptions.m_parameterDisabledSet.begin(); setIt != lastLevelOptions.m_parameterDisabledSet.end(); ++setIt) {
4079 unsigned int paramId = *setIt;
4080 if (paramId < m_vectorSpace.dimLocal()) {
4081 m_numDisabledParameters++;
4082 m_parameterEnabledStatus[paramId] =
false;
4087 #ifdef QUESO_USES_SEQUENCE_STATISTICAL_OPTIONS
4088 if (lastLevelOptions.m_rawChainComputeStats) {
4090 m_env.openOutputFile(lastLevelOptions.m_dataOutputFileName,
4092 lastLevelOptions.m_dataOutputAllowedSet,
4096 currChain.computeStatistics(*lastLevelOptions.m_rawChainStatisticalOptionsObj,
4106 currChain.
unifiedWriteContents (lastLevelOptions.m_rawChainDataOutputFileName,lastLevelOptions.m_rawChainDataOutputFileType);
4107 currLogLikelihoodValues.
unifiedWriteContents(lastLevelOptions.m_rawChainDataOutputFileName,lastLevelOptions.m_rawChainDataOutputFileType);
4108 currLogTargetValues.
unifiedWriteContents (lastLevelOptions.m_rawChainDataOutputFileName,lastLevelOptions.m_rawChainDataOutputFileType);
4111 if (lastLevelOptions.m_filteredChainGenerate) {
4113 m_env.openOutputFile(lastLevelOptions.m_dataOutputFileName,
4115 lastLevelOptions.m_dataOutputAllowedSet,
4119 unsigned int filterInitialPos = (
unsigned int) (lastLevelOptions.m_filteredChainDiscardedPortion * (
double) currChain.
subSequenceSize());
4120 unsigned int filterSpacing = lastLevelOptions.m_filteredChainLag;
4121 if (filterSpacing == 0) {
4128 currChain.
filter(filterInitialPos,
4130 currChain.
setName(lastLevelOptions.m_prefix +
"filtChain");
4132 currLogLikelihoodValues.
filter(filterInitialPos,
4134 currLogLikelihoodValues.
setName(lastLevelOptions.m_prefix +
"filtLogLikelihood");
4136 currLogTargetValues.
filter(filterInitialPos,
4138 currLogTargetValues.
setName(lastLevelOptions.m_prefix +
"filtLogTarget");
4140 #ifdef QUESO_USES_SEQUENCE_STATISTICAL_OPTIONS
4141 if (lastLevelOptions.m_filteredChainComputeStats) {
4142 currChain.computeStatistics(*lastLevelOptions.m_filteredChainStatisticalOptionsObj,
4151 currChain.
unifiedWriteContents (lastLevelOptions.m_filteredChainDataOutputFileName,lastLevelOptions.m_filteredChainDataOutputFileType);
4152 currLogLikelihoodValues.
unifiedWriteContents(lastLevelOptions.m_filteredChainDataOutputFileName,lastLevelOptions.m_filteredChainDataOutputFileType);
4153 currLogTargetValues.
unifiedWriteContents (lastLevelOptions.m_filteredChainDataOutputFileName,lastLevelOptions.m_filteredChainDataOutputFileType);
4163 if (currOptions.m_parameterDisabledSet.size() > 0) {
4164 for (std::set<unsigned int>::iterator setIt = currOptions.m_parameterDisabledSet.begin(); setIt != currOptions.m_parameterDisabledSet.end(); ++setIt) {
4165 unsigned int paramId = *setIt;
4166 if (paramId < m_vectorSpace.dimLocal()) {
4167 m_numDisabledParameters++;
4168 m_parameterEnabledStatus[paramId] =
false;
4173 generateSequence_Level0_all(currOptions,
4174 currUnifiedRequestedNumSamples,
4176 currLogLikelihoodValues,
4177 currLogTargetValues);
4179 stopAtEndOfLevel = currOptions.m_stopAtEnd;
4180 bool performCheckpoint = stopAtEndOfLevel;
4181 if (m_options.m_restartOutput_levelPeriod > 0) {
4182 performCheckpoint = performCheckpoint || ( ((m_currLevel + 1) % m_options.m_restartOutput_levelPeriod) == 0 );
4184 if (performCheckpoint) {
4185 checkpointML(currExponent,
4188 currLogLikelihoodValues,
4189 currLogTargetValues);
4195 double minLogLike = -INFINITY;
4196 double maxLogLike = INFINITY;
4201 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
4202 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence()"
4204 <<
", sub minLogLike = " << minLogLike
4205 <<
", sub maxLogLike = " << maxLogLike
4209 m_env.fullComm().Barrier();
4211 minLogLike = -INFINITY;
4212 maxLogLike = INFINITY;
4213 currLogLikelihoodValues.
unifiedMinMaxExtra(m_vectorSpace.numOfProcsForStorage() == 1,
4218 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
4219 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence()"
4221 <<
", unified minLogLike = " << minLogLike
4222 <<
", unified maxLogLike = " << maxLogLike
4229 while ((currExponent < 1. ) &&
4230 (stopAtEndOfLevel ==
false)) {
4233 struct timeval timevalLevelBegin;
4235 iRC = gettimeofday(&timevalLevelBegin, NULL);
4237 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
4238 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence()"
4240 <<
", at " << ctime(&timevalLevelBegin.tv_sec)
4241 <<
", after " << timevalLevelBegin.tv_sec - timevalRoutineBegin.tv_sec
4242 <<
" seconds from entering the routine"
4243 <<
", after " << timevalLevelBegin.tv_sec - m_env.timevalBegin().tv_sec
4244 <<
" seconds from queso environment instatiation"
4249 struct timeval timevalLevel;
4250 iRC = gettimeofday(&timevalLevel, NULL);
4251 double cumulativeRawChainRunTime = 0.;
4252 unsigned int cumulativeRawChainRejections = 0;
4254 bool tryExponentEta =
true;
4255 double failedExponent = 0.;
4256 double failedEta = 0.;
4262 double prevExponent = 0.;
4263 unsigned int indexOfFirstWeight = 0;
4264 unsigned int indexOfLastWeight = 0;
4265 P_M* unifiedCovMatrix = NULL;
4266 bool useBalancedChains =
false;
4272 unsigned int exponentEtaTriedAmount = 0;
4273 while (tryExponentEta) {
4274 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
4275 *m_env.subDisplayFile() <<
"In IMLSampling<P_V,P_M>::generateSequence()"
4277 <<
", beginning 'do-while(tryExponentEta)"
4278 <<
": failedExponent = " << failedExponent
4279 <<
", failedEta = " << failedEta
4293 unsigned int paramId = *setIt;
4294 if (paramId < m_vectorSpace.dimLocal()) {
4295 m_numDisabledParameters++;
4296 m_parameterEnabledStatus[paramId] =
false;
4301 if (m_env.inter0Rank() >= 0) {
4302 generateSequence_Step01_inter0(currOptions,
4303 currUnifiedRequestedNumSamples);
4310 prevExponent = currExponent;
4311 double prevEta = currEta;
4312 unsigned int prevUnifiedRequestedNumSamples = currUnifiedRequestedNumSamples;
4315 m_options.m_prefix+
"prev_chain");
4317 indexOfFirstWeight = 0;
4318 indexOfLastWeight = 0;
4321 if (m_env.inter0Rank() >= 0) {
4322 generateSequence_Step02_inter0(currOptions,
4324 currLogLikelihoodValues,
4326 currLogTargetValues,
4328 prevLogLikelihoodValues,
4329 prevLogTargetValues,
4340 if (m_env.inter0Rank() >= 0) {
4341 generateSequence_Step03_inter0(currOptions,
4342 prevLogLikelihoodValues,
4351 "MLSampling<P_V,P_M>::generateSequence()",
4352 "failed MPI.Bcast() for currExponent");
4353 m_debugExponent = currExponent;
4355 if (currExponent == 1.) {
4356 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
4357 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence()"
4359 <<
", step " << m_currStep
4360 <<
": copying 'last' level options to current options"
4364 currOptions = &lastLevelOptions;
4366 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
4367 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence()"
4369 <<
", step " << m_currStep
4370 <<
": after copying 'last' level options to current options, the current options are"
4371 <<
"\n" << *currOptions
4375 if (m_env.inter0Rank() >= 0) {
4380 "MLSampling<P_V,P_M>::generateSequence()",
4381 "failed MPI.Allreduce() for requested num samples in step 3");
4389 P_V oneVec(m_vectorSpace.zeroVector());
4392 unifiedCovMatrix = NULL;
4393 if (m_env.inter0Rank() >= 0) {
4394 unifiedCovMatrix = m_vectorSpace.newMatrix();
4397 unifiedCovMatrix =
new P_M(oneVec);
4400 if (m_env.inter0Rank() >= 0) {
4401 generateSequence_Step04_inter0(*prevChain,
4410 std::vector<unsigned int> unifiedIndexCountersAtProc0Only(0);
4411 std::vector<double> unifiedWeightStdVectorAtProc0Only(0);
4412 if (m_env.inter0Rank() >= 0) {
4413 generateSequence_Step05_inter0(currUnifiedRequestedNumSamples,
4415 unifiedIndexCountersAtProc0Only,
4416 unifiedWeightStdVectorAtProc0Only);
4423 useBalancedChains =
false;
4424 std::vector<ExchangeInfoStruct> exchangeStdVec(0);
4426 generateSequence_Step06_all(currOptions,
4429 unifiedIndexCountersAtProc0Only,
4440 if (m_env.inter0Rank() >= 0) {
4441 generateSequence_Step07_inter0(useBalancedChains,
4444 unifiedIndexCountersAtProc0Only,
4445 *unbalancedLinkControl,
4450 prevLogLikelihoodValues,
4451 prevLogTargetValues,
4453 *balancedLinkControl);
4464 m_likelihoodFunction,
4472 generateSequence_Step08_all(*currPdf,
4479 generateSequence_Step09_all(*prevChain,
4482 prevLogLikelihoodValues,
4483 prevLogTargetValues,
4486 unifiedWeightStdVectorAtProc0Only,
4494 tryExponentEta =
false;
4496 (currEta < currOptions->m_minAcceptableEta)) {
4497 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
4498 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence()"
4500 <<
", preparing to retry ExponentEta"
4501 <<
": currExponent = " << currExponent
4502 <<
", currEta = " << currEta
4505 exponentEtaTriedAmount++;
4506 tryExponentEta =
true;
4507 failedExponent = currExponent;
4508 failedEta = currEta;
4516 delete balancedLinkControl;
4517 balancedLinkControl = NULL;
4518 delete unbalancedLinkControl;
4519 unbalancedLinkControl = NULL;
4521 delete unifiedCovMatrix;
4522 unifiedCovMatrix = NULL;
4524 currExponent = prevExponent;
4526 currUnifiedRequestedNumSamples = prevUnifiedRequestedNumSamples;
4529 currChain = (*prevChain);
4533 currLogLikelihoodValues = prevLogLikelihoodValues;
4534 currLogTargetValues = prevLogTargetValues;
4538 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
4539 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence()"
4541 <<
", exited 'do-while(tryExponentEta)"
4542 <<
", failedExponent = " << failedExponent
4543 <<
", failedEta = " << failedEta
4552 generateSequence_Step10_all(*currOptions,
4556 *unbalancedLinkControl,
4561 prevLogLikelihoodValues,
4562 prevLogTargetValues,
4563 *balancedLinkControl,
4565 cumulativeRawChainRunTime,
4566 cumulativeRawChainRejections,
4567 &currLogLikelihoodValues,
4568 &currLogTargetValues);
4574 bool performCheckpoint = stopAtEndOfLevel;
4575 if (m_options.m_restartOutput_levelPeriod > 0) {
4576 performCheckpoint = performCheckpoint || ( ((m_currLevel + 1) % m_options.m_restartOutput_levelPeriod) == 0 );
4577 if (currExponent == 1.) {
4578 performCheckpoint =
true;
4581 if (performCheckpoint) {
4582 checkpointML(currExponent,
4585 currLogLikelihoodValues,
4586 currLogTargetValues);
4593 delete unifiedCovMatrix;
4595 for (
unsigned int i = 0; i < balancedLinkControl->
balLinkedChains.size(); ++i) {
4607 unsigned int unifiedNumberOfRejections = 0;
4608 if (m_env.inter0Rank() >= 0) {
4609 generateSequence_Step11_inter0(currOptions,
4610 currUnifiedRequestedNumSamples,
4611 cumulativeRawChainRejections,
4613 currLogLikelihoodValues,
4614 currLogTargetValues,
4615 unifiedNumberOfRejections);
4618 minLogLike = -INFINITY;
4619 maxLogLike = INFINITY;
4624 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
4625 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence()"
4627 <<
", sub minLogLike = " << minLogLike
4628 <<
", sub maxLogLike = " << maxLogLike
4632 m_env.fullComm().Barrier();
4634 minLogLike = -INFINITY;
4635 maxLogLike = INFINITY;
4636 currLogLikelihoodValues.
unifiedMinMaxExtra(m_vectorSpace.numOfProcsForStorage() == 1,
4641 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
4642 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence()"
4644 <<
", unified minLogLike = " << minLogLike
4645 <<
", unified maxLogLike = " << maxLogLike
4653 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
4654 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence()"
4657 <<
" chain positions"
4658 <<
", cumulativeRawChainRunTime = " << cumulativeRawChainRunTime <<
" seconds"
4659 <<
", total level time = " << levelRunTime <<
" seconds"
4660 <<
", cumulativeRawChainRejections = " << cumulativeRawChainRejections
4661 <<
" (" << 100.*((double) cumulativeRawChainRejections)/((double) currOptions->
m_rawChainSize)
4662 <<
"% at this processor)"
4663 <<
" (" << 100.*((double) unifiedNumberOfRejections)/((double) currUnifiedRequestedNumSamples)
4664 <<
"% over all processors)"
4665 <<
", stopAtEndOfLevel = " << stopAtEndOfLevel
4669 if (m_env.inter0Rank() >= 0) {
4670 double minCumulativeRawChainRunTime = 0.;
4672 "MLSampling<P_V,P_M>::generateSequence()",
4673 "failed MPI.Allreduce() for min cumulative raw chain run time");
4675 double maxCumulativeRawChainRunTime = 0.;
4677 "MLSampling<P_V,P_M>::generateSequence()",
4678 "failed MPI.Allreduce() for max cumulative raw chain run time");
4680 double avgCumulativeRawChainRunTime = 0.;
4682 "MLSampling<P_V,P_M>::generateSequence()",
4683 "failed MPI.Allreduce() for sum cumulative raw chain run time");
4684 avgCumulativeRawChainRunTime /= ((double) m_env.inter0Comm().NumProc());
4686 double minLevelRunTime = 0.;
4688 "MLSampling<P_V,P_M>::generateSequence()",
4689 "failed MPI.Allreduce() for min level run time");
4691 double maxLevelRunTime = 0.;
4693 "MLSampling<P_V,P_M>::generateSequence()",
4694 "failed MPI.Allreduce() for max level run time");
4696 double avgLevelRunTime = 0.;
4698 "MLSampling<P_V,P_M>::generateSequence()",
4699 "failed MPI.Allreduce() for sum level run time");
4700 avgLevelRunTime /= ((double) m_env.inter0Comm().NumProc());
4702 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
4703 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence()"
4705 <<
": min cumul seconds = " << minCumulativeRawChainRunTime
4706 <<
", avg cumul seconds = " << avgCumulativeRawChainRunTime
4707 <<
", max cumul seconds = " << maxCumulativeRawChainRunTime
4708 <<
", min level seconds = " << minLevelRunTime
4709 <<
", avg level seconds = " << avgLevelRunTime
4710 <<
", max level seconds = " << maxLevelRunTime
4715 if (currExponent != 1.)
delete currOptions;
4717 struct timeval timevalLevelEnd;
4719 iRC = gettimeofday(&timevalLevelEnd, NULL);
4721 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
4722 *m_env.subDisplayFile() <<
"Getting at the end of level " << m_currLevel+
LEVEL_REF_ID
4723 <<
", as part of a 'while' on levels"
4724 <<
", at " << ctime(&timevalLevelEnd.tv_sec)
4725 <<
", after " << timevalLevelEnd.tv_sec - timevalRoutineBegin.tv_sec
4726 <<
" seconds from entering the routine"
4727 <<
", after " << timevalLevelEnd.tv_sec - m_env.timevalBegin().tv_sec
4728 <<
" seconds from queso environment instatiation"
4742 if (m_env.inter0Rank() >= 0) {
4745 for (
unsigned int i = 0; i < m_logEvidenceFactors.size(); ++i) {
4746 m_logEvidence += m_logEvidenceFactors[i];
4749 #if 1 // prudenci-2012-07-06
4750 m_meanLogLikelihood = currLogLikelihoodValues.
unifiedMeanPlain(m_vectorSpace.numOfProcsForStorage() == 1);
4752 m_meanLogLikelihood = currLogLikelihoodValues.
unifiedMeanExtra(m_vectorSpace.numOfProcsForStorage() == 1,
4757 m_eig = m_meanLogLikelihood - m_logEvidence;
4759 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
4760 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence()"
4761 <<
", log(evidence) = " << m_logEvidence
4762 <<
", evidence = " << exp(m_logEvidence)
4763 <<
", meanLogLikelihood = " << m_meanLogLikelihood
4764 <<
", eig = " << m_eig
4770 "MLSampling<P_V,P_M>::generateSequence()",
4771 "failed MPI.Bcast() for m_logEvidence");
4774 "MLSampling<P_V,P_M>::generateSequence()",
4775 "failed MPI.Bcast() for m_meanLogLikelihood");
4778 "MLSampling<P_V,P_M>::generateSequence()",
4779 "failed MPI.Bcast() for m_eig");
4784 workingChain.
clear();
4786 P_V auxVec(m_vectorSpace.zeroVector());
4788 if (m_env.inter0Rank() >= 0) {
4794 if (workingLogLikelihoodValues) *workingLogLikelihoodValues = currLogLikelihoodValues;
4795 if (workingLogTargetValues ) *workingLogTargetValues = currLogTargetValues;
4797 struct timeval timevalRoutineEnd;
4799 iRC = gettimeofday(&timevalRoutineEnd, NULL);
4801 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
4802 *m_env.subDisplayFile() <<
"Leaving MLSampling<P_V,P_M>::generateSequence()"
4803 <<
", at " << ctime(&timevalRoutineEnd.tv_sec)
4804 <<
", after " << timevalRoutineEnd.tv_sec - timevalRoutineBegin.tv_sec
4805 <<
" seconds from entering the routine"
4806 <<
", after " << timevalRoutineEnd.tv_sec - m_env.timevalBegin().tv_sec
4807 <<
" seconds from queso environment instatiation"
4814 template<
class P_V,
class P_M>
4815 std::ostream& operator<<(std::ostream& os, const MLSampling<P_V,P_M>& obj)
4822 template <
class P_V,
class P_M>
4825 return m_logEvidence;
4828 template <
class P_V,
class P_M>
4831 return m_meanLogLikelihood;
4834 template <
class P_V,
class P_M>
VectorSet< V, M > * InstantiateIntersection(const VectorSet< V, M > &domain1, const VectorSet< V, M > &domain2)
This method calculates the intersection of domain1 and domain2.
bool decideOnBalancedChains_all(const MLSamplingLevelOptions *currOptions, unsigned int indexOfFirstWeight, unsigned int indexOfLastWeight, const std::vector< unsigned int > &unifiedIndexCountersAtProc0Only, std::vector< ExchangeInfoStruct > &exchangeStdVec)
void generateSequence_Step06_all(const MLSamplingLevelOptions *currOptions, unsigned int indexOfFirstWeight, unsigned int indexOfLastWeight, const std::vector< unsigned int > &unifiedIndexCountersAtProc0Only, bool &useBalancedChains, std::vector< ExchangeInfoStruct > &exchangeStdVec)
Decides on wheter or not to use balanced chains (Step 06 from ML algorithm).
#define RawValue_MPI_IN_PLACE
void setName(const std::string &newName)
Sets a new name to the sequence of scalars.
void generateSequence_Step07_inter0(bool useBalancedChains, unsigned int indexOfFirstWeight, unsigned int indexOfLastWeight, const std::vector< unsigned int > &unifiedIndexCountersAtProc0Only, UnbalancedLinkedChainsPerNodeStruct &unbalancedLinkControl, const MLSamplingLevelOptions *currOptions, const SequenceOfVectors< P_V, P_M > &prevChain, double prevExponent, double currExponent, const ScalarSequence< double > &prevLogLikelihoodValues, const ScalarSequence< double > &prevLogTargetValues, std::vector< ExchangeInfoStruct > &exchangeStdVec, BalancedLinkedChainsPerNodeStruct< P_V > &balancedLinkControl)
Plans for number of linked chains for each node so that all nodes generate the closest possible to th...
double m_filteredChainDiscardedPortion
Initial discarded portion for chain filtering.
unsigned int m_loadBalanceAlgorithmId
Perform load balancing with chosen algorithm (0 = no balancing).
void append(const BaseVectorSequence< V, M > &src, unsigned int initialPos, unsigned int numPos)
Appends the vector src to this vector.
double meanLogLikelihood() const
Method to calculate the mean of the logarithm of the likelihood.
MLSampling(const char *prefix, const BaseVectorRV< P_V, P_M > &priorRv, const BaseScalarFunction< P_V, P_M > &likelihoodFunction)
Constructor.
void clear()
Clears the sequence of scalars.
void generateSequence_Step09_all(const SequenceOfVectors< P_V, P_M > &prevChain, double prevExponent, double currExponent, const ScalarSequence< double > &prevLogLikelihoodValues, const ScalarSequence< double > &prevLogTargetValues, unsigned int indexOfFirstWeight, unsigned int indexOfLastWeight, const std::vector< double > &unifiedWeightStdVectorAtProc0Only, const ScalarSequence< double > &weightSequence, double prevEta, const GenericVectorRV< P_V, P_M > &currRv, MLSamplingLevelOptions *currOptions, P_M &unifiedCovMatrix, double &currEta)
Scales the unified covariance matrix until min <= rejection rate <= max (Step 09 from ML algorithm)...
const T & unifiedMaxPlain(bool useOnlyInter0Comm) const
Finds the maximum value of the unified sequence of scalars.
std::string m_dataOutputFileName
Name of generic output file.
unsigned int sample() const
Samples.
unsigned int numberOfPositions
void generateSequence_Step01_inter0(const MLSamplingLevelOptions *currOptions, unsigned int &unifiedRequestedNumSamples)
Reads options for the ML algorithm (Step 01 from ML algorithm).
void computeFilterParams(std::ofstream *passedOfs, unsigned int &initialPos, unsigned int &spacing)
Computes the filtering parameters spacing for the sequence of vectors.
void generateSequence_Step04_inter0(const SequenceOfVectors< P_V, P_M > &prevChain, const ScalarSequence< double > &weightSequence, P_M &unifiedCovMatrix)
Creates covariance matrix for current level (Step 04 from ML algorithm).
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...
MPI_Status RawType_MPI_Status
void generateSequence_Step11_inter0(const MLSamplingLevelOptions *currOptions, unsigned int unifiedRequestedNumSamples, unsigned int cumulativeRawChainRejections, SequenceOfVectors< P_V, P_M > &currChain, ScalarSequence< double > &currLogLikelihoodValues, ScalarSequence< double > &currLogTargetValues, unsigned int &unifiedNumberOfRejections)
Filters chain (Step 11 from ML algorithm).
const T & unifiedMeanPlain(bool useOnlyInter0Comm) const
Finds the mean value of the unified sequence of scalars.
void resizeSequence(unsigned int newSequenceSize)
Resizes the size of the sequence of scalars.
A templated class that represents a Metropolis-Hastings generator of samples.
void filter(unsigned int initialPos, unsigned int spacing)
Filters positions in the sequence of vectors.
void unifiedReadContents(const std::string &fileName, const std::string &fileType, const unsigned int subSequenceSize)
Reads the unified sequence from a file.
void generateSequence(BaseVectorSequence< P_V, P_M > &workingChain, ScalarSequence< double > *workingLogLikelihoodValues, ScalarSequence< double > *workingLogTargetValues)
Method to generate the chain.
void prepareBalLinkedChains_inter0(const MLSamplingLevelOptions *currOptions, const SequenceOfVectors< P_V, P_M > &prevChain, double prevExponent, double currExponent, const ScalarSequence< double > &prevLogLikelihoodValues, const ScalarSequence< double > &prevLogTargetValues, std::vector< ExchangeInfoStruct > &exchangeStdVec, BalancedLinkedChainsPerNodeStruct< P_V > &balancedLinkControl)
std::ofstream * ofsVar
Provides a stream interface to write data to files.
#define ML_CHECKPOINT_FIXED_AMOUNT_OF_DATA
Struct for handling data input and output from files.
double m_minRejectionRate
minimum allowed attempted rejection rate at current level
void generateBalLinkedChains_all(MLSamplingLevelOptions &inputOptions, const P_M &unifiedCovMatrix, const GenericVectorRV< P_V, P_M > &rv, const BalancedLinkedChainsPerNodeStruct< P_V > &balancedLinkControl, SequenceOfVectors< P_V, P_M > &workingChain, double &cumulativeRunTime, unsigned int &cumulativeRejections, ScalarSequence< double > *currLogLikelihoodValues, ScalarSequence< double > *currLogTargetValues)
bool m_totallyMute
Whether or not to be totally mute (no printout message).
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...
#define queso_require_less_equal_msg(expr1, expr2, msg)
A struct that represents a Metropolis-Hastings sample.
bool m_filteredChainGenerate
Whether or not to generate filtered chain.
void scanOptionsValues(const MLSamplingLevelOptions *defaultOptions)
unsigned int initialPositionIndexInPreviousChain
bool m_initialPositionUsePreviousLevelLikelihood
Use previous level likelihood for initial chain position instead of re-computing it from target pdf...
#define queso_error_msg(msg)
unsigned int unifiedSequenceSize(bool useOnlyInter0Comm) const
Size of the unified sequence of scalars.
void generateSequence_Step08_all(BayesianJointPdf< P_V, P_M > &currPdf, GenericVectorRV< P_V, P_M > &currRv)
Creates a vector RV for current level (Step 08 from ML algorithm).
double logEvidence() const
Method to calculate the logarithm of the evidence.
double m_minAcceptableEta
minimum acceptable eta,
This class provides options for each level of the Multilevel sequence generator if no input file is a...
void restartML(double &currExponent, double &currEta, SequenceOfVectors< P_V, P_M > &currChain, ScalarSequence< double > &currLogLikelihoodValues, ScalarSequence< double > &currLogTargetValues)
Restarts ML algorithm.
void append(const ScalarSequence< T > &src, unsigned int srcInitialPos, unsigned int srcNumPos)
Appends the scalar sequence src to this sequence.
void mpiExchangePositions_inter0(const SequenceOfVectors< P_V, P_M > &prevChain, double prevExponent, double currExponent, const ScalarSequence< double > &prevLogLikelihoodValues, const ScalarSequence< double > &prevLogTargetValues, const std::vector< ExchangeInfoStruct > &exchangeStdVec, const std::vector< unsigned int > &finalNumChainsPerNode, const std::vector< unsigned int > &finalNumPositionsPerNode, BalancedLinkedChainsPerNodeStruct< P_V > &balancedLinkControl)
double eig() const
Calculates the expected information gain value, EIG.
std::string m_rawChainDataOutputFileName
Name of output file for raw chain.
void checkpointML(double currExponent, double currEta, const SequenceOfVectors< P_V, P_M > &currChain, const ScalarSequence< double > &currLogLikelihoodValues, const ScalarSequence< double > &currLogTargetValues)
Writes checkpoint data for the ML method.
unsigned int m_rawChainSize
Size of raw chain.
void generateSequence_Step02_inter0(const MLSamplingLevelOptions *currOptions, SequenceOfVectors< P_V, P_M > &currChain, ScalarSequence< double > &currLogLikelihoodValues, ScalarSequence< double > &currLogTargetValues, SequenceOfVectors< P_V, P_M > &prevChain, ScalarSequence< double > &prevLogLikelihoodValues, ScalarSequence< double > &prevLogTargetValues, unsigned int &indexOfFirstWeight, unsigned int &indexOfLastWeight)
Saves chain and corresponding target pdf values from previous level (Step 02 from ML algorithm)...
double m_maxRejectionRate
maximum allowed attempted rejection rate at current level.
std::set< unsigned int > m_dataOutputAllowedSet
subEnvs that will write to generic output file.
std::vector< UnbalancedLinkedChainControlStruct > unbLinkedChains
if the work is an executable linked with the with the complete machine readable work that uses the as object code and or source so that the user can modify the Library and then relink to produce a modified executable containing the modified rather than copying library functions into the if the user installs as long as the modified version is interface compatible with the version that the work was made with c Accompany the work with a written valid for at least three to give the same user the materials specified in for a charge no more than the cost of performing this distribution d If distribution of the work is made by offering access to copy from a designated offer equivalent access to copy the above specified materials from the same place e Verify that the user has already received a copy of these materials or that you have already sent this user a copy For an the required form of the work that uses the Library must include any data and utility programs needed for reproducing the executable from it as a special the materials to be distributed need not include anything that is normally and so on of the operating system on which the executable unless that component itself accompanies the executable It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system Such a contradiction means you cannot use both them and the Library together in an executable that you distribute You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities not covered by this and distribute such a combined provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise and provided that you do these two uncombined with any other library facilities This must be distributed under the terms of the Sections above b Give prominent notice with the combined library of the fact that part of it is a work based on the and explaining where to find the accompanying uncombined form of the same work You may not link or distribute the Library except as expressly provided under this License Any attempt otherwise to link or distribute the Library is and will automatically terminate your rights under this License parties who have received or from you under this License will not have their licenses terminated so long as such parties remain in full compliance You are not required to accept this since you have not signed it nothing else grants you permission to modify or distribute the Library or its derivative works These actions are prohibited by law if you do not accept this License by modifying or distributing the you indicate your acceptance of this License to do and all its terms and conditions for distributing or modifying the Library or works based on it Each time you redistribute the the recipient automatically receives a license from the original licensor to link with or modify the Library subject to these terms and conditions You may not impose any further restrictions on the recipients exercise of the rights granted herein You are not responsible for enforcing compliance by third parties with this License as a consequence of a court judgment or allegation of patent infringement or for any other reason(not limited to patent issues)
std::set< unsigned int > m_parameterDisabledSet
#define queso_require_equal_to_msg(expr1, expr2, msg)
void clear()
Reset the values and the size of the sequence of vectors.
double m_covRejectionRate
c.o.v. for judging attempted rejection rate at current level.
std::string m_rawChainDataOutputFileType
Type of output file for raw chain.
void setPositionValues(unsigned int posId, const V &vec)
Set the values in vec at position posId of the 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 UQ_MH_SG_FILENAME_FOR_NO_FILE
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
unsigned int m_amAdaptInterval
'am' adaptation interval.
#define queso_require_less_msg(expr1, expr2, msg)
int finalNodeOfInitialPosition
GslMatrix matrixProduct(const GslVector &v1, const GslVector &v2)
unsigned int originalIndexOfInitialPosition
void unifiedWriteContents(const std::string &fileName, const std::string &fileType) const
Writes the unified sequence to a file.
void generateSequence_Level0_all(const MLSamplingLevelOptions &currOptions, unsigned int &unifiedRequestedNumSamples, SequenceOfVectors< P_V, P_M > &currChain, ScalarSequence< double > &currLogLikelihoodValues, ScalarSequence< double > &currLogTargetValues)
Generates the sequence at the level 0.
void generateSequence_Step03_inter0(const MLSamplingLevelOptions *currOptions, const ScalarSequence< double > &prevLogLikelihoodValues, double prevExponent, double failedExponent, double &currExponent, ScalarSequence< double > &weightSequence)
Computes currExponent and sequence of weights for current level and update 'm_logEvidenceFactors' (St...
void setPdf(BaseJointPdf< V, M > &pdf)
Sets the PDF of this vector RV to pdf.
#define UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT
void generateSequence_Step10_all(MLSamplingLevelOptions &currOptions, const P_M &unifiedCovMatrix, const GenericVectorRV< P_V, P_M > &currRv, bool useBalancedChains, const UnbalancedLinkedChainsPerNodeStruct &unbalancedLinkControl, unsigned int indexOfFirstWeight, const SequenceOfVectors< P_V, P_M > &prevChain, double prevExponent, double currExponent, const ScalarSequence< double > &prevLogLikelihoodValues, const ScalarSequence< double > &prevLogTargetValues, const BalancedLinkedChainsPerNodeStruct< P_V > &balancedLinkControl, SequenceOfVectors< P_V, P_M > &currChain, double &cumulativeRawChainRunTime, unsigned int &cumulativeRawChainRejections, ScalarSequence< double > *currLogLikelihoodValues, ScalarSequence< double > *currLogTargetValues)
Samples the vector RV of current level (Step 10 from ML algorithm).
unsigned int numRejections
std::string m_filteredChainDataOutputFileType
Type of output file for filtered chain.
unsigned int numberOfPositions
void generateSequence(BaseVectorSequence< P_V, P_M > &workingChain, ScalarSequence< double > *workingLogLikelihoodValues, ScalarSequence< double > *workingLogTargetValues)
Method to generate the chain.
bool m_scaleCovMatrix
Whether or not scale proposal covariance matrix.
unsigned int m_filteredChainLag
Spacing for chain filtering.
void sampleIndexes_proc0(unsigned int unifiedRequestedNumSamples, const std::vector< double > &unifiedWeightStdVectorAtProc0Only, std::vector< unsigned int > &unifiedIndexCountersAtProc0Only)
std::string m_filteredChainDataOutputFileName
Name of output file for filtered chain.
int originalNodeOfInitialPosition
unsigned int subSequenceSize() const
Size of the sub-sequence of vectors.
void justBalance_proc0(const MLSamplingLevelOptions *currOptions, std::vector< ExchangeInfoStruct > &exchangeStdVec)
A templated class that represents a Multilevel generator of samples.
void getPositionValues(unsigned int posId, V &vec) const
Gets the values of the sequence at position posId and stores them at vec.
void getRawChainInfo(MHRawChainInfoStruct &info) const
Gets information from the raw chain.
virtual void resizeSequence(unsigned int newSubSequenceSize)=0
Resize the sequence. See template specialization.
std::vector< double > m_initialValuesOfDisabledParameters
double m_loadBalanceTreshold
Perform load balancing if load unbalancing ratio > threshold.
void generateUnbLinkedChains_all(MLSamplingLevelOptions &inputOptions, const P_M &unifiedCovMatrix, const GenericVectorRV< P_V, P_M > &rv, const UnbalancedLinkedChainsPerNodeStruct &unbalancedLinkControl, unsigned int indexOfFirstWeight, const SequenceOfVectors< P_V, P_M > &prevChain, double prevExponent, double currExponent, const ScalarSequence< double > &prevLogLikelihoodValues, const ScalarSequence< double > &prevLogTargetValues, SequenceOfVectors< P_V, P_M > &workingChain, double &cumulativeRunTime, unsigned int &cumulativeRejections, ScalarSequence< double > *currLogLikelihoodValues, ScalarSequence< double > *currLogTargetValues)
void generateSequence_Step05_inter0(unsigned int unifiedRequestedNumSamples, const ScalarSequence< double > &weightSequence, std::vector< unsigned int > &unifiedIndexCountersAtProc0Only, std::vector< double > &unifiedWeightStdVectorAtProc0Only)
Creates unified finite distribution for current level (Step 05 from ML algorithm).
#define queso_require_greater_equal_msg(expr1, expr2, msg)
#define RawValue_MPI_CHAR
void resizeSequence(unsigned int newSubSequenceSize)
Resizes the sequence.
void prepareUnbLinkedChains_inter0(unsigned int indexOfFirstWeight, unsigned int indexOfLastWeight, const std::vector< unsigned int > &unifiedIndexCountersAtProc0Only, UnbalancedLinkedChainsPerNodeStruct &unbalancedLinkControl)
const BaseEnvironment & m_env
Queso enviroment.
bool m_stopAtEnd
Stop at end of such level.
void getUnifiedContentsAtProc0Only(bool useOnlyInter0Comm, std::vector< T > &outputVec) const
Gets the unified contents of processor of rank equals to 0.
virtual unsigned int subSequenceSize() const =0
Size of the sub-sequence of vectors. See template specialization.
A templated class for a finite distribution.
unsigned int subSequenceSize() const
Size of the sub-sequence of scalars.
bool MiscCheckForSameValueInAllNodes(T &inputValue, double acceptableTreshold, const MpiComm &comm, const char *whereString)
#define RawValue_MPI_DOUBLE
unsigned int m_drMaxNumExtraStages
'dr' maximum number of extra stages.
double m_minEffectiveSizeRatio
Minimum allowed effective size ratio wrt previous level.
#define RawValue_MPI_UNSIGNED
void filter(unsigned int initialPos, unsigned int spacing)
Filters positions in the sequence of vectors.
std::vector< BalancedLinkedChainControlStruct< P_V > > balLinkedChains
void setName(const std::string &newName)
Changes the name of the sequence of vectors.
void unifiedReadContents(const std::string &fileName, const std::string &fileType, const unsigned int subSequenceSize)
Reads the unified sequence from a file.
void unifiedWriteContents(const std::string &fileName, const std::string &fileType) const
double m_maxEffectiveSizeRatio
Maximum allowed effective size ratio wrt previous level.
unsigned int unifiedSequenceSize() const
Calculates the size of the unified sequence of vectors.
virtual void setPositionValues(unsigned int posId, const V &vec)=0
Set the values in vec at position posId of the sequence. See template specialization.