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 145 void set_reps_auto();
154 void allocate(
size_t n);
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];
329 if (urep.size()>0) urep.clear();
337 void update(
double x,
double val=1.0);
346 const double &get_wgt_i(
size_t i)
const;
349 double &get_wgt_i(
size_t i);
353 return get_wgt_i(get_bin_index(x));
358 return get_wgt_i(get_bin_index(x));
362 void set_wgt_i(
size_t i,
double val);
366 set_wgt_i(get_bin_index(x),val);
392 size_t get_bin_index(
double x)
const;
395 double &get_bin_low_i(
size_t i);
398 const double &get_bin_low_i(
size_t i)
const;
401 double &get_bin_high_i(
size_t i);
404 const double &get_bin_high_i(
size_t i)
const;
408 return get_bin_low_i(get_bin_index(x));
413 return get_bin_low_i(get_bin_index(x));
418 return get_bin_high_i(get_bin_index(x));
423 return get_bin_high_i(get_bin_index(x));
436 double get_max_wgt()
const;
440 size_t get_max_index()
const;
444 double get_max_rep();
448 double get_min_wgt()
const;
452 size_t get_min_index()
const;
456 double get_min_rep();
472 static const size_t rmode_avg=0;
474 static const size_t rmode_user=1;
476 static const size_t rmode_low=2;
478 static const size_t rmode_high=3;
480 static const size_t rmode_gmean=4;
486 template<
class vec_t>
void set_reps(
size_t n,
const vec_t &v) {
488 std::string s=
"Expected a vector of size "+
itos(hsize)+
489 " and got a vector of size "+
itos(n)+
" in hist::set_reps().";
493 if (user_rep.size()>0) user_rep.clear();
495 for(
size_t i=0;i<n;i++) user_rep[i]=v[i];
504 void set_rep_mode(
size_t mode);
517 double get_rep_i(
size_t i);
521 return get_rep_i(get_bin_index(x));
529 for(
size_t i=0;i<hsize;i++) {
539 double operator()(
double x);
545 double deriv(
double x);
548 double deriv2(
double x);
551 double integ(
double x,
double y);
554 void set_interp_type(
size_t interp_type);
576 #if !O2SCL_NO_RANGE_CHECK 580 if (rmode==rmode_user) {
581 for(
size_t i=0;i<hsize;i++) {
587 if (urep.size()==0) set_reps_auto();
589 for(
size_t i=0;i<hsize;i++) {
600 void swap_reps(ubvector &v);
608 void normalize(
double new_sum=1.0);
615 void is_valid()
const;
626 void copy_to_table(
table<> &t, std::string reps, std::string lower_edges,
627 std::string upper_edges, std::string weights);
640 #ifndef DOXYGEN_NO_O2NS Interpolation class for pre-specified vector.
interp_vec< ubvector > interp_t
Interpolation typedef.
ubvector ubin
Bin locations (N+1)
size_t size() const
The histogram size.
size_t itype
Interpolation type.
The main O<span style='position: relative; top: 0.3em; font-size: 0.8em'>2</span>scl O$_2$scl names...
size_t get_rep_mode() const
Get mode used to compute bin representatives.
size_t get_nlines() const
Return the number of lines.
void set_wgt(double x, double val)
Set contents of bin for x to value val.
invalid argument supplied by user
ubvector uwgt
Bin contents (N)
const ubvector & get_wgts() const
Get a reference to the full y vector.
bool extend_rhs
If true, allow abcissae beyond the last bin (default false)
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...
hist(const vec_t &v, size_t n_bins)
Create a histogram from a vector of data.
A one-dimensional histogram class.
ubvector urep
Bin representative values (N)
const vec_t & get_column(std::string scol) const
Returns a reference to the column named col. .
void from_table(o2scl::table<> &t, std::string colx, size_t n_bins)
Create a histogram from a column in a o2scl::table object.
bool extend_lhs
If true, allow abcissae before the first bin (default false)
const double & get_bin_high(double x) const
Get the upper edge of bin of index i.
double get_rep(double x)
Return the representative of bin containing x.
void update_i(size_t i, double val=1.0)
Increment bin with index i by value val.
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.
ubvector user_rep
User-defined representative values (N)
#define O2SCL_ERR2(d, d2, n)
Set an error, two-string version.
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.
const ubvector & get_bins() const
Get a reference to the full vector of bin specifications.
The O<span style='position: relative; top: 0.3em; font-size: 0.8em'>2</span>scl O$_2$scl namespace ...
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.
const double & operator[](size_t i) const
Get a reference to the weight for the bin at index i.
#define O2SCL_ERR(d, n)
Set an error with message d and code n.
double & get_wgt(double x)
Return contents of bin for x.
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_low(double x)
Get the lower edge of bin of index i.
double & get_bin_high(double x)
Get the upper edge of bin of index i.
size_t rmode
Representative mode.
const double & get_bin_low(double x) const
Get the lower edge of bin of index i.
void set_reps(size_t n, const vec_t &v)
Set the representative x-values for each bin.
size_t hsize
Number of bins.
void create_rep_vec(resize_vec_t &v)
Create a vector filled with the representatives for each bin.
Store data in an O<span style='position: relative; top: 0.3em; font-size: 0.8em'>2</span>scl O$_2$sc...
const double & get_wgt(double x) const
Return contents of bin for x.
double & operator[](size_t i)
Get a reference to the weight for the bin at index i.
std::string itos(int x)
Convert an integer to a string.
void hdf_input(hdf_file &hf, o2scl::table< vec_t > &t, std::string name)
Input a o2scl::table object from a hdf_file.
void set_bin_edges(size_t n, const vec_t &v)
Set the bins from a vector.
Interpolation class for general vectors.