An open API service indexing awesome lists of open source software.

https://github.com/phcerdan/histogram

Histogram in C++11, 1D, simple header-only, inspired by R, calculate and optimize breaks automatically. Accepts different precissions.
https://github.com/phcerdan/histogram

Last synced: about 1 year ago
JSON representation

Histogram in C++11, 1D, simple header-only, inspired by R, calculate and optimize breaks automatically. Accepts different precissions.

Awesome Lists containing this project

README

          

You might be interested in the modern and more mature [boost::histogram](https://github.com/boostorg/histogram) header only library.

# Histogram
Histogram in C++11, 1D, simple header-only, inspired by R, calculate and optimize breaks automatically. Accepts different precissions.
# Documentation

[Doxygen generated Docs](http://phcerdan.github.io/histogram/docs/html/index.html)

Warning, docs are not generated automatically and might be outdated.

# Downloading
You can use the header as is, just download it, and include it in your project.
MIT License, but please contribute back if you add any extra feature!

# Using it.
You should read the test file as a sample for usage.
```cpp
vector data{1.0, 1.0, 2.0, 3.0, 19.0, 0.5, 14.0};
histo::Histo h_scott(data); // Default method to calculate Breaks.
size_t bins = 10;
auto breaks_with_bins = histo::GenerateBreaksFromRangeAndBins(0.0, 20.0, bins);
double width = 1.0;
auto breaks_with_fixed_width = histo::GenerateBreaksFromRangeAndWidth(0.0, 20.0, width);
histo::Histo h_with_bins(data, breaks_with_bins);
histo::Histo h_with_width(data, breaks_with_width);
```

Each histogram has public members: `bins`, `breaks`, `counts` and `range`.
We can fill the histogram with `FillCounts(data)`, called at constructor.
The data is not stored in the histogram.

We can fill the bins with more data to an existing histogram.
```cpp
vector extra_data{7.0, 13.0};
h_with_bins.FillCounts(extra_data);
```

We can also normalize the histogram to get a probability density function from it.

```cpp
histo::Histo regular_histo(data);
histo::Histo normalized_histogram = histo::NormalizeByArea(regular_histo);
```

Optionally, we can use VTK (vtkChartXY) to visualize the histogram.

```cpp
vector data{0.0, 1.0, 1.0,1.0, 2.0, 3.0, 5.0, 5.0, 8.0, 8.0, 12.0};
Histo h(data, histo::GenerateBreaksFromRangeAndBins(0.0,15.0, 5));
h.PrintBreaksAndCounts(std::cout);
h.name = "withJustData";
visualize_histo(h, vtkChart::LINE);
visualize_histo(h, vtkChart::BAR);
```

Line
Bar

# Test
All the features are tested using gtest.