Tomographer
v1.0a
Tomographer C++ Framework Documentation
|
Simple binning analysis for determining error bars. More...
#include <tomographer/mhrw_bin_err.h>
Public Types | |
enum | |
Constants for error bar convergence analysis. More... | |
typedef Params::ValueType | ValueType |
Type of the value(s) for which we are calculating error bars. See BinningAnalysisParams::ValueType. | |
typedef Params::CountIntType | CountIntType |
Type used to count the number of samples. See BinningAnalysisParams::CountIntType. | |
typedef Params::SamplesArray | SamplesArray |
Type of the internal buffer for the raw samples. See BinningAnalysisParams::SamplesArray. | |
typedef Params::BinSumArray | BinSumArray |
Type used to store the sum of values. See BinningAnalysisParams::BinSumArray. | |
typedef Params::BinSumSqArray | BinSumSqArray |
Type used to store the sum of squares of values at each binning level. See BinningAnalysisParams::BinSumSqArray. | |
typedef LoggerType_ | LoggerType |
Type of the logger we will be logging debugging messages to. | |
Public Member Functions | |
BinningAnalysis (int num_track_values_, int num_levels_, LoggerType &logger_) | |
Constructor. More... | |
void | reset () |
Reset this object and start again as if freshly constructed. More... | |
template<typename Derived > | |
void | process_new_values (const Eigen::DenseBase< Derived > &vals) |
Process new raw samples. More... | |
template<typename CalcValType , ENABLED_IF(NumTrackValuesCTime==1) > | |
void | process_new_value (const CalcValType val) |
Process a new value (if we're tracking a single function only) More... | |
CountIntType | get_n_flushes () const |
Return the number of times the collected samples were flushed. More... | |
template<ENABLED_IF(StoreBinSums) > | |
auto | get_bin_means () const |
Get the average of each tracked value observed. More... | |
auto | get_bin_sqmeans () const |
Get the raw average of the squared values observed, for each binning level. More... | |
template<ENABLED_IF(StoreBinSums) > | |
const BinSumArray & | get_bin_sum () const |
Get the sum of each tracked value observed. More... | |
const BinSumSqArray & | get_bin_sumsq () const |
Get the raw sums of the squared values observed, at each binning level. More... | |
template<typename Derived > | |
BinSumSqArray | calc_error_levels (const Eigen::ArrayBase< Derived > &means) const |
Calculate the error bars of samples at different binning levels. More... | |
template<typename Derived > | |
BinSumArray | calc_error_lastlevel (const Eigen::ArrayBase< Derived > &means) const |
Calculate the error bar of samples (from the last binning level). More... | |
template<ENABLED_IF(StoreBinSums) > | |
BinSumSqArray | calc_error_levels () const |
Calculate the error bars of samples at different binning levels. More... | |
template<ENABLED_IF(StoreBinSums) > | |
BinSumArray | calc_error_lastlevel () const |
Calculate the error bar of samples (from the last binning level). More... | |
Eigen::ArrayXi | determine_error_convergence (const Eigen::Ref< const BinSumSqArray > &error_levels) const |
Attempt to determine if the error bars have converged. More... | |
Public Attributes | |
const Tools::static_or_dynamic< int, NumTrackValuesCTime > | num_track_values |
The number of functions being tracked/analyzed. More... | |
const Tools::static_or_dynamic< int, NumLevelsCTime > | num_levels |
The number of levels in the binning analysis. More... | |
const Tools::static_or_dynamic< CountIntType, SamplesSizeCTime > | samples_size |
The size of our samples buffer. (avoid using, might change in the future) More... | |
Static Public Attributes | |
static constexpr int | NumTrackValuesCTime = Params::NumTrackValuesCTime |
Number of values we are tracking/analyzing, if known at compile-time or Eigen::Dynamic. See BinningAnalysisParams::NumTrackValuesCTime. | |
static constexpr int | NumLevelsCTime = Params::NumLevelsCTime |
Number of binning levels in our binning analysis, if known at compile-time or Eigen::Dynamic. See BinningAnalysisParams::NumLevelsCTime. | |
static constexpr int | NumLevelsPlusOneCTime = Params::NumLevelsPlusOneCTime |
Number of binning levels in our binning analysis plus one, if known at compile-time or Eigen::Dynamic. See BinningAnalysisParams::NumLevelsPlusOneCTime. | |
static constexpr int | SamplesSizeCTime = Params::SamplesSizeCTime |
Size of the buffer which holds the raw sequence, if of fixed size and known at compile-time. See BinningAnalysisParams::SamplesSizeCTime. | |
static constexpr bool | StoreBinSums = Params::StoreBinSums |
Whether we should store the bin sums, or whether they can be provided independently by the user. See BinningAnalysisParams::StoreBinSums. | |
Simple binning analysis for determining error bars.
This class implements the theoretical procedure described in the theory page Binning Analysis.
This class in fact can perform binning analysis in parallel on several different functions (or values you're integrating). This is useful, for example, to determine error bars and run the binning analysis independently on each bin of a histogram (see ValueHistogramWithBinningMHRWStatsCollector).
Several values here may be either specified at compile-time or at run-time, inspired by Eigen's mechanism using Eigen::Dynamic. For example, the number of independent values to track may be fixed at compile-time in the NumTrackValues
template parameter of BinningAnalysisParams which you specify as the Params parameter here; however if the number of values will be determined dynamically at run-time, the NumTrackValues
template parameter should be set to Eigen::Dynamic.
Raw samples are added to the analysis by calling process_new_values() with a list of values, one new value per independent function integration that we are tracking. You should call this function repeatedly, once per sample. This class then takes care of adding those raw samples to an internal samples buffer and flushing this buffer whenever is needed.
The final results of the binning analysis can be obtained by calling calc_error_levels() to get the error bars at each binning level. Note that the analysis will only include all the flushed samples, i.e. all samples up to a multiple of samples_size(). If additional samples were given which didn't fill the samples buffer, they are ignored for the error analysis but they are included in get_bin_means() and get_bin_sum().
To calculate the error levels, this class also needs to keep track of the sum of all samples to calculate their mean. However, this is often done independently, e.g. with a ValueHistogramMHRWStatsCollector. In order to avoid calculating this twice, you may tell this BinningAnalysis class NOT to worry about calculating the means of the samples and that you will provide the sample means yourself. This is specified using the StoreBinSums template parameter to BinningAnalysisParams. In this case, you'll need to use the variants of calc_error_levels() and calc_error_lastlevel() with one argument, where you specify the bin means yourself.
You may also access some other information such as the sum of the squares of the samples at different binning levels (see get_bin_sqmeans()).
Params | is a BinningAnalysisParams with template parameters. This type specifies such types and values as the type of the values we're integrating, the number of independent functions we're integrating, and so on. |
LoggerType | a logger type as usual, for us to provide information about what we're doing and how the values look like. |
Definition at line 249 of file mhrw_bin_err.h.
anonymous enum |
Constants for error bar convergence analysis.
Enumerator | |
---|---|
UNKNOWN_CONVERGENCE |
Unable to determine whether the error bars have converged. |
CONVERGED |
The error bars appear to have converged. |
NOT_CONVERGED |
The error bars don't seem to have converged. |
Definition at line 319 of file mhrw_bin_err.h.
|
inline |
Constructor.
You must specify also the number of values that we will be tracking independently (num_track_values) and the number of binning levels (num_levels). If compile-time values have been provided as template parameters not equal to Eigen::Dynamic, these values MUST be equal to their compile-time given counterpart values.
Specify also a reference to a logger for logging messages. See Logging and Loggers.
Definition at line 393 of file mhrw_bin_err.h.
|
inline |
Calculate the error bar of samples (from the last binning level).
Return a vector of num_track_values elements, where the i -th item corresponds to the error bar of the i -th value determined from binning level num_levels.
If the error bars converged (see determine_error_convergence()), this should be a good estimate of the error bars on the corresponding values.
Use this variant of the function if this class doesn't store the bin means. If so, you need to provide the value of the means explicitly to the parameter means.
Definition at line 652 of file mhrw_bin_err.h.
|
inline |
Calculate the error bar of samples (from the last binning level).
Return a vector of num_track_values elements, where the i -th item corresponds to the error bar of the i -th value determined from binning level num_levels.
If the error bars converged (see determine_error_convergence()), this should be a good estimate of the error bars on the corresponding values.
Use this variant of the function if this class stores the bin means. If this is not the case, you will need to call the variant calc_error_lastlevel(const Eigen::ArrayBase<Derived> & means) with the values of the means.
Definition at line 690 of file mhrw_bin_err.h.
|
inline |
Calculate the error bars of samples at different binning levels.
Return an array of shape (num_track_values, num_levels) where element (i,k) corresponds to the error of the i -th value at binning level k. Binning level k=0 corresponds to the naive error bar from of the samples (no binning).
Use this variant of the function if this class doesn't store the bin means. If so, you need to provide the value of the means explicitly to the parameter means.
Definition at line 607 of file mhrw_bin_err.h.
|
inline |
Calculate the error bars of samples at different binning levels.
Return an array of shape (num_track_values, num_levels) where element (i,k) corresponds to the error of the i -th value at binning level k. Binning level k=0 corresponds to the naive error bar from of the samples (no binning).
Use this variant of the function if this class stores the bin means. If this is not the case, you will need to call the variant calc_error_levels(const Eigen::ArrayBase<Derived> & means) with the values of the means.
Definition at line 672 of file mhrw_bin_err.h.
|
inline |
Attempt to determine if the error bars have converged.
Call this method after calculating the error bars for each level with calc_error_levels(). Use the return value of that function to feed in the input here.
Contains code inspired by ALPS project, see https://alps.comp-phys.org/svn/alps1/trunk/alps/src/alps/alea/simplebinning.h.
Definition at line 707 of file mhrw_bin_err.h.
|
inline |
Get the average of each tracked value observed.
Definition at line 543 of file mhrw_bin_err.h.
|
inline |
Get the raw average of the squared values observed, for each binning level.
The vector bin_sqmeans.col(0) contains the raw average of the squares of the raw values observed, bin_sqmeans.col(1) the raw average of the squares of the values averaged 2 by 2 (i.e. at the first binning level), and so on.
Definition at line 557 of file mhrw_bin_err.h.
|
inline |
Get the sum of each tracked value observed.
This is only available if the StoreBinSums template parameter was set to true
.
Definition at line 583 of file mhrw_bin_err.h.
|
inline |
Get the raw sums of the squared values observed, at each binning level.
The vector bin_sumsq.col(0) contains the raw sum of the squares of the raw values observed, bin_sumsq.col(1) the raw sum of the squares of the values averaged 2 by 2 (i.e. at the first binning level), and so on.
Definition at line 591 of file mhrw_bin_err.h.
|
inline |
Return the number of times the collected samples were flushed.
This corresponds to the number of values of which the most coarse-grained binned averaging consists of.
Definition at line 537 of file mhrw_bin_err.h.
|
inline |
Process a new value (if we're tracking a single function only)
Use this variant of the function if we're tracking a single function only, so that you don't have to specify a 1-element "array" to process_new_values().
Definition at line 498 of file mhrw_bin_err.h.
|
inline |
Process new raw samples.
Call this function whenever you have a new sample with corresponding values. The argument should evaluate to a column vector; each element of the vector corresponds to the value of a function we're tracking. The length of the vector must equal num_track_values().
This will add the samples to the internal raw sample buffer, and flush the buffer as required.
Definition at line 435 of file mhrw_bin_err.h.
|
inline |
Reset this object and start again as if freshly constructed.
After calling reset(), you may use this object as if you had freshly constructed it. All values are reset to zero and the samples buffer is emptied.
Definition at line 415 of file mhrw_bin_err.h.
const Tools::static_or_dynamic<int, NumLevelsCTime> Tomographer::BinningAnalysis< Params, LoggerType_ >::num_levels |
The number of levels in the binning analysis.
The number may be obtained by calling binning_analysis.num_levels()
. This will either return the compile-time fixed value NumTrackValuesCTime, or the value which was set dynamically at runtime.
Eigen::Dynamic is never returned. See Tools::static_or_dynamic.
Definition at line 310 of file mhrw_bin_err.h.
const Tools::static_or_dynamic<int, NumTrackValuesCTime> Tomographer::BinningAnalysis< Params, LoggerType_ >::num_track_values |
The number of functions being tracked/analyzed.
The number may be obtained by calling binning_analysis.num_track_values()
. This will either return the compile-time fixed value NumTrackValuesCTime, or the value which was set dynamically at runtime.
Eigen::Dynamic is never returned. See Tools::static_or_dynamic.
Definition at line 300 of file mhrw_bin_err.h.
const Tools::static_or_dynamic<CountIntType, SamplesSizeCTime> Tomographer::BinningAnalysis< Params, LoggerType_ >::samples_size |
The size of our samples buffer. (avoid using, might change in the future)
See BinningAnalysisParams::SamplesSizeCTime. Avoid using this, this might change in the future.
Definition at line 316 of file mhrw_bin_err.h.