|
TRIQS/TRIQS 4.0.0
Researching Interacting Quantum Systems
|
#include <triqs/stat/lin_binning.hpp>
Linear binning accumulator.
Accumulate consecutive data points into either a fixed number of bins with a dynamic bin capacity or a growing number of bins with a fixed bin capacity.
The bins are stored and can be accessed at any time to perform further analysis, e.g. to estimate the error of the mean and the integrated autocorrelation time or to resample via the Jackknife method. The data stored in the bins is the mean of the accumulated samples in each bin.
Depending on the parameter max_n_bins, which is given during construction, linear binning is done in the following way:
Any other value of max_n_bins is rejected at construction. bin_capacity must always be \( \geq 1 \).
In addition to the linear bins, the accumulator further keeps track of the overall mean and the sum of the squared deviations from the mean. This is used to provide an estimate for the integrated autocorrelation time.
| T | triqs::stat::AccCompatible type. |
Definition at line 108 of file lin_binning.hpp.
Public Types | |
| using | callback_t = std::function<void(lin_binning const &)> |
| Type of the callback function that is called when bins are compressed. | |
| 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 | |
| lin_binning ()=default | |
| Default construct a linear binning accumulator. | |
| lin_binning (T const &sample, long max_n_bins, long bin_capacity, callback_t callback={}) | |
| Construct a linear binning accumulator with a dummy sample, the maximum number of bins, the bin capacity and a callback function. | |
| long | bin_capacity () const |
| Get the current bin capacity. | |
| auto const & | bins () const |
| Get all the bins containing data including the currently active bin. | |
| auto const & | callback () const |
| Get the callback function. | |
| void | compress (int fac) |
| Compress bins and increase bin capacity. | |
| long | count () const |
| Get the total number of accumulated samples. | |
| std::vector< T > | full_bins () const |
| Get only the full bins, i.e. bins that are filled up to the bin capacity. | |
| bool | is_unbounded () const |
| True if the accumulator was constructed with an unbounded number of bins. | |
| long | last_bin_count () const |
| Get the number of samples in the currently active bin. | |
| long | max_n_bins () const |
| Get the maximum number of bins. | |
| auto const & | mean () const |
| Get the overall mean. | |
| auto | mean_error_and_tau () const |
| Get the mean, its standard error and an estimate for the integrated autocorrelation time. | |
| auto | mean_error_and_tau (mpi::communicator c) const |
| Get the mean, its standard error and an estimate for the integrated autocorrelation time from accumulators on multiple MPI processes. | |
| auto | mpi_all_gather (mpi::communicator c, bool same_capacity=true) const |
| Allgather full bins from multiple MPI processes. | |
| auto | mpi_all_reduce (mpi::communicator c) const |
| Allreduce the overall mean and sum of squared deviations from the mean over multiple MPI processes. | |
| long | n_bins () const |
| Get the number of bins containing data including the currently active bin. | |
| long | n_full_bins () const |
| Get the number of full bins, i.e. bins that are filled up to the bin capacity. | |
| template<typename U> | |
| auto & | operator<< (U &&x) |
| Accumulate a new sample. | |
| auto const & | var_data () const |
| Get the overall 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, lin_binning &acc) |
| Read a triqs::stat::lin_binning accumulator from HDF5. | |
| void | h5_write (h5::group g, std::string const &name, lin_binning const &acc) |
| Write a triqs::stat::lin_binning accumulator to HDF5. | |
|
default |
Default construct a linear binning accumulator.
The accumulator is unbounded (max_n_bins is set to \( -1 \)) with a bin capacity of \( 1 \) and no callback function. No memory is allocated for the bins until the first sample is added to the accumulator.
|
inline |
Construct a linear binning accumulator with a dummy sample, the maximum number of bins, the bin capacity and a callback function.
The callback function is called just before the bins are compressed. See also lin_binning::compress.
| sample | Dummy sample to determine which type is stored and accumulated in the bins. |
| max_n_bins | Maximum number of bins. |
| bin_capacity | Initial/Fixed capacity of each bin. |
| callback | Callback function of type lin_binning::callback_t. |
Definition at line 138 of file lin_binning.hpp.
|
inline |
Compress bins and increase bin capacity.
The compression factor determines the number of adjacent bins that are merged together and the factor the bin capacity is multiplied with.
The data of the bins is averaged and stored in the first n_full_bins() / fac bins. If there are any left over bins, the data is put into a new bin, which becomes the currently active bin.
It does nothing, if linear binning is turned off, if there is only one bin or if the compression factor is less than 2.
| fac | Compression factor. |
Definition at line 258 of file lin_binning.hpp.
|
inlinenodiscard |
Get the mean, its standard error and an estimate for the integrated autocorrelation time.
For definitions of the standard error and the integrated autocorrelation time, see log_binning::mean_errors_and_taus.
Definition at line 299 of file lin_binning.hpp.
|
inlinenodiscard |
Get the mean, its standard error and an estimate for the integrated autocorrelation time from accumulators on multiple MPI processes.
The overall mean and the sum of squared deviations from the mean are reduced and (full) bins are gathered from all MPI processes.
The results will be available on all MPI processes.
For definitions of the standard error and the integrated autocorrelation time, see log_binning::mean_errors_and_taus.
| c | MPI communicator. |
Definition at line 320 of file lin_binning.hpp.
|
inlinenodiscard |
Allgather full bins from multiple MPI processes.
Only full bins are considered. Furthermore, if same_capacity is set to true, the bins are compressed to have the same capacity on all processes and only those bins are then gathered.
| c | MPI communicator. |
| same_capacity | Compress bins to have the same capacity on all processes and only gather those bins. |
Definition at line 361 of file lin_binning.hpp.
|
inlinenodiscard |
Allreduce the overall mean and sum of squared deviations from the mean over multiple MPI processes.
The results will be available on all MPI processes.
| c | MPI communicator. |
Definition at line 336 of file lin_binning.hpp.
|
inline |
Accumulate a new sample.
Let \( x_i \) be the ith sample that is currently being added to the accumulator.
The data point is accumulated into the currently active bin. In case that the active bin is full and the maximum number of bins is reached, the bins are compressed by merging two adjacent bins into one (see lin_binning::compress). Otherwise, a new bin with the given data point is added.
Let \( m_n(k_n) \) be the stored mean of the data in the currently active bin \( n \) and let \( k_n \) be the number of data points in that bin. The mean in the bin is then updated as
\[ m_n(k_n) = m_n(k_n - 1) + \frac{x_i - m_n(k_n - 1)}{k_n} \; . \]
The overall mean \( m(N) \) is updated similarly, whereas the overall sum of the squared deviations is updated as
\[ q(N) = q(N - 1) + \frac{N - 1}{N} \left| x_i - m(N - 1) \right|^2 \; , \]
where \( N \) is the total number of data points accumulated.
| U | Type of the data point to be added to the accumulator. |
| x | Data point to be added to the accumulator. |
Definition at line 214 of file lin_binning.hpp.
|
friend |
Read a triqs::stat::lin_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 415 of file lin_binning.hpp.
|
friend |
Write a triqs::stat::lin_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 396 of file lin_binning.hpp.