25 #include <queso/asserts.h>
26 #include <queso/MetropolisHastingsSG.h>
27 #include <queso/GslVector.h>
28 #include <queso/GslMatrix.h>
30 #include <queso/HessianCovMatricesTKGroup.h>
31 #include <queso/ScaledCovMatrixTKGroup.h>
32 #include <queso/TransformedScaledCovMatrixTKGroup.h>
34 #include <queso/InvLogitGaussianJointPdf.h>
36 #include <queso/GaussianJointPdf.h>
124 "MHRawChainInfoStruct::mpiSum()",
125 "failed MPI.Allreduce() for sum of doubles");
128 "MHRawChainInfoStruct::mpiSum()",
129 "failed MPI.Allreduce() for sum of unsigned ints");
135 template<
class P_V,
class P_M>
143 m_env (sourceRv.env()),
144 m_vectorSpace (sourceRv.imageSet().vectorSpace()),
145 m_targetPdf (sourceRv.pdf()),
146 m_initialPosition (initialPosition),
147 m_initialProposalCovMatrix (m_vectorSpace.zeroVector()),
148 m_nullInputProposalCovMatrix(inputProposalCovMatrix == NULL),
149 m_numDisabledParameters (0),
150 m_parameterEnabledStatus (m_vectorSpace.dimLocal(),
true),
153 m_positionIdForDebugging (0),
154 m_stageIdForDebugging (0),
155 m_idsOfUniquePositions (0),
157 m_alphaQuotients (0),
160 m_lastAdaptedCovMatrix (NULL),
161 m_numPositionsNotSubWritten (0),
162 m_optionsObj (alternativeOptionsValues),
163 m_computeInitialPriorAndLikelihoodValues(
true),
164 m_initialLogPriorValue (0.),
165 m_initialLogLikelihoodValue (0.),
166 m_userDidNotProvideOptions(
false)
168 if (inputProposalCovMatrix != NULL) {
169 m_initialProposalCovMatrix = *inputProposalCovMatrix;
172 if (m_optionsObj == NULL) {
177 m_optionsObj = tempOptions;
180 m_userDidNotProvideOptions =
true;
183 if (m_optionsObj->m_help !=
"") {
184 if (m_env.subDisplayFile() && !m_optionsObj->m_totallyMute) {
185 *m_env.subDisplayFile() << (*m_optionsObj) << std::endl;
189 if ((m_env.subDisplayFile() ) &&
190 (m_optionsObj->m_totallyMute ==
false)) {
191 *m_env.subDisplayFile() <<
"Entering MetropolisHastingsSG<P_V,P_M>::constructor(1)"
192 <<
": prefix = " << prefix
193 <<
", alternativeOptionsValues = " << alternativeOptionsValues
194 <<
", m_env.optionsInputFileName() = " << m_env.optionsInputFileName()
195 <<
", m_initialProposalCovMatrix = " << m_initialProposalCovMatrix
199 queso_require_equal_to_msg(sourceRv.imageSet().vectorSpace().dimLocal(), initialPosition.sizeLocal(),
"'sourceRv' and 'initialPosition' should have equal dimensions");
201 if (inputProposalCovMatrix) {
202 queso_require_equal_to_msg(sourceRv.imageSet().vectorSpace().dimLocal(), inputProposalCovMatrix->numRowsLocal(),
"'sourceRv' and 'inputProposalCovMatrix' should have equal dimensions");
203 queso_require_equal_to_msg(inputProposalCovMatrix->numCols(), inputProposalCovMatrix->numRowsGlobal(),
"'inputProposalCovMatrix' should be a square matrix");
208 if ((m_env.subDisplayFile() ) &&
209 (m_optionsObj->m_totallyMute ==
false)) {
210 *m_env.subDisplayFile() <<
"Leaving MetropolisHastingsSG<P_V,P_M>::constructor(1)"
214 template<
class P_V,
class P_M>
224 m_env (sourceRv.env()),
225 m_vectorSpace (sourceRv.imageSet().vectorSpace()),
226 m_targetPdf (sourceRv.pdf()),
227 m_initialPosition (initialPosition),
228 m_initialProposalCovMatrix (m_vectorSpace.zeroVector()),
229 m_nullInputProposalCovMatrix(inputProposalCovMatrix == NULL),
230 m_numDisabledParameters (0),
231 m_parameterEnabledStatus (m_vectorSpace.dimLocal(),
true),
234 m_positionIdForDebugging (0),
235 m_stageIdForDebugging (0),
236 m_idsOfUniquePositions (0),
238 m_alphaQuotients (0),
241 m_lastAdaptedCovMatrix (NULL),
242 m_numPositionsNotSubWritten (0),
243 m_optionsObj (alternativeOptionsValues),
244 m_computeInitialPriorAndLikelihoodValues(
false),
245 m_initialLogPriorValue (initialLogPrior),
246 m_initialLogLikelihoodValue (initialLogLikelihood),
247 m_userDidNotProvideOptions(
false)
249 if (inputProposalCovMatrix != NULL) {
250 m_initialProposalCovMatrix = *inputProposalCovMatrix;
254 if (m_optionsObj == NULL) {
259 m_optionsObj = tempOptions;
261 m_userDidNotProvideOptions =
true;
264 if (m_optionsObj->m_help !=
"") {
265 if (m_env.subDisplayFile() && !m_optionsObj->m_totallyMute) {
266 *m_env.subDisplayFile() << (*m_optionsObj) << std::endl;
270 if ((m_env.subDisplayFile() ) &&
271 (m_optionsObj->m_totallyMute ==
false)) {
272 *m_env.subDisplayFile() <<
"Entering MetropolisHastingsSG<P_V,P_M>::constructor(2)"
273 <<
": prefix = " << prefix
274 <<
", alternativeOptionsValues = " << alternativeOptionsValues
275 <<
", m_env.optionsInputFileName() = " << m_env.optionsInputFileName()
276 <<
", m_initialProposalCovMatrix = " << m_initialProposalCovMatrix
280 queso_require_equal_to_msg(sourceRv.imageSet().vectorSpace().dimLocal(), initialPosition.sizeLocal(),
"'sourceRv' and 'initialPosition' should have equal dimensions");
282 if (inputProposalCovMatrix) {
283 queso_require_equal_to_msg(sourceRv.imageSet().vectorSpace().dimLocal(), inputProposalCovMatrix->numRowsLocal(),
"'sourceRv' and 'inputProposalCovMatrix' should have equal dimensions");
284 queso_require_equal_to_msg(inputProposalCovMatrix->numCols(), inputProposalCovMatrix->numRowsGlobal(),
"'inputProposalCovMatrix' should be a square matrix");
289 if ((m_env.subDisplayFile() ) &&
290 (m_optionsObj->m_totallyMute ==
false)) {
291 *m_env.subDisplayFile() <<
"Leaving MetropolisHastingsSG<P_V,P_M>::constructor(2)"
296 template<
class P_V,
class P_M>
300 const P_V& initialPosition,
301 const P_M* inputProposalCovMatrix)
303 m_env (sourceRv.env()),
304 m_vectorSpace (sourceRv.imageSet().vectorSpace()),
305 m_targetPdf (sourceRv.pdf()),
306 m_initialPosition (initialPosition),
307 m_initialProposalCovMatrix (m_vectorSpace.zeroVector()),
308 m_nullInputProposalCovMatrix(inputProposalCovMatrix == NULL),
309 m_numDisabledParameters (0),
310 m_parameterEnabledStatus (m_vectorSpace.dimLocal(),true),
313 m_positionIdForDebugging (0),
314 m_stageIdForDebugging (0),
315 m_idsOfUniquePositions (0),
317 m_alphaQuotients (0),
320 m_lastAdaptedCovMatrix (NULL),
321 m_computeInitialPriorAndLikelihoodValues(true),
322 m_initialLogPriorValue (0.),
323 m_initialLogLikelihoodValue (0.),
324 m_userDidNotProvideOptions(true)
336 if (inputProposalCovMatrix != NULL) {
360 template<
class P_V,
class P_M>
364 const P_V& initialPosition,
365 double initialLogPrior,
366 double initialLogLikelihood,
367 const P_M* inputProposalCovMatrix)
369 m_env (sourceRv.env()),
370 m_vectorSpace (sourceRv.imageSet().vectorSpace()),
371 m_targetPdf (sourceRv.pdf()),
372 m_initialPosition (initialPosition),
373 m_initialProposalCovMatrix (m_vectorSpace.zeroVector()),
374 m_nullInputProposalCovMatrix(inputProposalCovMatrix == NULL),
375 m_numDisabledParameters (0),
376 m_parameterEnabledStatus (m_vectorSpace.dimLocal(),true),
379 m_positionIdForDebugging (0),
380 m_stageIdForDebugging (0),
381 m_idsOfUniquePositions (0),
383 m_alphaQuotients (0),
386 m_lastAdaptedCovMatrix (NULL),
387 m_computeInitialPriorAndLikelihoodValues(false),
388 m_initialLogPriorValue (initialLogPrior),
389 m_initialLogLikelihoodValue (initialLogLikelihood),
390 m_userDidNotProvideOptions(true)
402 if (inputProposalCovMatrix != NULL) {
426 template<
class P_V,
class P_M>
434 if (m_lastAdaptedCovMatrix)
delete m_lastAdaptedCovMatrix;
435 if (m_lastMean)
delete m_lastMean;
437 m_rawChainInfo.reset();
438 m_alphaQuotients.clear();
439 m_logTargets.clear();
440 m_numDisabledParameters = 0;
441 m_parameterEnabledStatus.clear();
442 m_positionIdForDebugging = 0;
443 m_stageIdForDebugging = 0;
444 m_idsOfUniquePositions.clear();
446 if (m_tk )
delete m_tk;
447 if (m_targetPdfSynchronizer)
delete m_targetPdfSynchronizer;
452 if (m_optionsObj && m_userDidNotProvideOptions) {
463 template<
class P_V,
class P_M>
470 if ((m_env.subDisplayFile() ) &&
471 (m_optionsObj->m_totallyMute ==
false)) {
472 *m_env.subDisplayFile() <<
"Entering MetropolisHastingsSG<P_V,P_M>::commonConstructor()"
476 if (m_optionsObj->m_initialPositionDataInputFileName !=
".") {
477 std::set<unsigned int> tmpSet;
478 tmpSet.insert(m_env.subId());
479 m_initialPosition.subReadContents((m_optionsObj->m_initialPositionDataInputFileName+
"_sub"+m_env.subIdString()),
480 m_optionsObj->m_initialPositionDataInputFileType,
482 if ((m_env.subDisplayFile() ) &&
483 (m_optionsObj->m_totallyMute ==
false)) {
484 *m_env.subDisplayFile() <<
"In MetropolisHastingsSG<P_V,P_M>::commonConstructor()"
485 <<
": just read initial position contents = " << m_initialPosition
490 if (m_optionsObj->m_parameterDisabledSet.size() > 0) {
491 for (std::set<unsigned int>::iterator setIt = m_optionsObj->m_parameterDisabledSet.begin(); setIt != m_optionsObj->m_parameterDisabledSet.end(); ++setIt) {
492 unsigned int paramId = *setIt;
493 if (paramId < m_vectorSpace.dimLocal()) {
494 m_numDisabledParameters++;
495 m_parameterEnabledStatus[paramId] =
false;
500 std::vector<double> drScalesAll(m_optionsObj->m_drScalesForExtraStages.size()+1,1.);
501 for (
unsigned int i = 1; i < (m_optionsObj->m_drScalesForExtraStages.size()+1); ++i) {
502 drScalesAll[i] = m_optionsObj->m_drScalesForExtraStages[i-1];
504 if (m_optionsObj->m_tkUseLocalHessian) {
508 *m_targetPdfSynchronizer);
509 if ((m_env.subDisplayFile() ) &&
510 (m_optionsObj->m_totallyMute ==
false)) {
511 *m_env.subDisplayFile() <<
"In MetropolisHastingsSG<P_V,P_M>::commonConstructor()"
512 <<
": just instantiated a 'HessianCovMatrices' TK class"
517 if (m_optionsObj->m_initialProposalCovMatrixDataInputFileName !=
".") {
518 std::set<unsigned int> tmpSet;
519 tmpSet.insert(m_env.subId());
520 m_initialProposalCovMatrix.subReadContents((m_optionsObj->m_initialProposalCovMatrixDataInputFileName+
"_sub"+m_env.subIdString()),
521 m_optionsObj->m_initialProposalCovMatrixDataInputFileType,
523 if ((m_env.subDisplayFile() ) &&
524 (m_optionsObj->m_totallyMute ==
false)) {
525 *m_env.subDisplayFile() <<
"In MetropolisHastingsSG<P_V,P_M>::commonConstructor()"
526 <<
": just read initial proposal cov matrix contents = " << m_initialProposalCovMatrix
531 queso_require_msg(!(m_nullInputProposalCovMatrix),
"proposal cov matrix should have been passed by user, since, according to the input algorithm options, local Hessians will not be used in the proposal");
535 if (m_optionsObj->m_doLogitTransform) {
537 transformInitialCovMatrixToGaussianSpace(
543 m_optionsObj->m_prefix.c_str(),
545 drScalesAll, m_initialProposalCovMatrix);
549 m_optionsObj->m_prefix.c_str(), m_vectorSpace, drScalesAll,
550 m_initialProposalCovMatrix);
553 if ((m_env.subDisplayFile() ) &&
554 (m_optionsObj->m_totallyMute ==
false)) {
555 *m_env.subDisplayFile() <<
"In MetropolisHastingsSG<P_V,P_M>::commonConstructor()"
556 <<
": just instantiated a 'ScaledCovMatrix' TK class"
561 if ((m_env.subDisplayFile() ) &&
562 (m_optionsObj->m_totallyMute ==
false)) {
563 *m_env.subDisplayFile() <<
"Leaving MetropolisHastingsSG<P_V,P_M>::commonConstructor()"
569 template<
class P_V,
class P_M>
574 unsigned int xStageId,
575 unsigned int yStageId,
576 double* alphaQuotientPtr)
578 double alphaQuotient = 0.;
583 ( (boost::math::isnan)(x.
logTarget()) )) {
584 std::cerr <<
"WARNING In MetropolisHastingsSG<P_V,P_M>::alpha(x,y)"
585 <<
", worldRank " << m_env.worldRank()
586 <<
", fullRank " << m_env.fullRank()
587 <<
", subEnvironment " << m_env.subId()
588 <<
", subRank " << m_env.subRank()
589 <<
", inter0Rank " << m_env.inter0Rank()
590 <<
", positionId = " << m_positionIdForDebugging
591 <<
", stageId = " << m_stageIdForDebugging
597 else if ((y.
logTarget() == -INFINITY ) ||
599 ( (boost::math::isnan)(y.
logTarget()) )) {
600 std::cerr <<
"WARNING In MetropolisHastingsSG<P_V,P_M>::alpha(x,y)"
601 <<
", worldRank " << m_env.worldRank()
602 <<
", fullRank " << m_env.fullRank()
603 <<
", subEnvironment " << m_env.subId()
604 <<
", subRank " << m_env.subRank()
605 <<
", inter0Rank " << m_env.inter0Rank()
606 <<
", positionId = " << m_positionIdForDebugging
607 <<
", stageId = " << m_stageIdForDebugging
616 if (m_tk->symmetric()) {
617 alphaQuotient = std::exp(yLogTargetToUse - x.
logTarget());
619 if ((m_env.subDisplayFile() ) &&
620 (m_env.displayVerbosity() >= 3 ) &&
621 (m_optionsObj->m_totallyMute ==
false)) {
622 *m_env.subDisplayFile() <<
"In MetropolisHastingsSG<P_V,P_M>::alpha(x,y)"
623 <<
": symmetric proposal case"
626 <<
", yLogTargetToUse = " << yLogTargetToUse
628 <<
", alpha = " << alphaQuotient
633 double qyx = m_tk->rv(yStageId).pdf().lnValue(x.
vecValues(),NULL,NULL,NULL,NULL);
634 if ((m_env.subDisplayFile() ) &&
635 (m_env.displayVerbosity() >= 10 ) &&
636 (m_optionsObj->m_totallyMute ==
false)) {
638 *m_env.subDisplayFile() <<
"In MetropolisHastingsSG<P_V,P_M>::alpha(x,y)"
644 double qxy = m_tk->rv(xStageId).pdf().lnValue(y.
vecValues(),NULL,NULL,NULL,NULL);
645 if ((m_env.subDisplayFile() ) &&
646 (m_env.displayVerbosity() >= 10 ) &&
647 (m_optionsObj->m_totallyMute ==
false)) {
649 *m_env.subDisplayFile() <<
"In MetropolisHastingsSG<P_V,P_M>::alpha(x,y)"
655 alphaQuotient = std::exp(yLogTargetToUse +
659 if ((m_env.subDisplayFile() ) &&
660 (m_env.displayVerbosity() >= 3 ) &&
661 (m_optionsObj->m_totallyMute ==
false)) {
662 *m_env.subDisplayFile() <<
"In MetropolisHastingsSG<P_V,P_M>::alpha(x,y)"
663 <<
": asymmetric proposal case"
664 <<
", xStageId = " << xStageId
665 <<
", yStageId = " << yStageId
668 <<
", yLogTargetToUse = " << yLogTargetToUse
669 <<
", q(y,x) = " << qyx
671 <<
", q(x,y) = " << qxy
672 <<
", alpha = " << alphaQuotient
679 if ((m_env.subDisplayFile() ) &&
680 (m_env.displayVerbosity() >= 10 ) &&
681 (m_optionsObj->m_totallyMute ==
false)) {
682 *m_env.subDisplayFile() <<
"In MetropolisHastingsSG<P_V,P_M>::alpha(x,y)"
688 if (alphaQuotientPtr != NULL) *alphaQuotientPtr = alphaQuotient;
690 return std::min(1.,alphaQuotient);
693 template<
class P_V,
class P_M>
697 const std::vector<unsigned int >& inputTKStageIds)
699 unsigned int inputSize = inputPositionsData.size();
700 if ((m_env.subDisplayFile() ) &&
701 (m_env.displayVerbosity() >= 10 ) &&
702 (m_optionsObj->m_totallyMute ==
false)) {
703 *m_env.subDisplayFile() <<
"Entering MetropolisHastingsSG<P_V,P_M>::alpha(vec)"
704 <<
", inputSize = " << inputSize
710 if (inputPositionsData[0 ]->outOfTargetSupport())
return 0.;
711 if (inputPositionsData[inputSize-1]->outOfTargetSupport())
return 0.;
713 if ((inputPositionsData[0]->logTarget() == -INFINITY ) ||
714 (inputPositionsData[0]->logTarget() == INFINITY ) ||
715 ( (boost::math::isnan)(inputPositionsData[0]->logTarget()) )) {
716 std::cerr <<
"WARNING In MetropolisHastingsSG<P_V,P_M>::alpha(vec)"
717 <<
", worldRank " << m_env.worldRank()
718 <<
", fullRank " << m_env.fullRank()
719 <<
", subEnvironment " << m_env.subId()
720 <<
", subRank " << m_env.subRank()
721 <<
", inter0Rank " << m_env.inter0Rank()
722 <<
", positionId = " << m_positionIdForDebugging
723 <<
", stageId = " << m_stageIdForDebugging
724 <<
": inputSize = " << inputSize
725 <<
", inputPositionsData[0]->logTarget() = " << inputPositionsData[0]->logTarget()
726 <<
", [0]->values() = " << inputPositionsData[0]->vecValues()
727 <<
", [inputSize - 1]->values() = " << inputPositionsData[inputSize-1]->vecValues()
731 else if ((inputPositionsData[inputSize - 1]->logTarget() == -INFINITY ) ||
732 (inputPositionsData[inputSize - 1]->logTarget() == INFINITY ) ||
733 ( (boost::math::isnan)(inputPositionsData[inputSize - 1]->logTarget()) )) {
734 std::cerr <<
"WARNING In MetropolisHastingsSG<P_V,P_M>::alpha(vec)"
735 <<
", worldRank " << m_env.worldRank()
736 <<
", fullRank " << m_env.fullRank()
737 <<
", subEnvironment " << m_env.subId()
738 <<
", subRank " << m_env.subRank()
739 <<
", inter0Rank " << m_env.inter0Rank()
740 <<
", positionId = " << m_positionIdForDebugging
741 <<
", stageId = " << m_stageIdForDebugging
742 <<
": inputSize = " << inputSize
743 <<
", inputPositionsData[inputSize - 1]->logTarget() = " << inputPositionsData[inputSize-1]->logTarget()
744 <<
", [0]->values() = " << inputPositionsData[0]->vecValues()
745 <<
", [inputSize - 1]->values() = " << inputPositionsData[inputSize-1]->vecValues()
751 if (inputSize == 2)
return this->alpha(*(inputPositionsData[0 ]),
752 *(inputPositionsData[inputSize - 1]),
754 inputTKStageIds[inputSize-1]);
757 std::vector<MarkovChainPositionData<P_V>*> positionsData (inputSize,NULL);
758 std::vector<MarkovChainPositionData<P_V>*> backwardPositionsData (inputSize,NULL);
760 std::vector<unsigned int > tkStageIds (inputSize,0);
761 std::vector<unsigned int > backwardTKStageIds (inputSize,0);
763 std::vector<unsigned int > tkStageIdsLess1(inputSize,0);
764 std::vector<unsigned int > backwardTKStageIdsLess1(inputSize,0);
766 for (
unsigned int i = 0; i < inputSize; ++i) {
767 positionsData [i] = inputPositionsData[i];
768 backwardPositionsData [i] = inputPositionsData[inputSize-i-1];
770 tkStageIds [i] = inputTKStageIds [i];
771 backwardTKStageIds [i] = inputTKStageIds [inputSize-i-1];
773 tkStageIdsLess1[i] = inputTKStageIds [i];
774 backwardTKStageIdsLess1[i] = inputTKStageIds [inputSize-i-1];
777 tkStageIdsLess1.pop_back();
778 backwardTKStageIdsLess1.pop_back();
781 double logNumerator = 0.;
782 double logDenominator = 0.;
783 double alphasNumerator = 1.;
784 double alphasDenominator = 1.;
787 const P_V& _lastTKPosition = m_tk->preComputingPosition( tkStageIds[inputSize-1]);
788 const P_V& _lastBackwardTKPosition = m_tk->preComputingPosition(backwardTKStageIds[inputSize-1]);
790 double numContrib = m_tk->rv(backwardTKStageIdsLess1).pdf().lnValue(_lastBackwardTKPosition,NULL,NULL,NULL,NULL);
791 double denContrib = m_tk->rv(tkStageIdsLess1).pdf().lnValue(_lastTKPosition,NULL,NULL,NULL,NULL);
792 if ((m_env.subDisplayFile() ) &&
793 (m_env.displayVerbosity() >= 10 ) &&
794 (m_optionsObj->m_totallyMute ==
false)) {
795 *m_env.subDisplayFile() <<
"In MetropolisHastingsSG<P_V,P_M>::alpha(vec)"
796 <<
", inputSize = " << inputSize
798 <<
": numContrib = " << numContrib
799 <<
", denContrib = " << denContrib
802 logNumerator += numContrib;
803 logDenominator += denContrib;
805 for (
unsigned int i = 0; i < (inputSize-2); ++i) {
806 positionsData.pop_back();
807 backwardPositionsData.pop_back();
809 const P_V& lastTKPosition = m_tk->preComputingPosition( tkStageIds[inputSize-2-i]);
810 const P_V& lastBackwardTKPosition = m_tk->preComputingPosition(backwardTKStageIds[inputSize-2-i]);
812 tkStageIds.pop_back();
813 backwardTKStageIds.pop_back();
815 tkStageIdsLess1.pop_back();
816 backwardTKStageIdsLess1.pop_back();
818 numContrib = m_tk->rv(backwardTKStageIdsLess1).pdf().lnValue(lastBackwardTKPosition,NULL,NULL,NULL,NULL);
819 denContrib = m_tk->rv(tkStageIdsLess1).pdf().lnValue(lastTKPosition,NULL,NULL,NULL,NULL);
820 if ((m_env.subDisplayFile() ) &&
821 (m_env.displayVerbosity() >= 10 ) &&
822 (m_optionsObj->m_totallyMute ==
false)) {
823 *m_env.subDisplayFile() <<
"In MetropolisHastingsSG<P_V,P_M>::alpha(vec)"
824 <<
", inputSize = " << inputSize
825 <<
", in loop, i = " << i
826 <<
": numContrib = " << numContrib
827 <<
", denContrib = " << denContrib
830 logNumerator += numContrib;
831 logDenominator += denContrib;
833 alphasNumerator *= (1. - this->alpha(backwardPositionsData,backwardTKStageIds));
834 alphasDenominator *= (1. - this->alpha( positionsData, tkStageIds));
837 double numeratorLogTargetToUse = backwardPositionsData[0]->logTarget();
838 numContrib = numeratorLogTargetToUse;
839 denContrib = positionsData[0]->logTarget();
840 if ((m_env.subDisplayFile() ) &&
841 (m_env.displayVerbosity() >= 10 ) &&
842 (m_optionsObj->m_totallyMute ==
false)) {
843 *m_env.subDisplayFile() <<
"In MetropolisHastingsSG<P_V,P_M>::alpha(vec)"
844 <<
", inputSize = " << inputSize
846 <<
": numContrib = " << numContrib
847 <<
", denContrib = " << denContrib
850 logNumerator += numContrib;
851 logDenominator += denContrib;
853 if ((m_env.subDisplayFile() ) &&
854 (m_env.displayVerbosity() >= 10 ) &&
855 (m_optionsObj->m_totallyMute ==
false)) {
856 *m_env.subDisplayFile() <<
"Leaving MetropolisHastingsSG<P_V,P_M>::alpha(vec)"
857 <<
", inputSize = " << inputSize
858 <<
": alphasNumerator = " << alphasNumerator
859 <<
", alphasDenominator = " << alphasDenominator
860 <<
", logNumerator = " << logNumerator
861 <<
", logDenominator = " << logDenominator
866 return std::min(1.,(alphasNumerator/alphasDenominator)*std::exp(logNumerator-logDenominator));
869 template<
class P_V,
class P_M>
875 if (alpha <= 0. ) result =
false;
876 else if (alpha >= 1. ) result =
true;
877 else if (alpha >= m_env.rngObject()->uniformSample()) result =
true;
883 template<
class P_V,
class P_M>
887 std::ofstream& ofsvar)
const
889 if ((m_env.subDisplayFile() ) &&
890 (m_optionsObj->m_totallyMute ==
false)) {
891 *m_env.subDisplayFile() <<
"\n"
892 <<
"\n-----------------------------------------------------"
893 <<
"\n Writing more information about the Markov chain " << workingChain.
name() <<
" to output file ..."
894 <<
"\n-----------------------------------------------------"
901 if (m_optionsObj->m_rawChainGenerateExtra) {
903 ofsvar << m_optionsObj->m_prefix <<
"logTargets_sub" << m_env.subIdString() <<
" = zeros(" << m_logTargets.size()
907 ofsvar << m_optionsObj->m_prefix <<
"logTargets_sub" << m_env.subIdString() <<
" = [";
908 for (
unsigned int i = 0; i < m_logTargets.size(); ++i) {
909 ofsvar << m_logTargets[i]
915 ofsvar << m_optionsObj->m_prefix <<
"alphaQuotients_sub" << m_env.subIdString() <<
" = zeros(" << m_alphaQuotients.size()
919 ofsvar << m_optionsObj->m_prefix <<
"alphaQuotients_sub" << m_env.subIdString() <<
" = [";
920 for (
unsigned int i = 0; i < m_alphaQuotients.size(); ++i) {
921 ofsvar << m_alphaQuotients[i]
928 ofsvar << m_optionsObj->m_prefix <<
"rejected = " << (double) m_rawChainInfo.numRejections/(
double) (workingChain.
subSequenceSize()-1)
934 ofsvar << m_optionsObj->m_prefix <<
"componentNames = {";
935 m_vectorSpace.printComponentsNames(ofsvar,
false);
939 ofsvar << m_optionsObj->m_prefix <<
"outTargetSupport = " << (double) m_rawChainInfo.numOutOfTargetSupport/(
double) (workingChain.
subSequenceSize()-1)
944 ofsvar << m_optionsObj->m_prefix <<
"runTime = " << m_rawChainInfo.runTime
949 if ((m_env.subDisplayFile() ) &&
950 (m_optionsObj->m_totallyMute ==
false)) {
951 *m_env.subDisplayFile() <<
"\n-----------------------------------------------------"
952 <<
"\n Finished writing more information about the Markov chain " << workingChain.
name()
953 <<
"\n-----------------------------------------------------"
961 template <
class P_V,
class P_M>
975 template <
class P_V,
class P_M>
982 if ((m_env.subDisplayFile() ) &&
983 (m_env.displayVerbosity() >= 5 ) &&
984 (m_optionsObj->m_totallyMute ==
false)) {
985 *m_env.subDisplayFile() <<
"Entering MetropolisHastingsSG<P_V,P_M>::generateSequence()..."
990 std::cerr <<
"'m_vectorSpace' and 'workingChain' are related to vector"
991 <<
"spaces of different dimensions"
997 bool writeLogLikelihood;
998 if ((workingLogLikelihoodValues != NULL) &&
999 (m_optionsObj->m_outputLogLikelihood)) {
1000 writeLogLikelihood =
true;
1003 writeLogLikelihood =
false;
1007 bool writeLogTarget;
1008 if ((workingLogTargetValues != NULL) &&
1009 (m_optionsObj->m_outputLogTarget)) {
1010 writeLogTarget =
true;
1013 writeLogTarget =
false;
1016 MiscCheckTheParallelEnvironment<P_V,P_V>(m_initialPosition,
1019 P_V valuesOf1stPosition(m_initialPosition);
1022 workingChain.
setName(m_optionsObj->m_prefix +
"rawChain");
1028 generateFullChain(valuesOf1stPosition,
1029 m_optionsObj->m_rawChainSize,
1031 workingLogLikelihoodValues,
1032 workingLogTargetValues);
1035 readFullChain(m_optionsObj->m_rawChainDataInputFileName,
1036 m_optionsObj->m_rawChainDataInputFileType,
1037 m_optionsObj->m_rawChainSize,
1044 if ((m_env.subDisplayFile() ) &&
1045 (m_optionsObj->m_totallyMute ==
false)) {
1046 *m_env.subDisplayFile() <<
"In MetropolisHastingsSG<P_V,P_M>::generateSequence()"
1047 <<
", prefix = " << m_optionsObj->m_prefix
1048 <<
", chain name = " << workingChain.
name()
1049 <<
": about to try to open generic output file '" << m_optionsObj->m_dataOutputFileName
1051 <<
"', subId = " << m_env.subId()
1052 <<
", subenv is allowed to write (1/true or 0/false) = " << (m_optionsObj->m_dataOutputAllowedSet.find(m_env.subId()) != m_optionsObj->m_dataOutputAllowedSet.end())
1058 m_env.openOutputFile(m_optionsObj->m_dataOutputFileName,
1060 m_optionsObj->m_dataOutputAllowedSet,
1064 if ((m_env.subDisplayFile() ) &&
1065 (m_optionsObj->m_totallyMute ==
false)) {
1066 *m_env.subDisplayFile() <<
"In MetropolisHastingsSG<P_V,P_M>::generateSequence()"
1067 <<
", prefix = " << m_optionsObj->m_prefix
1068 <<
", raw chain name = " << workingChain.
name()
1069 <<
": returned from opening generic output file '" << m_optionsObj->m_dataOutputFileName
1071 <<
"', subId = " << m_env.subId()
1081 (m_optionsObj->m_totallyMute ==
false )) {
1084 if ((m_env.subDisplayFile() ) &&
1085 (m_optionsObj->m_totallyMute ==
false)) {
1086 *m_env.subDisplayFile() <<
"In MetropolisHastingsSG<P_V,P_M>::generateSequence()"
1087 <<
", prefix = " << m_optionsObj->m_prefix
1088 <<
", raw chain name = " << workingChain.
name()
1089 <<
": about to try to write raw sub chain output file '" << m_optionsObj->m_rawChainDataOutputFileName
1090 <<
"." << m_optionsObj->m_rawChainDataOutputFileType
1091 <<
"', subId = " << m_env.subId()
1092 <<
", subenv is allowed to write 1/true or 0/false) = " << (m_optionsObj->m_rawChainDataOutputAllowedSet.find(m_env.subId()) != m_optionsObj->m_rawChainDataOutputAllowedSet.end())
1097 if ((m_numPositionsNotSubWritten > 0 ) &&
1098 (m_optionsObj->m_rawChainDataOutputFileName !=
".")) {
1099 workingChain.
subWriteContents(m_optionsObj->m_rawChainSize - m_numPositionsNotSubWritten,
1100 m_numPositionsNotSubWritten,
1101 m_optionsObj->m_rawChainDataOutputFileName,
1102 m_optionsObj->m_rawChainDataOutputFileType,
1103 m_optionsObj->m_rawChainDataOutputAllowedSet);
1104 if ((m_env.subDisplayFile() ) &&
1105 (m_optionsObj->m_totallyMute ==
false)) {
1106 *m_env.subDisplayFile() <<
"In MetropolisHastingsSG<P_V,P_M>::generateSequence()"
1107 <<
": just wrote (per period request) remaining " << m_numPositionsNotSubWritten <<
" chain positions "
1108 <<
", " << m_optionsObj->m_rawChainSize - m_numPositionsNotSubWritten <<
" <= pos <= " << m_optionsObj->m_rawChainSize - 1
1112 if (writeLogLikelihood) {
1113 workingLogLikelihoodValues->
subWriteContents(m_optionsObj->m_rawChainSize - m_numPositionsNotSubWritten,
1114 m_numPositionsNotSubWritten,
1115 m_optionsObj->m_rawChainDataOutputFileName +
"_loglikelihood",
1116 m_optionsObj->m_rawChainDataOutputFileType,
1117 m_optionsObj->m_rawChainDataOutputAllowedSet);
1120 if (writeLogTarget) {
1121 workingLogTargetValues->
subWriteContents(m_optionsObj->m_rawChainSize - m_numPositionsNotSubWritten,
1122 m_numPositionsNotSubWritten,
1123 m_optionsObj->m_rawChainDataOutputFileName +
"_logtarget",
1124 m_optionsObj->m_rawChainDataOutputFileType,
1125 m_optionsObj->m_rawChainDataOutputAllowedSet);
1128 m_numPositionsNotSubWritten = 0;
1132 if (workingLogLikelihoodValues) {
1135 rawSubMLEpositions);
1138 if ((m_env.subDisplayFile() ) &&
1139 (m_optionsObj->m_totallyMute ==
false)) {
1140 P_V tmpVec(m_vectorSpace.zeroVector());
1142 *m_env.subDisplayFile() <<
"In MetropolisHastingsSG<P_V,P_M>::generateSequence()"
1143 <<
": just computed MLE"
1144 <<
", rawSubMLEvalue = " << rawSubMLEvalue
1145 <<
", rawSubMLEpositions.subSequenceSize() = " << rawSubMLEpositions.
subSequenceSize()
1146 <<
", rawSubMLEpositions[0] = " << tmpVec
1152 if (workingLogTargetValues) {
1155 rawSubMAPpositions);
1158 if ((m_env.subDisplayFile() ) &&
1159 (m_optionsObj->m_totallyMute ==
false)) {
1160 P_V tmpVec(m_vectorSpace.zeroVector());
1162 *m_env.subDisplayFile() <<
"In MetropolisHastingsSG<P_V,P_M>::generateSequence()"
1163 <<
": just computed MAP"
1164 <<
", rawSubMAPvalue = " << rawSubMAPvalue
1165 <<
", rawSubMAPpositions.subSequenceSize() = " << rawSubMAPpositions.
subSequenceSize()
1166 <<
", rawSubMAPpositions[0] = " << tmpVec
1171 if ((m_env.subDisplayFile() ) &&
1172 (m_optionsObj->m_totallyMute ==
false)) {
1173 *m_env.subDisplayFile() <<
"In MetropolisHastingsSG<P_V,P_M>::generateSequence()"
1174 <<
", prefix = " << m_optionsObj->m_prefix
1175 <<
", raw chain name = " << workingChain.
name()
1176 <<
": returned from writing raw sub chain output file '" << m_optionsObj->m_rawChainDataOutputFileName
1177 <<
"." << m_optionsObj->m_rawChainDataOutputFileType
1178 <<
"', subId = " << m_env.subId()
1183 if ((m_env.subDisplayFile() ) &&
1184 (m_optionsObj->m_totallyMute ==
false)) {
1185 *m_env.subDisplayFile() <<
"In MetropolisHastingsSG<P_V,P_M>::generateSequence()"
1186 <<
", prefix = " << m_optionsObj->m_prefix
1187 <<
", raw chain name = " << workingChain.
name()
1188 <<
": about to try to write raw unified chain output file '" << m_optionsObj->m_rawChainDataOutputFileName
1189 <<
"." << m_optionsObj->m_rawChainDataOutputFileType
1190 <<
"', subId = " << m_env.subId()
1196 m_optionsObj->m_rawChainDataOutputFileType);
1197 if ((m_env.subDisplayFile() ) &&
1198 (m_optionsObj->m_totallyMute ==
false)) {
1199 *m_env.subDisplayFile() <<
"In MetropolisHastingsSG<P_V,P_M>::generateSequence()"
1200 <<
", prefix = " << m_optionsObj->m_prefix
1201 <<
", raw chain name = " << workingChain.
name()
1202 <<
": returned from writing raw unified chain output file '" << m_optionsObj->m_rawChainDataOutputFileName
1203 <<
"." << m_optionsObj->m_rawChainDataOutputFileType
1204 <<
"', subId = " << m_env.subId()
1208 if (writeLogLikelihood) {
1209 workingLogLikelihoodValues->
unifiedWriteContents(m_optionsObj->m_rawChainDataOutputFileName +
"_loglikelihood",
1210 m_optionsObj->m_rawChainDataOutputFileType);
1213 if (writeLogTarget) {
1214 workingLogTargetValues->
unifiedWriteContents(m_optionsObj->m_rawChainDataOutputFileName +
"_logtarget",
1215 m_optionsObj->m_rawChainDataOutputFileType);
1219 if (workingLogLikelihoodValues) {
1223 rawUnifiedMLEpositions);
1225 if ((m_env.subDisplayFile() ) &&
1226 (m_optionsObj->m_totallyMute ==
false)) {
1227 P_V tmpVec(m_vectorSpace.zeroVector());
1233 *m_env.subDisplayFile() <<
"In MetropolisHastingsSG<P_V,P_M>::generateSequence()"
1234 <<
": just computed MLE"
1235 <<
", rawUnifiedMLEvalue = " << rawUnifiedMLEvalue
1236 <<
", rawUnifiedMLEpositions.subSequenceSize() = " << rawUnifiedMLEpositions.
subSequenceSize()
1237 <<
", rawUnifiedMLEpositions[0] = " << tmpVec
1244 if (workingLogTargetValues) {
1247 rawUnifiedMAPpositions);
1249 if ((m_env.subDisplayFile() ) &&
1250 (m_optionsObj->m_totallyMute ==
false)) {
1251 P_V tmpVec(m_vectorSpace.zeroVector());
1257 *m_env.subDisplayFile() <<
"In MetropolisHastingsSG<P_V,P_M>::generateSequence()"
1258 <<
": just computed MAP"
1259 <<
", rawUnifiedMAPvalue = " << rawUnifiedMAPvalue
1260 <<
", rawUnifiedMAPpositions.subSequenceSize() = " << rawUnifiedMAPpositions.
subSequenceSize()
1261 <<
", rawUnifiedMAPpositions[0] = " << tmpVec
1269 if ((genericFilePtrSet.
ofsVar ) &&
1270 (m_optionsObj->m_totallyMute ==
false)) {
1272 iRC = writeInfo(workingChain,
1273 *genericFilePtrSet.
ofsVar);
1277 #ifdef QUESO_USES_SEQUENCE_STATISTICAL_OPTIONS
1278 if (m_optionsObj->m_rawChainComputeStats) {
1279 workingChain.computeStatistics(*m_optionsObj->m_rawChainStatisticalOptionsObj,
1280 genericFilePtrSet.
ofsVar);
1290 if (m_optionsObj->m_filteredChainGenerate) {
1292 unsigned int filterInitialPos = (
unsigned int) (m_optionsObj->m_filteredChainDiscardedPortion * (
double) workingChain.
subSequenceSize());
1293 unsigned int filterSpacing = m_optionsObj->m_filteredChainLag;
1294 if (filterSpacing == 0) {
1301 workingChain.
filter(filterInitialPos,
1303 workingChain.
setName(m_optionsObj->m_prefix +
"filtChain");
1305 if (workingLogLikelihoodValues) workingLogLikelihoodValues->
filter(filterInitialPos,
1308 if (workingLogTargetValues) workingLogTargetValues->
filter(filterInitialPos,
1312 if ((m_env.subDisplayFile() ) &&
1313 (m_optionsObj->m_totallyMute ==
false)) {
1314 *m_env.subDisplayFile() <<
"In MetropolisHastingsSG<P_V,P_M>::generateSequence()"
1315 <<
", prefix = " << m_optionsObj->m_prefix
1316 <<
": checking necessity of opening output files for filtered chain " << workingChain.
name()
1323 (m_optionsObj->m_totallyMute ==
false )) {
1326 m_optionsObj->m_filteredChainDataOutputFileName,
1327 m_optionsObj->m_filteredChainDataOutputFileType,
1328 m_optionsObj->m_filteredChainDataOutputAllowedSet);
1329 if ((m_env.subDisplayFile() ) &&
1330 (m_optionsObj->m_totallyMute ==
false)) {
1331 *m_env.subDisplayFile() <<
"In MetropolisHastingsSG<P_V,P_M>::generateSequence()"
1332 <<
", prefix = " << m_optionsObj->m_prefix
1333 <<
": closed sub output file '" << m_optionsObj->m_filteredChainDataOutputFileName
1334 <<
"' for filtered chain " << workingChain.
name()
1338 if (writeLogLikelihood) {
1341 m_optionsObj->m_filteredChainDataOutputFileName +
"_loglikelihood",
1342 m_optionsObj->m_filteredChainDataOutputFileType,
1343 m_optionsObj->m_filteredChainDataOutputAllowedSet);
1346 if (writeLogTarget) {
1349 m_optionsObj->m_filteredChainDataOutputFileName +
"_logtarget",
1350 m_optionsObj->m_filteredChainDataOutputFileType,
1351 m_optionsObj->m_filteredChainDataOutputAllowedSet);
1359 (m_optionsObj->m_totallyMute == false )) {
1361 m_optionsObj->m_filteredChainDataOutputFileType);
1362 if ((m_env.subDisplayFile() ) &&
1363 (m_optionsObj->m_totallyMute ==
false)) {
1364 *m_env.subDisplayFile() <<
"In MetropolisHastingsSG<P_V,P_M>::generateSequence()"
1365 <<
", prefix = " << m_optionsObj->m_prefix
1366 <<
": closed unified output file '" << m_optionsObj->m_filteredChainDataOutputFileName
1367 <<
"' for filtered chain " << workingChain.
name()
1371 if (writeLogLikelihood) {
1372 workingLogLikelihoodValues->
unifiedWriteContents(m_optionsObj->m_filteredChainDataOutputFileName +
"_loglikelihood",
1373 m_optionsObj->m_filteredChainDataOutputFileType);
1376 if (writeLogTarget) {
1377 workingLogTargetValues->
unifiedWriteContents(m_optionsObj->m_filteredChainDataOutputFileName +
"_logtarget",
1378 m_optionsObj->m_filteredChainDataOutputFileType);
1385 #ifdef QUESO_USES_SEQUENCE_STATISTICAL_OPTIONS
1386 if (m_optionsObj->m_filteredChainComputeStats) {
1387 workingChain.computeStatistics(*m_optionsObj->m_filteredChainStatisticalOptionsObj,
1388 genericFilePtrSet.
ofsVar);
1396 if (genericFilePtrSet.
ofsVar) {
1398 delete genericFilePtrSet.
ofsVar;
1399 if ((m_env.subDisplayFile() ) &&
1400 (m_optionsObj->m_totallyMute ==
false)) {
1401 *m_env.subDisplayFile() <<
"In MetropolisHastingsSG<P_V,P_M>::generateSequence()"
1402 <<
", prefix = " << m_optionsObj->m_prefix
1403 <<
": closed generic output file '" << m_optionsObj->m_dataOutputFileName
1404 <<
"' (chain name is " << workingChain.
name()
1410 if ((m_env.subDisplayFile() ) &&
1411 (m_optionsObj->m_totallyMute ==
false)) {
1412 *m_env.subDisplayFile() << std::endl;
1417 if ((m_env.subDisplayFile() ) &&
1418 (m_env.displayVerbosity() >= 5 ) &&
1419 (m_optionsObj->m_totallyMute ==
false)) {
1420 *m_env.subDisplayFile() <<
"Leaving MetropolisHastingsSG<P_V,P_M>::generateSequence()"
1428 template<
class P_V,
class P_M>
1432 info = m_rawChainInfo;
1436 template <
class P_V,
class P_M>
1439 const std::string& inputFileName,
1440 const std::string& inputFileType,
1441 unsigned int chainSize,
1448 template <
class P_V,
class P_M>
1451 const P_V& valuesOf1stPosition,
1452 unsigned int chainSize,
1459 if ((m_env.subDisplayFile() ) &&
1460 (m_optionsObj->m_totallyMute ==
false)) {
1461 *m_env.subDisplayFile() <<
"Starting the generation of Markov chain " << workingChain.
name()
1462 <<
", with " << chainSize
1468 struct timeval timevalChain;
1469 struct timeval timevalCandidate;
1470 struct timeval timevalTarget;
1471 struct timeval timevalMhAlpha;
1472 struct timeval timevalDrAlpha;
1473 struct timeval timevalDR;
1475 m_positionIdForDebugging = 0;
1476 m_stageIdForDebugging = 0;
1478 m_rawChainInfo.reset();
1480 iRC = gettimeofday(&timevalChain, NULL);
1482 if ((m_env.subDisplayFile() ) &&
1483 (m_optionsObj->m_totallyMute ==
false)) {
1484 *m_env.subDisplayFile() <<
"\nIn MetropolisHastingsSG<P_V,P_M>::generateFullChain()"
1485 <<
": contents of initial position are:";
1486 *m_env.subDisplayFile() << valuesOf1stPosition;
1487 *m_env.subDisplayFile() <<
"\nIn MetropolisHastingsSG<P_V,P_M>::generateFullChain()"
1488 <<
": targetPdf.domaintSet() info is:"
1489 << m_targetPdf.domainSet();
1490 *m_env.subDisplayFile() << std::endl;
1494 bool writeLogLikelihood;
1495 if ((workingLogLikelihoodValues != NULL) &&
1496 (m_optionsObj->m_outputLogLikelihood)) {
1497 writeLogLikelihood =
true;
1500 writeLogLikelihood =
false;
1504 bool writeLogTarget;
1505 if ((workingLogTargetValues != NULL) &&
1506 (m_optionsObj->m_outputLogTarget)) {
1507 writeLogTarget =
true;
1510 writeLogTarget =
false;
1513 bool outOfTargetSupport = !m_targetPdf.domainSet().contains(valuesOf1stPosition);
1514 if ((m_env.subDisplayFile()) &&
1515 (outOfTargetSupport )) {
1516 *m_env.subDisplayFile() <<
"ERROR: In MetropolisHastingsSG<P_V,P_M>::generateFullChain()"
1517 <<
": contents of initial position are:\n";
1518 *m_env.subDisplayFile() << valuesOf1stPosition;
1519 *m_env.subDisplayFile() <<
"\nERROR: In MetropolisHastingsSG<P_V,P_M>::generateFullChain()"
1520 <<
": targetPdf.domaintSet() info is:\n"
1521 << m_targetPdf.domainSet();
1522 *m_env.subDisplayFile() << std::endl;
1524 queso_require_msg(!(outOfTargetSupport),
"initial position should not be out of target pdf support");
1526 double logPrior = 0.;
1527 double logLikelihood = 0.;
1528 double logTarget = 0.;
1529 if (m_computeInitialPriorAndLikelihoodValues) {
1530 if (m_optionsObj->m_rawChainMeasureRunTimes) iRC = gettimeofday(&timevalTarget, NULL);
1531 logTarget = m_targetPdfSynchronizer->callFunction(&valuesOf1stPosition,NULL,NULL,NULL,NULL,&logPrior,&logLikelihood);
1532 if (m_optionsObj->m_rawChainMeasureRunTimes) {
1535 m_rawChainInfo.numTargetCalls++;
1536 if ((m_env.subDisplayFile() ) &&
1537 (m_env.displayVerbosity() >= 3 ) &&
1538 (m_optionsObj->m_totallyMute ==
false)) {
1539 *m_env.subDisplayFile() <<
"In MetropolisHastingsSG<P_V,P_M>::generateFullChain()"
1540 <<
": just returned from likelihood() for initial chain position"
1541 <<
", m_rawChainInfo.numTargetCalls = " << m_rawChainInfo.numTargetCalls
1542 <<
", logPrior = " << logPrior
1543 <<
", logLikelihood = " << logLikelihood
1544 <<
", logTarget = " << logTarget
1549 logPrior = m_initialLogPriorValue;
1550 logLikelihood = m_initialLogLikelihoodValue;
1551 logTarget = logPrior + logLikelihood;
1552 if ((m_env.subDisplayFile() ) &&
1553 (m_env.displayVerbosity() >= 3 ) &&
1554 (m_optionsObj->m_totallyMute ==
false)) {
1555 *m_env.subDisplayFile() <<
"In MetropolisHastingsSG<P_V,P_M>::generateFullChain()"
1556 <<
": used input prior and likelihood for initial chain position"
1557 <<
", m_rawChainInfo.numTargetCalls = " << m_rawChainInfo.numTargetCalls
1558 <<
", logPrior = " << logPrior
1559 <<
", logLikelihood = " << logLikelihood
1560 <<
", logTarget = " << logTarget
1567 valuesOf1stPosition,
1572 P_V gaussianVector(m_vectorSpace.zeroVector());
1573 P_V tmpVecValues(m_vectorSpace.zeroVector());
1580 m_numPositionsNotSubWritten = 0;
1581 if (workingLogLikelihoodValues) workingLogLikelihoodValues->
resizeSequence(chainSize);
1582 if (workingLogTargetValues ) workingLogTargetValues->
resizeSequence (chainSize);
1583 if (
true) m_idsOfUniquePositions.resize(chainSize,0);
1584 if (m_optionsObj->m_rawChainGenerateExtra) {
1585 m_logTargets.resize (chainSize,0.);
1586 m_alphaQuotients.resize(chainSize,0.);
1589 unsigned int uniquePos = 0;
1591 m_numPositionsNotSubWritten++;
1592 if ((m_optionsObj->m_rawChainDataOutputPeriod > 0 ) &&
1593 (((0+1) % m_optionsObj->m_rawChainDataOutputPeriod) == 0 ) &&
1594 (m_optionsObj->m_rawChainDataOutputFileName !=
".")) {
1595 workingChain.
subWriteContents(0 + 1 - m_optionsObj->m_rawChainDataOutputPeriod,
1596 m_optionsObj->m_rawChainDataOutputPeriod,
1597 m_optionsObj->m_rawChainDataOutputFileName,
1598 m_optionsObj->m_rawChainDataOutputFileType,
1599 m_optionsObj->m_rawChainDataOutputAllowedSet);
1600 if ((m_env.subDisplayFile() ) &&
1601 (m_optionsObj->m_totallyMute ==
false)) {
1602 *m_env.subDisplayFile() <<
"In MetropolisHastingsSG<P_V,P_M>::generateFullChain()"
1603 <<
": just wrote (per period request) " << m_numPositionsNotSubWritten <<
" chain positions "
1604 <<
", " << 0 + 1 - m_optionsObj->m_rawChainDataOutputPeriod <<
" <= pos <= " << 0
1608 if (writeLogLikelihood) {
1609 workingLogLikelihoodValues->
subWriteContents(0 + 1 - m_optionsObj->m_rawChainDataOutputPeriod,
1610 m_optionsObj->m_rawChainDataOutputPeriod,
1611 m_optionsObj->m_rawChainDataOutputFileName +
"_loglikelihood",
1612 m_optionsObj->m_rawChainDataOutputFileType,
1613 m_optionsObj->m_rawChainDataOutputAllowedSet);
1616 if (writeLogTarget) {
1617 workingLogTargetValues->
subWriteContents(0 + 1 - m_optionsObj->m_rawChainDataOutputPeriod,
1618 m_optionsObj->m_rawChainDataOutputPeriod,
1619 m_optionsObj->m_rawChainDataOutputFileName +
"_logtarget",
1620 m_optionsObj->m_rawChainDataOutputFileType,
1621 m_optionsObj->m_rawChainDataOutputAllowedSet);
1624 m_numPositionsNotSubWritten = 0;
1627 if (workingLogLikelihoodValues) (*workingLogLikelihoodValues)[0] = currentPositionData.
logLikelihood();
1628 if (workingLogTargetValues ) (*workingLogTargetValues )[0] = currentPositionData.
logTarget();
1629 if (
true) m_idsOfUniquePositions[uniquePos++] = 0;
1630 if (m_optionsObj->m_rawChainGenerateExtra) {
1631 m_logTargets [0] = currentPositionData.
logTarget();
1632 m_alphaQuotients[0] = 1.;
1636 if ((m_env.subDisplayFile() ) &&
1637 (m_env.displayVerbosity() >= 10 ) &&
1638 (m_optionsObj->m_totallyMute ==
false)) {
1639 *m_env.subDisplayFile() <<
"\n"
1640 <<
"\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
1650 if ((m_env.numSubEnvironments() < (
unsigned int) m_env.fullComm().NumProc()) &&
1651 (m_initialPosition.numOfProcsForStorage() == 1 ) &&
1652 (m_env.subRank() != 0 )) {
1655 aux = m_targetPdfSynchronizer->callFunction(NULL,
1663 for (
unsigned int positionId = 1; positionId < workingChain.
subSequenceSize(); ++positionId) {
1667 m_rawChainInfo.numRejections++;
1670 else for (
unsigned int positionId = 1; positionId < workingChain.
subSequenceSize(); ++positionId) {
1675 m_positionIdForDebugging = positionId;
1676 if ((m_env.subDisplayFile() ) &&
1677 (m_env.displayVerbosity() >= 3 ) &&
1678 (m_optionsObj->m_totallyMute ==
false)) {
1679 *m_env.subDisplayFile() <<
"In MetropolisHastingsSG<P_V,P_M>::generateFullChain()"
1680 <<
": beginning chain position of id = " << positionId
1681 <<
", m_optionsObj->m_drMaxNumExtraStages = " << m_optionsObj->m_drMaxNumExtraStages
1684 unsigned int stageId = 0;
1685 m_stageIdForDebugging = stageId;
1687 m_tk->clearPreComputingPositions();
1689 if ((m_env.subDisplayFile() ) &&
1690 (m_env.displayVerbosity() >= 5 ) &&
1691 (m_optionsObj->m_totallyMute ==
false)) {
1692 *m_env.subDisplayFile() <<
"In MetropolisHastingsSG<P_V,P_M>::generateFullChain()"
1693 <<
": about to set TK pre computing position of local id " << 0
1694 <<
", values = " << currentPositionData.
vecValues()
1697 bool validPreComputingPosition = m_tk->setPreComputingPosition(currentPositionData.
vecValues(),0);
1698 if ((m_env.subDisplayFile() ) &&
1699 (m_env.displayVerbosity() >= 5 ) &&
1700 (m_optionsObj->m_totallyMute ==
false)) {
1701 *m_env.subDisplayFile() <<
"In MetropolisHastingsSG<P_V,P_M>::generateFullChain()"
1702 <<
": returned from setting TK pre computing position of local id " << 0
1703 <<
", values = " << currentPositionData.
vecValues()
1704 <<
", valid = " << validPreComputingPosition
1707 queso_require_msg(validPreComputingPosition,
"initial position should not be an invalid pre computing position");
1713 bool keepGeneratingCandidates =
true;
1714 while (keepGeneratingCandidates) {
1715 if (m_optionsObj->m_rawChainMeasureRunTimes) {
1716 iRC = gettimeofday(&timevalCandidate, NULL);
1719 m_tk->rv(0).realizer().realization(tmpVecValues);
1721 if (m_numDisabledParameters > 0) {
1722 for (
unsigned int paramId = 0; paramId < m_vectorSpace.dimLocal(); ++paramId) {
1723 if (m_parameterEnabledStatus[paramId] ==
false) {
1724 tmpVecValues[paramId] = m_initialPosition[paramId];
1728 if (m_optionsObj->m_rawChainMeasureRunTimes) m_rawChainInfo.candidateRunTime +=
MiscGetEllapsedSeconds(&timevalCandidate);
1730 outOfTargetSupport = !m_targetPdf.domainSet().contains(tmpVecValues);
1732 bool displayDetail = (m_env.displayVerbosity() >= 10) || m_optionsObj->m_displayCandidates;
1733 if ((m_env.subDisplayFile() ) &&
1735 (m_optionsObj->m_totallyMute ==
false)) {
1736 *m_env.subDisplayFile() <<
"In MetropolisHastingsSG<P_V,P_M>::generateFullChain()"
1737 <<
": for chain position of id = " << positionId
1738 <<
", candidate = " << tmpVecValues
1739 <<
", outOfTargetSupport = " << outOfTargetSupport
1743 if (m_optionsObj->m_putOutOfBoundsInChain) keepGeneratingCandidates =
false;
1744 else keepGeneratingCandidates = outOfTargetSupport;
1747 if ((m_env.subDisplayFile() ) &&
1748 (m_env.displayVerbosity() >= 5 ) &&
1749 (m_optionsObj->m_totallyMute ==
false)) {
1750 *m_env.subDisplayFile() <<
"In MetropolisHastingsSG<P_V,P_M>::generateFullChain()"
1751 <<
": about to set TK pre computing position of local id " << stageId+1
1752 <<
", values = " << tmpVecValues
1755 validPreComputingPosition = m_tk->setPreComputingPosition(tmpVecValues,stageId+1);
1756 if ((m_env.subDisplayFile() ) &&
1757 (m_env.displayVerbosity() >= 5 ) &&
1758 (m_optionsObj->m_totallyMute ==
false)) {
1759 *m_env.subDisplayFile() <<
"In MetropolisHastingsSG<P_V,P_M>::generateFullChain()"
1760 <<
": returned from setting TK pre computing position of local id " << stageId+1
1761 <<
", values = " << tmpVecValues
1762 <<
", valid = " << validPreComputingPosition
1766 if (outOfTargetSupport) {
1767 m_rawChainInfo.numOutOfTargetSupport++;
1768 logPrior = -INFINITY;
1769 logLikelihood = -INFINITY;
1770 logTarget = -INFINITY;
1773 if (m_optionsObj->m_rawChainMeasureRunTimes) iRC = gettimeofday(&timevalTarget, NULL);
1774 logTarget = m_targetPdfSynchronizer->callFunction(&tmpVecValues,NULL,NULL,NULL,NULL,&logPrior,&logLikelihood);
1775 if (m_optionsObj->m_rawChainMeasureRunTimes) m_rawChainInfo.targetRunTime +=
MiscGetEllapsedSeconds(&timevalTarget);
1776 m_rawChainInfo.numTargetCalls++;
1777 if ((m_env.subDisplayFile() ) &&
1778 (m_env.displayVerbosity() >= 3 ) &&
1779 (m_optionsObj->m_totallyMute ==
false)) {
1780 *m_env.subDisplayFile() <<
"In MetropolisHastingsSG<P_V,P_M>::generateFullChain()"
1781 <<
": just returned from likelihood() for chain position of id " << positionId
1782 <<
", m_rawChainInfo.numTargetCalls = " << m_rawChainInfo.numTargetCalls
1783 <<
", logPrior = " << logPrior
1784 <<
", logLikelihood = " << logLikelihood
1785 <<
", logTarget = " << logTarget
1789 currentCandidateData.set(tmpVecValues,
1794 if ((m_env.subDisplayFile() ) &&
1795 (m_env.displayVerbosity() >= 10 ) &&
1796 (m_optionsObj->m_totallyMute ==
false)) {
1797 *m_env.subDisplayFile() <<
"\n"
1798 <<
"\n-----------------------------------------------------------\n"
1802 bool accept =
false;
1803 double alphaFirstCandidate = 0.;
1804 if (outOfTargetSupport) {
1805 if (m_optionsObj->m_rawChainGenerateExtra) {
1806 m_alphaQuotients[positionId] = 0.;
1810 if (m_optionsObj->m_rawChainMeasureRunTimes) iRC = gettimeofday(&timevalMhAlpha, NULL);
1811 if (m_optionsObj->m_rawChainGenerateExtra) {
1812 alphaFirstCandidate = this->alpha(currentPositionData,currentCandidateData,0,1,&m_alphaQuotients[positionId]);
1815 alphaFirstCandidate = this->alpha(currentPositionData,currentCandidateData,0,1,NULL);
1817 if (m_optionsObj->m_rawChainMeasureRunTimes) m_rawChainInfo.mhAlphaRunTime +=
MiscGetEllapsedSeconds(&timevalMhAlpha);
1818 if ((m_env.subDisplayFile() ) &&
1819 (m_env.displayVerbosity() >= 10 ) &&
1820 (m_optionsObj->m_totallyMute ==
false)) {
1821 *m_env.subDisplayFile() <<
"In MetropolisHastingsSG<P_V,P_M>::generateFullChain()"
1822 <<
": for chain position of id = " << positionId
1825 accept = acceptAlpha(alphaFirstCandidate);
1828 bool displayDetail = (m_env.displayVerbosity() >= 10) || m_optionsObj->m_displayCandidates;
1829 if ((m_env.subDisplayFile() ) &&
1831 (m_optionsObj->m_totallyMute ==
false)) {
1832 *m_env.subDisplayFile() <<
"In MetropolisHastingsSG<P_V,P_M>::generateFullChain()"
1833 <<
": for chain position of id = " << positionId
1834 <<
", outOfTargetSupport = " << outOfTargetSupport
1835 <<
", alpha = " << alphaFirstCandidate
1836 <<
", accept = " << accept
1837 <<
", currentCandidateData.vecValues() = ";
1838 *m_env.subDisplayFile() << currentCandidateData.vecValues();
1839 *m_env.subDisplayFile() <<
"\n"
1840 <<
"\n curLogTarget = " << currentPositionData.
logTarget()
1842 <<
"\n canLogTarget = " << currentCandidateData.logTarget()
1846 if ((m_env.subDisplayFile() ) &&
1847 (m_env.displayVerbosity() >= 10 ) &&
1848 (m_optionsObj->m_totallyMute ==
false)) {
1849 *m_env.subDisplayFile() <<
"\n"
1850 <<
"\n-----------------------------------------------------------\n"
1860 std::vector<MarkovChainPositionData<P_V>*> drPositionsData(stageId+2,NULL);
1861 std::vector<unsigned int> tkStageIds (stageId+2,0);
1862 if ((accept ==
false) &&
1863 (outOfTargetSupport ==
false) &&
1864 (m_optionsObj->m_drMaxNumExtraStages > 0 )) {
1865 if ((m_optionsObj->m_drDuringAmNonAdaptiveInt ==
false ) &&
1866 (m_optionsObj->m_tkUseLocalHessian ==
false ) &&
1867 (m_optionsObj->m_amInitialNonAdaptInterval > 0 ) &&
1868 (m_optionsObj->m_amAdaptInterval > 0 ) &&
1869 (positionId <= m_optionsObj->m_amInitialNonAdaptInterval)) {
1873 if (m_optionsObj->m_rawChainMeasureRunTimes) iRC = gettimeofday(&timevalDR, NULL);
1881 while ((validPreComputingPosition ==
true ) &&
1882 (accept == false ) &&
1883 (stageId < m_optionsObj->m_drMaxNumExtraStages)) {
1884 if ((m_env.subDisplayFile() ) &&
1885 (m_env.displayVerbosity() >= 10 ) &&
1886 (m_optionsObj->m_totallyMute ==
false)) {
1887 *m_env.subDisplayFile() <<
"\n"
1888 <<
"\n+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-"
1892 m_rawChainInfo.numDRs++;
1894 m_stageIdForDebugging = stageId;
1895 if ((m_env.subDisplayFile() ) &&
1896 (m_env.displayVerbosity() >= 10 ) &&
1897 (m_optionsObj->m_totallyMute ==
false)) {
1898 *m_env.subDisplayFile() <<
"In MetropolisHastingsSG<P_V,P_M>::generateFullChain()"
1899 <<
": for chain position of id = " << positionId
1900 <<
", beginning stageId = " << stageId
1904 keepGeneratingCandidates =
true;
1905 while (keepGeneratingCandidates) {
1906 if (m_optionsObj->m_rawChainMeasureRunTimes) iRC = gettimeofday(&timevalCandidate, NULL);
1907 m_tk->rv(tkStageIds).realizer().realization(tmpVecValues);
1908 if (m_numDisabledParameters > 0) {
1909 for (
unsigned int paramId = 0; paramId < m_vectorSpace.dimLocal(); ++paramId) {
1910 if (m_parameterEnabledStatus[paramId] ==
false) {
1911 tmpVecValues[paramId] = m_initialPosition[paramId];
1915 if (m_optionsObj->m_rawChainMeasureRunTimes) m_rawChainInfo.candidateRunTime +=
MiscGetEllapsedSeconds(&timevalCandidate);
1917 outOfTargetSupport = !m_targetPdf.domainSet().contains(tmpVecValues);
1919 if (m_optionsObj->m_putOutOfBoundsInChain) keepGeneratingCandidates =
false;
1920 else keepGeneratingCandidates = outOfTargetSupport;
1923 if ((m_env.subDisplayFile() ) &&
1924 (m_env.displayVerbosity() >= 5 ) &&
1925 (m_optionsObj->m_totallyMute ==
false)) {
1926 *m_env.subDisplayFile() <<
"In MetropolisHastingsSG<P_V,P_M>::generateFullChain()"
1927 <<
": about to set TK pre computing position of local id " << stageId+1
1928 <<
", values = " << tmpVecValues
1931 validPreComputingPosition = m_tk->setPreComputingPosition(tmpVecValues,stageId+1);
1932 if ((m_env.subDisplayFile() ) &&
1933 (m_env.displayVerbosity() >= 5 ) &&
1934 (m_optionsObj->m_totallyMute ==
false)) {
1935 *m_env.subDisplayFile() <<
"In MetropolisHastingsSG<P_V,P_M>::generateFullChain()"
1936 <<
": returned from setting TK pre computing position of local id " << stageId+1
1937 <<
", values = " << tmpVecValues
1938 <<
", valid = " << validPreComputingPosition
1942 if (outOfTargetSupport) {
1943 m_rawChainInfo.numOutOfTargetSupportInDR++;
1944 logPrior = -INFINITY;
1945 logLikelihood = -INFINITY;
1946 logTarget = -INFINITY;
1949 if (m_optionsObj->m_rawChainMeasureRunTimes) iRC = gettimeofday(&timevalTarget, NULL);
1950 logTarget = m_targetPdfSynchronizer->callFunction(&tmpVecValues,NULL,NULL,NULL,NULL,&logPrior,&logLikelihood);
1951 if (m_optionsObj->m_rawChainMeasureRunTimes) m_rawChainInfo.targetRunTime +=
MiscGetEllapsedSeconds(&timevalTarget);
1952 m_rawChainInfo.numTargetCalls++;
1953 if ((m_env.subDisplayFile() ) &&
1954 (m_env.displayVerbosity() >= 3 ) &&
1955 (m_optionsObj->m_totallyMute ==
false)) {
1956 *m_env.subDisplayFile() <<
"In MetropolisHastingsSG<P_V,P_M>::generateFullChain()"
1957 <<
": just returned from likelihood() for chain position of id " << positionId
1958 <<
", m_rawChainInfo.numTargetCalls = " << m_rawChainInfo.numTargetCalls
1959 <<
", stageId = " << stageId
1960 <<
", logPrior = " << logPrior
1961 <<
", logLikelihood = " << logLikelihood
1962 <<
", logTarget = " << logTarget
1966 currentCandidateData.set(tmpVecValues,
1972 tkStageIds.push_back (stageId+1);
1974 double alphaDR = 0.;
1975 if (outOfTargetSupport ==
false) {
1976 if (m_optionsObj->m_rawChainMeasureRunTimes) iRC = gettimeofday(&timevalDrAlpha, NULL);
1977 alphaDR = this->alpha(drPositionsData,tkStageIds);
1978 if (m_optionsObj->m_rawChainMeasureRunTimes) m_rawChainInfo.drAlphaRunTime +=
MiscGetEllapsedSeconds(&timevalDrAlpha);
1979 accept = acceptAlpha(alphaDR);
1982 displayDetail = (m_env.displayVerbosity() >= 10) || m_optionsObj->m_displayCandidates;
1983 if ((m_env.subDisplayFile() ) &&
1985 (m_optionsObj->m_totallyMute ==
false)) {
1986 *m_env.subDisplayFile() <<
"In MetropolisHastingsSG<P_V,P_M>::generateFullChain()"
1987 <<
": for chain position of id = " << positionId
1988 <<
" and stageId = " << stageId
1989 <<
", outOfTargetSupport = " << outOfTargetSupport
1990 <<
", alpha = " << alphaDR
1991 <<
", accept = " << accept
1992 <<
", currentCandidateData.vecValues() = ";
1993 *m_env.subDisplayFile() << currentCandidateData.vecValues();
1994 *m_env.subDisplayFile() << std::endl;
1998 if (m_optionsObj->m_rawChainMeasureRunTimes) m_rawChainInfo.drRunTime +=
MiscGetEllapsedSeconds(&timevalDR);
2002 for (
unsigned int i = 0; i < drPositionsData.size(); ++i) {
2003 if (drPositionsData[i])
delete drPositionsData[i];
2012 if (
true) m_idsOfUniquePositions[uniquePos++] = positionId;
2013 currentPositionData = currentCandidateData;
2017 m_rawChainInfo.numRejections++;
2019 m_numPositionsNotSubWritten++;
2020 if ((m_optionsObj->m_rawChainDataOutputPeriod > 0 ) &&
2021 (((positionId+1) % m_optionsObj->m_rawChainDataOutputPeriod) == 0 ) &&
2022 (m_optionsObj->m_rawChainDataOutputFileName !=
".")) {
2023 if ((m_env.subDisplayFile() ) &&
2024 (m_env.displayVerbosity() >= 10 ) &&
2025 (m_optionsObj->m_totallyMute ==
false)) {
2026 *m_env.subDisplayFile() <<
"In MetropolisHastingsSG<P_V,P_M>::generateFullChain()"
2027 <<
", for chain position of id = " << positionId
2028 <<
": about to write (per period request) " << m_numPositionsNotSubWritten <<
" chain positions "
2029 <<
", " << positionId + 1 - m_optionsObj->m_rawChainDataOutputPeriod <<
" <= pos <= " << positionId
2032 workingChain.
subWriteContents(positionId + 1 - m_optionsObj->m_rawChainDataOutputPeriod,
2033 m_optionsObj->m_rawChainDataOutputPeriod,
2034 m_optionsObj->m_rawChainDataOutputFileName,
2035 m_optionsObj->m_rawChainDataOutputFileType,
2036 m_optionsObj->m_rawChainDataOutputAllowedSet);
2037 if ((m_env.subDisplayFile() ) &&
2038 (m_optionsObj->m_totallyMute ==
false)) {
2039 *m_env.subDisplayFile() <<
"In MetropolisHastingsSG<P_V,P_M>::generateFullChain()"
2040 <<
", for chain position of id = " << positionId
2041 <<
": just wrote (per period request) " << m_numPositionsNotSubWritten <<
" chain positions "
2042 <<
", " << positionId + 1 - m_optionsObj->m_rawChainDataOutputPeriod <<
" <= pos <= " << positionId
2046 if (writeLogLikelihood) {
2047 workingLogLikelihoodValues->
subWriteContents(0 + 1 - m_optionsObj->m_rawChainDataOutputPeriod,
2048 m_optionsObj->m_rawChainDataOutputPeriod,
2049 m_optionsObj->m_rawChainDataOutputFileName +
"_loglikelihood",
2050 m_optionsObj->m_rawChainDataOutputFileType,
2051 m_optionsObj->m_rawChainDataOutputAllowedSet);
2054 if (writeLogTarget) {
2055 workingLogTargetValues->
subWriteContents(0 + 1 - m_optionsObj->m_rawChainDataOutputPeriod,
2056 m_optionsObj->m_rawChainDataOutputPeriod,
2057 m_optionsObj->m_rawChainDataOutputFileName +
"_logtarget",
2058 m_optionsObj->m_rawChainDataOutputFileType,
2059 m_optionsObj->m_rawChainDataOutputAllowedSet);
2062 m_numPositionsNotSubWritten = 0;
2066 if (workingLogLikelihoodValues) (*workingLogLikelihoodValues)[positionId] = currentPositionData.
logLikelihood();
2067 if (workingLogTargetValues ) (*workingLogTargetValues )[positionId] = currentPositionData.
logTarget();
2069 if (m_optionsObj->m_rawChainGenerateExtra) {
2070 m_logTargets[positionId] = currentPositionData.
logTarget();
2073 if (m_optionsObj->m_enableBrooksGelmanConvMonitor > 0) {
2074 if (positionId % m_optionsObj->m_enableBrooksGelmanConvMonitor == 0 &&
2075 positionId > m_optionsObj->m_BrooksGelmanLag + 1) {
2078 m_optionsObj->m_BrooksGelmanLag,
2079 positionId - m_optionsObj->m_BrooksGelmanLag);
2081 if (m_env.subDisplayFile()) {
2082 *m_env.subDisplayFile() <<
"positionId = " << positionId
2083 <<
", conv_est = " << conv_est
2085 (*m_env.subDisplayFile()).flush();
2094 this->adapt(positionId, workingChain);
2100 if ((m_env.subDisplayFile() ) &&
2101 (m_env.displayVerbosity() >= 3 ) &&
2102 (m_optionsObj->m_totallyMute ==
false)) {
2103 *m_env.subDisplayFile() <<
"In MetropolisHastingsSG<P_V,P_M>::generateFullChain()"
2104 <<
": finishing chain position of id = " << positionId
2105 <<
", accept = " << accept
2106 <<
", curLogTarget = " << currentPositionData.
logTarget()
2107 <<
", canLogTarget = " << currentCandidateData.logTarget()
2111 if ((m_optionsObj->m_rawChainDisplayPeriod > 0) &&
2112 (((positionId+1) % m_optionsObj->m_rawChainDisplayPeriod) == 0)) {
2113 if ((m_env.subDisplayFile() ) &&
2114 (m_optionsObj->m_totallyMute ==
false)) {
2115 *m_env.subDisplayFile() <<
"Finished generating " << positionId+1
2117 <<
", current rejection percentage = " << (100. * ((double) m_rawChainInfo.numRejections)/((double) (positionId+1)))
2123 if ((m_env.subDisplayFile() ) &&
2124 (m_env.displayVerbosity() >= 10 ) &&
2125 (m_optionsObj->m_totallyMute ==
false)) {
2126 *m_env.subDisplayFile() <<
"\n"
2127 <<
"\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
2133 if ((m_env.numSubEnvironments() < (
unsigned int) m_env.fullComm().NumProc()) &&
2134 (m_initialPosition.numOfProcsForStorage() == 1 ) &&
2135 (m_env.subRank() == 0 )) {
2138 aux = m_targetPdfSynchronizer->callFunction(NULL,
2152 if ((m_env.subDisplayFile() ) &&
2153 (m_optionsObj->m_totallyMute ==
false)) {
2154 *m_env.subDisplayFile() <<
"Finished the generation of Markov chain " << workingChain.
name()
2157 *m_env.subDisplayFile() <<
"\nSome information about this chain:"
2158 <<
"\n Chain run time = " << m_rawChainInfo.runTime
2160 if (m_optionsObj->m_rawChainMeasureRunTimes) {
2161 *m_env.subDisplayFile() <<
"\n\n Breaking of the chain run time:\n";
2162 *m_env.subDisplayFile() <<
"\n Candidate run time = " << m_rawChainInfo.candidateRunTime
2163 <<
" seconds (" << 100.*m_rawChainInfo.candidateRunTime/m_rawChainInfo.runTime
2165 *m_env.subDisplayFile() <<
"\n Num target calls = " << m_rawChainInfo.numTargetCalls;
2166 *m_env.subDisplayFile() <<
"\n Target d. run time = " << m_rawChainInfo.targetRunTime
2167 <<
" seconds (" << 100.*m_rawChainInfo.targetRunTime/m_rawChainInfo.runTime
2169 *m_env.subDisplayFile() <<
"\n Avg target run time = " << m_rawChainInfo.targetRunTime/((double) m_rawChainInfo.numTargetCalls)
2171 *m_env.subDisplayFile() <<
"\n Mh alpha run time = " << m_rawChainInfo.mhAlphaRunTime
2172 <<
" seconds (" << 100.*m_rawChainInfo.mhAlphaRunTime/m_rawChainInfo.runTime
2174 *m_env.subDisplayFile() <<
"\n Dr alpha run time = " << m_rawChainInfo.drAlphaRunTime
2175 <<
" seconds (" << 100.*m_rawChainInfo.drAlphaRunTime/m_rawChainInfo.runTime
2177 *m_env.subDisplayFile() <<
"\n---------------------- --------------";
2178 double sumRunTime = m_rawChainInfo.candidateRunTime + m_rawChainInfo.targetRunTime + m_rawChainInfo.mhAlphaRunTime + m_rawChainInfo.drAlphaRunTime;
2179 *m_env.subDisplayFile() <<
"\n Sum = " << sumRunTime
2180 <<
" seconds (" << 100.*sumRunTime/m_rawChainInfo.runTime
2182 *m_env.subDisplayFile() <<
"\n\n Other run times:";
2183 *m_env.subDisplayFile() <<
"\n DR run time = " << m_rawChainInfo.drRunTime
2184 <<
" seconds (" << 100.*m_rawChainInfo.drRunTime/m_rawChainInfo.runTime
2186 *m_env.subDisplayFile() <<
"\n AM run time = " << m_rawChainInfo.amRunTime
2187 <<
" seconds (" << 100.*m_rawChainInfo.amRunTime/m_rawChainInfo.runTime
2190 *m_env.subDisplayFile() <<
"\n Number of DRs = " << m_rawChainInfo.numDRs <<
"(num_DRs/chain_size = " << (double) m_rawChainInfo.numDRs/(
double) workingChain.
subSequenceSize()
2192 *m_env.subDisplayFile() <<
"\n Out of target support in DR = " << m_rawChainInfo.numOutOfTargetSupportInDR;
2193 *m_env.subDisplayFile() <<
"\n Rejection percentage = " << 100. * (double) m_rawChainInfo.numRejections/(
double) workingChain.
subSequenceSize()
2195 *m_env.subDisplayFile() <<
"\n Out of target support percentage = " << 100. * (double) m_rawChainInfo.numOutOfTargetSupport/(
double) workingChain.
subSequenceSize()
2197 *m_env.subDisplayFile() << std::endl;
2208 template <
class P_V,
class P_M>
2214 struct timeval timevalAM;
2217 if ((m_optionsObj->m_tkUseLocalHessian ==
true) ||
2218 (m_optionsObj->m_amInitialNonAdaptInterval == 0) ||
2219 (m_optionsObj->m_amAdaptInterval == 0)) {
2224 if (m_optionsObj->m_rawChainMeasureRunTimes) {
2225 iRC = gettimeofday(&timevalAM, NULL);
2228 unsigned int idOfFirstPositionInSubChain = 0;
2232 bool printAdaptedMatrix =
false;
2233 if (positionId < m_optionsObj->m_amInitialNonAdaptInterval) {
2236 else if (positionId == m_optionsObj->m_amInitialNonAdaptInterval) {
2237 idOfFirstPositionInSubChain = 0;
2238 partialChain.
resizeSequence(m_optionsObj->m_amInitialNonAdaptInterval+1);
2239 m_lastMean = m_vectorSpace.newVector();
2240 m_lastAdaptedCovMatrix = m_vectorSpace.newMatrix();
2241 printAdaptedMatrix =
true;
2244 unsigned int interval = positionId - m_optionsObj->m_amInitialNonAdaptInterval;
2245 if ((interval % m_optionsObj->m_amAdaptInterval) == 0) {
2246 idOfFirstPositionInSubChain = positionId - m_optionsObj->m_amAdaptInterval;
2249 if (m_optionsObj->m_amAdaptedMatricesDataOutputPeriod > 0) {
2250 if ((interval % m_optionsObj->m_amAdaptedMatricesDataOutputPeriod) == 0) {
2251 printAdaptedMatrix =
true;
2260 if (m_optionsObj->m_rawChainMeasureRunTimes) {
2268 P_V transporterVec(m_vectorSpace.zeroVector());
2274 if (this->m_optionsObj->m_doLogitTransform ==
true) {
2278 P_V transformedTransporterVec(m_vectorSpace.zeroVector());
2280 m_tk)->transformToGaussianSpace(transporterVec,
2281 transformedTransporterVec);
2289 updateAdaptedCovMatrix(partialChain,
2290 idOfFirstPositionInSubChain,
2293 *m_lastAdaptedCovMatrix);
2296 if ((printAdaptedMatrix ==
true) &&
2297 (m_optionsObj->m_amAdaptedMatricesDataOutputFileName !=
"." )) {
2298 char varNamePrefix[64];
2299 sprintf(varNamePrefix,
"mat_am%d",positionId);
2302 sprintf(tmpChar,
"_am%d",positionId);
2304 std::set<unsigned int> tmpSet;
2305 tmpSet.insert(m_env.subId());
2307 m_lastAdaptedCovMatrix->subWriteContents(varNamePrefix,
2308 (m_optionsObj->m_amAdaptedMatricesDataOutputFileName+tmpChar),
2309 m_optionsObj->m_amAdaptedMatricesDataOutputFileType,
2311 if ((m_env.subDisplayFile() ) &&
2312 (m_optionsObj->m_totallyMute ==
false)) {
2313 *m_env.subDisplayFile() <<
"In MetropolisHastingsSG<P_V,P_M>::generateFullChain()"
2314 <<
": just wrote last adapted proposal cov matrix contents = " << *m_lastAdaptedCovMatrix
2320 bool tmpCholIsPositiveDefinite =
false;
2321 P_M tmpChol(*m_lastAdaptedCovMatrix);
2322 P_M attemptedMatrix(tmpChol);
2323 if ((m_env.subDisplayFile() ) &&
2324 (m_env.displayVerbosity() >= 10)) {
2326 *m_env.subDisplayFile() <<
"In MetropolisHastingsSG<P_V,P_M>::generateFullChain()"
2327 <<
", positionId = " << positionId
2328 <<
": 'am' calling first tmpChol.chol()"
2331 iRC = tmpChol.chol();
2333 std::string err1 =
"In MetropolisHastingsSG<P_V,P_M>::adapt(): first ";
2334 err1 +=
"Cholesky factorisation of proposal covariance matrix ";
2335 err1 +=
"failed. QUESO will now attempt to regularise the ";
2336 err1 +=
"matrix before proceeding. This is not a fatal error.";
2337 std::cerr << err1 << std::endl;
2341 if ((m_env.subDisplayFile() ) &&
2342 (m_env.displayVerbosity() >= 10)) {
2344 *m_env.subDisplayFile() <<
"In MetropolisHastingsSG<P_V,P_M>::generateFullChain()"
2345 <<
", positionId = " << positionId
2346 <<
": 'am' got first tmpChol.chol() with iRC = " << iRC
2349 double diagMult = 1.;
2350 for (
unsigned int j = 0; j < tmpChol.numRowsLocal(); ++j) {
2351 diagMult *= tmpChol(j,j);
2353 *m_env.subDisplayFile() <<
"diagMult = " << diagMult
2358 #if 0 // tentative logic
2360 double diagMult = 1.;
2361 for (
unsigned int j = 0; j < tmpChol.numRowsLocal(); ++j) {
2362 diagMult *= tmpChol(j,j);
2364 if (diagMult < 1.e-40) {
2375 P_M* tmpDiag = m_vectorSpace.newDiagMatrix(m_optionsObj->m_amEpsilon);
2376 if (m_numDisabledParameters > 0) {
2377 for (
unsigned int paramId = 0; paramId < m_vectorSpace.dimLocal(); ++paramId) {
2378 if (m_parameterEnabledStatus[paramId] ==
false) {
2379 (*tmpDiag)(paramId,paramId) = 0.;
2383 tmpChol = *m_lastAdaptedCovMatrix + *tmpDiag;
2384 attemptedMatrix = tmpChol;
2387 if ((m_env.subDisplayFile() ) &&
2388 (m_env.displayVerbosity() >= 10)) {
2389 *m_env.subDisplayFile() <<
"In MetropolisHastingsSG<P_V,P_M>::generateFullChain()"
2390 <<
", positionId = " << positionId
2391 <<
": 'am' calling second tmpChol.chol()"
2396 iRC = tmpChol.chol();
2398 std::string err2 =
"In MetropolisHastingsSG<P_V,P_M>::adapt(): second ";
2399 err2 +=
"Cholesky factorisation of (regularised) proposal ";
2400 err2 +=
"covariance matrix failed. QUESO is falling back to ";
2401 err2 +=
"the last factorisable proposal covariance matrix. ";
2402 err2 +=
"This is not a fatal error.";
2403 std::cerr << err2 << std::endl;
2407 if ((m_env.subDisplayFile() ) &&
2408 (m_env.displayVerbosity() >= 10)) {
2409 *m_env.subDisplayFile() <<
"In MetropolisHastingsSG<P_V,P_M>::generateFullChain()"
2410 <<
", positionId = " << positionId
2411 <<
": 'am' got second tmpChol.chol() with iRC = " << iRC
2414 double diagMult = 1.;
2415 for (
unsigned int j = 0; j < tmpChol.numRowsLocal(); ++j) {
2416 diagMult *= tmpChol(j,j);
2418 *m_env.subDisplayFile() <<
"diagMult = " << diagMult
2422 *m_env.subDisplayFile() <<
"attemptedMatrix = " << attemptedMatrix
2433 tmpCholIsPositiveDefinite =
true;
2437 tmpCholIsPositiveDefinite =
true;
2441 if (tmpCholIsPositiveDefinite) {
2442 P_M tmpMatrix(m_optionsObj->m_amEta*attemptedMatrix);
2443 if (m_numDisabledParameters > 0) {
2444 for (
unsigned int paramId = 0; paramId < m_vectorSpace.dimLocal(); ++paramId) {
2445 if (m_parameterEnabledStatus[paramId] ==
false) {
2446 for (
unsigned int i = 0; i < m_vectorSpace.dimLocal(); ++i) {
2447 tmpMatrix(i,paramId) = 0.;
2449 for (
unsigned int j = 0; j < m_vectorSpace.dimLocal(); ++j) {
2450 tmpMatrix(paramId,j) = 0.;
2452 tmpMatrix(paramId,paramId) = 1.;
2459 if (this->m_optionsObj->m_doLogitTransform) {
2461 ->updateLawCovMatrix(tmpMatrix);
2465 ->updateLawCovMatrix(tmpMatrix);
2468 #ifdef UQ_DRAM_MCG_REQUIRES_INVERTED_COV_MATRICES
2479 if (m_optionsObj->m_rawChainMeasureRunTimes) {
2485 template <
class P_V,
class P_M>
2489 unsigned int idOfFirstPositionInSubChain,
2490 double& lastChainSize,
2492 P_M& lastAdaptedCovMatrix)
2495 if (lastChainSize == 0) {
2498 #if 1 // prudenci-2012-07-06
2504 P_V tmpVec(m_vectorSpace.zeroVector());
2505 lastAdaptedCovMatrix = -doubleSubChainSize *
matrixProduct(lastMean,lastMean);
2510 lastAdaptedCovMatrix /= (doubleSubChainSize - 1.);
2516 P_V tmpVec (m_vectorSpace.zeroVector());
2517 P_V diffVec(m_vectorSpace.zeroVector());
2519 double doubleCurrentId = (double) (idOfFirstPositionInSubChain+i);
2521 diffVec = tmpVec - lastMean;
2523 double ratio1 = (1. - 1./doubleCurrentId);
2524 double ratio2 = (1./(1.+doubleCurrentId));
2525 lastAdaptedCovMatrix = ratio1 * lastAdaptedCovMatrix + ratio2 *
matrixProduct(diffVec,diffVec);
2526 lastMean += ratio2 * diffVec;
2529 lastChainSize += doubleSubChainSize;
2531 if (m_numDisabledParameters > 0) {
2532 for (
unsigned int paramId = 0; paramId < m_vectorSpace.dimLocal(); ++paramId) {
2533 if (m_parameterEnabledStatus[paramId] ==
false) {
2534 for (
unsigned int i = 0; i < m_vectorSpace.dimLocal(); ++i) {
2535 lastAdaptedCovMatrix(i,paramId) = 0.;
2537 for (
unsigned int j = 0; j < m_vectorSpace.dimLocal(); ++j) {
2538 lastAdaptedCovMatrix(paramId,j) = 0.;
2540 lastAdaptedCovMatrix(paramId,paramId) = 1.;
2548 template <
class P_V,
class P_M>
2553 P_V min_domain_bounds(boxSubset.
minValues());
2554 P_V max_domain_bounds(boxSubset.
maxValues());
2556 for (
unsigned int i = 0; i < min_domain_bounds.sizeLocal(); i++) {
2557 double min_val = min_domain_bounds[i];
2558 double max_val = max_domain_bounds[i];
2560 if (boost::math::isfinite(min_val) && boost::math::isfinite(max_val)) {
2561 if (m_initialProposalCovMatrix(i, i) >= max_val - min_val) {
2564 std::cerr <<
"Proposal variance element "
2567 << m_initialProposalCovMatrix(i, i)
2568 <<
" but domain is of size "
2569 << max_val - min_val
2571 std::cerr <<
"QUESO does not support uniform-like proposal "
2572 <<
"distributions. Try making the proposal variance smaller"
2577 double transformJacobian = 4.0 / (max_val - min_val);
2581 for (
unsigned int j = 0; j < min_domain_bounds.sizeLocal(); j++) {
2583 m_initialProposalCovMatrix(j, i) *= transformJacobian;
2585 for (
unsigned int j = 0; j < min_domain_bounds.sizeLocal(); j++) {
2587 m_initialProposalCovMatrix(i, j) *= transformJacobian;
const MhOptionsValues * m_optionsObj
unsigned int vectorSizeLocal() const
Local dimension (size) of the vector space.
const V & lawExpVector() const
Access to the vector of mean values of the Gaussian (not transformed) and private attribute: m_lawExp...
void transformInitialCovMatrixToGaussianSpace(const BoxSubset< P_V, P_M > &boxSubset)
double logTarget() const
Logarithm of the value of the target; access to private attribute m_logTarget.
MHRawChainInfoStruct & operator=(const MHRawChainInfoStruct &rhs)
Assignment operator.
double unifiedPositionsOfMaximum(const ScalarSequence< double > &subCorrespondingScalarValues, BaseVectorSequence< V, M > &unifiedPositionsOfMaximum)
Finds the positions where the maximum element occurs in the unified sequence.
void computeFilterParams(std::ofstream *passedOfs, unsigned int &initialPos, unsigned int &spacing)
Computes the filtering parameters spacing for the sequence of vectors.
This class allows the representation of a transition kernel with Hessians.
MetropolisHastingsSG(const char *prefix, const MhOptionsValues *alternativeOptionsValues, const BaseVectorRV< P_V, P_M > &sourceRv, const P_V &initialPosition, const P_M *inputProposalCovMatrix)
Constructor.
unsigned int numTargetCalls
virtual void subWriteContents(unsigned int initialPos, unsigned int numPos, const std::string &fileName, const std::string &fileType, const std::set< unsigned int > &allowedSubEnvIds) const =0
Writes info of the sub-sequence to a file. See template specialization.
double subPositionsOfMaximum(const ScalarSequence< double > &subCorrespondingScalarValues, BaseVectorSequence< V, M > &subPositionsOfMaximum)
Finds the positions where the maximum element occurs in the sub-sequence.
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 generateSequence(BaseVectorSequence< P_V, P_M > &workingChain, ScalarSequence< double > *workingLogLikelihoodValues, ScalarSequence< double > *workingLogTargetValues)
Method to generate the chain.
const BaseTKGroup< P_V, P_M > & transitionKernel() const
Returns the underlying transition kernel for this sequence generator.
void generateFullChain(const P_V &valuesOf1stPosition, unsigned int chainSize, BaseVectorSequence< P_V, P_M > &workingChain, ScalarSequence< double > *workingLogLikelihoodValues, ScalarSequence< double > *workingLogTargetValues)
This method generates the chain.
std::ofstream * ofsVar
Provides a stream interface to write data to files.
MHRawChainInfoStruct & operator+=(const MHRawChainInfoStruct &rhs)
Addition assignment operator.
#define queso_require_not_equal_to_msg(expr1, expr2, msg)
Struct for handling data input and output from files.
unsigned int numOutOfTargetSupportInDR
This class allows the representation of a transition kernel with a scaled covariance matrix...
A struct that represents a Metropolis-Hastings sample.
const V & lawVarVector() const
Access to the vector of variance values and private attribute: m_lawVarVector.
void updateAdaptedCovMatrix(const BaseVectorSequence< P_V, P_M > &subChain, unsigned int idOfFirstPositionInSubChain, double &lastChainSize, P_V &lastMean, P_M &lastAdaptedCovMatrix)
This method updates the adapted covariance matrix.
This class provides options for each level of the Multilevel sequence generator if no input file is a...
const V & vecValues() const
Values of the chain (vector); access to private attribute m_vecValues.
The QUESO MPI Communicator Class.
void commonConstructor()
Reads the options values from the options input file.
~MHRawChainInfoStruct()
Destructor.
#define queso_require_equal_to_msg(expr1, expr2, msg)
A templated class that represents a Markov Chain.
virtual void unifiedReadContents(const std::string &fileName, const std::string &fileType, const unsigned int subSequenceSize)=0
Reads info of the unified sequence from a file. See template specialization.
This class represents a transition kernel with a scaled covariance matrix on hybrid bounded/unbounded...
void setPositionValues(unsigned int posId, const V &vec)
Set the values in vec at position posId of the sequence.
const int UQ_MATRIX_IS_NOT_POS_DEFINITE_RC
double MiscGetEllapsedSeconds(struct timeval *timeval0)
#define queso_require_msg(asserted, msg)
#define UQ_MH_SG_FILENAME_FOR_NO_FILE
const V & maxValues() const
Vector of the maximum values of the box subset.
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
A class for handling hybrid (transformed) Gaussians with bounds.
const V & minValues() const
Vector of the minimum values of the box subset.
void adapt(unsigned int positionId, BaseVectorSequence< P_V, P_M > &workingChain)
Adaptive Metropolis method that deals with adapting the proposal covariance matrix.
GslMatrix matrixProduct(const GslVector &v1, const GslVector &v2)
unsigned int numOutOfTargetSupport
void unifiedWriteContents(const std::string &fileName, const std::string &fileType) const
Writes the unified sequence to a file.
#define UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT
unsigned int numRejections
bool acceptAlpha(double alpha)
Decides whether or not to accept alpha.
This class provides options for the Metropolis-Hastings generator of samples if no input file is avai...
void readFullChain(const std::string &inputFileName, const std::string &inputFileType, unsigned int chainSize, BaseVectorSequence< P_V, P_M > &workingChain)
This method reads the chain contents.
int writeInfo(const BaseVectorSequence< P_V, P_M > &workingChain, std::ofstream &ofsvar) const
Writes information about the Markov chain in a file.
virtual void unifiedWriteContents(const std::string &fileName, const std::string &fileType) const =0
Writes info of the unified sequence to a file. See template specialization.
double alpha(const MarkovChainPositionData< P_V > &x, const MarkovChainPositionData< P_V > &y, unsigned int xStageId, unsigned int yStageId, double *alphaQuotientPtr=NULL)
Calculates acceptance ration.
const std::string & name() const
Access to protected attribute m_name: name of the sequence of vectors.
~MetropolisHastingsSG()
Destructor.
unsigned int subSequenceSize() const
Size of the sub-sequence of vectors.
const M & lawCovMatrix() const
Returns the covariance matrix; access to protected attribute m_lawCovMatrix.
virtual void getPositionValues(unsigned int posId, V &vec) const =0
Gets the values of the sequence at position posId and stores them at vec. See template specialization...
bool m_totallyMute
If true, zero output is written to files. Default is false.
MetropolisHastingsSGOptions * m_oldOptions
MHRawChainInfoStruct()
Constructor.
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.
const int UQ_INCOMPLETE_IMPLEMENTATION_RC
bool outOfTargetSupport() const
Whether or not a position is out of target support; access to private attribute m_outOfTargetSupport...
void mpiSum(const MpiComm &comm, MHRawChainInfoStruct &sumInfo) const
Calculates the MPI sum of this.
#define queso_require_greater_equal_msg(expr1, expr2, msg)
void resizeSequence(unsigned int newSubSequenceSize)
Resizes the sequence.
void reset()
Resets Metropolis-Hastings chain info.
MhOptionsValues m_ov
This class is where the actual options are stored.
void subWriteContents(unsigned int initialPos, unsigned int numPos, const std::string &fileName, const std::string &fileType, const std::set< unsigned int > &allowedSubEnvIds) const
Writes the sub-sequence to a file.
double logLikelihood() const
Logarithm of the value of the likelihood; access to private attribute m_logLikelihood.
This class reads the options for the Metropolis-Hastings generator of samples from an input file...
virtual void subMeanExtra(unsigned int initialPos, unsigned int numPos, V &meanVec) const =0
Finds the mean value of the sub-sequence, considering numPos positions starting at position initialPo...
virtual unsigned int subSequenceSize() const =0
Size of the sub-sequence of vectors. See template specialization.
#define RawValue_MPI_DOUBLE
void Allreduce(void *sendbuf, void *recvbuf, int count, RawType_MPI_Datatype datatype, RawType_MPI_Op op, const char *whereMsg, const char *whatMsg) const
Combines values from all processes and distributes the result back to all processes.
#define RawValue_MPI_UNSIGNED
virtual double estimateConvBrooksGelman(unsigned int initialPos, unsigned int numPos) const =0
Estimates convergence rate using Brooks & Gelman method. See template specialization.
void filter(unsigned int initialPos, unsigned int spacing)
Filters positions in the sequence of vectors.
void setName(const std::string &newName)
Changes the name of the sequence of vectors.
const V & subMeanPlain() const
Finds the mean value of the sub-sequence.
virtual void filter(unsigned int initialPos, unsigned int spacing)=0
Filters positions in the sequence of vectors, starting at initialPos, and with spacing given by spaci...
P_M m_initialProposalCovMatrix
const BaseEnvironment & m_env
void copy(const MHRawChainInfoStruct &src)
Copies Metropolis-Hastings chain info from src to this.
virtual void setPositionValues(unsigned int posId, const V &vec)=0
Set the values in vec at position posId of the sequence. See template specialization.