Histogram

class Histogram

A one-dimensional histogram. The histogram is defined by a contiguous set of “bins” which may be of constant or variable width. Each time a value is added to the histogram, the bin is found and incremented.

Arguments

  • width: constant bin width (optional)

  • max: maximum value (required)

  • min: minimum value (default: 0)

Public Functions

bool expandable() const

Depending on the way the bins are defined, the histogram may be told how to automatically expand in size if the value is outside of the current bounds. Otherwise, adding a value outside of the current bounds will result in an error.

void set_bin_size(const std::shared_ptr<Formula> bin_size)

Set the size of the bins according to a formula, where the initial bin is defined by the formula evaluated at zero. This makes the histogram expandable.

void set_width_center(const double width, const double center)

Set a constant bin width and fix the center of the initial bin. This makes the histogram expandable.

void set_width_min_max(const double width, const double min, const double max)

Same as above, but initializes histogram from min to max values.

void set_edges(const std::deque<double> edges)

Set the edges or boundaries manually. This makes the histogram not expandable.

void set_edges(const std::vector<double> edges)

Same as above, but with a vector.

void set_not_expandable()

Force the histogram not to be expandable.

const std::deque<double> &edges() const

The edges or boundaries of the contiguous set of bins.

double max() const

Return the maximum edge.

double min() const

Return the minimum edge.

int size() const

Return the number of bins.

int bin(const double value) const

Return the bin for a given value.

double center_of_bin(const int bin) const

Return the center of the bin (e.g., the average of the boundaries).

double center_of_last_bin() const

Return the center of the last bin.

void add(const double value, const bool update = true)

Update the histogram by adding a value.

param update:

If true, update histogram. Otherwise, simply initialize sizes.

const std::deque<double> &histogram() const

Return the histogram.

const std::string str() const

Return Histogram in a human-readable format.