28 #ifndef _TOMOGRAPHER_MHRWVALUEERRORBINSCONVERGEDCONTROLLER_H 29 #define _TOMOGRAPHER_MHRWVALUEERRORBINSCONVERGEDCONTROLLER_H 66 template<
typename ValueHistogramWithBinningMHRWStatsCollectorType_,
67 typename IterCountIntType_,
68 typename BaseLoggerType_>
76 typedef ValueHistogramWithBinningMHRWStatsCollectorType_
77 ValueHistogramWithBinningMHRWStatsCollectorType;
79 typedef IterCountIntType_ IterCountIntType;
81 typedef BaseLoggerType_ BaseLoggerType;
84 const ValueHistogramWithBinningMHRWStatsCollectorType & value_stats_collector;
86 const IterCountIntType check_frequency_sweeps;
88 IterCountIntType last_forbidden_iter_number;
90 const Eigen::Index max_allowed_unknown;
91 const Eigen::Index max_allowed_unknown_notisolated;
92 const Eigen::Index max_allowed_not_converged;
103 const ValueHistogramWithBinningMHRWStatsCollectorType & value_stats_collector_,
104 BaseLoggerType & baselogger_,
105 IterCountIntType check_frequency_sweeps_ = 1024,
106 Eigen::Index max_allowed_unknown_ = 0,
107 Eigen::Index max_allowed_unknown_notisolated_ = 0,
108 Eigen::Index max_allowed_not_converged_ = 0
110 : value_stats_collector(value_stats_collector_),
111 check_frequency_sweeps(check_frequency_sweeps_),
112 last_forbidden_iter_number(0),
113 max_allowed_unknown(max_allowed_unknown_),
114 max_allowed_unknown_notisolated(max_allowed_unknown_notisolated_),
115 max_allowed_not_converged(max_allowed_not_converged_),
116 llogger(
"Tomographer::MHRWValueErrorBinsConvergedAdjuster", baselogger_)
120 template<
typename MHRWParamsType,
typename MHWalker,
typename MHRandomWalkType>
121 inline void init(MHRWParamsType & ,
const MHWalker & ,
122 const MHRandomWalkType & )
const 126 template<
typename MHRWParamsType,
typename MHWalker,
typename CountIntType,
typename MHRandomWalkType>
127 bool allowDoneThermalization(
const MHRWParamsType & ,
const MHWalker & ,
128 CountIntType ,
const MHRandomWalkType & )
const 133 template<
typename MHRWParamsType,
typename MHWalker,
typename MHRandomWalkType>
134 bool allowDoneRuns(
const MHRWParamsType & params,
const MHWalker & ,
135 IterCountIntType iter_k,
const MHRandomWalkType & )
138 if (check_frequency_sweeps == 0) {
145 if (last_forbidden_iter_number > 0 &&
146 (iter_k-last_forbidden_iter_number) < params.n_sweep*check_frequency_sweeps) {
154 const auto& binning_analysis = value_stats_collector.getBinningAnalysis();
155 const auto binmeans = value_stats_collector.binMeans();
157 const auto error_levels = binning_analysis.calcErrorLevels(binmeans);
158 const auto conv_status = binning_analysis.determineErrorConvergence(error_levels);
162 logger.longdebug([&](
std::ostream & stream) { stream <<
"Convergence summary = " << conv_summary; }) ;
164 if (conv_summary.n_not_converged > max_allowed_not_converged ||
165 conv_summary.n_unknown > max_allowed_unknown ||
166 (conv_summary.n_unknown-conv_summary.n_unknown_isolated) > max_allowed_unknown_notisolated) {
175 template<
typename MHRWParamsType,
typename MHWalker,
typename MHRandomWalkType>
176 inline void thermalizingDone(
const MHRWParamsType & ,
const MHWalker & ,
177 const MHRandomWalkType & )
const 181 template<
typename MHRWParamsType,
typename MHWalker,
typename MHRandomWalkType>
182 inline void done(MHRWParamsType & ,
const MHWalker & ,
183 const MHRandomWalkType & )
const 194 template<
typename IterCountIntType_ = int,
196 typename ValueHistogramWithBinningMHRWStatsCollectorType_ = void,
197 typename BaseLoggerType_ =
void>
202 const ValueHistogramWithBinningMHRWStatsCollectorType_ & value_stats_collector_,
203 BaseLoggerType_ & baselogger_,
204 IterCountIntType_ check_frequency_sweeps_ = 1024,
205 Eigen::Index max_allowed_unknown_ = 0,
206 Eigen::Index max_allowed_unknown_notisolated_ = 0,
207 Eigen::Index max_allowed_not_converged_ = 0
213 value_stats_collector_,
215 check_frequency_sweeps_,
216 max_allowed_unknown_,
217 max_allowed_unknown_notisolated_,
218 max_allowed_not_converged_
Utilities for formatting strings.
static BinningErrorBarConvergenceSummary fromConvergedStatus(const Eigen::Ref< const Eigen::ArrayXi > &converged_status)
Construct a summary object from a list of converged status obtained from BinningAnalysis::determineEr...
A MHRWController Interface which stops the random walk after enough samples have been taken to make a...
MHRWValueErrorBinsConvergedController< ValueHistogramWithBinningMHRWStatsCollectorType_, IterCountIntType_, BaseLoggerType_ > mkMHRWValueErrorBinsConvergedController(const ValueHistogramWithBinningMHRWStatsCollectorType_ &value_stats_collector_, BaseLoggerType_ &baselogger_, IterCountIntType_ check_frequency_sweeps_=1024, Eigen::Index max_allowed_unknown_=0, Eigen::Index max_allowed_unknown_notisolated_=0, Eigen::Index max_allowed_not_converged_=0)
Convenience function to create a MHRWValueErrorBinsConvergedController (using template argument deduc...
Base namespace for the Tomographer project.
MHRWValueErrorBinsConvergedController(const ValueHistogramWithBinningMHRWStatsCollectorType &value_stats_collector_, BaseLoggerType &baselogger_, IterCountIntType check_frequency_sweeps_=1024, Eigen::Index max_allowed_unknown_=0, Eigen::Index max_allowed_unknown_notisolated_=0, Eigen::Index max_allowed_not_converged_=0)
Constructor.
#define TOMO_ORIGIN
Use this as argument for a Tomographer::Logger::LocalLogger constructor .
LocalLogger< LocalLogger< BaseLoggerType > > subLogger(std::string new_prefix)
Create a sub-logger.
Never adjust the parameters of the random walk.
Some C++ utilities, with a tad of C++11 tricks.
Managing the need for specific overrides to operator new() for some types (especially Eigen types) ...
Definitions for MHRWStatsCollector Interface's.
Routines for performing a Metropolis-Hastings random walk.
Utilities for logging messages.