![]() |
Home | Libraries | People | FAQ | More |
The Statistical Accumulators Library defines accumulators for incremental statistial computations. It is built on top of The Accumulator Framework.
The count feature is a
simple counter that tracks the number of samples pushed into the accumulator
set.
std::size_t
none
none
none
none
none
O(1)
O(1)
Header
#include <boost/accumulators/statistics/count.hpp>
Example
accumulator_set<int, features<tag::count> > acc; acc(0); acc(0); acc(0); assert(3 == count(acc));
See also
The covariance feature
is an iterative Monte Carlo estimator for the covariance. It is specified
as tag::covariance<.
variate-type, variate-tag>
numeric::functional::outer_product< numeric::functional::average<sample-type, std::size_t>::result_type , numeric::functional::average<variate-type, std::size_t>::result_type >::result_type
count
mean
mean_of_variates<
variate-type, variate-tag>
abstract_covariance
none
variate-tag
none
TODO
O(1)
Header
#include <boost/accumulators/statistics/covariance.hpp>
Example
accumulator_set<double, stats<tag::covariance<double, tag::covariate1> > > acc; acc(1., covariate1 = 2.); acc(1., covariate1 = 4.); acc(2., covariate1 = 3.); acc(6., covariate1 = 1.); assert(covariance(acc) == -1.75);
See also
The tag::density feature returns a histogram of
the sample distribution. For more implementation details, see density_impl.
iterator_range< std::vector< std::pair< numeric::functional::average<sample-type, std::size_t>::result_type , numeric::functional::average<sample-type, std::size_t>::result_type > >::iterator >
count
min
max
none
density::cache_size
density::num_bins
none
none
TODO
O(N), when N is density::num_bins
Header
#include <boost/accumulators/statistics/density.hpp>
See also
The error_of<mean>
feature calculates the error of the mean feature. It is equal to sqrt(variance /
(count
- 1)).
numeric::functional::average<sample-type, std::size_t>::result_type
count
variance
error_of<immediate_mean>
none
none
none
TODO
O(1)
Header
#include <boost/accumulators/statistics/error_of.hpp> #include <boost/accumulators/statistics/error_of_mean.hpp>
Example
accumulator_set<double, stats<tag::error_of<tag::mean> > > acc; acc(1.1); acc(1.2); acc(1.3); assert(0.057735 == error_of<tag::mean>(acc));
See also
Multiple quantile estimation with the extended P^2 algorithm.
For further details, see extended_p_square_impl.
boost::iterator_range<
implementation-defined
>
count
none
tag::extended_p_square::probabilities
none
none
TODO
O(1)
Header
#include <boost/accumulators/statistics/extended_p_square.hpp>
Example
boost::array<double> probs = {0.001,0.01,0.1,0.25,0.5,0.75,0.9,0.99,0.999}; accumulator_set<double, stats<tag::extended_p_square> > acc(tag::extended_p_square::probabilities = probs); boost::lagged_fibonacci607 rng; // a random number generator for (int i=0; i<10000; ++i) acc(rng()); BOOST_CHECK_CLOSE(extended_p_square(acc)[0], probs[0], 25); BOOST_CHECK_CLOSE(extended_p_square(acc)[1], probs[1], 10); BOOST_CHECK_CLOSE(extended_p_square(acc)[2], probs[2], 5); for (std::size_t i=3; i < probs.size(); ++i) { BOOST_CHECK_CLOSE(extended_p_square(acc)[i], probs[i], 2); }
See also
Quantile estimation using the extended P^2 algorithm
for weighted and unweighted samples. By default, the calculation is linear
and unweighted, but quadratic and weighted variants are also provided.
For further implementation details, see extended_p_square_quantile_impl.
All the variants share the tag::quantile
feature and can be extracted using the quantile() extractor.
numeric::functional::average<sample-type, std::size_t>::result_type
weighted variants depend on weighted_extended_p_square
unweighted variants depend on extended_p_square
extended_p_square_quantile_quadratic
weighted_extended_p_square_quantile
weighted_extended_p_square_quantile_quadratic
tag::extended_p_square::probabilities
weight for the weighted
variants
quantile_probability
TODO
O(N) where N is the count of probabilities.
Header
#include <boost/accumulators/statistics/extended_p_square_quantile.hpp>
Example
typedef accumulator_set<double, stats<tag::extended_p_square_quantile> > accumulator_t; typedef accumulator_set<double, stats<tag::weighted_extended_p_square_quantile>, double > accumulator_t_weighted; typedef accumulator_set<double, stats<tag::extended_p_square_quantile(quadratic)> > accumulator_t_quadratic; typedef accumulator_set<double, stats<tag::weighted_extended_p_square_quantile(quadratic)>, double > accumulator_t_weighted_quadratic; // tolerance double epsilon = 1; // a random number generator boost::lagged_fibonacci607 rng; boost::array<double> probs = { 0.990, 0.991, 0.992, 0.993, 0.994, 0.995, 0.996, 0.997, 0.998, 0.999 }; accumulator_t acc(extended_p_square_probabilities = probs); accumulator_t_weighted acc_weighted(extended_p_square_probabilities = probs); accumulator_t_quadratic acc2(extended_p_square_probabilities = probs); accumulator_t_weighted_quadratic acc_weighted2(extended_p_square_probabilities = probs); for (int i=0; i<10000; ++i) { double sample = rng(); acc(sample); acc2(sample); acc_weighted(sample, weight = 1.); acc_weighted2(sample, weight = 1.); } for (std::size_t i = 0; i < probs.size() - 1; ++i) { BOOST_CHECK_CLOSE( quantile(acc, quantile_probability = 0.99025 + i*0.001) , 0.99025 + i*0.001 , epsilon ); BOOST_CHECK_CLOSE( quantile(acc2, quantile_probability = 0.99025 + i*0.001) , 0.99025 + i*0.001 , epsilon ); BOOST_CHECK_CLOSE( quantile(acc_weighted, quantile_probability = 0.99025 + i*0.001) , 0.99025 + i*0.001 , epsilon ); BOOST_CHECK_CLOSE( quantile(acc_weighted2, quantile_probability = 0.99025 + i*0.001) , 0.99025 + i*0.001 , epsilon ); }
See also
The kurtosis of a sample distribution is defined as the ratio of the 4th
central moment and the square of the 2nd central moment (the variance)
of the samples, minus 3. The term -3 is added in order
to ensure that the normal distribution has zero kurtosis. For more implementation
details, see kurtosis_impl
numeric::functional::average<sample-type,sample-type>::result_type
mean
moment<2>
moment<3>
moment<4>
none
none
none
none
O(1)
O(1)
Header
#include <boost/accumulators/statistics/kurtosis.hpp>
Example
accumulator_set<int, stats<tag::kurtosis > > acc; acc(2); acc(7); acc(4); acc(9); acc(3); BOOST_CHECK_EQUAL( mean(acc), 5 ); BOOST_CHECK_EQUAL( moment<2>(acc), 159./5. ); BOOST_CHECK_EQUAL( moment<3>(acc), 1171./5. ); BOOST_CHECK_EQUAL( moment<4>(acc), 1863 ); BOOST_CHECK_CLOSE( kurtosis(acc), -1.39965397924, 1e-6 );
See also
Calculates the maximum value of all the samples.
sample-type
none
none
none
none
none
O(1)
O(1)
Header
#include <boost/accumulators/statistics/max.hpp>
Example
accumulator_set<int, stats<tag::max> > acc; acc(1); BOOST_CHECK_EQUAL(1, (max)(acc)); acc(0); BOOST_CHECK_EQUAL(1, (max)(acc)); acc(2); BOOST_CHECK_EQUAL(2, (max)(acc));
See also
Calculates the mean of samples, weights or variates. The calculation is
either lazy (in the result extractor), or immediate (in the accumulator).
The lazy implementation is the default. For more implementation details,
see mean_impl
or. immediate_mean_impl
For samples, numeric::functional::average< sample-type, std::size_t>::result_type
For weights,
numeric::functional::average<
weight-type, std::size_t>::result_type
For variates, numeric::functional::average<
variate-type, std::size_t>::result_type
count
The lazy
mean of samples depends on sum
The lazy mean of weights depends on sum_of_weights
The lazy mean of variates depends on sum_of_variates<>
mean_of_weights
mean_of_variates<
variate-type, variate-tag>
immediate_mean
immediate_mean_of_weights
immediate_mean_of_variates<
variate-type, variate-tag>
none
none
none
O(1)
O(1)
Header
#include <boost/accumulators/statistics/mean.hpp>
Example
accumulator_set< int , stats< tag::mean , tag::mean_of_weights , tag::mean_of_variates<int, tag::covariate1> > , int > acc; acc(1, weight = 2, covariate1 = 3); BOOST_CHECK_CLOSE(1., mean(acc), 1e-5); BOOST_CHECK_EQUAL(1u, count(acc)); BOOST_CHECK_EQUAL(2, sum(acc)); BOOST_CHECK_CLOSE(2., mean_of_weights(acc), 1e-5); BOOST_CHECK_CLOSE(3., (mean_of_variates<int, tag::covariate1>(acc)), 1e-5); acc(0, weight = 4, covariate1 = 4); BOOST_CHECK_CLOSE(0.33333333333333333, mean(acc), 1e-5); BOOST_CHECK_EQUAL(2u, count(acc)); BOOST_CHECK_EQUAL(2, sum(acc)); BOOST_CHECK_CLOSE(3., mean_of_weights(acc), 1e-5); BOOST_CHECK_CLOSE(3.5, (mean_of_variates<int, tag::covariate1>(acc)), 1e-5); acc(2, weight = 9, covariate1 = 8); BOOST_CHECK_CLOSE(1.33333333333333333, mean(acc), 1e-5); BOOST_CHECK_EQUAL(3u, count(acc)); BOOST_CHECK_EQUAL(20, sum(acc)); BOOST_CHECK_CLOSE(5., mean_of_weights(acc), 1e-5); BOOST_CHECK_CLOSE(5., (mean_of_variates<int, tag::covariate1>(acc)), 1e-5); accumulator_set< int , stats< tag::mean(immediate) , tag::mean_of_weights(immediate) , tag::mean_of_variates<int, tag::covariate1>(immediate) > , int > acc2; acc2(1, weight = 2, covariate1 = 3); BOOST_CHECK_CLOSE(1., mean(acc2), 1e-5); BOOST_CHECK_EQUAL(1u, count(acc2)); BOOST_CHECK_CLOSE(2., mean_of_weights(acc2), 1e-5); BOOST_CHECK_CLOSE(3., (mean_of_variates<int, tag::covariate1>(acc2)), 1e-5); acc2(0, weight = 4, covariate1 = 4); BOOST_CHECK_CLOSE(0.33333333333333333, mean(acc2), 1e-5); BOOST_CHECK_EQUAL(2u, count(acc2)); BOOST_CHECK_CLOSE(3., mean_of_weights(acc2), 1e-5); BOOST_CHECK_CLOSE(3.5, (mean_of_variates<int, tag::covariate1>(acc2)), 1e-5); acc2(2, weight = 9, covariate1 = 8); BOOST_CHECK_CLOSE(1.33333333333333333, mean(acc2), 1e-5); BOOST_CHECK_EQUAL(3u, count(acc2)); BOOST_CHECK_CLOSE(5., mean_of_weights(acc2), 1e-5); BOOST_CHECK_CLOSE(5., (mean_of_variates<int, tag::covariate1>(acc2)), 1e-5);
See also
Median estimation based on the P^2 quantile estimator,
the density estimator, or the P^2 cumulative distribution
estimator. For more implementation details, see median_impl,
with_density_median_impl,
and with_p_square_cumulative_distribution_median_impl.
The three median accumulators all satisfy the tag::median
feature, and can all be extracted with the median() extractor.
numeric::functional::average<sample-type, std::size_t>::result_type
median depends on
p_square_quantile_for_median
with_density_median
depends on count and
density
with_p_square_cumulative_distribution_median
depends on p_square_cumulative_distribution
with_density_median
with_p_square_cumulative_distribution_median
with_density_median
requires tag::density::cache_size and tag::density::num_bins
with_p_square_cumulative_distribution_median
requires tag::p_square_cumulative_distribution::num_cells
none
none
TODO
TODO
Header
#include <boost/accumulators/statistics/median.hpp>
Example
// two random number generators double mu = 1.; boost::lagged_fibonacci607 rng; boost::normal_distribution<> mean_sigma(mu,1); boost::variate_generator<boost::lagged_fibonacci607&, boost::normal_distribution<> > normal(rng, mean_sigma); accumulator_set<double, stats<tag::median(with_p_square_quantile) > > acc; accumulator_set<double, stats<tag::median(with_density) > > acc_dens( density_cache_size = 10000, density_num_bins = 1000 ); accumulator_set<double, stats<tag::median(with_p_square_cumulative_distribution) > > acc_cdist( p_square_cumulative_distribution_num_cells = 100 ); for (std::size_t i=0; i<100000; ++i) { double sample = normal(); acc(sample); acc_dens(sample); acc_cdist(sample); } BOOST_CHECK_CLOSE(1., median(acc), 1.); BOOST_CHECK_CLOSE(1., median(acc_dens), 1.); BOOST_CHECK_CLOSE(1., median(acc_cdist), 3.);
See also
Calculates the minimum value of all the samples.
sample-type
none
none
none
none
none
O(1)
O(1)
Header
#include <boost/accumulators/statistics/min.hpp>
Example
accumulator_set<int, stats<tag::min> > acc; acc(1); BOOST_CHECK_EQUAL(1, (min)(acc)); acc(0); BOOST_CHECK_EQUAL(0, (min)(acc)); acc(2); BOOST_CHECK_EQUAL(0, (min)(acc));
See also
Calculates the N-th moment of the samples, which is defined as the sum of the N-th power of the samples over the count of samples.
numeric::functional::average<sample-type, std::size_t>::result_type
count
none
none
none
none
O(1)
O(1)
Header
#include <boost/accumulators/statistics/moment.hpp>
Example
accumulator_set<int, stats<tag::moment<2> > > acc1; acc1(2); // 4 acc1(4); // 16 acc1(5); // + 25 // = 45 / 3 = 15 BOOST_CHECK_CLOSE(15., moment<2>(acc1), 1e-5); accumulator_set<int, stats<tag::moment<5> > > acc2; acc2(2); // 32 acc2(3); // 243 acc2(4); // 1024 acc2(5); // + 3125 // = 4424 / 4 = 1106 BOOST_CHECK_CLOSE(1106., moment<5>(acc2), 1e-5);
See also
Histogram calculation of the cumulative distribution with the P^2
algorithm. For more implementation details, see p_square_cumulative_distribution_impl
iterator_range< std::vector< std::pair< numeric::functional::average<sample-type, std::size_t>::result_type , numeric::functional::average<sample-type, std::size_t>::result_type > >::iterator >
count
none
tag::p_square_cumulative_distribution::num_cells
none
none
TODO
O(N) where N is num_cells
Header
#include <boost/accumulators/statistics/p_square_cumulative_distribution.hpp>
Example
// tolerance in % double epsilon = 3; typedef accumulator_set<double, stats<tag::p_square_cumulative_distribution> > accumulator_t; accumulator_t acc(tag::p_square_cumulative_distribution::num_cells = 100); // two random number generators boost::lagged_fibonacci607 rng; boost::normal_distribution<> mean_sigma(0,1); boost::variate_generator<boost::lagged_fibonacci607&, boost::normal_distribution<> > normal(rng, mean_sigma); for (std::size_t i=0; i<100000; ++i) { acc(normal()); } typedef iterator_range<std::vector<std::pair<double, double> >::iterator > histogram_type; histogram_type histogram = p_square_cumulative_distribution(acc); for (std::size_t i = 0; i < histogram.size(); ++i) { // problem with small results: epsilon is relative (in percent), not absolute! if ( histogram[i].second > 0.001 ) BOOST_CHECK_CLOSE( 0.5 * (1.0 + erf( histogram[i].first / sqrt(2.0) )), histogram[i].second, epsilon ); }
See also
Single quantile estimation with the P^2 algorithm. For
more implementation details, see p_square_quantile_impl
numeric::functional::average<sample-type, std::size_t>::result_type
count
p_square_quantile_for_median
quantile_probability,
which defaults to 0.5.
(Note: for p_square_quantile_for_median,
the quantile_probability
parameter is ignored and is always 0.5.)
none
none
TODO
O(1)
Header
#include <boost/accumulators/statistics/p_square_quantile.hpp>
Example
typedef accumulator_set<double, stats<tag::p_square_quantile