Object-oriented Scientific Computing Library: Version 0.910
Public Member Functions | Data Fields | Protected Types | Protected Member Functions | Protected Attributes
hist Class Reference

A one-dimensional histogram class. More...

#include <hist.h>


Detailed Description

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.


Bin Representatives

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.


Todo:
Check that the actions of set_bins(), clear() and other functions perform the correct actions on the user_rep vector. I'm a bit concerned that set_bins_auto() shouldn't call user_rep.allocate().
Todo:
More documentation and testing.
Idea for Future:
Would be nice not to have to create a new search_vec object in get_bin_index().
Idea for Future:
Consider adding the analogs of the GSL histogram sampling functions
Idea for Future:
Add a function which computes the bin sizes?

Definition at line 94 of file hist.h.

Public Member Functions

 hist (const hist &h)
 Copy constructor.
histoperator= (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 uvectorget_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 uvectorget_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 uvectorget_reps ()
 Get a reference to the full representative vector.
const uvectorget_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.

Member Function Documentation

void hist::allocate ( size_t  n) [protected]

This function also sets all the weights to zero.

int hist::set_bins ( uniform_grid< double >  g)
Note:
If the size of the histogram uniform_grid is not equal to the current histogram size, this function requires the histogram be empty so it can reallocate the vectors for both the bins and the weights.
template<class vec_t >
int hist::set_bins ( size_t  n,
const vec_t &  v 
) [inline]
Note:
If n is not equal to the current histogram size, this function requires the histogram be empty so it can reallocate the vectors for both the bins and the weights.

Definition at line 179 of file hist.h.


The documentation for this class was generated from the following file:
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Documentation generated with Doxygen. Provided under the GNU Free Documentation License (see License Information).

Get Object-oriented Scientific Computing
Lib at SourceForge.net. Fast, secure and Free Open Source software
downloads.