See discussion in the User's guide in the Histograms section.
One may set the histogram bins using set_bin_edges() or one may manually set the limit of one bin using the reference returned by get_bin_low(), get_bin_low_i(), get_bin_high(), or get_bin_high_i(). Note that if one attempts to set the bins on a histogram where the bins have already been set, one must ensure that the new and old bin sets have the same size. This ensures that there is no ambiguity in rebinning the data and also prevents accidental data loss. One may set the bin edges either with a generic vector, or as a uniform_grid object.
To save space, representative vectors are not allocated until they are used.
- Note
- In order to ensure the histogram does not employ user-specified representative values that are not defined, the function set_rep_mode() does not allow one to change the mode to rmode_user directly. Instead, use set_reps() which automatically sets the mode to rmode_user and allows the user to specify the representatives.
-
If the user changes the bin edges and the histogram is in mode rmode_user, the bin weights will not be modified and the same representative values will be assumed for the new bin edges.
- Todo:
Check implementation of hist::extend_lhs
.
More testing.
- Idea for Future:
- Add a counter which counts the number of calls to update()?
- Add conversions back and forth from GSL histograms
- Create extend_lhs too?
- Would be nice not to have to create a new o2scl::search_vec object in o2scl::hist::get_bin_index() (make a search_vec data member?)
- Consider adding the analogs of the GSL histogram sampling functions (separate class?)
- Add a function which computes the bin sizes?
- Allow rebinning?
- Add histograms of float and integer values
- Allow addition and other operations for two histograms.
- Make the interpolation functions
const
(this is a bit complicated because of o2scl::hist::set_reps_auto() ).
Internally, none of the vectors should have memory allocated for them when hsize is zero, and the vector sizes should match the histogram size. These and other checks are performed by is_valid() . Also, the function set_reps_auto() should not be called when mode is rmode_user.
Definition at line 113 of file hist.h.
|
| hist () |
| Create an empty histogram.
|
|
| hist (const hist &h) |
| Copy constructor.
|
|
hist & | operator= (const hist &h) |
| Copy constructor.
|
|
template<class vec_t > |
| hist (size_t nv, const vec_t &v, size_t n_bins) |
| Create a histogram from the first nv entries in a vector of data. More...
|
|
template<class vec_t , class vec2_t > |
| hist (size_t nv, const vec_t &v, const vec2_t &w, size_t n_bins) |
| Create a histogram from the first nv entries in a vector of data and a vector of weights. More...
|
|
template<class vec_t > |
| hist (const vec_t &v, size_t n_bins) |
| Create a histogram from a vector of data. More...
|
|
template<class vec_t , class vec2_t > |
| hist (const vec_t &v, const vec2_t &w, size_t n_bins) |
| Create a histogram from a vector of data and a vector of weights. More...
|
|
void | from_table (o2scl::table<> &t, std::string colx, size_t n_bins) |
| Create a histogram from a column in a o2scl::table object. More...
|
|
void | from_table (o2scl::table<> &t, std::string colx, std::string coly, size_t n_bins) |
| Create a histogram from a column of data and a column of weights in a o2scl::table object. More...
|
|
size_t | size () const |
| The histogram size.
|
|
|
void | set_bin_edges (uniform_grid< double > g) |
| Set bins from a uniform_grid object. More...
|
|
template<class vec_t > |
void | set_bin_edges (size_t n, const vec_t &v) |
| Set the bins from a vector. More...
|
|
|
void | update (double x, double val=1.0) |
| Increment bin for x by value val .
|
|
void | update_i (size_t i, double val=1.0) |
| Increment bin with index i by value val .
|
|
const double & | get_wgt_i (size_t i) const |
| Return contents of bin with index i .
|
|
double & | get_wgt_i (size_t i) |
| Return contents of bin with index i .
|
|
const double & | get_wgt (double x) const |
| Return contents of bin for x .
|
|
double & | get_wgt (double x) |
| Return contents of bin for x .
|
|
void | set_wgt_i (size_t i, double val) |
| Set contents of bin with index i to value val .
|
|
void | set_wgt (double x, double val) |
| Set contents of bin for x to value val .
|
|
const ubvector & | get_wgts () const |
| Get a reference to the full y vector.
|
|
const double & | operator[] (size_t i) const |
| Get a reference to the weight for the bin at index i .
|
|
double & | operator[] (size_t i) |
| Get a reference to the weight for the bin at index i .
|
|
|
size_t | get_bin_index (double x) const |
| Get the index of the bin which holds x . More...
|
|
double & | get_bin_low_i (size_t i) |
| Get the lower edge of bin of index i .
|
|
const double & | get_bin_low_i (size_t i) const |
| Get the lower edge of bin of index i .
|
|
double & | get_bin_high_i (size_t i) |
| Get the upper edge of bin of index i .
|
|
const double & | get_bin_high_i (size_t i) const |
| Get the upper edge of bin of index i .
|
|
double & | get_bin_low (double x) |
| Get the lower edge of bin of index i .
|
|
const double & | get_bin_low (double x) const |
| Get the lower edge of bin of index i .
|
|
double & | get_bin_high (double x) |
| Get the upper edge of bin of index i .
|
|
const double & | get_bin_high (double x) const |
| Get the upper edge of bin of index i .
|
|
const ubvector & | get_bins () const |
| Get a reference to the full vector of bin specifications.
|
|
int | function (std::string func) |
| Apply a function. More...
|
|
|
double | get_max_wgt () const |
| Get maximum weight.
|
|
size_t | get_max_index () const |
| Get the bin index of the maximum weight.
|
|
double | get_max_rep () |
| Get the representative for the bin with maximum weight.
|
|
double | get_min_wgt () const |
| Get minimum weight.
|
|
size_t | get_min_index () const |
| Get the bin index of the minimum weight.
|
|
double | get_min_rep () |
| Get the representative for the bin with minimum weight.
|
|
|
void | clear_wgts () |
| Clear the data, but leave the bins as is.
|
|
void | clear () |
| Clear the entire histogram.
|
|
|
template<class vec_t > |
void | set_reps (size_t n, const vec_t &v) |
| Set the representative x-values for each bin.
|
|
void | set_rep_mode (size_t mode) |
| Set mode used to compute bin representatives. More...
|
|
size_t | get_rep_mode () const |
| Get mode used to compute bin representatives.
|
|
double | get_rep_i (size_t i) |
| Return the representative of bin of index i . More...
|
|
double | get_rep (double x) |
| Return the representative of bin containing x .
|
|
template<class resize_vec_t > |
void | create_rep_vec (resize_vec_t &v) |
| Create a vector filled with the representatives for each bin. More...
|
|
|
double | operator() (double x) |
| Return the value of the function at x .
|
|
double | interp (double x) |
| Return the value of the function at x .
|
|
double | deriv (double x) |
| Return the derivative of the function at x .
|
|
double | deriv2 (double x) |
| Return the second derivative of the function at x .
|
|
double | integ (double x, double y) |
| Return the integral of the function between x and y .
|
|
void | set_interp_type (size_t interp_type) |
| Set the interpolation type.
|
|