28 #ifndef _TOMOGRAPHER_MHRW_H 29 #define _TOMOGRAPHER_MHRW_H 38 #include <type_traits> 40 #include <boost/serialization/serialization.hpp> 45 #include <tomographer/tools/statusprovider.h> 96 template<
typename StepRealType_ =
double>
99 typedef StepRealType_ StepRealType;
104 StepRealType step_size;
107 friend boost::serialization::access;
108 template<
typename Archive>
109 void serialize(Archive & a,
unsigned int )
115 template<
typename StepRealType>
116 inline std::ostream & operator<<(std::ostream & stream, MHWalkerParamsStepSize<StepRealType> p)
118 return stream <<
"step_size=" << p.step_size;
134 template<
typename MHWalkerParams_ = MHWalkerParamsStepSize<
double>,
typename CountIntType_ =
int >
137 typedef MHWalkerParams_ MHWalkerParams;
138 typedef CountIntType_ CountIntType;
144 : mhwalker_params(), n_sweep(0), n_therm(0), n_run(0)
153 template<
typename MHWalkerParamsInit>
155 CountIntType n_sweep_, CountIntType n_therm_, CountIntType n_run_)
156 : mhwalker_params(
std::forward<MHWalkerParamsInit>(mhwalker_params_)),
157 n_sweep(n_sweep_), n_therm(n_therm_), n_run(n_run_)
163 template<
typename MHWalkerParamsOtherType,
typename CountIntOtherType>
165 : mhwalker_params(copy.mhwalker_params),
166 n_sweep(copy.n_sweep), n_therm(copy.n_therm), n_run(copy.n_run)
187 friend boost::serialization::access;
188 template<
typename Archive,
191 typename MHWalkerParams2 = MHWalkerParams>
192 void serialize(Archive & a,
unsigned int )
194 MHWalkerParams2 & mhwalker_params_ref = mhwalker_params;
195 a & mhwalker_params_ref;
204 template<
typename CountIntType,
typename MHWalkerParams>
205 inline std::ostream & operator<<(std::ostream & str, const MHRWParams<MHWalkerParams,CountIntType> & p)
207 str <<
"MHRWParams(" << p.mhwalker_params <<
";n_sweep=" << p.n_sweep
208 <<
",n_therm=" << p.n_therm <<
",n_run=" << p.n_run <<
")";
273 template<
typename MHRWControllerType_>
276 typedef MHRWControllerType_ MHRWControllerType;
277 enum { AdjustmentStrategy = MHRWControllerType::AdjustmentStrategy };
280 constexpr
static bool _enabled_callback(
bool IsThermalizing,
bool IsAfterSample)
293 template<
typename... Args>
294 static inline void invokeInit(MHRWControllerType & x, Args && ... args) {
295 x.init(std::forward<Args>(args)...) ;
298 template<
typename MHRWParamsType,
typename MHWalker,
typename CountIntType,
typename MHRandomWalkType>
299 static inline bool invokeAllowDoneThermalization(MHRWControllerType & x,
300 const MHRWParamsType & params,
301 const MHWalker & mhwalker,
303 const MHRandomWalkType & mhrw)
305 return x.allowDoneThermalization(params, mhwalker, iter_k, mhrw);
308 template<
typename MHRWParamsType,
typename MHWalker,
typename CountIntType,
typename MHRandomWalkType>
309 static inline bool invokeAllowDoneRuns(MHRWControllerType & x,
310 const MHRWParamsType & params,
311 const MHWalker & mhwalker,
313 const MHRandomWalkType & mhrw)
315 return x.allowDoneRuns(params, mhwalker, iter_k, mhrw);
319 template<
bool IsThermalizing,
bool IsAfterSample,
typename ... Args>
322 invokeAdjustParams(MHRWControllerType & x, Args && ... args)
324 x.template adjustParams<IsThermalizing, IsAfterSample>(std::forward<Args>(args)...);
326 template<
bool IsThermalizing,
bool IsAfterSample,
typename ... Args>
329 invokeAdjustParams(MHRWControllerType & , Args && ... )
339 namespace tomo_internal {
341 template<
unsigned int AdjustmentStrategy,
unsigned int OtherAdjustmentStrategy>
342 struct controller_flags_compatible {
343 static constexpr
bool value =
349 template<
bool RestOk,
unsigned int ProcessedAdjustmentStrategyFlags,
350 typename... MHRWControllerTypes>
351 struct controllers_compatible_helper;
353 template<
bool RestOk,
unsigned int ProcessedAdjustmentStrategyFlags,
typename MHRWControllerAType,
354 typename... MHRWControllerRestTypes>
355 struct controllers_compatible_helper<RestOk, ProcessedAdjustmentStrategyFlags, MHRWControllerAType,
356 MHRWControllerRestTypes...>
357 : controllers_compatible_helper<
358 RestOk && controller_flags_compatible<MHRWControllerAType::AdjustmentStrategy,
359 ProcessedAdjustmentStrategyFlags>::value ,
360 ProcessedAdjustmentStrategyFlags | MHRWControllerAType::AdjustmentStrategy,
361 MHRWControllerRestTypes...
364 template<
bool RestOk,
unsigned int ProcessedAdjustmentStrategyFlags>
365 struct controllers_compatible_helper<RestOk, ProcessedAdjustmentStrategyFlags> {
366 static constexpr
bool value = RestOk;
367 static constexpr
unsigned int CombinedAdjustmentStrategy = ProcessedAdjustmentStrategyFlags;
371 template<
typename... MHRWControllerTypes>
372 struct controllers_compatible : controllers_compatible_helper<true, 0, MHRWControllerTypes...> { };
397 template<
typename ... MHRWControllerTypes>
405 static constexpr
int NumControllers =
sizeof...(MHRWControllerTypes) ;
415 tomo_internal::controllers_compatible<MHRWControllerTypes...>::CombinedAdjustmentStrategy
420 : controllers(controllers_...)
426 inline const typename std::tuple_element<I, TupleRefType>::type getController()
const 428 return std::get<I>(controllers) ;
432 template<
typename MHRWParamsType,
typename MHWalker,
typename MHRandomWalkType,
433 int I = 0, TOMOGRAPHER_ENABLED_IF_TMPL(I < NumControllers)>
434 inline void init(MHRWParamsType & params,
const MHWalker & mhwalker,
435 const MHRandomWalkType & mhrw)
437 std::get<I>(controllers).init(params, mhwalker, mhrw);
438 init<MHRWParamsType, MHWalker, MHRandomWalkType, I+1>(params, mhwalker, mhrw);
440 template<
typename MHRWParamsType,
typename MHWalker,
typename MHRandomWalkType,
441 int I = 0, TOMOGRAPHER_ENABLED_IF_TMPL(I == NumControllers)>
442 inline void init(
const MHRWParamsType &,
const MHWalker &,
const MHRandomWalkType &)
const 446 template<
typename MHRWParamsType,
typename MHWalker,
typename MHRandomWalkType,
447 int I = 0, TOMOGRAPHER_ENABLED_IF_TMPL(I < NumControllers)>
448 inline void thermalizingDone(MHRWParamsType & params,
const MHWalker & mhwalker,
449 const MHRandomWalkType & mhrw)
451 std::get<I>(controllers).thermalizingDone(params, mhwalker, mhrw);
452 thermalizingDone<MHRWParamsType, MHWalker, MHRandomWalkType, I+1>(params, mhwalker, mhrw);
454 template<
typename MHRWParamsType,
typename MHWalker,
typename MHRandomWalkType,
455 int I = 0, TOMOGRAPHER_ENABLED_IF_TMPL(I == NumControllers)>
456 inline void thermalizingDone(
const MHRWParamsType & ,
const MHWalker & ,
457 const MHRandomWalkType & )
const 461 template<
typename MHRWParamsType,
typename MHWalker,
typename MHRandomWalkType,
462 int I = 0, TOMOGRAPHER_ENABLED_IF_TMPL(I < NumControllers)>
463 inline void done(MHRWParamsType & params,
const MHWalker & mhwalker,
464 const MHRandomWalkType & mhrw)
466 std::get<I>(controllers).done(params, mhwalker, mhrw);
467 done<MHRWParamsType, MHWalker, MHRandomWalkType, I+1>(params, mhwalker, mhrw);
469 template<
typename MHRWParamsType,
typename MHWalker,
typename MHRandomWalkType,
470 int I = 0, TOMOGRAPHER_ENABLED_IF_TMPL(I == NumControllers)>
471 inline void done(
const MHRWParamsType & ,
const MHWalker & ,
472 const MHRandomWalkType & )
const 476 template<
bool IsThermalizing,
bool IsAfterSample,
477 typename MHRWParamsType,
typename CountIntType,
478 typename MHWalker,
typename MHRandomWalkType,
479 int I = 0, TOMOGRAPHER_ENABLED_IF_TMPL(I < NumControllers)>
480 inline void adjustParams(MHRWParamsType & params,
const MHWalker & mhwalker,
481 CountIntType iter_k,
const MHRandomWalkType & mhrw)
486 ::template invokeAdjustParams<IsThermalizing,IsAfterSample>(
487 std::get<I>(controllers), params, mhwalker, iter_k, mhrw
489 adjustParams<IsThermalizing,IsAfterSample,MHRWParamsType,CountIntType,MHWalker,MHRandomWalkType,I+1>(
490 params, mhwalker, iter_k, mhrw
493 template<
bool IsThermalizing,
bool IsAfterSample,
494 typename MHRWParamsType,
typename CountIntType,
495 typename MHWalker,
typename MHRandomWalkType,
496 int I = 0, TOMOGRAPHER_ENABLED_IF_TMPL(I == NumControllers)>
497 inline void adjustParams(
const MHRWParamsType &,
const MHWalker &,
498 CountIntType ,
const MHRandomWalkType &)
const 502 template<
typename MHRWParamsType,
typename MHWalker,
typename CountIntType,
typename MHRandomWalkType,
503 int I = 0, TOMOGRAPHER_ENABLED_IF_TMPL(I < NumControllers)>
504 inline bool allowDoneThermalization(
const MHRWParamsType & params,
const MHWalker & mhwalker,
505 CountIntType iter_k,
const MHRandomWalkType & mhrw)
507 return std::get<I>(controllers).allowDoneThermalization(params, mhwalker, iter_k, mhrw) &&
508 allowDoneThermalization<MHRWParamsType,MHWalker,CountIntType,MHRandomWalkType,I+1>(
509 params, mhwalker, iter_k, mhrw
512 template<
typename MHRWParamsType,
typename MHWalker,
typename CountIntType,
typename MHRandomWalkType,
513 int I = 0, TOMOGRAPHER_ENABLED_IF_TMPL(I == NumControllers)>
514 inline bool allowDoneThermalization(
const MHRWParamsType & ,
const MHWalker & ,
515 CountIntType ,
const MHRandomWalkType & )
const 520 template<
typename MHRWParamsType,
typename MHWalker,
typename CountIntType,
typename MHRandomWalkType,
521 int I = 0, TOMOGRAPHER_ENABLED_IF_TMPL(I < NumControllers)>
522 inline bool allowDoneRuns(
const MHRWParamsType & params,
const MHWalker & mhwalker,
523 CountIntType iter_k,
const MHRandomWalkType & mhrw)
525 return std::get<I>(controllers).allowDoneRuns(params, mhwalker, iter_k, mhrw) &&
526 allowDoneRuns<MHRWParamsType,MHWalker,CountIntType,MHRandomWalkType,I+1>(
527 params, mhwalker, iter_k, mhrw
530 template<
typename MHRWParamsType,
typename MHWalker,
typename CountIntType,
typename MHRandomWalkType,
531 int I = 0, TOMOGRAPHER_ENABLED_IF_TMPL(I == NumControllers)>
532 inline bool allowDoneRuns(
const MHRWParamsType & ,
const MHWalker & ,
533 CountIntType ,
const MHRandomWalkType & )
const 538 template<
typename ... MHRWControllerTypes>
547 template<
typename... MHRWControllerTypes>
570 namespace tomo_internal {
573 template<
typename T,
bool use_const>
574 struct const_type_helper {
578 struct const_type_helper<T, true> {
579 typedef const T type;
582 template<
typename MHWalker,
bool has_FnValueType>
583 struct helper_FnValueType_or_dummy {
584 typedef typename MHWalker::FnValueType type;
586 template<
typename MHWalker>
587 struct helper_FnValueType_or_dummy<MHWalker,false> {
639 template<
typename Rng_,
typename MHWalker_,
typename MHRWStatsCollector_,
642 typename CountIntType_ =
int>
669 enum { MHRWControllerStrategy = MHRWController::AdjustmentStrategy };
675 #ifndef TOMOGRAPHER_PARSED_BY_DOXYGEN 676 typedef typename tomo_internal::helper_FnValueType_or_dummy<
685 UseFnSyntaxType = MHWalker::UseFnSyntaxType
691 typename tomo_internal::const_type_helper<
697 MHWalker & _mhwalker;
698 MHRWStatsCollector & _stats;
699 MHRWController & _mhrw_controller;
708 FnValueType curptval;
714 CountIntType num_accepted;
718 CountIntType num_live_points;
724 MHRandomWalk(MHWalkerParams mhwalker_params, CountIntType n_sweep, CountIntType n_therm, CountIntType n_run,
725 MHWalker & mhwalker, MHRWStatsCollector & stats, MHRWController & mhrw_controller,
726 Rng & rng, LoggerType & logger_)
727 : _n(mhwalker_params, n_sweep, n_therm, n_run),
731 _mhrw_controller(mhrw_controller),
739 stream <<
"constructor(). n_sweep=" << n_sweep <<
", mhwalker_params=" << mhwalker_params
740 <<
"n_therm=" << n_therm <<
", n_run=" << n_run;
744 template<
typename MHRWParamsTypeInit>
746 MHWalker & mhwalker, MHRWStatsCollector & stats, MHRWController & mhrw_controller,
747 Rng & rng, LoggerType & logger_)
748 : _n(
std::forward<MHRWParamsTypeInit>(n_rw)),
752 _mhrw_controller(mhrw_controller),
759 _logger.
debug([&](
std::ostream & s) { s <<
"constructor(). mhrw parameters = " << _n; });
769 inline const MHRWController &
mhrwController()
const {
return _mhrw_controller; }
779 inline CountIntType
nSweep()
const {
return _n.n_sweep; }
781 inline CountIntType
nTherm()
const {
return _n.n_therm; }
783 inline CountIntType
nRun()
const {
return _n.n_run; }
791 return (num_live_points > 0);
795 template<
typename RatioType =
double>
798 return RatioType(num_accepted) / RatioType(num_live_points);
831 curptval = _get_ptval(curpt);
833 s <<
"setCurrentPoint: set internal state. Value = " << curptval <<
"; Point =\n" << pt <<
"\n";
848 curpt = _mhwalker.startPoint();
849 curptval = _get_ptval(curpt);
854 _mhrw_controller.init(_n, _mhwalker, *
this);
860 inline void _thermalizing_done()
862 _mhwalker.thermalizingDone();
863 _stats.thermalizingDone();
865 _mhrw_controller.thermalizingDone(_n, _mhwalker, *
this);
867 _logger.
longdebug(
"_thermalizing_done() done.");
876 _mhrw_controller.done(_n, _mhwalker, *
this);
888 template<
bool IsThermalizing>
889 inline void _move(CountIntType k,
bool is_live_iter)
896 const PointType newpt = _mhwalker.jumpFn(curpt, _n.mhwalker_params);
898 const FnValueType newptval = _get_ptval(newpt);
900 const double a = _get_a_value(newpt, newptval, curpt, curptval);
903 bool accept = ( a >= 1.0 ?
true : bool( _rng()-_rng.min() <= a*(_rng.max()-_rng.min()) ) ) ;
906 if (!IsThermalizing) {
907 num_accepted += accept ? 1 : 0;
911 _stats.rawMove(k, IsThermalizing, is_live_iter, accept, a, newpt, newptval, curpt, curptval, *
this);
914 stream << (IsThermalizing?
"T":
"#") <<
std::setw(3) << k <<
": " << (accept?
"AC":
"RJ") <<
" " 917 <<
", curptval=" <<
std::setw(5) << curptval <<
", accept_ratio=" 934 inline void _process_sample(CountIntType k, CountIntType n)
936 _stats.processSample(k, n, curpt, curptval, *
this);
937 _logger.
longdebug(
"_process_sample() done.");
946 #ifdef TOMOGRAPHER_PARSED_BY_DOXYGEN 953 inline FnValueType _get_ptval(PointType curpt)
const { }
967 inline double _get_a_value(PointType newpt, FnValueType newptval,
968 PointType curpt, FnValueType curptval)
const { }
973 template<
typename PtType, TOMOGRAPHER_ENABLED_IF_TMPL(UseFnSyntaxType == MHUseFnValue)>
974 inline FnValueType _get_ptval(PtType && curpt)
const 976 return _mhwalker.fnVal(curpt);
978 template<
typename PtType1,
typename PtType2, TOMOGRAPHER_ENABLED_IF_TMPL(UseFnSyntaxType == MHUseFnValue)>
979 inline double _get_a_value(PtType1 && , FnValueType newptval,
980 PtType2 && , FnValueType curptval)
const 982 return ((
double)newptval) / curptval;
986 template<
typename PtType, TOMOGRAPHER_ENABLED_IF_TMPL(UseFnSyntaxType == MHUseFnLogValue)>
987 inline FnValueType _get_ptval(PtType && curpt)
const 989 return _mhwalker.fnLogVal(curpt);
991 template<
typename PtType1,
typename PtType2, TOMOGRAPHER_ENABLED_IF_TMPL(UseFnSyntaxType == MHUseFnLogValue)>
992 inline double _get_a_value(PtType1 && , FnValueType newptval,
993 PtType2 && , FnValueType curptval)
const 996 return (newptval > curptval) ? 1.0 :
exp(
double(newptval - curptval));
1000 template<
typename PtType, TOMOGRAPHER_ENABLED_IF_TMPL(UseFnSyntaxType == MHUseFnRelativeValue)>
1001 inline FnValueType _get_ptval(PtType && )
const 1005 template<
typename PtType1,
typename PtType2, TOMOGRAPHER_ENABLED_IF_TMPL(UseFnSyntaxType == MHUseFnRelativeValue)>
1006 inline double _get_a_value(PtType1 && newpt, FnValueType ,
1007 PtType2 && curpt, FnValueType )
const 1009 using namespace std;
1010 return _mhwalker.fnRelVal(std::forward<PtType1>(newpt), std::forward<PtType2>(curpt));
1017 template<
bool IsThermalizing>
1018 inline void _controller_adjust_afteriter(CountIntType iter_k)
1020 MHRWControllerInvokerType::template invokeAdjustParams<IsThermalizing, false>(
1021 _mhrw_controller, _n, _mhwalker, iter_k, *this
1024 inline void _controller_adjust_aftersample(CountIntType iter_k)
1026 MHRWControllerInvokerType::template invokeAdjustParams<false, true>(
1027 _mhrw_controller, _n, _mhwalker, iter_k, *this
1030 inline bool _controller_allow_therm_done(CountIntType iter_k)
1032 return (iter_k % _n.n_sweep == 0) &&
1033 MHRWControllerInvokerType::template invokeAllowDoneThermalization(
1034 _mhrw_controller, _n, _mhwalker, iter_k, *
this 1037 inline bool _controller_allow_runs_done(CountIntType iter_k)
1039 return (iter_k % _n.n_sweep == 0) &&
1040 MHRWControllerInvokerType::template invokeAllowDoneRuns(
1041 _mhrw_controller, _n, _mhwalker, iter_k, *
this 1061 "Error: integer type " << boost::core::demangle(
typeid(CountIntType).name())
1062 <<
" cannot be used to represent number of iterations, will overflow with given params " 1075 s <<
"Starting random walk, parameters are = " << _n;
1081 for ( k = 0 ; (k < (_n.n_sweep * _n.n_therm)) || !_controller_allow_therm_done(k) ; ++k ) {
1082 _move<true>(k,
false);
1083 _controller_adjust_afteriter<true>(k);
1086 _thermalizing_done();
1088 _logger.
longdebug(
"Thermalizing done, starting live runs.");
1095 for (k = 0 ; (k < (_n.n_sweep * _n.n_run)) || !_controller_allow_runs_done(k) ; ++k) {
1097 bool is_live_iter = ((k+1) % _n.n_sweep == 0);
1100 _move<false>(k, is_live_iter);
1101 _controller_adjust_afteriter<false>(k);
1104 _process_sample(k, n);
1106 _controller_adjust_aftersample(k);
1113 _logger.
longdebug(
"Random walk completed.");
1141 template<
typename MHRWParamsType>
1144 typedef typename MHRWParamsType::CountIntType IterCountIntType;
1148 IterCountIntType kstep_ = 0, MHRWParamsType mhrw_params_ = MHRWParamsType(),
1149 double acceptance_ratio_ = 0.0)
1150 : MultiProc::TaskStatusReport(fdone, msg),
1152 mhrw_params(mhrw_params_),
1153 acceptance_ratio(acceptance_ratio_),
1154 n_total_iters(mhrw_params.n_sweep*(mhrw_params.n_therm + mhrw_params.n_run))
1184 template<
typename MHRandomWalkType,
typename MHRWStatsCollectorType,
typename MHRWControllerType>
1186 createFromRandWalkStatInfo(IterCountIntType k,
bool is_thermalizing,
1187 const MHRandomWalkType & rw,
1188 const MHRWStatsCollectorType & stats_collector,
1189 const MHRWControllerType & mhrw_controller) {
1191 IterCountIntType totiters = rw.nSweep()*(rw.nTherm()+rw.nRun());
1193 IterCountIntType kreal = is_thermalizing ? k : k + rw.nSweep()*rw.nTherm();
1194 double fdone = ( is_thermalizing ? (double)k : (
double)k + rw.nSweep()*rw.nTherm() ) / (
double)totiters;
1196 bool warn_accept_ratio =
false;
1198 if (rw.hasAcceptanceRatio()) {
1199 accept_ratio = rw.acceptanceRatio();
1200 warn_accept_ratio = (accept_ratio > MHRWAcceptanceRatioRecommendedMax ||
1202 accept_ratio_msg =
std::string(
" [") + (warn_accept_ratio ?
"!!** " :
"") +
1204 (warn_accept_ratio ?
" **!!" :
"") +
"]";
1215 if (is_thermalizing) {
1216 msgstr <<
"therm. sweep " <<
std::setw(ndigrw) << (k / rw.nSweep()) <<
"/" 1218 <<
" [+rn:" << rw.nRun() <<
"]";
1220 msgstr <<
"run sweep " <<
std::setw(ndigrw) << (k / rw.nSweep()) <<
"/" 1222 <<
" [+th:" << rw.nTherm() <<
"]";
1224 msgstr <<
" : " <<
Tools::fmts(
"%5.2f", fdone*100.0) <<
"% done";
1225 if (accept_ratio_msg.
size()) {
1226 msgstr << accept_ratio_msg;
1282 template<
typename... Args>
1288 static constexpr
int NumControllers = MHRWControllerType::NumControllers;
1290 static constexpr
bool CanProvideStatusLine =
true;
1292 template<int I = 0, typename std::enable_if<(I < NumControllers), bool>::type dummy =
true>
1295 typedef typename std::tuple_element<I, typename MHRWControllerType::TupleType>::type
1301 getStatusLine<I+1>(ctrl) );
1304 template<int I = 0, typename std::enable_if<(I == NumControllers), bool>::type dummy =
true>
1319 template<
typename... Args>
1321 template<
typename... Args>
A Metropolis-Hastings Random Walk.
Utilities for formatting strings.
MHRWMultipleControllers MHRWNoController
A MHRWController Interface which does not adjust anything.
MHRWMultipleControllers< MHRWControllerTypes... > mkMHRWMultipleControllers(MHRWControllerTypes &... controllers)
Convenience function to create a MHRWMultipleControllers (using template argument deduction) ...
Mask out bits which decide at which random walk stage (thermalizing and/or running) adjustments are p...
Adjustments are enabled during both thermalization and live (running) sweeps.
IterCountIntType kstep
the current iteration number
MHRWParams(MHWalkerParamsInit &&mhwalker_params_, CountIntType n_sweep_, CountIntType n_therm_, CountIntType n_run_)
standard constructor – initializes fields to given values
const MHRWStatsCollector & statsCollector() const
Access the stats collector.
Adjustemnts should be performed after each individual iteration.
double acceptance_ratio
the current acceptance ratio of the random walk (see Tomographer::MHRandomWalk::acceptanceRatio() ) ...
Base namespace for the Tomographer project.
MHRWStatusReport(double fdone=0.0, const std::string &msg=std::string(), IterCountIntType kstep_=0, MHRWParamsType mhrw_params_=MHRWParamsType(), double acceptance_ratio_=0.0)
Constructor which initializes all fields.
CountIntType nTherm() const
Number of thermalizing sweeps.
CountIntType_ CountIntType
The type used for counting numbers of iterations (see, e.g. nSweep() or MHRWParams) ...
void error(const char *fmt,...)
Generate a log message with level Logger::ERROR (printf-like syntax)
MHWalker::PointType PointType
The type of a point in the random walk.
Adjustments are enabled during thermalization sweeps.
An MHWalkerParams type which just stores a step size.
const FnValueType & getCurrentPointValue() const
Access the current function value of the random walk.
CountIntType n_run
Number of live sweeps.
Logger that discards all messages.
constexpr const double MHRWAcceptanceRatioRecommendedMax
Maximal recommended acceptance ratio.
MHRWStatsCollector_ MHRWStatsCollector
The stats collector type (see MHRWStatsCollector Interface)
MHWalker::WalkerParams MHWalkerParams
The parameters type of the MHWalker implememtation, typically just a double storing the step size of ...
MHWalker_ MHWalker
The random walker type which knows about the state space and jump function.
CountIntType n_therm
Number of thermalization sweeps.
MHRandomWalk(MHWalkerParams mhwalker_params, CountIntType n_sweep, CountIntType n_therm, CountIntType n_run, MHWalker &mhwalker, MHRWStatsCollector &stats, MHRWController &mhrw_controller, Rng &rng, LoggerType &logger_)
Simple constructor, initializes the given fields.
constexpr const double MHRWAcceptanceRatioRecommendedMin
Minimal recommended acceptance ratio.
#define TOMO_ORIGIN
Use this as argument for a Tomographer::Logger::LocalLogger constructor .
MHRandomWalk(MHRWParamsTypeInit &&n_rw, MHWalker &mhwalker, MHRWStatsCollector &stats, MHRWController &mhrw_controller, Rng &rng, LoggerType &logger_)
Simple constructor, initializes the given fields.
const MHRWController & mhrwController() const
Access the random walk controller.
Adjustemnts should be performed only while thermalizing, after each individual iteration.
MHWalkerParams mhWalkerParams() const
Get the MHWalker parameters.
void debug(const char *fmt,...)
Generate a log message with level Logger::DEBUG (printf-like syntax)
IterCountIntType n_total_iters
the total number of iterations required for this random walk
Provides the logarithm MH function value at each point (see Role of UseFnSyntaxType) ...
CountIntType n_sweep
The number of individual updates to collect together in a "sweep".
#define TOMO_STATIC_ASSERT_EXPR(...)
Tool for static assertions without message.
MHRWParamsType mhrwParams() const
The parameters of the random walk.
Never adjust the parameters of the random walk.
MHRWParams(const MHRWParams< MHWalkerParamsOtherType, CountIntOtherType > ©)
copy constructor
MHRWController_ MHRWController
The type which will take care of dynamically adjusting the parameters of the random walk...
MHRWControllerAdjustmentStrategy
Describe how frequently the parameters of the random walk should be dynamically adjusted.
Provides the MH function value at each point (see Role of UseFnSyntaxType)
MHRWControllerInvoker< MHRWController > MHRWControllerInvokerType
The MHRWControllerInvoker for our random walk controller, for convenience.
Mask out bits which decide at which frequency (after each iteration and/or after each sample) adjustm...
A MHRWController Interface which combines several independent random walk controllers.
bool hasAcceptanceRatio() const
Query whether we have any statistics about acceptance ratio. This is false, for example, during the thermalizing runs.
_FnValueType FnValueType
The type of the Metropolis-Hastings function value. (See class documentation)
Some C++ utilities, with a tad of C++11 tricks.
Basic status report class.
void setCurrentPoint(const PointType &pt)
Force manual state of random walk.
CountIntType nRun() const
Number of live run sweeps.
CountIntType nSweep() const
Number of iterations in a sweep.
void longdebug(const char *fmt,...)
Generate a log message with level Logger::LONGDEBUG (printf-like syntax)
Managing the need for specific overrides to operator new() for some types (especially Eigen types) ...
Status Report structure representing the status of a MHRandomWalk.
const PointType & getCurrentPoint() const
Access the current state of the random walk.
Some common definitions for multiprocessing interfaces.
Specify the parameters of a Metropolis-Hastings random walk.
LoggerType_ LoggerType
The logger type which will be provided by user to constructor (see Logging and Loggers) ...
Adjustemnts should be performed after a sample is taken (during live runs only)
void run()
Run the random walk. (pun intended)
MHRWParams< MHWalkerParams, CountIntType > MHRWParamsType
The struct which can hold the parameters of this random walk.
Adjustments are enabled during live (running) sweeps.
VarValueDecoder< T >::RetType value(const Var &var)
Access the value of the given variable, as a C++ type.
Adjustemnts should be performed all the time, after each individual iteration.
Provides directly the ratio of the function values for two consecutive points of the MH random walk (...
RatioType acceptanceRatio() const
Return the acceptance ratio so far.
#define streamstr(tokens)
Utility macro to format stream tokens to a std::string.
Helper class to invoke a MHRWController Interface 's callbacks.
T setprecision(T... args)
MHRWParams()
default constructor – sets values to zero and default-initializes the mhwalker_params ...
Rng_ Rng
Random number generator type (see C++ std::random)
MHRWParamsType mhrw_params
the parameters of the random walk
Binning Analysis in a Metropolis-Hastings random walk.
MHWalkerParams mhwalker_params
The parameters of the mh-walker, typically just the step size of the random walk. ...
Utilities for logging messages.