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);
170 template<
class vec_t>
hist(
size_t nv,
const vec_t &v,
size_t n_bins) {
183 for(
size_t i=0;i<nv;i++) {
190 template<
class vec_t,
class vec2_t>
191 hist(
size_t nv,
const vec_t &v,
192 const vec2_t &v2,
size_t n_bins) {
205 for(
size_t i=0;i<nv;i++) {
212 template<
class vec_t>
hist(
const vec_t &v,
size_t n_bins) {
219 template<
class vec_t,
class vec2_t>
hist 220 (
const vec_t &v,
const vec2_t &v2,
size_t n_bins) {
223 hist(nv,v,v2,n_bins);
235 void from_table(
o2scl::table<> &t, std::string colx, std::string coly,
288 O2SCL_ERR2(
"Requested binning change in non-empty ",
289 "histogram in hist::set_bin_edges().",
exc_efailed);
293 for(
size_t i=0;i<n;i++) ubin[i]=v[i];
295 if (urep.size()>0) urep.clear();
303 void update(
double x,
double val=1.0);
312 const double &get_wgt_i(
size_t i)
const;
315 double &get_wgt_i(
size_t i);
319 return get_wgt_i(get_bin_index(x));
324 return get_wgt_i(get_bin_index(x));
328 void set_wgt_i(
size_t i,
double val);
332 set_wgt_i(get_bin_index(x),val);
358 size_t get_bin_index(
double x)
const;
361 double &get_bin_low_i(
size_t i);
364 const double &get_bin_low_i(
size_t i)
const;
367 double &get_bin_high_i(
size_t i);
370 const double &get_bin_high_i(
size_t i)
const;
374 return get_bin_low_i(get_bin_index(x));
379 return get_bin_low_i(get_bin_index(x));
384 return get_bin_high_i(get_bin_index(x));
389 return get_bin_high_i(get_bin_index(x));
402 double get_max_wgt()
const;
406 size_t get_max_index()
const;
410 double get_max_rep();
414 double get_min_wgt()
const;
418 size_t get_min_index()
const;
422 double get_min_rep();
438 static const size_t rmode_avg=0;
440 static const size_t rmode_user=1;
442 static const size_t rmode_low=2;
444 static const size_t rmode_high=3;
446 static const size_t rmode_gmean=4;
452 template<
class vec_t>
void set_reps(
size_t n,
const vec_t &v) {
454 std::string s=
"Expected a vector of size "+
itos(hsize)+
455 " and got a vector of size "+
itos(n)+
" in hist::set_reps().";
459 if (user_rep.size()>0) user_rep.clear();
461 for(
size_t i=0;i<n;i++) user_rep[i]=v[i];
470 void set_rep_mode(
size_t mode);
483 double get_rep_i(
size_t i);
487 return get_rep_i(get_bin_index(x));
495 for(
size_t i=0;i<hsize;i++) {
505 double operator()(
double x);
511 double deriv(
double x);
514 double deriv2(
double x);
517 double integ(
double x,
double y);
520 void set_interp_type(
size_t interp_type);
541 #if !O2SCL_NO_RANGE_CHECK 545 if (rmode==rmode_user) {
546 for(
size_t i=0;i<hsize;i++) {
552 if (urep.size()==0) set_reps_auto();
554 for(
size_t i=0;i<hsize;i++) {
565 void swap_reps(ubvector &v);
573 void normalize(
double new_sum);
576 void is_valid()
const;
587 void copy_to_table(
table<> &t, std::string reps, std::string lower_edges,
588 std::string upper_edges, std::string weights);
601 #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)
hist(const vec_t &v, size_t n_bins)
Create from vectors 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. .
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.
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 from a vectors 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.
hist(size_t nv, const vec_t &v, const vec2_t &v2, size_t n_bins)
Create from a vectors of data.
void set_bin_edges(size_t n, const vec_t &v)
Set the bins from a vector.
Interpolation class for general vectors.