|
TRIQS/TRIQS 4.0.0
Researching Interacting Quantum Systems
|
#include <triqs/stat/log_binning.hpp>
Logarithmic binning accumulator.
Estimate the autocorrelation time of the samples by calculating the standard error of the data binned with different bin sizes. For correlated samples, the error should increase as the bin size increases up to the point where the bin size is large enough such that the binned samples become statistically independent.
Logarithmic binning uses bin sizes that are powers of two, i.e. \( 1, 2, 4, 8, 16, \dots \), up to an optional user-defined maximum.
Depending on the given parameter max_n_bins, which is given during construction, logarithmic binning is done in the following way:
Any other value of max_n_bins is rejected at construction. To toggle accumulation on/off at runtime, wrap the accumulator in std::optional<log_binning>.
See log_binning::operator<< for details on how the data is accumulated.
| T | triqs::stat::AccCompatible type. |
Definition at line 78 of file log_binning.hpp.
Public Types | |
| using | real_t = get_real_t<T> |
| Real type of the accumulated data type. | |
| using | value_t = T |
| Type of the accumulated data. | |
Public Member Functions | |
| log_binning ()=default | |
| Default construct a logarithmic binning accumulator. | |
| log_binning (T const &sample, int max_n_bins) | |
| Construct a logarithmic binning accumulator with a dummy sample and the maximum number of bins. | |
| auto const & | bare_bins () const |
| Get the bins that are used for accumulating the bare samples. | |
| auto const & | bare_counts () const |
| Get the number of samples currently in the bare bins. | |
| long | count () const |
| Get the total number of accumulated samples. | |
| auto | effective_counts () const |
| Get the number of effective samples accumulated in each bin. | |
| bool | is_unbounded () const |
| True if the accumulator was constructed with an unbounded number of bins. | |
| long | max_n_bins () const |
| Get the maximum number of bins. | |
| auto const & | mean_bins () const |
| Get the bins that store the mean data. | |
| auto | mean_errors_and_taus (int min_samples=2) const |
| Get the overall mean of the data as well as the estimated standard error, integrated autocorrelation time and effective number of samples for each bin. | |
| auto | mean_errors_and_taus (mpi::communicator c, int min_samples=2) const |
| Get the overall mean of the data as well as the estimated standard error, integrated autocorrelation time and effective number of samples for each bin on multiple MPI processes. | |
| auto | mpi_all_reduce (mpi::communicator c) const |
| Allreduce the accumulated data over multiple MPI processes. | |
| long | n_bins () const |
| Get the current number of bins. | |
| template<typename U> | |
| log_binning< T > & | operator<< (U const &x) |
| Accumulate a new sample. | |
| auto const & | var_bins () const |
| Get the bins that store the sum of the squared deviations from the mean. | |
Static Public Member Functions | |
| static std::string | hdf5_format () |
| Get the HDF5 format string. | |
Friends | |
| void | h5_read (h5::group g, std::string const &name, log_binning &acc) |
| Read a triqs::stat::log_binning accumulator from HDF5. | |
| void | h5_write (h5::group g, std::string const &name, log_binning const &acc) |
| Write a triqs::stat::log_binning accumulator to HDF5. | |
|
default |
Default construct a logarithmic binning accumulator.
The accumulator is unbounded (max_n_bins is set to \( -1 \)). No memory is allocated for the bins until the first sample is added to the accumulator.
|
inline |
Construct a logarithmic binning accumulator with a dummy sample and the maximum number of bins.
| sample | Dummy sample to determine which type is stored and accumulated in the bins. |
| max_n_bins | Maximum number of bins. |
Definition at line 100 of file log_binning.hpp.
|
inlinenodiscard |
Get the overall mean of the data as well as the estimated standard error, integrated autocorrelation time and effective number of samples for each bin.
The standard error, \( s_n \), is defined as the square root of the variance
\[ s_n^2 = \frac{1}{k_n (k_n - 1)} \sum_{i=1}^{k_n} (y_i - m_n)^2 = \frac{q_n}{k_n (k_n - 1)} \; , \]
where \( m_n \) and \( q_n \) is the mean and the sum of the squared deviations from the mean currently stored in the accumulator for each bin \( n \), respectively. \( k_n \) is the number of effective samples in a bin and \( y_i \) is an effective sample.
The integrated autocorrelation time, \( \tau_n \), can then be estimated as
\[ \tau_n = \frac{1}{2} \left( \frac{s_n^2}{s_0^2} - 1 \right) \; . \]
\( \tau_n \) and \( s_n \) are expected to increase with \( n \) and saturate for large enough bin sizes. At this point, the effective samples in the bins become statistically independent.
Only bins with at least min_samples effective samples are considered for error and autocorrelation time estimation.
| min_samples | Minimum number of effective samples required ( \( \geq 2 \)). |
Definition at line 274 of file log_binning.hpp.
|
inlinenodiscard |
Get the overall mean of the data as well as the estimated standard error, integrated autocorrelation time and effective number of samples for each bin on multiple MPI processes.
The data in each bin is first reduced across all MPI processes using log_binning::mpi_all_reduce, before the overall mean, standard error and integrated autocorrelation time are calculated for the reduced bins.
Only bins with at least min_samples effective samples after the reduction are considered for error and autocorrelation time estimation.
The results will be available on all MPI processes.
See also log_binning::mean_errors_and_taus.
| c | MPI communicator. |
| min_samples | Minimum number of effective samples required ( \( \geq 2 \)). |
Definition at line 297 of file log_binning.hpp.
|
inlinenodiscard |
Allreduce the accumulated data over multiple MPI processes.
First the bins are resized to the maximum number of bins across all processes. Then the number of effective samples, the mean and sum of squared deviations from the mean are reduced for each bin separately.
| c | MPI communicator. |
Definition at line 314 of file log_binning.hpp.
|
inline |
Accumulate a new sample.
Let \( x_i \) be the ith sample that is currently being added to the accumulator.
For each bin \( n = 0, 1, \dots, N - 1 \), let us define the following quantities:
The new data point is first added to the bare samples of each bin:
\[ p_n(i) = \begin{cases} p_n(i-1) + x_i & \text{if } 1 < l_n(i) \leq b_n \\ x_i & \text{if } l_n(i) = 1 \end{cases} \; . \]
If the number of bare samples is equal to the bin size, i.e. \( l_n(i) = b_n \), we take the mean of the accumulated bare samples to get the effective sample \( y_n[k_n(i)] = p_n(i) / b_n \). The effective sample is then added to the mean
\[ m_n[k_n(i)] = m_n[k_n(i) - 1] + \frac{ y_n[k_n(i)] - m_n[k_n(i) - 1]}{k} \]
and to the sum of squared deviations from the mean
\[ q_n[k_n(i)] = q_n[k_n(i) - 1] + \frac{k - 1}{k} \left\{ y_n[k_n(i)] - m_n[k_n(i) - 1] \right\}^2 \; . \]
In case, \( i = 2^{N - 1} \) and the maximum number of bins is not reached yet, a new bin with bin size \( 2^{N} \) will be added.
For more information, see e.g. Wikipedia or Chan, Golub, LeVeque. Am. Stat. 37, 242 (1983).
| U | Type of the data point to be added to the accumulator. |
| x | Data point to be added to the accumulator. |
Definition at line 148 of file log_binning.hpp.
|
friend |
Read a triqs::stat::log_binning accumulator from HDF5.
| g | h5::group containing the subgroup. |
| name | Name of the subgroup from which the accumulator will be read. |
| acc | Accumulator to be read into. |
Definition at line 368 of file log_binning.hpp.
|
friend |
Write a triqs::stat::log_binning accumulator to HDF5.
| g | h5::group in which the subgroup is created. |
| name | Name of the subgroup to which the accumulator will be written. |
| acc | Accumulator to be written. |
Definition at line 350 of file log_binning.hpp.