Go to the documentation of this file.
31 #include <boost/numeric/ublas/vector.hpp>
33 #include <o2scl/convert_units.h>
34 #include <o2scl/interp.h>
35 #include <o2scl/uniform_grid.h>
36 #include <o2scl/table.h>
47 void hdf_output(hdf_file &hf,
o2scl::hist &t, std::string name);
50 #ifndef DOXYGEN_NO_O2NS
178 template<
class vec_t>
hist(
size_t nv,
const vec_t &v,
size_t n_bins) {
191 for(
size_t i=0;i<nv;i++) {
206 template<
class vec_t,
class vec2_t>
207 hist(
size_t nv,
const vec_t &v,
const vec2_t &w,
size_t n_bins) {
220 for(
size_t i=0;i<nv;i++) {
234 template<
class vec_t>
hist(
const vec_t &v,
size_t n_bins) {
249 template<
class vec_t,
class vec2_t>
hist
250 (
const vec_t &v,
const vec2_t &w,
size_t n_bins) {
322 O2SCL_ERR2(
"Requested binning change in non-empty ",
323 "histogram in hist::set_bin_edges().",
exc_efailed);
327 for(
size_t i=0;i<n;i++)
ubin[i]=v[i];
337 void update(
double x,
double val=1.0);
442 int function(std::string func);
499 template<
class vec_t>
void set_reps(
size_t n,
const vec_t &v) {
501 std::string s=
"Expected a vector of size "+
itos(
hsize)+
502 " and got a vector of size "+
itos(n)+
" in hist::set_reps().";
508 for(
size_t i=0;i<n;i++)
user_rep[i]=v[i];
542 for(
size_t i=0;i<
hsize;i++) {
558 double deriv(
double x);
564 double integ(
double x,
double y);
589 #if !O2SCL_NO_RANGE_CHECK
594 for(
size_t i=0;i<
hsize;i++) {
602 for(
size_t i=0;i<
hsize;i++) {
640 std::string upper_edges, std::string weights);
653 #ifndef DOXYGEN_NO_O2NS
void set_reps_auto()
Set the representative array according to current rmode (if not in user rep mode)
A one-dimensional histogram class.
ubvector user_rep
User-defined representative values (N)
bool extend_rhs
If true, allow abcissae beyond the last bin (default false)
void copy_to_table(table<> &t, std::string reps, std::string lower_edges, std::string upper_edges, std::string weights)
Copy histogram data to a table.
void clear_wgts()
Clear the data, but leave the bins as is.
size_t get_nlines() const
Return the number of lines.
const double & get_bin_low(double x) const
Get the lower edge of bin of index i.
void set_wgt(double x, double val)
Set contents of bin for x to value val.
static const size_t rmode_user
Use user-specified representative.
double get_max_rep()
Get the representative for the bin with maximum weight.
double deriv2(double x)
Return the second derivative of the function at x.
bool extend_lhs
If true, allow abcissae before the first bin (default false)
void update_i(size_t i, double val=1.0)
Increment bin with index i by value val.
@ exc_efailed
generic failure
size_t hsize
Number of bins.
double sum_wgts()
Return the sum of all of the weights.
void swap_reps(ubvector &v)
Get the representative values for the bins and store them in vector v using std::swap .
#define O2SCL_ERR2(d, d2, n)
Set an error, two-string version.
double integ_wgts()
Return the integral under the histogram.
hist(const vec_t &v, size_t n_bins)
Create a histogram from a vector of data.
The main O<span style='position: relative; top: 0.3em; font-size: 0.8em'>2</span>scl O$_2$scl names...
double get_rep_i(size_t i)
Return the representative of bin of index i.
void clear()
Clear the entire histogram.
const ubvector & get_bins() const
Get a reference to the full vector of bin specifications.
void set_rep_mode(size_t mode)
Set mode used to compute bin representatives.
double & get_wgt(double x)
Return contents of bin for x.
static const size_t rmode_low
Use lower edge.
double interp(double x)
Return the value of the function at x.
void vector_minmax_value(size_t n, vec_t &data, data_t &min, data_t &max)
Compute the minimum and maximum of the first n elements of a vector.
void hdf_input(hdf_file &hf, o2scl::table< vec_t > &t, std::string name)
Input a o2scl::table object from a hdf_file.
const double & get_bin_high(double x) const
Get the upper edge of bin of index i.
const ubvector & get_wgts() const
Get a reference to the full y vector.
Interpolation class for pre-specified vector.
void set_reps(size_t n, const vec_t &v)
Set the representative x-values for each bin.
void copy_reps(vec_t &v)
This function copies all bin representative values to the vector v, presuming that it has already bee...
double & get_bin_high_i(size_t i)
Get the upper edge of bin of index i.
size_t get_max_index() const
Get the bin index of the maximum weight.
size_t itype
Interpolation type.
@ exc_einval
invalid argument supplied by user
void set_bin_edges(uniform_grid< double > g)
Set bins from a uniform_grid object.
double get_max_wgt() const
Get maximum weight.
static const size_t rmode_high
Use upper edge.
ubvector uwgt
Bin contents (N)
size_t size() const
The histogram size.
double & operator[](size_t i)
Get a reference to the weight for the bin at index i.
const double & get_wgt(double x) const
Return contents of bin for x.
double get_min_wgt() const
Get minimum weight.
The O<span style='position: relative; top: 0.3em; font-size: 0.8em'>2</span>scl O$_2$scl namespace ...
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.
size_t get_bin_index(double x) const
Get the index of the bin which holds x.
static const size_t rmode_gmean
Use the geometric mean of the lower and upper edges.
hist()
Create an empty histogram.
const vec_t & get_column(std::string scol) const
Returns a reference to the column named col. .
std::string itos(int x)
Convert an integer to a string.
interp_vec< ubvector > interp_t
Interpolation typedef.
void set_interp_type(size_t interp_type)
Set the interpolation type.
double & get_bin_low_i(size_t i)
Get the lower edge of bin of index i.
size_t get_rep_mode() const
Get mode used to compute bin representatives.
size_t get_min_index() const
Get the bin index of the minimum weight.
Store data in an O<span style='position: relative; top: 0.3em; font-size: 0.8em'>2</span>scl O$_2$sc...
double integ(double x, double y)
Return the integral of the function between x and y.
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.
void normalize(double new_sum=1.0)
Renormalize the weights to fix the integral.
void create_rep_vec(resize_vec_t &v)
Create a vector filled with the representatives for each bin.
hist & operator=(const hist &h)
Copy constructor.
#define O2SCL_ERR(d, n)
Set an error with message d and code n.
ubvector urep
Bin representative values (N)
ubvector ubin
Bin locations (N+1)
double operator()(double x)
Return the value of the function at x.
void set_bin_edges(size_t n, const vec_t &v)
Set the bins from a vector.
void set_wgt_i(size_t i, double val)
Set contents of bin with index i to value val.
double get_min_rep()
Get the representative for the bin with minimum weight.
static const size_t rmode_avg
Average lower and upper edge.
const double & operator[](size_t i) const
Get a reference to the weight for the bin at index i.
void update(double x, double val=1.0)
Increment bin for x by value val.
const double & get_wgt_i(size_t i) const
Return contents of bin with index i.
void from_table(o2scl::table<> &t, std::string colx, size_t n_bins)
Create a histogram from a column in a o2scl::table object.
double get_rep(double x)
Return the representative of bin containing x.
void is_valid() const
Internal consistency check.
size_t rmode
Representative mode.
void allocate(size_t n)
Allocate vectors for a histogram of size n.
double & get_bin_low(double x)
Get the lower edge of bin of index i.
double deriv(double x)
Return the derivative of the function at x.
double & get_bin_high(double x)
Get the upper edge of bin of index i.
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.
Documentation generated with Doxygen. Provided under the
GNU Free Documentation License (see License Information).