28 #ifndef _TOMOGRAPHER_MHRW_H 29 #define _TOMOGRAPHER_MHRW_H 36 #include <type_traits> 41 #include <tomographer/tools/statusprovider.h> 92 template<
typename StepRealType_ =
double>
95 typedef StepRealType_ StepRealType;
100 StepRealType step_size;
103 template<
typename StepRealType>
104 inline std::ostream & operator<<(std::ostream & stream, MHWalkerParamsStepSize<StepRealType> p)
106 return stream <<
"step_size=" << p.step_size;
119 template<
typename MHWalkerParams_ = MHWalkerParamsStepSize<
double>,
typename CountIntType_ =
int >
122 typedef MHWalkerParams_ MHWalkerParams;
123 typedef CountIntType_ CountIntType;
126 : mhwalker_params(), n_sweep(0), n_therm(0), n_run(0)
129 template<
typename MHWalkerParamsInit>
130 MHRWParams(MHWalkerParamsInit && mhwalker_params_,
131 CountIntType n_sweep_, CountIntType n_therm_, CountIntType n_run_)
132 : mhwalker_params(std::forward<MHWalkerParamsInit>(mhwalker_params_)),
133 n_sweep(n_sweep_), n_therm(n_therm_), n_run(n_run_)
137 template<
typename MHWalkerParamsOtherType,
typename CountIntOtherType>
163 template<
typename CountIntType,
typename MHWalkerParams>
164 inline std::ostream & operator<<(std::ostream & str, const MHRWParams<MHWalkerParams,CountIntType> & p)
166 str <<
"MHRWParams(" << p.mhwalker_params <<
";n_sweep=" << p.n_sweep
167 <<
",n_therm=" << p.n_therm <<
",n_run=" << p.n_run <<
")";
232 template<
typename MHRWControllerType_>
235 typedef MHRWControllerType_ MHRWControllerType;
236 enum { AdjustmentStrategy = MHRWControllerType::AdjustmentStrategy };
239 constexpr
static bool _enabled_callback(
bool IsThermalizing,
bool IsAfterSample)
252 template<
typename... Args>
253 static inline void invokeInit(MHRWControllerType & x, Args && ... args) {
254 x.init(std::forward<Args>(args)...) ;
257 template<
typename MHRWParamsType,
typename MHWalker,
typename CountIntType,
typename MHRandomWalkType>
258 static inline bool invokeAllowDoneThermalization(MHRWControllerType & x,
259 const MHRWParamsType & params,
260 const MHWalker & mhwalker,
262 const MHRandomWalkType & mhrw)
264 return x.allowDoneThermalization(params, mhwalker, iter_k, mhrw);
267 template<
typename MHRWParamsType,
typename MHWalker,
typename CountIntType,
typename MHRandomWalkType>
268 static inline bool invokeAllowDoneRuns(MHRWControllerType & x,
269 const MHRWParamsType & params,
270 const MHWalker & mhwalker,
272 const MHRandomWalkType & mhrw)
274 return x.allowDoneRuns(params, mhwalker, iter_k, mhrw);
278 template<
bool IsThermalizing,
bool IsAfterSample,
typename ... Args>
281 invokeAdjustParams(MHRWControllerType & x, Args && ... args)
283 x.template adjustParams<IsThermalizing, IsAfterSample>(std::forward<Args>(args)...);
285 template<
bool IsThermalizing,
bool IsAfterSample,
typename ... Args>
288 invokeAdjustParams(MHRWControllerType & , Args && ... )
298 namespace tomo_internal {
300 template<
unsigned int AdjustmentStrategy,
unsigned int OtherAdjustmentStrategy>
301 struct controller_flags_compatible {
302 static constexpr
bool value =
308 template<
bool RestOk,
unsigned int ProcessedAdjustmentStrategyFlags,
309 typename... MHRWControllerTypes>
310 struct controllers_compatible_helper;
312 template<
bool RestOk,
unsigned int ProcessedAdjustmentStrategyFlags,
typename MHRWControllerAType,
313 typename... MHRWControllerRestTypes>
314 struct controllers_compatible_helper<RestOk, ProcessedAdjustmentStrategyFlags, MHRWControllerAType,
315 MHRWControllerRestTypes...>
316 : controllers_compatible_helper<
317 RestOk && controller_flags_compatible<MHRWControllerAType::AdjustmentStrategy,
318 ProcessedAdjustmentStrategyFlags>::value ,
319 ProcessedAdjustmentStrategyFlags | MHRWControllerAType::AdjustmentStrategy,
320 MHRWControllerRestTypes...
323 template<
bool RestOk,
unsigned int ProcessedAdjustmentStrategyFlags>
324 struct controllers_compatible_helper<RestOk, ProcessedAdjustmentStrategyFlags> {
325 static constexpr
bool value = RestOk;
326 static constexpr
unsigned int CombinedAdjustmentStrategy = ProcessedAdjustmentStrategyFlags;
330 template<
typename... MHRWControllerTypes>
331 struct controllers_compatible : controllers_compatible_helper<true, 0, MHRWControllerTypes...> { };
356 template<
typename ... MHRWControllerTypes>
364 static constexpr
int NumControllers =
sizeof...(MHRWControllerTypes) ;
374 tomo_internal::controllers_compatible<MHRWControllerTypes...>::CombinedAdjustmentStrategy
379 : controllers(controllers_...)
385 inline const typename std::tuple_element<I, TupleRefType>::type getController()
const 387 return std::get<I>(controllers) ;
391 template<
typename MHRWParamsType,
typename MHWalker,
typename MHRandomWalkType,
392 int I = 0, TOMOGRAPHER_ENABLED_IF_TMPL(I < NumControllers)>
393 inline void init(MHRWParamsType & params,
const MHWalker & mhwalker,
394 const MHRandomWalkType & mhrw)
396 std::get<I>(controllers).init(params, mhwalker, mhrw);
397 init<MHRWParamsType, MHWalker, MHRandomWalkType, I+1>(params, mhwalker, mhrw);
399 template<
typename MHRWParamsType,
typename MHWalker,
typename MHRandomWalkType,
400 int I = 0, TOMOGRAPHER_ENABLED_IF_TMPL(I == NumControllers)>
401 inline void init(
const MHRWParamsType &,
const MHWalker &,
const MHRandomWalkType &)
const 405 template<
typename MHRWParamsType,
typename MHWalker,
typename MHRandomWalkType,
406 int I = 0, TOMOGRAPHER_ENABLED_IF_TMPL(I < NumControllers)>
407 inline void thermalizingDone(MHRWParamsType & params,
const MHWalker & mhwalker,
408 const MHRandomWalkType & mhrw)
410 std::get<I>(controllers).thermalizingDone(params, mhwalker, mhrw);
411 thermalizingDone<MHRWParamsType, MHWalker, MHRandomWalkType, I+1>(params, mhwalker, mhrw);
413 template<
typename MHRWParamsType,
typename MHWalker,
typename MHRandomWalkType,
414 int I = 0, TOMOGRAPHER_ENABLED_IF_TMPL(I == NumControllers)>
415 inline void thermalizingDone(
const MHRWParamsType & ,
const MHWalker & ,
416 const MHRandomWalkType & )
const 420 template<
typename MHRWParamsType,
typename MHWalker,
typename MHRandomWalkType,
421 int I = 0, TOMOGRAPHER_ENABLED_IF_TMPL(I < NumControllers)>
422 inline void done(MHRWParamsType & params,
const MHWalker & mhwalker,
423 const MHRandomWalkType & mhrw)
425 std::get<I>(controllers).done(params, mhwalker, mhrw);
426 done<MHRWParamsType, MHWalker, MHRandomWalkType, I+1>(params, mhwalker, mhrw);
428 template<
typename MHRWParamsType,
typename MHWalker,
typename MHRandomWalkType,
429 int I = 0, TOMOGRAPHER_ENABLED_IF_TMPL(I == NumControllers)>
430 inline void done(
const MHRWParamsType & ,
const MHWalker & ,
431 const MHRandomWalkType & )
const 435 template<
bool IsThermalizing,
bool IsAfterSample,
436 typename MHRWParamsType,
typename CountIntType,
437 typename MHWalker,
typename MHRandomWalkType,
438 int I = 0, TOMOGRAPHER_ENABLED_IF_TMPL(I < NumControllers)>
439 inline void adjustParams(MHRWParamsType & params,
const MHWalker & mhwalker,
440 CountIntType iter_k,
const MHRandomWalkType & mhrw)
445 ::template invokeAdjustParams<IsThermalizing,IsAfterSample>(
446 std::get<I>(controllers), params, mhwalker, iter_k, mhrw
448 adjustParams<IsThermalizing,IsAfterSample,MHRWParamsType,CountIntType,MHWalker,MHRandomWalkType,I+1>(
449 params, mhwalker, iter_k, mhrw
452 template<
bool IsThermalizing,
bool IsAfterSample,
453 typename MHRWParamsType,
typename CountIntType,
454 typename MHWalker,
typename MHRandomWalkType,
455 int I = 0, TOMOGRAPHER_ENABLED_IF_TMPL(I == NumControllers)>
456 inline void adjustParams(
const MHRWParamsType &,
const MHWalker &,
457 CountIntType ,
const MHRandomWalkType &)
const 461 template<
typename MHRWParamsType,
typename MHWalker,
typename CountIntType,
typename MHRandomWalkType,
462 int I = 0, TOMOGRAPHER_ENABLED_IF_TMPL(I < NumControllers)>
463 inline bool allowDoneThermalization(
const MHRWParamsType & params,
const MHWalker & mhwalker,
464 CountIntType iter_k,
const MHRandomWalkType & mhrw)
466 return std::get<I>(controllers).allowDoneThermalization(params, mhwalker, iter_k, mhrw) &&
467 allowDoneThermalization<MHRWParamsType,MHWalker,CountIntType,MHRandomWalkType,I+1>(
468 params, mhwalker, iter_k, mhrw
471 template<
typename MHRWParamsType,
typename MHWalker,
typename CountIntType,
typename MHRandomWalkType,
472 int I = 0, TOMOGRAPHER_ENABLED_IF_TMPL(I == NumControllers)>
473 inline bool allowDoneThermalization(
const MHRWParamsType & ,
const MHWalker & ,
474 CountIntType ,
const MHRandomWalkType & )
const 479 template<
typename MHRWParamsType,
typename MHWalker,
typename CountIntType,
typename MHRandomWalkType,
480 int I = 0, TOMOGRAPHER_ENABLED_IF_TMPL(I < NumControllers)>
481 inline bool allowDoneRuns(
const MHRWParamsType & params,
const MHWalker & mhwalker,
482 CountIntType iter_k,
const MHRandomWalkType & mhrw)
484 return std::get<I>(controllers).allowDoneRuns(params, mhwalker, iter_k, mhrw) &&
485 allowDoneRuns<MHRWParamsType,MHWalker,CountIntType,MHRandomWalkType,I+1>(
486 params, mhwalker, iter_k, mhrw
489 template<
typename MHRWParamsType,
typename MHWalker,
typename CountIntType,
typename MHRandomWalkType,
490 int I = 0, TOMOGRAPHER_ENABLED_IF_TMPL(I == NumControllers)>
491 inline bool allowDoneRuns(
const MHRWParamsType & ,
const MHWalker & ,
492 CountIntType ,
const MHRandomWalkType & )
const 497 template<
typename ... MHRWControllerTypes>
506 template<
typename... MHRWControllerTypes>
529 namespace tomo_internal {
532 template<
typename T,
bool use_const>
533 struct const_type_helper {
537 struct const_type_helper<T, true> {
538 typedef const T type;
541 template<
typename MHWalker,
bool has_FnValueType>
542 struct helper_FnValueType_or_dummy {
543 typedef typename MHWalker::FnValueType type;
545 template<
typename MHWalker>
546 struct helper_FnValueType_or_dummy<MHWalker,false> {
598 template<
typename Rng_,
typename MHWalker_,
typename MHRWStatsCollector_,
601 typename CountIntType_ =
int>
628 enum { MHRWControllerStrategy = MHRWController::AdjustmentStrategy };
634 #ifndef TOMOGRAPHER_PARSED_BY_DOXYGEN 635 typedef typename tomo_internal::helper_FnValueType_or_dummy<
644 UseFnSyntaxType = MHWalker::UseFnSyntaxType
650 typename tomo_internal::const_type_helper<
656 MHWalker & _mhwalker;
657 MHRWStatsCollector & _stats;
658 MHRWController & _mhrw_controller;
667 FnValueType curptval;
673 CountIntType num_accepted;
677 CountIntType num_live_points;
683 MHRandomWalk(MHWalkerParams mhwalker_params, CountIntType n_sweep, CountIntType n_therm, CountIntType n_run,
684 MHWalker & mhwalker, MHRWStatsCollector & stats, MHRWController & mhrw_controller,
685 Rng & rng, LoggerType & logger_)
686 : _n(mhwalker_params, n_sweep, n_therm, n_run),
690 _mhrw_controller(mhrw_controller),
698 stream <<
"constructor(). n_sweep=" << n_sweep <<
", mhwalker_params=" << mhwalker_params
699 <<
"n_therm=" << n_therm <<
", n_run=" << n_run;
703 template<
typename MHRWParamsTypeInit>
705 MHWalker & mhwalker, MHRWStatsCollector & stats, MHRWController & mhrw_controller,
706 Rng & rng, LoggerType & logger_)
707 : _n(
std::forward<MHRWParamsTypeInit>(n_rw)),
711 _mhrw_controller(mhrw_controller),
718 _logger.
debug([&](
std::ostream & s) { s <<
"constructor(). mhrw parameters = " << _n; });
728 inline const MHRWController &
mhrwController()
const {
return _mhrw_controller; }
738 inline CountIntType
nSweep()
const {
return _n.n_sweep; }
740 inline CountIntType
nTherm()
const {
return _n.n_therm; }
742 inline CountIntType
nRun()
const {
return _n.n_run; }
750 return (num_live_points > 0);
754 template<
typename RatioType =
double>
757 return RatioType(num_accepted) / RatioType(num_live_points);
790 curptval = _get_ptval(curpt);
792 s <<
"setCurrentPoint: set internal state. Value = " << curptval <<
"; Point =\n" << pt <<
"\n";
807 curpt = _mhwalker.startPoint();
808 curptval = _get_ptval(curpt);
813 _mhrw_controller.init(_n, _mhwalker, *
this);
819 inline void _thermalizing_done()
821 _mhwalker.thermalizingDone();
822 _stats.thermalizingDone();
824 _mhrw_controller.thermalizingDone(_n, _mhwalker, *
this);
826 _logger.
longdebug(
"_thermalizing_done() done.");
835 _mhrw_controller.done(_n, _mhwalker, *
this);
847 template<
bool IsThermalizing>
848 inline void _move(CountIntType k,
bool is_live_iter)
855 const PointType newpt = _mhwalker.jumpFn(curpt, _n.mhwalker_params);
857 const FnValueType newptval = _get_ptval(newpt);
859 const double a = _get_a_value(newpt, newptval, curpt, curptval);
862 bool accept = ( a >= 1.0 ?
true : bool( _rng()-_rng.min() <= a*(_rng.max()-_rng.min()) ) ) ;
865 if (!IsThermalizing) {
866 num_accepted += accept ? 1 : 0;
870 _stats.rawMove(k, IsThermalizing, is_live_iter, accept, a, newpt, newptval, curpt, curptval, *
this);
873 stream << (IsThermalizing?
"T":
"#") <<
std::setw(3) << k <<
": " << (accept?
"AC":
"RJ") <<
" " 876 <<
", curptval=" <<
std::setw(5) << curptval <<
", accept_ratio=" 893 inline void _process_sample(CountIntType k, CountIntType n)
895 _stats.processSample(k, n, curpt, curptval, *
this);
896 _logger.
longdebug(
"_process_sample() done.");
905 #ifdef TOMOGRAPHER_PARSED_BY_DOXYGEN 912 inline FnValueType _get_ptval(PointType curpt)
const { }
926 inline double _get_a_value(PointType newpt, FnValueType newptval,
927 PointType curpt, FnValueType curptval)
const { }
932 template<
typename PtType, TOMOGRAPHER_ENABLED_IF_TMPL(UseFnSyntaxType == MHUseFnValue)>
933 inline FnValueType _get_ptval(PtType && curpt)
const 935 return _mhwalker.fnVal(curpt);
937 template<
typename PtType1,
typename PtType2, TOMOGRAPHER_ENABLED_IF_TMPL(UseFnSyntaxType == MHUseFnValue)>
938 inline double _get_a_value(PtType1 && , FnValueType newptval,
939 PtType2 && , FnValueType curptval)
const 941 return ((
double)newptval) / curptval;
945 template<
typename PtType, TOMOGRAPHER_ENABLED_IF_TMPL(UseFnSyntaxType == MHUseFnLogValue)>
946 inline FnValueType _get_ptval(PtType && curpt)
const 948 return _mhwalker.fnLogVal(curpt);
950 template<
typename PtType1,
typename PtType2, TOMOGRAPHER_ENABLED_IF_TMPL(UseFnSyntaxType == MHUseFnLogValue)>
951 inline double _get_a_value(PtType1 && , FnValueType newptval,
952 PtType2 && , FnValueType curptval)
const 955 return (newptval > curptval) ? 1.0 :
exp(
double(newptval - curptval));
959 template<
typename PtType, TOMOGRAPHER_ENABLED_IF_TMPL(UseFnSyntaxType == MHUseFnRelativeValue)>
960 inline FnValueType _get_ptval(PtType && )
const 964 template<
typename PtType1,
typename PtType2, TOMOGRAPHER_ENABLED_IF_TMPL(UseFnSyntaxType == MHUseFnRelativeValue)>
965 inline double _get_a_value(PtType1 && newpt, FnValueType ,
966 PtType2 && curpt, FnValueType )
const 969 return _mhwalker.fnRelVal(std::forward<PtType1>(newpt), std::forward<PtType2>(curpt));
976 template<
bool IsThermalizing>
977 inline void _controller_adjust_afteriter(CountIntType iter_k)
979 MHRWControllerInvokerType::template invokeAdjustParams<IsThermalizing, false>(
980 _mhrw_controller, _n, _mhwalker, iter_k, *this
983 inline void _controller_adjust_aftersample(CountIntType iter_k)
985 MHRWControllerInvokerType::template invokeAdjustParams<false, true>(
986 _mhrw_controller, _n, _mhwalker, iter_k, *this
989 inline bool _controller_allow_therm_done(CountIntType iter_k)
991 return MHRWControllerInvokerType::template invokeAllowDoneThermalization(
992 _mhrw_controller, _n, _mhwalker, iter_k, *
this 995 inline bool _controller_allow_runs_done(CountIntType iter_k)
997 return MHRWControllerInvokerType::template invokeAllowDoneRuns(
998 _mhrw_controller, _n, _mhwalker, iter_k, *
this 1018 "Error: integer type " << boost::core::demangle(
typeid(CountIntType).name())
1019 <<
" cannot be used to represent number of iterations, will overflow with given params " 1032 s <<
"Starting random walk, parameters are = " << _n;
1038 for ( k = 0 ; (k < (_n.n_sweep * _n.n_therm)) || !_controller_allow_therm_done(k) ; ++k ) {
1039 _move<true>(k,
false);
1040 _controller_adjust_afteriter<true>(k);
1043 _thermalizing_done();
1045 _logger.
longdebug(
"Thermalizing done, starting live runs.");
1052 for (k = 0 ; (k < (_n.n_sweep * _n.n_run)) || !_controller_allow_runs_done(k) ; ++k) {
1054 bool is_live_iter = ((k+1) % _n.n_sweep == 0);
1057 _move<false>(k, is_live_iter);
1058 _controller_adjust_afteriter<false>(k);
1061 _process_sample(k, n);
1063 _controller_adjust_aftersample(k);
1070 _logger.
longdebug(
"Random walk completed.");
1098 template<
typename MHRWParamsType>
1101 typedef typename MHRWParamsType::CountIntType IterCountIntType;
1105 IterCountIntType kstep_ = 0, MHRWParamsType mhrw_params_ = MHRWParamsType(),
1106 double acceptance_ratio_ = 0.0)
1107 : MultiProc::TaskStatusReport(fdone, msg),
1109 mhrw_params(mhrw_params_),
1110 acceptance_ratio(acceptance_ratio_),
1111 n_total_iters(mhrw_params.n_sweep*(mhrw_params.n_therm + mhrw_params.n_run))
1141 template<
typename MHRandomWalkType,
typename MHRWStatsCollectorType,
typename MHRWControllerType>
1143 createFromRandWalkStatInfo(IterCountIntType k,
bool is_thermalizing,
1144 const MHRandomWalkType & rw,
1145 const MHRWStatsCollectorType & stats_collector,
1146 const MHRWControllerType & mhrw_controller) {
1148 IterCountIntType totiters = rw.nSweep()*(rw.nTherm()+rw.nRun());
1150 IterCountIntType kreal = is_thermalizing ? k : k + rw.nSweep()*rw.nTherm();
1151 double fdone = ( is_thermalizing ? (double)k : (
double)k + rw.nSweep()*rw.nTherm() ) / (
double)totiters;
1153 bool warn_accept_ratio =
false;
1155 if (rw.hasAcceptanceRatio()) {
1156 accept_ratio = rw.acceptanceRatio();
1157 warn_accept_ratio = (accept_ratio > MHRWAcceptanceRatioRecommendedMax ||
1159 accept_ratio_msg =
std::string(
" [") + (warn_accept_ratio ?
"!!** " :
"") +
1161 (warn_accept_ratio ?
" **!!" :
"") +
"]";
1168 if (is_thermalizing) {
1175 msg +=
" : " +
Tools::fmts(
"%5.2f", fdone*100.0) +
"% done";
1176 if (accept_ratio_msg.
size()) {
1177 msg += accept_ratio_msg;
1240 template<
typename... Args>
1246 static constexpr
int NumControllers = MHRWControllerType::NumControllers;
1248 static constexpr
bool CanProvideStatusLine =
true;
1250 template<int I = 0, typename std::enable_if<(I < NumControllers), bool>::type dummy =
true>
1253 typedef typename std::tuple_element<I, typename MHRWControllerType::TupleType>::type
1259 getStatusLine<I+1>(ctrl) );
1262 template<int I = 0, typename std::enable_if<(I == NumControllers), bool>::type dummy =
true>
1277 template<
typename... Args>
1279 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
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.
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)
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.