Fast multi-dimensional histogram with convenient interface for C++14
Coded with ❤. Powered by the Boost community and the Scikit-HEP Project.
| Branch | Linux [1] and OSX [2] | Windows [3] | Coverage |
|---|---|---|---|
| develop | |||
| master |
This header-only open-source library provides an easy-to-use state-of-the-art multi-dimensional histogram class for the professional statistician and everyone who needs to count things. The histogram is easy to use for the casual user and yet very customizable. It does not restrict the power-user. The library offers a unique safety guarantee: cell counts cannot overflow or be capped in the standard configuration. And it can do more than counting. The histogram can be equipped with arbitrary accumulators to compute means, medians, and whatever you fancy in each cell. The library is very fast single-threaded (see benchmarks) and several parallelization options are provided for multi-threaded programming.
The project has passed Boost review in September 2018 and is going to be first released with Boost-1.70 in April. The source code is licensed under the Boost Software License.
Check out the full documentation. Python bindings to this library are available elsewhere.
The following stripped-down example was taken from the Getting started section in the documentation. Have a look into the docs to see the full version with comments and more examples.
Example: Fill a 1d-histogram
#include <boost/histogram.hpp>
#include <boost/format.hpp> // used here for printing
#include <functional> // for std::ref
int main() {
using namespace boost::histogram;
auto h = make_histogram(
axis::regular<>(6, -1.0, 2.0, "x")
);
// fill histogram
auto data = { -10, -0.4, 1.1, 0.3, 1.3 };
std::for_each(data.begin(), data.end(), std::ref(h));
// iterate over bins
for (auto x : indexed(h)) {
std::cout << boost::format("bin %2i [%4.1f, %4.1f): %i\n")
% x.index() % x.bin().lower() % x.bin().upper() % *x;
}
std::cout << std::flush;
/* program output:
bin -1 [-inf, -1.0): 1
bin 0 [-1.0, -0.5): 0
bin 1 [-0.5, -0.0): 1
bin 2 [-0.0, 0.5): 1
bin 3 [ 0.5, 1.0): 0
bin 4 [ 1.0, 1.5): 2
bin 5 [ 1.5, 2.0): 0
bin 6 [ 2.0, inf): 0
*/
}
Boost.Histogram is more flexible and faster than other C/C++ libraries. It was compared to:
Details on the benchmark are given in the documentation.
John Buonagurio | Manager at Exponent®
"I just wanted to say 'thanks' for your awesome Histogram library. I'm working on a software package for processing meteorology data and I'm using it to generate wind roses with the help of Qt and QwtPolar. Looks like you thought of just about everything here – the circular axis type was practically designed for this application, everything 'just worked'."