hist.h
Go to the documentation of this file.
1 /*
2  -------------------------------------------------------------------
3 
4  Copyright (C) 2010-2020, Andrew W. Steiner
5 
6  This file is part of O2scl.
7 
8  O2scl is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 3 of the License, or
11  (at your option) any later version.
12 
13  O2scl is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with O2scl. If not, see <http://www.gnu.org/licenses/>.
20 
21  -------------------------------------------------------------------
22 */
23 #ifndef O2SCL_HIST_H
24 #define O2SCL_HIST_H
25 
26 /** \file hist.h
27  \brief File defining \ref o2scl::hist
28 */
29 #include <iostream>
30 
31 #include <boost/numeric/ublas/vector.hpp>
32 
33 #include <o2scl/convert_units.h>
34 #include <o2scl/interp.h>
35 #include <o2scl/uniform_grid.h>
36 #include <o2scl/table.h>
37 
38 // Forward definition of the hist class for HDF I/O
39 namespace o2scl {
40  class hist;
41 }
42 
43 // Forward definition of HDF I/O to extend friendship in hist
44 namespace o2scl_hdf {
45  class hdf_file;
46  void hdf_input(hdf_file &hf, o2scl::hist &t, std::string name);
47  void hdf_output(hdf_file &hf, o2scl::hist &t, std::string name);
48 }
49 
50 #ifndef DOXYGEN_NO_O2NS
51 namespace o2scl {
52 #endif
53 
54  /** \brief A one-dimensional histogram class
55 
56  See discussion in the User's guide in the \ref hist_section
57  section.
58 
59  One may set the histogram bins using \ref set_bin_edges() or one
60  may manually set the limit of one bin using the reference
61  returned by get_bin_low(), get_bin_low_i(), get_bin_high(), or
62  get_bin_high_i(). Note that if one attempts to set the bins on a
63  histogram where the bins have already been set, one must ensure
64  that the new and old bin sets have the same size. This ensures
65  that there is no ambiguity in rebinning the data and also
66  prevents accidental data loss. One may set the bin edges
67  either with a generic vector, or as a \ref uniform_grid object.
68 
69  To save space, representative vectors are not allocated until
70  they are used.
71 
72  \note In order to ensure the histogram does not employ
73  user-specified representative values that are not defined, the
74  function \ref set_rep_mode() does not allow one to change the
75  mode to \ref rmode_user directly. Instead, use \ref set_reps()
76  which automatically sets the mode to \ref rmode_user and allows
77  the user to specify the representatives.
78 
79  \note If the user changes the bin edges and the histogram is in
80  mode \ref rmode_user, the bin weights will not be modified and
81  the same representative values will be assumed for the new bin
82  edges.
83 
84  \hline
85 
86  \todo Check implementation of <tt>hist::extend_lhs</tt>.
87  \todo More testing.
88 
89  \future
90  - Add a counter which counts the number of calls to update()?
91  - Add conversions back and forth from GSL histograms
92  - Create extend_lhs too?
93  - Would be nice not to have to create a new \ref
94  o2scl::search_vec object in \ref o2scl::hist::get_bin_index()
95  (make a search_vec data member?)
96  - Consider adding the analogs of the GSL histogram
97  sampling functions (separate class?)
98  - Add a function which computes the bin sizes?
99  - Allow rebinning?
100  - Add histograms of float and integer values
101  - Allow addition and other operations for two histograms.
102  - Make the interpolation functions \c const (this is a bit
103  complicated because of \ref o2scl::hist::set_reps_auto() ).
104 
105  \hline
106 
107  Internally, none of the vectors should have memory allocated for
108  them when hsize is zero, and the vector sizes should match the
109  histogram size. These and other checks are performed by \ref
110  is_valid() . Also, the function \ref set_reps_auto() should not
111  be called when mode is \ref rmode_user.
112  */
113  class hist {
114 
115  public:
116 
118 
119  protected:
120 
121  /// Bin locations (N+1)
123 
124  /// Bin contents (N)
126 
127  /// Bin representative values (N)
129 
130  /// User-defined representative values (N)
132 
133  /// Number of bins
134  size_t hsize;
135 
136  /// Representative mode
137  size_t rmode;
138 
139  /// Interpolation type
140  size_t itype;
141 
142  /** \brief Set the representative array according to current
143  rmode (if not in user rep mode)
144  */
145  void set_reps_auto();
146 
147  /// Interpolation typedef
149 
150  /** \brief Allocate vectors for a histogram of size \c n
151 
152  This function also sets all the weights to zero.
153  */
154  void allocate(size_t n);
155 
156  public:
157 
158  /// Create an empty histogram
159  hist();
160 
161  ~hist();
162 
163  /// Copy constructor
164  hist(const hist &h);
165 
166  /// Copy constructor
167  hist &operator=(const hist &h);
168 
169  /** \brief Create a histogram from the first \c nv entries in
170  a vector of data
171 
172  This function creates a histogram with \c n_bins equally
173  spaced bins from the minimum element to the maximum element in
174  \c v . The values of \ref extend_lhs and \ref extend_rhs are
175  set to true, so the first and last bin are guaranteed to be at
176  least 1.
177  */
178  template<class vec_t> hist(size_t nv, const vec_t &v, size_t n_bins) {
179 
180  itype=1;
182  hsize=0;
183  extend_lhs=true;
184  extend_rhs=true;
185 
186  double min, max;
187  o2scl::vector_minmax_value(nv,v,min,max);
189  set_bin_edges(ug);
190 
191  for(size_t i=0;i<nv;i++) {
192  update(v[i]);
193  }
194  return;
195  }
196 
197  /** \brief Create a histogram from the first \c nv entries in
198  a vector of data and a vector of weights
199 
200  This function creates a histogram with \c n_bins equally
201  spaced bins from the minimum element to the maximum element in
202  \c v . The values of \ref extend_lhs and \ref extend_rhs are
203  set to true, so the first and last bin are guaranteed to be at
204  least 1.
205  */
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) {
208 
209  itype=1;
211  hsize=0;
212  extend_lhs=true;
213  extend_rhs=true;
214 
215  double min, max;
216  o2scl::vector_minmax_value(nv,v,min,max);
218  set_bin_edges(ug);
219 
220  for(size_t i=0;i<nv;i++) {
221  update(v[i],w[i]);
222  }
223  return;
224  }
225 
226  /** \brief Create a histogram from a vector of data
227 
228  This function creates a histogram with \c n_bins equally
229  spaced bins from the minimum element to the maximum element in
230  \c v . The values of \ref extend_lhs and \ref extend_rhs are
231  set to true, so the first and last bin are guaranteed to be at
232  least 1.
233  */
234  template<class vec_t> hist(const vec_t &v, size_t n_bins) {
235  size_t nv=v.size();
236  hist(nv,v,n_bins);
237  return;
238  }
239 
240  /** \brief Create a histogram from a vector of data and a vector
241  of weights
242 
243  This function creates a histogram with \c n_bins equally
244  spaced bins from the minimum element to the maximum element in
245  \c v . The values of \ref extend_lhs and \ref extend_rhs are
246  set to true, so the first and last bin are guaranteed to be at
247  least 1.
248  */
249  template<class vec_t, class vec2_t> hist
250  (const vec_t &v, const vec2_t &w, size_t n_bins) {
251 
252  size_t nv=v.size();
253  hist(nv,v,w,n_bins);
254  return;
255  }
256 
257  /** \brief Create a histogram from a column in a \ref o2scl::table
258  object
259  */
260  void from_table(o2scl::table<> &t, std::string colx,
261  size_t n_bins) {
262  *this=hist(t.get_nlines(),t.get_column(colx),n_bins);
263  return;
264  }
265 
266  /** \brief Create a histogram from a column of data and a column
267  of weights in a \ref o2scl::table object
268  */
269  void from_table(o2scl::table<> &t, std::string colx, std::string coly,
270  size_t n_bins) {
271  *this=hist(t.get_nlines(),t.get_column(colx),t.get_column(coly),
272  n_bins);
273  return;
274  }
275 
276  /// The histogram size
277  size_t size() const {
278  return hsize;
279  }
280 
281  /** \brief If true, allow abcissae beyond the last bin (default false)
282 
283  If this is true, the histogram will allow data with
284  corresponding to bins larger than the largest bin (for
285  increasing bin edges) or smaller than the smallest bin (for
286  decreasing bin edges).
287  */
289 
290  /** \brief If true, allow abcissae before the first bin (default false)
291  */
293 
294  /// \name Initial bin setup
295  //@{
296  /** \brief Set bins from a \ref uniform_grid object
297 
298  If the current histogram is not empty, then the number of bins
299  reported by \ref uniform_grid<>::get_nbins() should be equal
300  to the current histogram size so that the number of bins is
301  equal and we can use the same weights.
302 
303  If either the histogram is empty, or the current
304  representative mode is not \ref rmode_user, then the
305  representative mode is automatically set to \ref rmode_avg (or
306  \ref rmode_gmean if \ref uniform_grid::is_log() returns \c
307  true ) .
308  */
310 
311  /** \brief Set the bins from a vector
312 
313  The parameter \c n is the size of the vector, equal to the
314  number of edges (always one more than the number of bins). If
315  the current histogram is not empty, then \c n should be equal
316  one larger to the size reported by \ref size() so that the
317  number of bins is equal and we can use the same weights.
318  */
319  template<class vec_t> void set_bin_edges(size_t n, const vec_t &v) {
320  if (n!=hsize+1) {
321  if (hsize!=0) {
322  O2SCL_ERR2("Requested binning change in non-empty ",
323  "histogram in hist::set_bin_edges().",exc_efailed);
324  }
325  allocate(n-1);
326  }
327  for(size_t i=0;i<n;i++) ubin[i]=v[i];
328  // Reset internal reps
329  if (urep.size()>0) urep.clear();
330  return;
331  }
332  //@}
333 
334  /// \name Weight functions
335  //@{
336  /// Increment bin for \c x by value \c val
337  void update(double x, double val=1.0);
338 
339  /// Increment bin with index \c i by value \c val
340  void update_i(size_t i, double val=1.0) {
341  uwgt[i]+=val;
342  return;
343  }
344 
345  /// Return contents of bin with index \c i
346  const double &get_wgt_i(size_t i) const;
347 
348  /// Return contents of bin with index \c i
349  double &get_wgt_i(size_t i);
350 
351  /// Return contents of bin for \c x
352  const double &get_wgt(double x) const {
353  return get_wgt_i(get_bin_index(x));
354  }
355 
356  /// Return contents of bin for \c x
357  double &get_wgt(double x) {
358  return get_wgt_i(get_bin_index(x));
359  }
360 
361  /// Set contents of bin with index \c i to value \c val
362  void set_wgt_i(size_t i, double val);
363 
364  /// Set contents of bin for \c x to value \c val
365  void set_wgt(double x, double val) {
366  set_wgt_i(get_bin_index(x),val);
367  return;
368  }
369 
370  /// Get a reference to the full y vector
371  const ubvector &get_wgts() const {
372  return uwgt;
373  }
374 
375  /// Get a reference to the weight for the bin at index \c i
376  const double &operator[](size_t i) const {
377  return uwgt[i];
378  }
379 
380  /// Get a reference to the weight for the bin at index \c i
381  double &operator[](size_t i) {
382  return uwgt[i];
383  }
384  //@}
385 
386  /// \name Bin manipulation
387  //@{
388  /** \brief Get the index of the bin which holds \c x
389 
390  Always returns a value between 0 and size() (inclusive)
391  */
392  size_t get_bin_index(double x) const;
393 
394  /// Get the lower edge of bin of index \c i
395  double &get_bin_low_i(size_t i);
396 
397  /// Get the lower edge of bin of index \c i
398  const double &get_bin_low_i(size_t i) const;
399 
400  /// Get the upper edge of bin of index \c i
401  double &get_bin_high_i(size_t i);
402 
403  /// Get the upper edge of bin of index \c i
404  const double &get_bin_high_i(size_t i) const;
405 
406  /// Get the lower edge of bin of index \c i
407  double &get_bin_low(double x) {
408  return get_bin_low_i(get_bin_index(x));
409  }
410 
411  /// Get the lower edge of bin of index \c i
412  const double &get_bin_low(double x) const {
413  return get_bin_low_i(get_bin_index(x));
414  }
415 
416  /// Get the upper edge of bin of index \c i
417  double &get_bin_high(double x) {
418  return get_bin_high_i(get_bin_index(x));
419  }
420 
421  /// Get the upper edge of bin of index \c i
422  const double &get_bin_high(double x) const {
423  return get_bin_high_i(get_bin_index(x));
424  }
425 
426  /// Get a reference to the full vector of bin specifications
427  const ubvector &get_bins() const {
428  return ubin;
429  }
430 
431  /** \brief Apply a function
432 
433  This function sets the weights equal to a function of
434  five variables:
435  - i: the bin index
436  - n: the total number of bins
437  - l: the lower edge of the bin
438  - h: the upper edge of the bin
439  - r: the bin representative value
440  - w: the original weight
441  */
442  int function(std::string func);
443  //@}
444 
445  /// \name Max and min functions
446  //@{
447  /** \brief Get maximum weight
448  */
449  double get_max_wgt() const;
450 
451  /** \brief Get the bin index of the maximum weight
452  */
453  size_t get_max_index() const;
454 
455  /** \brief Get the representative for the bin with maximum weight
456  */
457  double get_max_rep();
458 
459  /** \brief Get minimum weight
460  */
461  double get_min_wgt() const;
462 
463  /** \brief Get the bin index of the minimum weight
464  */
465  size_t get_min_index() const;
466 
467  /** \brief Get the representative for the bin with minimum weight
468  */
469  double get_min_rep();
470  //@}
471 
472  /// \name Delete functions
473  //@{
474  /// Clear the data, but leave the bins as is
475  void clear_wgts();
476 
477  /// Clear the entire histogram
478  void clear();
479  //@}
480 
481  /// \name Representative modes (default is rmode_avg)
482  // Using \c rmode_avg in documentation doesn't work.
483  //@{
484  /// Average lower and upper edge
485  static const size_t rmode_avg=0;
486  /// Use user-specified representative
487  static const size_t rmode_user=1;
488  /// Use lower edge
489  static const size_t rmode_low=2;
490  /// Use upper edge
491  static const size_t rmode_high=3;
492  /// Use the geometric mean of the lower and upper edges
493  static const size_t rmode_gmean=4;
494  //@}
495 
496  /// \name Representative functions
497  //@{
498  /// Set the representative x-values for each bin
499  template<class vec_t> void set_reps(size_t n, const vec_t &v) {
500  if (n!=hsize) {
501  std::string s="Expected a vector of size "+itos(hsize)+
502  " and got a vector of size "+itos(n)+" in hist::set_reps().";
503  O2SCL_ERR(s.c_str(),exc_einval);
504  }
506  if (user_rep.size()>0) user_rep.clear();
507  user_rep.resize(n);
508  for(size_t i=0;i<n;i++) user_rep[i]=v[i];
509  return;
510  }
511 
512  /** \brief Set mode used to compute bin representatives
513 
514  Acceptable inputs are \ref rmode_avg, \ref rmode_low,
515  \ref rmode_high, and \ref rmode_gmean .
516  */
517  void set_rep_mode(size_t mode);
518 
519  /// Get mode used to compute bin representatives
520  size_t get_rep_mode() const {
521  return rmode;
522  }
523 
524  /** \brief Return the representative of bin of index \c i
525 
526  Note that this function returns a value and not a reference.
527  This is because we can't return a reference to the internally
528  computed representatives, since they don't always exist.
529  */
530  double get_rep_i(size_t i);
531 
532  /// Return the representative of bin containing \c x
533  double get_rep(double x) {
534  return get_rep_i(get_bin_index(x));
535  }
536 
537  /** \brief Create a vector filled with the representatives for
538  each bin
539  */
540  template<class resize_vec_t> void create_rep_vec(resize_vec_t &v) {
541  v.resize(hsize);
542  for(size_t i=0;i<hsize;i++) {
543  v[i]=get_rep_i(i);
544  }
545  return;
546  }
547  //@}
548 
549  /// \name Evaluation and interpolation functions
550  //@{
551  /// Return the value of the function at \c x
552  double operator()(double x);
553 
554  /// Return the value of the function at \c x
555  double interp(double x);
556 
557  /// Return the derivative of the function at \c x
558  double deriv(double x);
559 
560  /// Return the second derivative of the function at \c x
561  double deriv2(double x);
562 
563  /// Return the integral of the function between \c x and \c y
564  double integ(double x, double y);
565 
566  /// Set the interpolation type
567  void set_interp_type(size_t interp_type);
568  //@}
569 
570  /// \name Other functions
571  //@{
572  /// Return the sum of all of the weights
573  double sum_wgts();
574 
575  /** \brief Return the integral under the histogram
576 
577  This function returns
578  \f[
579  \sum_{i=0}^{N-1} w_i ( \mathrm{high}_i - \mathrm{low}_i) \, .
580  \f]
581  where \f$ N \f$ is the size of the histogram.
582  */
583  double integ_wgts();
584 
585  /** \brief This function copies all bin representative values to
586  the vector \c v, presuming that it has already been allocated
587  */
588  template<class vec_t> void copy_reps(vec_t &v) {
589 #if !O2SCL_NO_RANGE_CHECK
590  is_valid();
591 #endif
592  // If we're in user mode, just return the user value
593  if (rmode==rmode_user) {
594  for(size_t i=0;i<hsize;i++) {
595  v[i]=user_rep[i];
596  }
597  return;
598  }
599  // Check if the internal reps are not already computed
600  if (urep.size()==0) set_reps_auto();
601  // Copy the data over
602  for(size_t i=0;i<hsize;i++) {
603  v[i]=urep[i];
604  }
605  return;
606  }
607 
608  /** \brief Get the representative values for the bins
609  and store them in vector \c v using <tt>std::swap</tt> .
610 
611  This function resizes the vector \c v if necessary.
612  */
613  void swap_reps(ubvector &v);
614 
615  /** \brief Renormalize the weights to fix the integral
616 
617  This computes the integral using \ref integ() and so the
618  action of this function depends on the interpolation type.
619  If the histogram is empty, an exception is thrown.
620  */
621  void normalize(double new_sum=1.0);
622 
623  /** \brief Internal consistency check
624 
625  This function principally checks that the sizes of
626  the internal vectors match up.
627  */
628  void is_valid() const;
629 
630  /** \brief Copy histogram data to a table
631 
632  First, if the table \c t has less rows than the histogram has
633  bins, then new rows are added to the table and values in the
634  new rows of the current columns are set to zero. Second, this
635  creates new columns in the table named \c reps, \c
636  lower_edges, \c upper_edges, and \c weights . Finally,
637  the histogram data is copied to the four new columns.
638  */
639  void copy_to_table(table<> &t, std::string reps, std::string lower_edges,
640  std::string upper_edges, std::string weights);
641  //@}
642 
643  // Allow HDF I/O function to access hist data
644  friend void o2scl_hdf::hdf_output(o2scl_hdf::hdf_file &hf, o2scl::hist &h,
645  std::string name);
646 
647  // Allow HDF I/O function to access hist data
649  std::string name);
650 
651  };
652 
653 #ifndef DOXYGEN_NO_O2NS
654 }
655 #endif
656 
657 #endif
o2scl::hist::set_reps_auto
void set_reps_auto()
Set the representative array according to current rmode (if not in user rep mode)
o2scl::hist
A one-dimensional histogram class.
Definition: hist.h:113
o2scl::hist::user_rep
ubvector user_rep
User-defined representative values (N)
Definition: hist.h:131
o2scl::hist::extend_rhs
bool extend_rhs
If true, allow abcissae beyond the last bin (default false)
Definition: hist.h:288
o2scl::hist::copy_to_table
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.
o2scl::hist::clear_wgts
void clear_wgts()
Clear the data, but leave the bins as is.
o2scl::table
Data table table class.
Definition: table.h:49
o2scl::table::get_nlines
size_t get_nlines() const
Return the number of lines.
Definition: table.h:460
o2scl::hist::get_bin_low
const double & get_bin_low(double x) const
Get the lower edge of bin of index i.
Definition: hist.h:412
o2scl::hist::set_wgt
void set_wgt(double x, double val)
Set contents of bin for x to value val.
Definition: hist.h:365
o2scl::hist::rmode_user
static const size_t rmode_user
Use user-specified representative.
Definition: hist.h:487
o2scl::hist::get_max_rep
double get_max_rep()
Get the representative for the bin with maximum weight.
boost::numeric::ublas::vector< double >
o2scl::hist::deriv2
double deriv2(double x)
Return the second derivative of the function at x.
o2scl::hist::extend_lhs
bool extend_lhs
If true, allow abcissae before the first bin (default false)
Definition: hist.h:292
o2scl::hist::update_i
void update_i(size_t i, double val=1.0)
Increment bin with index i by value val.
Definition: hist.h:340
o2scl::exc_efailed
@ exc_efailed
generic failure
Definition: err_hnd.h:61
o2scl::hist::hsize
size_t hsize
Number of bins.
Definition: hist.h:134
o2scl::hist::sum_wgts
double sum_wgts()
Return the sum of all of the weights.
o2scl::hist::swap_reps
void swap_reps(ubvector &v)
Get the representative values for the bins and store them in vector v using std::swap .
O2SCL_ERR2
#define O2SCL_ERR2(d, d2, n)
Set an error, two-string version.
Definition: err_hnd.h:281
o2scl::hist::integ_wgts
double integ_wgts()
Return the integral under the histogram.
o2scl::hist::hist
hist(const vec_t &v, size_t n_bins)
Create a histogram from a vector of data.
Definition: hist.h:234
o2scl
The main O<span style='position: relative; top: 0.3em; font-size: 0.8em'>2</span>scl O$_2$scl names...
Definition: anneal.h:42
o2scl::hist::get_rep_i
double get_rep_i(size_t i)
Return the representative of bin of index i.
o2scl::hist::clear
void clear()
Clear the entire histogram.
o2scl::hist::get_bins
const ubvector & get_bins() const
Get a reference to the full vector of bin specifications.
Definition: hist.h:427
o2scl::hist::set_rep_mode
void set_rep_mode(size_t mode)
Set mode used to compute bin representatives.
o2scl::hist::get_wgt
double & get_wgt(double x)
Return contents of bin for x.
Definition: hist.h:357
o2scl::hist::rmode_low
static const size_t rmode_low
Use lower edge.
Definition: hist.h:489
o2scl::hist::interp
double interp(double x)
Return the value of the function at x.
o2scl::vector_minmax_value
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.
Definition: vector.h:1272
o2scl_hdf::hdf_input
void hdf_input(hdf_file &hf, o2scl::table< vec_t > &t, std::string name)
Input a o2scl::table object from a hdf_file.
Definition: hdf_io.h:148
o2scl::hist::get_bin_high
const double & get_bin_high(double x) const
Get the upper edge of bin of index i.
Definition: hist.h:422
o2scl::hist::get_wgts
const ubvector & get_wgts() const
Get a reference to the full y vector.
Definition: hist.h:371
o2scl::interp_vec
Interpolation class for pre-specified vector.
Definition: interp.h:1795
o2scl::hist::set_reps
void set_reps(size_t n, const vec_t &v)
Set the representative x-values for each bin.
Definition: hist.h:499
o2scl::hist::copy_reps
void copy_reps(vec_t &v)
This function copies all bin representative values to the vector v, presuming that it has already bee...
Definition: hist.h:588
o2scl::hist::get_bin_high_i
double & get_bin_high_i(size_t i)
Get the upper edge of bin of index i.
o2scl::hist::get_max_index
size_t get_max_index() const
Get the bin index of the maximum weight.
o2scl::hist::itype
size_t itype
Interpolation type.
Definition: hist.h:140
o2scl::exc_einval
@ exc_einval
invalid argument supplied by user
Definition: err_hnd.h:59
o2scl::hist::set_bin_edges
void set_bin_edges(uniform_grid< double > g)
Set bins from a uniform_grid object.
o2scl::hist::get_max_wgt
double get_max_wgt() const
Get maximum weight.
o2scl::uniform_grid_end
Linear grid with fixed number of bins and fixed endpoint.
Definition: uniform_grid.h:333
o2scl::hist::rmode_high
static const size_t rmode_high
Use upper edge.
Definition: hist.h:491
o2scl::hist::uwgt
ubvector uwgt
Bin contents (N)
Definition: hist.h:125
o2scl::hist::size
size_t size() const
The histogram size.
Definition: hist.h:277
o2scl::hist::operator[]
double & operator[](size_t i)
Get a reference to the weight for the bin at index i.
Definition: hist.h:381
o2scl::hist::get_wgt
const double & get_wgt(double x) const
Return contents of bin for x.
Definition: hist.h:352
o2scl::hist::get_min_wgt
double get_min_wgt() const
Get minimum weight.
o2scl_hdf
The O<span style='position: relative; top: 0.3em; font-size: 0.8em'>2</span>scl O$_2$scl namespace ...
Definition: table.h:59
o2scl::uniform_grid< double >
o2scl::hist::hist
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.
Definition: hist.h:178
o2scl::hist::get_bin_index
size_t get_bin_index(double x) const
Get the index of the bin which holds x.
o2scl::hist::rmode_gmean
static const size_t rmode_gmean
Use the geometric mean of the lower and upper edges.
Definition: hist.h:493
o2scl::hist::hist
hist()
Create an empty histogram.
o2scl::table::get_column
const vec_t & get_column(std::string scol) const
Returns a reference to the column named col. .
Definition: table.h:672
o2scl::itos
std::string itos(int x)
Convert an integer to a string.
o2scl::hist::interp_t
interp_vec< ubvector > interp_t
Interpolation typedef.
Definition: hist.h:148
o2scl::hist::set_interp_type
void set_interp_type(size_t interp_type)
Set the interpolation type.
o2scl::hist::get_bin_low_i
double & get_bin_low_i(size_t i)
Get the lower edge of bin of index i.
o2scl::hist::get_rep_mode
size_t get_rep_mode() const
Get mode used to compute bin representatives.
Definition: hist.h:520
o2scl::hist::get_min_index
size_t get_min_index() const
Get the bin index of the minimum weight.
o2scl_hdf::hdf_file
Store data in an O<span style='position: relative; top: 0.3em; font-size: 0.8em'>2</span>scl O$_2$sc...
Definition: hdf_file.h:105
o2scl::hist::integ
double integ(double x, double y)
Return the integral of the function between x and y.
o2scl::hist::hist
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.
Definition: hist.h:207
o2scl::hist::normalize
void normalize(double new_sum=1.0)
Renormalize the weights to fix the integral.
o2scl::hist::create_rep_vec
void create_rep_vec(resize_vec_t &v)
Create a vector filled with the representatives for each bin.
Definition: hist.h:540
o2scl::hist::operator=
hist & operator=(const hist &h)
Copy constructor.
O2SCL_ERR
#define O2SCL_ERR(d, n)
Set an error with message d and code n.
Definition: err_hnd.h:273
o2scl::hist::urep
ubvector urep
Bin representative values (N)
Definition: hist.h:128
o2scl::hist::ubin
ubvector ubin
Bin locations (N+1)
Definition: hist.h:122
o2scl::hist::operator()
double operator()(double x)
Return the value of the function at x.
o2scl::hist::set_bin_edges
void set_bin_edges(size_t n, const vec_t &v)
Set the bins from a vector.
Definition: hist.h:319
o2scl::hist::set_wgt_i
void set_wgt_i(size_t i, double val)
Set contents of bin with index i to value val.
o2scl::hist::get_min_rep
double get_min_rep()
Get the representative for the bin with minimum weight.
o2scl::hist::rmode_avg
static const size_t rmode_avg
Average lower and upper edge.
Definition: hist.h:485
o2scl::hist::operator[]
const double & operator[](size_t i) const
Get a reference to the weight for the bin at index i.
Definition: hist.h:376
o2scl::hist::update
void update(double x, double val=1.0)
Increment bin for x by value val.
o2scl::hist::get_wgt_i
const double & get_wgt_i(size_t i) const
Return contents of bin with index i.
o2scl::hist::from_table
void from_table(o2scl::table<> &t, std::string colx, size_t n_bins)
Create a histogram from a column in a o2scl::table object.
Definition: hist.h:260
o2scl::hist::get_rep
double get_rep(double x)
Return the representative of bin containing x.
Definition: hist.h:533
o2scl::hist::is_valid
void is_valid() const
Internal consistency check.
o2scl::hist::rmode
size_t rmode
Representative mode.
Definition: hist.h:137
o2scl::hist::allocate
void allocate(size_t n)
Allocate vectors for a histogram of size n.
o2scl::hist::get_bin_low
double & get_bin_low(double x)
Get the lower edge of bin of index i.
Definition: hist.h:407
o2scl::hist::deriv
double deriv(double x)
Return the derivative of the function at x.
o2scl::hist::get_bin_high
double & get_bin_high(double x)
Get the upper edge of bin of index i.
Definition: hist.h:417
o2scl::hist::from_table
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.
Definition: hist.h:269

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