23 #ifndef O2SCL_HIST_2D_H 24 #define O2SCL_HIST_2D_H 31 #include <boost/numeric/ublas/vector.hpp> 32 #include <boost/numeric/ublas/matrix.hpp> 34 #include <o2scl/convert_units.h> 35 #include <o2scl/interp.h> 36 #include <o2scl/uniform_grid.h> 37 #include <o2scl/table3d.h> 48 void hdf_output(hdf_file &hf,
o2scl::hist_2d &t, std::string name);
51 #ifndef DOXYGEN_NO_O2NS 149 void allocate(
size_t nx,
size_t ny);
154 void set_reps_auto();
169 template<
class vec_t,
class vec2_t>
hist_2d 170 (
size_t nv,
const vec_t &v,
const vec2_t &v2,
size_t n_bins_x,
180 double min_x, max_x, min_y, max_y;
185 set_bin_edges(ugx,ugy);
187 for(
size_t i=0;i<nv;i++) {
194 template<
class vec_t,
class vec2_t,
class vec3_t>
hist_2d 195 (
size_t nv,
const vec_t &v,
const vec2_t &v2,
const vec3_t &v3,
196 size_t n_bins_x,
size_t n_bins_y) {
205 double min_x, max_x, min_y, max_y;
210 set_bin_edges(ugx,ugy);
212 for(
size_t i=0;i<nv;i++) {
213 update(v[i],v2[i],v3[i]);
219 template<
class vec_t,
class vec2_t>
hist_2d 220 (
const vec_t &v,
const vec2_t &v2,
size_t n_bins_x,
223 hist_2d(v.size(),v,v2,n_bins_x,n_bins_y);
229 template<
class vec_t,
class vec2_t,
class vec3_t>
hist_2d 230 (
const vec_t &v,
const vec2_t &v2,
const vec3_t &v3,
size_t n_bins_x,
233 hist_2d(v.size(),v,v2,v3,n_bins_x,n_bins_y);
239 void from_table(
o2scl::table<> &t, std::string colx, std::string coly,
240 size_t n_bins_x,
size_t n_bins_y) {
247 void from_table(
o2scl::table<> &t, std::string colx, std::string coly,
248 std::string colz,
size_t n_bins_x,
size_t n_bins_y) {
285 size_t ny, vec_t &vy) {
286 if (nx!=hsize_x+1 || ny!=hsize_y+1) {
287 if (hsize_x!=0 || hsize_y!=0) {
288 O2SCL_ERR2(
"Requested binning change in non-empty ",
289 "histogram in hist_2d::set_bin_edges().",
294 for(
size_t i=0;i<nx;i++) xa[i]=vx[i];
295 for(
size_t i=0;i<ny;i++) ya[i]=vy[i];
297 if (xrep.size()>0) xrep.resize(0);
298 if (yrep.size()>0) yrep.resize(0);
306 void update_i(
size_t i,
size_t j,
double val=1.0) {
312 void update(
double x,
double y,
double val=1.0) {
314 get_bin_indices(x,y,i,j);
320 const double &get_wgt_i(
size_t i,
size_t j)
const;
323 const double &
get_wgt(
double x,
double y)
const {
325 get_bin_indices(x,y,i,j);
326 return get_wgt_i(i,j);
330 double &get_wgt_i(
size_t i,
size_t j);
335 get_bin_indices(x,y,i,j);
336 return get_wgt_i(i,j);
340 void set_wgt_i(
size_t i,
size_t j,
double val);
343 void set_wgt(
double x,
double y,
double val) {
345 get_bin_indices(x,y,i,j);
375 void get_bin_indices(
double x,
double y,
size_t &i,
size_t &j)
const;
378 size_t get_x_bin_index(
double x)
const;
381 size_t get_y_bin_index(
double y)
const;
384 double &get_x_low_i(
size_t i);
387 const double &get_x_low_i(
size_t i)
const;
390 double &get_x_high_i(
size_t i);
393 const double &get_x_high_i(
size_t i)
const;
396 double &get_y_low_i(
size_t j);
399 const double &get_y_low_i(
size_t j)
const;
402 double &get_y_high_i(
size_t j);
405 const double &get_y_high_i(
size_t j)
const;
410 static const size_t rmode_avg=0;
411 static const size_t rmode_user=1;
412 static const size_t rmode_low=2;
413 static const size_t rmode_high=3;
414 static const size_t rmode_gmean=4;
420 template<
class vec_t>
void set_reps(
size_t nx, vec_t &vx,
421 size_t ny, vec_t &vy) {
422 if (user_xrep.size()!=hsize_x || user_yrep.size()!=hsize_y) {
423 std::string s=
"Expected vectors of size "+
itos(hsize_x)+
424 ", "+
itos(hsize_y)+
" and got a vectors of size "+
itos(nx)+
425 ", "+
itos(ny)+
" in hist_2d::set_reps().";
430 if (user_xrep.size()>0) user_xrep.clear();
431 if (user_yrep.size()>0) user_yrep.clear();
432 user_xrep.resize(nx);
433 user_yrep.resize(ny);
434 for(
size_t i=0;i<nx;i++) user_xrep[i]=vx[i];
435 for(
size_t i=0;i<ny;i++) user_yrep[i]=vy[i];
440 template<
class vec_t>
void set_x_reps(
size_t nx, vec_t &vx) {
442 std::string s=
"Expected vector of size "+
itos(hsize_x)+
443 " and got a vector of size "+
itos(nx)+
" in hist_2d::set_reps().";
447 if (user_xrep.size()>0) user_xrep.clear();
448 user_xrep.resize(nx);
449 for(
size_t i=0;i<nx;i++) user_xrep[i]=vx[i];
454 template<
class vec_t>
void set_y_reps(
size_t ny, vec_t &vy) {
456 std::string s=
"Expected vector of size "+
itos(hsize_y)+
457 " and got a vector of size "+
itos(ny)+
" in hist_2d::set_reps().";
461 if (user_yrep.size()>0) user_yrep.clear();
462 user_yrep.resize(ny);
463 for(
size_t i=0;i<ny;i++) user_yrep[i]=vy[i];
468 void set_rep_mode(
size_t x_mode,
size_t y_mode);
512 if (xrmode!=rmode_user) {
513 O2SCL_ERR(
"Not user mode in hist::get_user_reps_x().",
531 if (yrmode!=rmode_user) {
532 O2SCL_ERR(
"Not user mode in hist::get_user_reps_y().",
544 double get_x_rep_i(
size_t i);
552 double get_y_rep_i(
size_t j);
567 void is_valid()
const;
571 void copy_to_table(
table3d &t, std::string xreps_name,
572 std::string yreps_name, std::string weights);
581 #ifndef DOXYGEN_NO_O2NS size_t get_y_rep_mode() const
Get mode used to compute bin reps.
size_t size_y() const
Return the histogram size of the y coordinate.
const ubvector & get_y_bins() const
Get a reference to the full vector of bin specifications.
The main O<span style='position: relative; top: 0.3em; font-size: 0.8em'>2</span>scl O$_2$scl names...
ubvector ya
Bin locations (Ny+1)
size_t get_nlines() const
Return the number of lines.
ubvector xa
Bin locations (Nx+1)
size_t size_x() const
Return the histogram size of the x coordinate.
const ubvector & get_user_reps_y() const
Get a reference to the user-specified reps for y coordinates.
const ubmatrix & get_wgts() const
Get a const reference to the full matrix of data.
void set_y_reps(size_t ny, vec_t &vy)
Set the representative y-values for each bin.
size_t hsize_y
Number of y-bins.
invalid argument supplied by user
void set_wgt(double x, double y, double val)
Set contents of bin for x to value val.
ubvector yrep
"Central" values for y-axis (N)
void set_reps(size_t nx, vec_t &vx, size_t ny, vec_t &vy)
Set the representative x-values for each bin.
A two-dimensional histogram class.
void set_x_reps(size_t nx, vec_t &vx)
Set the representative x-values for each bin.
ubmatrix & get_wgts()
Get a reference to the full matrix of data.
const vec_t & get_column(std::string scol) const
Returns a reference to the column named col. .
bool extend_lhs
If true, allow abcissa smaller than smallest bin limit to correspond to the lowest bin (default false...
const ubvector & get_x_bins() const
Get a reference to the full vector of bin specifications.
bool extend_rhs
If true, allow abcissa larger than largest bin limit to correspond to the highest bin (default false)...
ubvector xrep
"Central" values for x-axis (N)
void update(double x, double y, double val=1.0)
Increment bin for x by value val.
#define O2SCL_ERR2(d, d2, n)
Set an error, two-string version.
ubmatrix wgt
Values (Nx,Ny)
void set_bin_edges(size_t nx, vec_t &vx, size_t ny, vec_t &vy)
Set the bins from a vector.
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.
ubvector user_yrep
User-defined central values for y-axis (N)
size_t xrmode
Rep mode for x.
#define O2SCL_ERR(d, n)
Set an error with message d and code n.
const ubvector & get_user_reps_x() const
Get a reference to the user-specified reps for x coordinates.
void update_i(size_t i, size_t j, double val=1.0)
Increment bin at (i,j) by value val.
A data structure containing one or more slices of two-dimensional data points defined on a grid...
Store data in an O<span style='position: relative; top: 0.3em; font-size: 0.8em'>2</span>scl O$_2$sc...
size_t get_x_rep_mode() const
Get mode used to compute bin reps.
const double & get_wgt(double x, double y) const
Return contents of bin for x.
double & get_wgt(double x, double y)
Return contents of bin for x.
ubvector user_xrep
User-defined central values for x-axis (N)
std::string itos(int x)
Convert an integer to a string.
size_t hsize_x
Number of x-bins.
void hdf_input(hdf_file &hf, o2scl::table< vec_t > &t, std::string name)
Input a o2scl::table object from a hdf_file.
size_t yrmode
Rep mode for y.