1 #ifndef HOPS_MARKOVCHAINFACTORY_HPP
2 #define HOPS_MARKOVCHAINFACTORY_HPP
42 template<
typename MatrixType,
typename VectorType,
typename Proposal>
59 template<
typename MatrixType,
typename VectorType>
66 if (!isInteriorPoint(inequalityLhs, inequalityRhs, startingPoint)) {
67 throw std::domain_error(
"Starting point outside polytope is always constant.");
72 return addRecordersAndAdapter(
75 Eigen::Matrix<typename MatrixType::Scalar, Eigen::Dynamic, Eigen::Dynamic>(
76 inequalityLhs), inequalityRhs, startingPoint)
81 return addRecordersAndAdapter(
84 Eigen::Matrix<typename MatrixType::Scalar, Eigen::Dynamic, Eigen::Dynamic>(
85 inequalityLhs), inequalityRhs, startingPoint)
90 return addRecordersAndAdapter(
97 return addRecordersAndAdapter(
100 Eigen::Matrix<typename MatrixType::Scalar, Eigen::Dynamic, Eigen::Dynamic>(
101 inequalityLhs), inequalityRhs, startingPoint)
106 return addRecordersAndAdapter(
109 Eigen::Matrix<typename MatrixType::Scalar, Eigen::Dynamic, Eigen::Dynamic>(
110 inequalityLhs), inequalityRhs, startingPoint)
115 throw std::invalid_argument(
"MarkovChainType not supported for uniform sampling.");
130 template<
typename MatrixType,
typename VectorType,
typename Proposal>
136 return addRecordersAndAdapter(
139 m_proposal,
Transformation(unroundingTransformation, unroundingShift)
157 template<
typename MatrixType,
typename VectorType>
166 if (!isInteriorPoint(roundedInequalityLhs, roundedInequalityRhs, startingPoint)) {
167 throw std::domain_error(
"Starting point outside polytope is always constant.");
172 return addRecordersAndAdapter(
176 Eigen::Matrix<typename MatrixType::Scalar, Eigen::Dynamic, Eigen::Dynamic>(
177 roundedInequalityLhs),
178 roundedInequalityRhs,
186 return addRecordersAndAdapter(
190 Eigen::Matrix<typename MatrixType::Scalar, Eigen::Dynamic, Eigen::Dynamic>(
191 roundedInequalityLhs),
192 roundedInequalityRhs,
200 return addRecordersAndAdapter(
204 roundedInequalityLhs,
205 roundedInequalityRhs,
213 return addRecordersAndAdapter(
217 Eigen::Matrix<typename MatrixType::Scalar, Eigen::Dynamic, Eigen::Dynamic>(
218 roundedInequalityLhs),
219 roundedInequalityRhs,
227 return addRecordersAndAdapter(
231 Eigen::Matrix<typename MatrixType::Scalar, Eigen::Dynamic, Eigen::Dynamic>(
232 roundedInequalityLhs),
233 roundedInequalityRhs,
241 throw std::invalid_argument(
"MarkovChainType not supported for uniform sampling.");
256 template<
typename MatrixType,
typename VectorType,
typename Proposal>
259 std::shared_ptr<Model> model
261 return addRecordersAndAdapter(
285 template<
typename MatrixType,
typename VectorType>
291 const std::shared_ptr<Model> &model
293 if (!isInteriorPoint(inequalityLhs, inequalityRhs, startingPoint)) {
294 throw std::domain_error(
"Starting point outside polytope is always constant.");
299 return addRecordersAndAdapter(
303 decltype(inequalityRhs)>(
304 inequalityLhs, inequalityRhs, startingPoint),
311 return addRecordersAndAdapter(
315 BallWalkProposal<Eigen::Matrix<typename MatrixType::Scalar, Eigen::Dynamic, Eigen::Dynamic>,
316 decltype(inequalityRhs)>(
317 inequalityLhs, inequalityRhs, startingPoint),
325 return addRecordersAndAdapter(
330 decltype(inequalityRhs),
332 inequalityLhs, inequalityRhs, startingPoint),
340 return addRecordersAndAdapter(
352 return addRecordersAndAdapter(
364 return addRecordersAndAdapter(
369 Eigen::Matrix<typename MatrixType::Scalar, Eigen::Dynamic, Eigen::Dynamic>,
370 decltype(inequalityRhs)
371 >(inequalityLhs, inequalityRhs, startingPoint),
379 return addRecordersAndAdapter(
383 HitAndRunProposal<Eigen::Matrix<typename MatrixType::Scalar, Eigen::Dynamic, Eigen::Dynamic>,
384 decltype(inequalityRhs),
386 inequalityLhs, inequalityRhs, startingPoint),
394 throw std::invalid_argument(
"Type not supported.");
412 template<
typename MatrixType,
typename VectorType>
418 const std::shared_ptr<Model> &model,
421 if (!isInteriorPoint(inequalityLhs, inequalityRhs, startingPoint)) {
422 throw std::domain_error(
"Starting point outside polytope is always constant.");
427 return addRecordersAndAdapter(
431 decltype(inequalityRhs)>(
432 inequalityLhs, inequalityRhs, startingPoint),
436 synchronizedRandomNumberGenerator
440 return addRecordersAndAdapter(
444 BallWalkProposal<Eigen::Matrix<typename MatrixType::Scalar, Eigen::Dynamic, Eigen::Dynamic>,
445 decltype(inequalityRhs)>(
446 inequalityLhs, inequalityRhs, startingPoint),
451 synchronizedRandomNumberGenerator
455 return addRecordersAndAdapter(
460 decltype(inequalityRhs),
462 inequalityLhs, inequalityRhs, startingPoint),
467 synchronizedRandomNumberGenerator
471 return addRecordersAndAdapter(
480 synchronizedRandomNumberGenerator
484 return addRecordersAndAdapter(
493 synchronizedRandomNumberGenerator
497 return addRecordersAndAdapter(
502 Eigen::Matrix<typename MatrixType::Scalar, Eigen::Dynamic, Eigen::Dynamic>,
503 decltype(inequalityRhs)
504 >(inequalityLhs, inequalityRhs, startingPoint),
509 synchronizedRandomNumberGenerator
513 return addRecordersAndAdapter(
517 HitAndRunProposal<Eigen::Matrix<typename MatrixType::Scalar, Eigen::Dynamic, Eigen::Dynamic>,
518 decltype(inequalityRhs),
520 inequalityLhs, inequalityRhs, startingPoint),
525 synchronizedRandomNumberGenerator
529 throw std::invalid_argument(
"Type not supported.");
546 template<
typename MatrixType,
typename VectorType,
typename Proposal>
551 std::shared_ptr<Model> model
554 return addRecordersAndAdapter(
583 template<
typename MatrixType,
typename VectorType>
591 const std::shared_ptr<Model> &model
593 if (!isInteriorPoint(roundedInequalityLhs, roundedInequalityRhs, startingPoint)) {
594 throw std::domain_error(
"Starting point outside polytope is always constant.");
599 return addRecordersAndAdapter(
604 BallWalkProposal<Eigen::Matrix<typename MatrixType::Scalar, Eigen::Dynamic, Eigen::Dynamic>,
605 decltype(roundedInequalityRhs)>(
606 roundedInequalityLhs,
607 roundedInequalityRhs,
618 return addRecordersAndAdapter(
624 decltype(roundedInequalityRhs),
626 roundedInequalityLhs,
627 roundedInequalityRhs,
638 return addRecordersAndAdapter(
644 Eigen::Matrix<typename MatrixType::Scalar, Eigen::Dynamic, Eigen::Dynamic>,
645 decltype(roundedInequalityRhs)>(
646 roundedInequalityLhs,
647 roundedInequalityRhs,
659 return addRecordersAndAdapter(
664 HitAndRunProposal<Eigen::Matrix<typename MatrixType::Scalar, Eigen::Dynamic, Eigen::Dynamic>,
665 decltype(roundedInequalityRhs),
667 roundedInequalityLhs,
668 roundedInequalityRhs,
679 throw std::invalid_argument(
"Type not supported.");
699 template<
typename MatrixType,
typename VectorType>
707 const std::shared_ptr<Model>& model,
710 if (!isInteriorPoint(roundedInequalityLhs, roundedInequalityRhs, startingPoint)) {
711 throw std::domain_error(
"Starting point outside polytope is always constant.");
716 return addRecordersAndAdapter(
721 BallWalkProposal<Eigen::Matrix<typename MatrixType::Scalar, Eigen::Dynamic, Eigen::Dynamic>,
722 decltype(roundedInequalityRhs)>(
723 roundedInequalityLhs,
724 roundedInequalityRhs,
732 synchronizedRandomNumberGenerator
736 return addRecordersAndAdapter(
742 decltype(roundedInequalityRhs),
744 roundedInequalityLhs,
745 roundedInequalityRhs,
753 synchronizedRandomNumberGenerator
757 return addRecordersAndAdapter(
763 Eigen::Matrix<typename MatrixType::Scalar, Eigen::Dynamic, Eigen::Dynamic>,
764 decltype(roundedInequalityRhs)>(
765 roundedInequalityLhs,
766 roundedInequalityRhs,
775 synchronizedRandomNumberGenerator
779 return addRecordersAndAdapter(
784 HitAndRunProposal<Eigen::Matrix<typename MatrixType::Scalar, Eigen::Dynamic, Eigen::Dynamic>,
785 decltype(roundedInequalityRhs),
787 roundedInequalityLhs,
788 roundedInequalityRhs,
796 synchronizedRandomNumberGenerator
800 throw std::invalid_argument(
"Type not supported.");
807 template<
typename MatrixType,
typename VectorType>
809 return ((b - A * x).array() >= 0).all();
817 template<
typename MarkovChainImpl>
818 static std::unique_ptr<MarkovChain>
819 addRecordersAndAdapter(
const MarkovChainImpl &markovChainImpl,
821 if constexpr(IsSetColdnessAvailable<MarkovChainImpl>::value) {
822 auto mc = MarkovChainAdapter(
824 AcceptanceRateRecorder(
831 synchronizedRandomNumberGenerator
834 return std::make_unique<decltype(mc)>(mc);
836 throw std::invalid_argument(
"Can not use Parallel Tempering without model.");
845 template<
typename MarkovChainImpl>
846 static std::unique_ptr<MarkovChain>
847 addRecordersAndAdapter(
const MarkovChainImpl &markovChainImpl) {
848 auto mc = MarkovChainAdapter(
849 AcceptanceRateRecorder(
857 return std::make_unique<decltype(mc)>(mc);
862 #endif //HOPS_MARKOVCHAINFACTORY_HPP