...one of the most highly
regarded and expertly designed C++ library projects in the
world.

— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards

boost::accumulators::impl::weighted_density_impl — Histogram density estimator for weighted samples.

// In header: <boost/accumulators/statistics/weighted_density.hpp>template<typenameSample,typenameWeight>structweighted_density_impl {// typestypedefnumeric::functional::average< Weight, std::size_t >::result_type float_type;typedefstd::vector< std::pair< float_type, float_type > > histogram_type;typedefstd::vector< float_type > array_type;typedefiterator_range<typenamehistogram_type::iterator > result_type;// construct/copy/destructtemplate<typenameArgs> weighted_density_impl(Argsconst&);// public member functionstemplate<typenameArgs>voidoperator()(Argsconst&) ;template<typenameArgs> result_type result(Argsconst&)const; };

The histogram density estimator returns a histogram of the sample distribution. The positions and sizes of the bins are determined using a specifiable number of cached samples (cache_size). The range between the minimum and the maximum of the cached samples is subdivided into a specifiable number of bins (num_bins) of same size. Additionally, an under- and an overflow bin is added to capture future under- and overflow samples. Once the bins are determined, the cached samples and all subsequent samples are added to the correct bins. At the end, a range of std::pair is returned, where each pair contains the position of the bin (lower bound) and the sum of the weights (normalized with the sum of all weights).