![]() |
Object-oriented Scientific Computing Library: Version 0.910
|
A one-dimensional histogram class. More...
#include <hist.h>
Experimental.
One may set the histogram bins using set_bins() 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 binnings have the same size. This requirement is designed to help prevent accidental data loss.
The upper edge of bin i
is always equal to the lower edge of bin i+1
.
By convention, all functions which take a bin index as an argument have an extra "_i"
suffix to distinguish them from functions which take a floating-point value to be binned as their argument.
Empty histograms have zero size.
The set_bins() functions can only be used if (i) the current histogram is empty or (ii) the new number of bins is equal to the histogram size so that no reallocation is necessary.
To save space, representative vectors are not allocated until they are used.
One way to operate on a histogram as a function is to designate a particular value inside each bin which represents the coordinate associated with that bin. These "bin representative values" are automatically created and can be used by the function evaluation and interpolation functions operator(double), interp(), deriv(), integ() for some particular interpolation type. By default, these representative values are taken to be the midpoint of each bin, but this option is configurable and the representative values may be set by the user for each individual bin.
Public Member Functions | |
hist (const hist &h) | |
Copy constructor. | |
hist & | operator= (const hist &h) |
Copy constructor. | |
size_t | size () const |
The histogram size. | |
double | get_max_wgt () |
Get maximum weight. | |
size_t | get_max_index () |
Get the index of the maximum weight. | |
double | get_max_rep () |
Get the representative for the bin with maximum weight. | |
Initial bin setup | |
int | set_bins (uniform_grid< double > g) |
Set bins from a uniform_grid object. | |
template<class vec_t > | |
int | set_bins (size_t n, const vec_t &v) |
Set the bins from a vector. | |
Weight functions | |
int | update (double x, double val=1.0) |
Increment bin for x by value val . | |
int | 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 . | |
int | set_wgt_i (size_t i, double val) |
Set contents of bin with index i to value val . | |
int | set_wgt (double x, double val) |
Set contents of bin for x to value val . | |
const uvector & | 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 . | |
Bin manipulation | |
size_t | get_bin_index (double x) const |
Get the index of the bin which holds x . | |
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 uvector & | get_bins () const |
Get a reference to the full vector of bin specifications. | |
Delete functions | |
int | clear_wgts () |
Clear the data, but leave the bins as is. | |
int | clear () |
Clear the entire histogram. | |
Representative functions | |
template<class vec_t > | |
int | set_reps (size_t n, const vec_t &v) |
Set the representative x-values for each bin. | |
int | set_rep_mode (size_t mode) |
Set mode used to compute bin representatives. | |
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 . | |
double & | get_rep (double x) |
Return the representative of bin containing x . | |
const uvector & | get_reps () |
Get a reference to the full representative vector. | |
const uvector & | get_user_reps () const |
Get a reference to the full data vector. | |
Evaluation and interpolation functions | |
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 . | |
int | set_interp (base_interp_mgr< uvector_const_view > &bi1, base_interp_mgr< uvector_const_subvector > &bi2) |
Set the base interpolation objects. | |
Data Fields | |
bool | extend_rhs |
If true, allow abcissa larger than largest bin limit to correspond to the highest bin (default false) | |
Static Public Attributes | |
Rep modes (default is \c rmode_avg) | |
static const size_t | rmode_avg = 0 |
static const size_t | rmode_user = 1 |
static const size_t | rmode_low = 2 |
static const size_t | rmode_high = 3 |
static const size_t | rmode_gmean = 4 |
Protected Types | |
typedef o2scl_interp_vec < uvector_const_view > | interp_t |
Interpolation typedef. | |
Protected Member Functions | |
void | set_reps_auto () |
Set the representative array according to current rmode. | |
void | allocate (size_t n) |
Allocate vectors for a histogram of size n . | |
Protected Attributes | |
uvector | ubin |
Bin locations (N+1) | |
uvector | uwgt |
Bin contents (N) | |
uvector | urep |
Bin representative values (N) | |
uvector | user_rep |
User-defined representative values (N) | |
size_t | hsize |
Number of bins. | |
size_t | rmode |
Representative mode. | |
base_interp_mgr < uvector_const_view > * | bim1 |
A pointer to the interpolation manager. | |
base_interp_mgr < uvector_const_subvector > * | bim2 |
A pointer to the subvector interpolation manager. | |
def_interp_mgr < uvector_const_view, cspline_interp > | dim1 |
Default interpolation manager. | |
def_interp_mgr < uvector_const_subvector, cspline_interp > | dim2 |
Default interpolation manager. |
void hist::allocate | ( | size_t | n | ) | [protected] |
This function also sets all the weights to zero.
int hist::set_bins | ( | uniform_grid< double > | g | ) |
int hist::set_bins | ( | size_t | n, |
const vec_t & | v | ||
) | [inline] |
Documentation generated with Doxygen. Provided under the GNU Free Documentation License (see License Information).