#include <liarsdice/statistics/histogram.hpp>
template<typename T = double>
Histogram class
Flexible histogram template using boost::histogram.
| Template parameters | |
|---|---|
| T | Value type for the axis |
Supports various axis types and provides statistical analysis of binned data. Optimized for game analytics and AI pattern recognition.
Public types
- using value_type = T
- using axis_type = typename std::conditional_t<std::is_integral_v<T>, bh::axis::integer<T>, bh::axis::regular<T>>
-
using histogram_type = decltype(bh::make_histogram(std::declval<axis_
type>()))
Constructors, destructors, conversion operators
- Histogram(std::size_t bins, T min, T max)
- Construct histogram with regular bins.
Public functions
- void add(T value, double weight = 1.0)
- Add a value to the histogram.
-
template<typename InputIt>void add_range(InputIt first, InputIt last)
- Add multiple values.
- auto count_at(T value) const -> double
- Get bin count for a specific value.
- auto total_count() const -> double
- Get total count across all bins.
- auto bin_count() const -> std::size_t
- Get number of bins.
- auto bin_edges() const -> std::vector<T>
- Get bin edges.
- auto bin_centers() const -> std::vector<T>
- Get bin centers.
- auto bin_counts() const -> std::vector<double>
- Get bin counts.
- auto normalized() const -> std::vector<double>
- Get normalized histogram (probability density)
- auto mode() const -> std::pair<T, double>
- Find mode (bin with highest count)
- auto mean() const -> double
- Calculate mean from histogram.
- auto variance() const -> double
- Calculate variance from histogram.
- auto standard_deviation() const -> double
- Calculate standard deviation.
- auto percentile(double p) const -> T
- Calculate percentile.
- auto entropy() const -> double
- Get entropy of the distribution.
- void merge(const Histogram& other)
- Merge another histogram.
- void reset()
- Reset histogram to empty state.
-
auto get_histogram() const -> const histogram_
type& - Access underlying boost histogram.
Function documentation
template<typename T>
liarsdice:: statistics:: Histogram<T>:: Histogram(std::size_t bins,
T min,
T max)
Construct histogram with regular bins.
| Parameters | |
|---|---|
| bins | Number of bins |
| min | Minimum value |
| max | Maximum value |
template<typename T>
void liarsdice:: statistics:: Histogram<T>:: add(T value,
double weight = 1.0)
Add a value to the histogram.
| Parameters | |
|---|---|
| value | Value to add |
| weight | Optional weight (default: 1) |
template<typename T>
template<typename InputIt>
void liarsdice:: statistics:: Histogram<T>:: add_range(InputIt first,
InputIt last)
Add multiple values.
| Template parameters | |
|---|---|
| InputIt | Input iterator type |
| Parameters | |
| first | Beginning of range |
| last | End of range |
template<typename T>
double liarsdice:: statistics:: Histogram<T>:: count_at(T value) const
Get bin count for a specific value.
| Parameters | |
|---|---|
| value | Value to query |
| Returns | Count in the bin containing value |
template<typename T>
double liarsdice:: statistics:: Histogram<T>:: total_count() const
Get total count across all bins.
| Returns | Sum of all bin counts |
|---|
template<typename T>
std::size_t liarsdice:: statistics:: Histogram<T>:: bin_count() const
Get number of bins.
| Returns | Number of histogram bins |
|---|
template<typename T>
std::vector<T> liarsdice:: statistics:: Histogram<T>:: bin_edges() const
Get bin edges.
| Returns | Vector of bin edge values |
|---|
template<typename T>
std::vector<T> liarsdice:: statistics:: Histogram<T>:: bin_centers() const
Get bin centers.
| Returns | Vector of bin center values |
|---|
template<typename T>
std::vector<double> liarsdice:: statistics:: Histogram<T>:: bin_counts() const
Get bin counts.
| Returns | Vector of counts for each bin |
|---|
template<typename T>
std::vector<double> liarsdice:: statistics:: Histogram<T>:: normalized() const
Get normalized histogram (probability density)
| Returns | Vector of normalized bin values |
|---|
template<typename T>
std::pair<T, double> liarsdice:: statistics:: Histogram<T>:: mode() const
Find mode (bin with highest count)
| Returns | Pair of (bin_center, count) |
|---|
template<typename T>
double liarsdice:: statistics:: Histogram<T>:: mean() const
Calculate mean from histogram.
| Returns | Weighted mean of bin centers |
|---|
template<typename T>
double liarsdice:: statistics:: Histogram<T>:: variance() const
Calculate variance from histogram.
| Returns | Variance of the distribution |
|---|
template<typename T>
double liarsdice:: statistics:: Histogram<T>:: standard_deviation() const
Calculate standard deviation.
| Returns | Standard deviation |
|---|
template<typename T>
T liarsdice:: statistics:: Histogram<T>:: percentile(double p) const
Calculate percentile.
| Parameters | |
|---|---|
| p | Percentile (0-100) |
| Returns | Value at percentile |
template<typename T>
double liarsdice:: statistics:: Histogram<T>:: entropy() const
Get entropy of the distribution.
| Returns | Shannon entropy |
|---|
template<typename T>
const histogram_ type& liarsdice:: statistics:: Histogram<T>:: get_histogram() const
Access underlying boost histogram.
| Returns | Reference to boost histogram |
|---|