Skip to content

A modern header-only library to calculate various statistics on a set of data

License

Notifications You must be signed in to change notification settings

nholthaus/statistics

Repository files navigation

Statistics

Build Status Build status language license copyright msvc2019 gcc-4.9.3

A modern C++ header-only library to calculate various statistics on a set of data

Build Instructions

To build and run the unit tests:

mkdir build
cd build
cmake -DBUILD_TESTS=ON ..
make -j
ctest

The library itself is a single header only. You can use the included CMake in a subdirectory and add the interface library, or just copy the statistics.h file (and license) into your project.

Usage

The Statistics object keeps incremental statistical information about a set of data. Operations work in constant time, with a fixed (and small) memory footprint.

  • Use the += or insert functions to add samples to the population
  • Get stats out with the following functions:
    • count() - the number of samples in the population.
    • min() - minimum valued sample in the population.
    • max() - maximum valued sample in the population.
    • mean() - average of the population.
    • sum() - the sum of all samples in the population.
    • variance() - the variance of the population.
    • standardDeviation() - the standard deviation of the population.

Example:

void main()
{
	Statistics<int> s;

	for(int i = 0; i < 10; ++i)
	{
		s += i;
	}

	std::cout << "mean = " << s.mean() << std::endl;		// prints 'mean = 4.5'
}