Rosetta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Histogram.hh
Go to the documentation of this file.
1 // -*- mode:c++;tab-width:2;indent-tabs-mode:t;show-trailing-whitespace:t;rm-trailing-spaces:t -*-
2 // vi: set ts=2 noet:
3 //
4 // (c) Copyright Rosetta Commons Member Institutions.
5 // (c) This file is part of the Rosetta software suite and is made available under license.
6 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
7 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
8 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
9 
10 /// @file numeric/interpolation/Histogram.hh
11 /// @brief A class for storing histogram data
12 /// @author Spencer Bliven <blivens@u.washington.edu>
13 /// @date 1/23/09
14 
15 #ifndef INCLUDED_numeric_interpolation_Histogram_hh
16 #define INCLUDED_numeric_interpolation_Histogram_hh
17 
18 // Unit Headers
21 
22 // Project Headers
25 #include <numeric/NumericTraits.hh>
27 
28 // Utility Headers
29 #include <utility/io/izstream.hh>
30 #include <utility/vector1.hh>
31 #include <utility/exit.hh>
32 
33 #include <cmath>
34 #include <map>
35 #include <algorithm>
36 
37 namespace numeric {
38 namespace interpolation {
39 
40 using numeric::Real;
41 
42 /**
43 * @brief A histogram with fixed-width bins
44 *
45 * @details Histograms are commonly used to approximate arbitrary functions.
46 * At their most basic level they just map X values to f(X) for discrete, regularly
47 * spaced values of X. Usually you then interpolate between the stored Y values
48 * so that all values of X can be evaluated.
49 *
50 * When creating a histogram the range and bin width must be given. Several
51 * parameters can also be specified to set how the interpolation will work.
52 * After that the function can be approximated for arbitrary X values by calling
53 * interpolate(). The important parameters describing how to interpolate are:
54 *
55 * - Periodicity:
56 * - nonperiodic - Only X values within the range of the function are strictly
57 * legal. See interpolate(X,Y&) for the behavior when out of this range.
58 * - periodic - All X values are taken modulus the length of the range of
59 * the function.
60 * - Bin Placement:\n
61 * Since bins span a range of X, it is ambiguous exactly what X value the
62 * bin gives the value of. The choice for BinPlacement should depend on
63 * the source of the data for the histogram.\n
64 * If bin[x] spans a range [x1,x2],
65 * - left - bin[x] corresponds to f(x1). This is streightforward, but you
66 * tend to over-estimate f(x) for areas with positive slope and
67 * under-estimate for areas with negative slope due to the stair-step
68 * shape of the histogram
69 * - center - bin[x] corresponds to f( (x1+x2)/2 )
70 * - right - bin[x] corresponds to f(x2). Equivalent to left with bin[x+1]
71 * - Interpolator:\n
72 * Specifies the algorithm used for interpolating between bins
73 * - flat - No interpolation. Gives a discontinuous function, but faithful
74 * to the raw data.
75 * - linear - Perform linear interpolation between the two adjacent bins.
76 * .
77 * Other (unimplemented) methods give functions which have continuous
78 * derivatives, etc.
79 *
80 * Bins can be visualized as follows:
81 * w is the bin width; n is the number of bins; X_0 is the value of the first bin
82 * - left histograms go from [ X0 to (X0 + w*n) )
83 * X = X0 + 0 w 2w ... (n-1)w n*w
84 * bin number | 1 | 2 | ... | n |
85 * - center histograms go from [ (X0 - w/2) to (X0 + (n-1)w/2)) )
86 * X = X0 + -w/2 (1/2)w (3/2)w ... (n-3/2)w (n-1/2)w
87 * bin number | 1 | 2 | ... | n |
88 * - right histograms go from ( (X0 - w) to (X0 + (n-1)w) ]
89 * X = X0 + -w 0 w ... (n-2)w (n-1)w
90 * bin number | 1 | 2 | ... | n |
91 *
92 * @tparam X The range of the function. Should support the operations expected
93 * of real types. Examples: numeric::Real, float, double
94 * @tparam Y The domain of the function. Should support the operations expected
95 * of real types.
96 */
97 template<typename X, typename Y>
99 public:
103  //, right //no one actually needs this yet, but would be easy to implement
104  };
105  /// @todo It would be cool to implement the different ways of interpolating
106  /// using subclasses of Histogram rather than this enum.
111  };
112 
113  std::string
115  if ( interpolator == flat ) return "flat";
116  if ( interpolator == linear ) return "linear";
117  if ( interpolator == spline ) return "spline";
118  return "unrecognized";
119  }
120 
121 protected:
122  /**
123  * @brief Read a score function from the minirosetta_database into an array
124  *
125  * @details The scoring function should be represented as a list of Energies,
126  * one number per line. Lines begining with '\#' are ignored as comments.
127  *
128  * Files can contain parameter settings such as the range and step size.
129  * These are given by directives beginning with '\@'.
130  *
131  * @note The database files should be ASCII. Unicode is not supported.
132  */
133  static void read_from_db(std::istream & db_file, utility::vector1<Y> /*out*/& energies,
134  std::map<std::string, std::string> /*out*/& params)
135  {
136  using namespace std;
137 
138  db_file >> skipws;
139 
140  while ( ! db_file.eof() && db_file.good() ) {
141  int nextchar = db_file.peek();
142 
143  switch (nextchar) {
144  case '#' : { // Ignore comments
145  string line;
146  getline(db_file,line);
147  continue;
148  }
149  case ' ' : //ignore leading whitespace
150  case '\t':
151  case '\r':
152  case '\n' :
153  db_file.ignore();
154  continue;
155  case EOF : //error or end of file
156  if ( ! db_file.good() && ! db_file.eof() ) { // error
157  cerr << __FILE__ << ":" << __LINE__ << " [ERROR] "
158  << "IO Error" << endl;
159  }
160  db_file.ignore(); //Make progress to avoid hanging
161  break;
162  case '@' : { //parameter
163  string key, value;
164  db_file.ignore(); // '@'
165  db_file >> key >> ws;
166  getline(db_file, value);
167  params[key] = value;
168  break;
169  }
170  default : //Energies
171  Y y;
172  db_file >> y;
173  energies.push_back(y);
174  continue;
175  }
176  }
177  }
178 
179  /**
180  * @brief Set properties of this histogram from a map of strings.
181  *
182  * Input is validated before being stored. Invalid input results in a
183  * printed warning and the previous (probably default) value being used
184  * instead.
185  *
186  * Parameters currently recognised:
187  * - \@minimum <X>
188  * - \@maximum <X>
189  * - \@step <X>
190  * - \@periodic <bool>
191  * - \@bins <BinPlacement>
192  * - \@interpolator <Interpolator>
193  */
194  void set_params(std::map<std::string, std::string> const& params)
195  {
196  using namespace std;
197 
198  //the value and whether it was set by the user
199  pair<X,bool> min( minimum(), false);
200  pair<X,bool> max( maximum(), false);
201  pair<X,bool> step( step_, false);
202 
203  for ( map<string,string>::const_iterator param = params.begin();
204  param != params.end(); ++param ) {
205  string key( param->first);
206  string value(param->second);
207  //to lowercase
208  transform(key.begin(), key.end(), key.begin(), ::tolower );
209 
210  if ( "minimum" == key ) {
211  istringstream value_strm(value);
212  value_strm >> min.first;
213  if ( value_strm.fail() ) {
214  cerr << __FILE__ << ":" << __LINE__ << " [WARNING] "
215  << "Unrecognized value for @minimum: "
216  << value << endl;
217  min.second=false;
218  } else {
219  min.second=true;
220  }
221  } else if ( "maximum" == key ) {
222  istringstream value_strm(value);
223  value_strm >> max.first;
224  if ( value_strm.fail() ) {
225  cerr << __FILE__ << ":" << __LINE__ << " [WARNING] "
226  << "Unrecognized value for @maximum: "
227  << value << endl;
228  max.second = false;
229  } else {
230  max.second = true;
231  }
232  } else if ( "step" == key ) {
233  istringstream value_strm(value);
234  value_strm >> step.first;
235  if ( value_strm.fail() ) {
236  cerr << __FILE__ << ":" << __LINE__ << " [WARNING] "
237  << "Unrecognized value for @minimum: "
238  << value << endl;
239  step.second = false;
240  } else {
241  step.second = true;
242  }
243  } else if ( "periodic" == key ) {
244  //lowercase
245  transform(value.begin(), value.end(), value.begin(), ::tolower );
246  if ( "true" == value ) {
247  periodic_ = true;
248  } else if ( "false" == value ) {
249  periodic_ = false;
250  } else {
251  cerr << __FILE__ << ":" << __LINE__ << " [WARNING] "
252  << "Unrecognized value for @periodic: "
253  << value << endl;
254  }
255  } else if ( "bins" == key ) {
256  //lowercase
257  transform(value.begin(), value.end(), value.begin(), ::tolower );
258  if ( "left" == value ) {
260  } else if ( "center" == value ) {
262  } else {
263  cerr << __FILE__ << ":" << __LINE__ << " [WARNING] "
264  << "Unrecognized value for @bins: "
265  << value << endl;
266  }
267  } else if ( "interpolator" == key ) {
268  transform(value.begin(), value.end(), value.begin(), ::tolower );
269  if ( "flat" == value ) {
271  } else if ( "linear" == value ) {
273  } else if ( "spline" == value ) {
275  } else {
276  cerr << __FILE__ << ":" << __LINE__ << " [WARNING] "
277  << "Unrecognized value for @interpolator: "
278  << value << endl;
279  }
280  } else {
281  cerr << __FILE__ << ":" << __LINE__ << " [WARNING] "
282  << "Ignoring unrecognized parameter @" << key << endl;
283  }
284  }
285 
286  //Done parsing parameters.
287 
288  // Set step first
289  if ( step.second ) {
290  step_ = step.first;
291  }
292  // Next min
293  if ( min.second ) {
294  switch (bin_placement_) {
295  case left :
296  min_ = min.first;
297  break;
298  case center :
299  min_ = min.first + step_/2.0;
300  break;
301  default :
302  utility_exit_with_message("Internal Error: Unrecognized BinPlacement");
303  }
304  }
305  // Finally, validate range against max
306  if ( max.second &&
307  ! eq_tol(max.first, last_bin_right(),
310  cerr << __FILE__ << ":" << __LINE__ << " [WARNING] "
311  << "Range missmatch. Expected range of ["
312  << min_ << ", " << max.first
313  << ") but densities cover ["
314  << min_ << ", " << last_bin_right()
315  << ")." << endl;
316  }
317 
319 
320  }
321 
322 public:
323  /**
324  * @brief Initialize a histogram with the given density distribution.
325  * @param densities A vector giving the densities of each bin
326  * @param first_bin The x-value of the first bin
327  * @param step_size The width of each bin
328  * @param bin_placement Indicate what x-value the bins are mapped to:
329  * the left corner, the center of the bin, or the right corner
330  */
332  const X first_bin,
333  const X step_size,
334  const bool periodic=false,
336  const Interpolator interp=linear) :
337  densities_(densities),
338  min_(first_bin),
339  step_(step_size),
342  interpolator_(interp)
343  { }
344 
345  /// @brief Copy Constructor
346  inline Histogram( Histogram const& h) :
347  ReferenceCount(h),
349  min_(h.min_),
350  step_(h.step_),
351  periodic_(h.periodic_),
354  { }
355 
356  /**
357  * @brief Generate Histogram from a file.
358  *
359  * The parameters for the histogram (eg range, step size, etc) are read from
360  * any @param fields in the file header present, otherwise they are set to
361  * default values and can be changed after instantiation.
362  *
363  * @note See Histogram::read_from_db() for more information about the file format.
364  */
365  inline Histogram(std::istream & file) :
366  densities_(),
367  min_(0.0),
368  step_(1.0),
369  periodic_(false),
372  {
373  using namespace std;
374 
375  map<string,string> params;
376  read_from_db(file,densities_,params);
377  set_params(params);
378  }
379 
380  /// @brief destructor
381  inline ~Histogram() { }
382 
383 
384  /// @brief The densities array.
385  inline utility::vector1<Y> densities() const { return densities_; }
386  inline utility::vector1<Y> & densities() { return densities_; }
387 
388  /// @brief The x-value of the left corner of the first bin
389  inline X first_bin() const { return min_; }
390  inline X & first_bin() { return min_; }
391 
392  /// @brief The x-value of the left corner of the last bin
393  inline X last_bin() const { return X(min_ + step_*(nbins()-1) ); }
394 
395  /// @brief The x-value of the right corner of the last bin
396  inline X last_bin_right() const { return X(min_ + step_*nbins() ); }
397 
398  /// @brief Return the distance between two bins
399  inline X step_size() const { return step_; }
400  inline X & step_size() { return step_; }
401 
402  /// @brief Return whether this histogram is periodic
403  inline bool periodic() const { return periodic_; }
404  inline bool & periodic() { return periodic_; }
405 
406  /// @brief The bin placement.
407  inline BinPlacement bin_placement() const { return bin_placement_; }
409 
410  inline Interpolator interpolator() const { return interpolator_; }
411  inline Interpolator & interpolator() { return interpolator_; }
412 
415  // create spline interpolator
416  if ( interpolator_ == spline ) {
417  Real lx = minimum();
418  Real ly = densities_[1];
419  Real ldy = (densities_[2]-densities_[1])/step_;
420  Real ux = maximum();
421  Real uy = densities_[nbins()];
422  Real udy = 0.0;
423  numeric::interpolation::spline::SplineGenerator gen( lx, ly, ldy, ux, uy, udy );
424  // add values skipping minimum and maximum
425  for ( Size i = 2; i < densities_.size(); ++i ) {
426  Real modx = minimum() + (step_*(i-1));
427  Real mody = densities_[i];
428  gen.add_known_value( modx, mody );
429  }
431  }
432  }
433 
434  /// @brief The smallest value for which we can interpolate
435  /// @details All values of x where minimum()<=x<maximum() can be interpolated.
436  inline X minimum() const {
437  switch( interpolator_ ) {
438  case flat :
439  return min_;
440  case linear :
441  switch (bin_placement_) {
442  case left :
443  return min_;
444  case center :
445  return X(min_ + step_*0.5);
446  default :
447  utility_exit_with_message("Internal Error: Unrecognized BinPlacement");
448  return X(-1.);
449  }
450  case spline :
451  return min_;
452  default :
453  utility_exit_with_message("Internal Error: Unrecognized interpolation method: "+to_string(interpolator_));
454  return X(-1);
455  }
456 
457  }
458 
459  /// @brief The largest value for which we can interpolate.
460  /// @details All values of x where minimum()<=x<maximum() can be interpolated.
461  inline X maximum() const {
462  switch( interpolator_ ) {
463  case flat :
464  return min_ + step_*nbins();
465  case linear :
466  switch (bin_placement_) {
467  case left :
468  return X(min_ + step_*(nbins()-1.0) );
469  case center :
470  return X(min_ + step_*(nbins()-0.5) );
471  default :
472  utility_exit_with_message("Internal Error: Unrecognized BinPlacement");
473  return X(-1.);
474  }
475  case spline :
476  return X(min_ + step_*(nbins()-1.0) );
477  default :
478  utility_exit_with_message("Internal Error: Unrecognized interpolation method: "+to_string(interpolator_));
479  return X(-1);
480  }
481 
482  }
483 
484  /// @brief The number of bins
485  inline size_type nbins() const{
486  return densities_.size();
487  }
488 
489 
490  /**
491  * @brief Interpolates a density for a given x-value from the histogram
492  * @details Takes the periodicity and bin placement into account.
493  * @param[in] x The independant axis value to be interpolated
494  * @param[out] y An approximation of f(x), as specified by the Interpolator
495  * @return Whether the interpolated value was within the bounds or not.
496  * Periodic functions always return true.
497  */
498  inline bool interpolate(X const& x, Y & y) const {
499  switch(interpolator_) {
500  case flat :
501  return interpolate_flat(x, y);
502  case linear :
503  return interpolate_linear(x, y);
504  case spline :
505  Real dy;
506  return interpolate_spline(x, y, dy);
507  default :
508  utility_exit_with_message("Internal Error: Unrecognized interpolation method: "+to_string(interpolator_));
509  return false;
510  }
511  }
512 
513  /**
514  * @brief Interpolates a density for a given x-value from the histogram
515  * @details Takes the periodicity and bin placement into account.
516  * @param[in] x The independant axis value to be interpolated
517  * @param[out] y An approximation of f(x), as specified by the Interpolator
518  * @param[out] dy derivative of f(x). Note: only with spline interpolator for now
519  * @return Whether the interpolated value was within the bounds or not.
520  * Periodic functions always return true.
521  */
522  inline bool interpolate(X const& x, Y & y, Real & dy) const {
523  switch(interpolator_) {
524  case spline :
525  return interpolate_spline(x, y, dy);
526  default :
527  utility_exit_with_message("Internal Error: Unrecognized interpolation method: "+to_string(interpolator_));
528  return false;
529  }
530  }
531 
532 
533  /**
534  * @brief The derivative of f(x), linearly interpolated.
535  * @details For x between bins, this is just the slope of the interpolation
536  * line. For x on a bin the slope of the line to the right is used.
537  * @param[in] x The point on the independant axis for which to get the derivative
538  * @param[out] dy An approximation of df/dx, cast to a Y.
539  */
540  inline bool derivative(X const& x, Y & dy) const {
541  switch(interpolator_) {
542  case flat : // Technically 0, but we'll just linearly interpolate
543  case linear :
544  return derivative_linear(x, dy);
545  case spline : {
546  Y y;
547  Real dY;
548  bool retval = interpolate_spline(x, y, dY);
549  dy = static_cast< Y >(dY);
550  return retval;
551  }
552  default :
553  utility_exit_with_message("Internal Error: Unrecognized interpolation method: "+to_string(interpolator_));
554  return false;
555  }
556  }
557 
558  inline bool interpolate_spline(X const& x, Y &y, Real &dy) const {
559  spline_interpolator_->interpolate( x, y, dy );
560  return true;
561  }
562 
563 protected: // Interpolation methods
564 
565  /**
566  * @brief get the number of the bin to the left of X.
567  *
568  * @details Takes periodicity and bin alignment into account.
569  * A periodic histogram will always return a number in [1,nbins]
570  * A nonperiodic histogram makes no guarentees that its return value will
571  * fall within the allowed bounds of 1 through nbins.
572  * <i>You should do bounds checking elsewhere to assert that x is within the
573  * allowed range.</i>
574  *
575  * @param x[in] The independent axis value
576  * @param a[out] The alpha fraction: (x-x_l)/(x_u-x_l) for bin [x_l,x_u]
577  *
578  * @precondition x is in the domain of the histogram. For nonperiodic histograms,
579  * this means minimum() <= x < maximum()
580  *
581  * @return The index of bin x_l
582  */
583  inline platform::SSize bin_number(X const& x, X & a) const{
584  X const x_normalized(numeric::modulo( (x-first_bin())/step_, X(nbins()) )); //Real [0, nbins)
585 
586  const platform::SSize bin( static_cast<platform::SSize>( std::floor(x_normalized) )); //int [0,nbins-1]
587  a = x_normalized - bin;
588  return bin+1;
589  }
590 
591  /**
592  * @brief Returns the density of the bin which x belongs to
593  * @details If x is outside of the range of bins, returns zero.
594  */
595  inline bool interpolate_flat(X const& x, Y &y) const {
596  //check bounds
597  if ( !periodic_ ) {
598  if ( minimum() > x ) { //too small; take the minimum
599  y = densities_[1];
600  return false;
601  }
602  if ( x >= maximum() ) { //too big; take the maximum
603  y = densities_[nbins()];
604  return false;
605  }
606  }
607 
608  X alpha; //ignored
609  platform::SSize bin = bin_number(x, alpha);
610  y = densities_[bin];
611  //check bounds
612  return true;
613  }
614 
615  inline bool interpolate_linear(X const& x, Y &y) const {
616  //check bounds
617  if ( !periodic_ ) {
618  if ( minimum() > x ) { //too small; take the minimum
619  y = densities_[1];
620  return false;
621  }
622  if ( x >= maximum() ) { //too big; take the maximum
623  y = densities_[nbins()];
624  return false;
625  }
626  }
627 
628  X alpha(0); //(x-x_l)/(x_u-x_l)
629  size_type lower(0), upper(0);
630  switch( bin_placement_ ) {
631  case left :
632  lower = static_cast<size_type>(bin_number(x, alpha));
633  break;
634  case center :
635  lower = static_cast<size_type>(bin_number(x-step_*0.5, alpha));
636  break;
637  default :
638  utility_exit_with_message("Internal Error: Unrecognized interpolation method: "+to_string(interpolator_));
639  }
640  // lower is [1,nbins]
641  upper = ( lower == nbins())?1:lower+1; //wrap around periodic values
642 
644 
645  return true;
646  }
647 
648  /**
649  * @brief The derivative of f(x), linearly interpolated.
650  * @details For x between bins, this is just the slope of the interpolation
651  * line. For x on a bin the slope of the line to the right is used.
652  *
653  * Note that the derivative will not be continuous when calculated in this way.
654  */
655  inline bool derivative_linear(X const& x, Y & y) const {
656  //check bounds
657  if ( !periodic_ ) {
658  if ( minimum() > x || x >= maximum() ) { //too big; take the maximum
659  y = Y(0); //Consistant with interpolate's return value here
660  return false;
661  }
662  }
663 
664  X alpha(0); //(x-x_l)/(x_u-x_l)
665  size_type lower(0), upper(0);
666  switch( bin_placement_ ) {
667  case left :
668  lower = static_cast<size_type>(bin_number(x, alpha));
669  break;
670  case center :
671  lower = static_cast<size_type>(bin_number(x-step_*0.5, alpha));
672  break;
673  default :
674  utility_exit_with_message("Internal Error: Unrecognized interpolation method: "+to_string(interpolator_));
675  }
676  // lower is [1,nbins]
677  upper = ( lower == nbins())?1:lower+1; //wrap around periodic values
678 
679  y = Y((densities_[upper]-densities_[lower])/step_);
680  return true;
681  }
682 
683 protected:
685  /// @brief the x value of densities_[0]. Not actually the minimum for BinPlacement other than left.
688  bool periodic_;
691  utility::pointer::shared_ptr< numeric::interpolation::spline::Interpolator > spline_interpolator_;
692 #ifdef SERIALIZATION
693 public:
694  Histogram() {}
695 #endif
696 
697 }; //Histogram
698 
699 } //interpolation
700 } //numeric
701 #endif //INCLUDED_numeric_Histogram_HH
size_type nbins() const
The number of bins.
Definition: Histogram.hh:485
ocstream cerr(std::cerr)
Wrapper around std::cerr.
Definition: ocstream.hh:290
static void read_from_db(std::istream &db_file, utility::vector1< Y > &energies, std::map< std::string, std::string > &params)
Read a score function from the minirosetta_database into an array.
Definition: Histogram.hh:133
#define utility_exit_with_message(m)
Exit with file + line + message.
Definition: exit.hh:47
Numeric type traits.
Histogram(std::istream &file)
Generate Histogram from a file.
Definition: Histogram.hh:365
utility::keys::lookup::gen< KeyType > const gen
X maximum() const
The largest value for which we can interpolate.
Definition: Histogram.hh:461
utility::vector1< Y > densities_
Definition: Histogram.hh:684
X last_bin() const
The x-value of the left corner of the last bin.
Definition: Histogram.hh:393
Histogram(Histogram const &h)
Copy Constructor.
Definition: Histogram.hh:346
utility::keys::KeyLookup< KeyType >::const_iterator const_iterator
Key collection iterators.
ReferenceCount base class – dispatch class.
bool derivative(X const &x, Y &dy) const
The derivative of f(x), linearly interpolated.
Definition: Histogram.hh:540
std::string X(int const w)
Blank string.
Definition: format.cc:263
bool eq_tol(T const &x, T const &y, T const &r_tol, T const &a_tol)
Equal within specified relative and absolute tolerances?
std::istream & getline(std::istream &stream, Fstring &s)
Get Line from Stream.
Definition: Fstring.cc:1610
bool periodic() const
Return whether this histogram is periodic.
Definition: Histogram.hh:403
NumericTraits: Numeric type traits.
def x
std::ssize_t SSize
Definition: types.hh:38
A histogram with fixed-width bins.
Interpolation functions.
Interpolator interpolator() const
Definition: Histogram.hh:410
BinPlacement bin_placement() const
The bin placement.
Definition: Histogram.hh:407
void set_params(std::map< std::string, std::string > const &params)
Set properties of this histogram from a map of strings.
Definition: Histogram.hh:194
platform::SSize bin_number(X const &x, X &a) const
get the number of the bin to the left of X.
Definition: Histogram.hh:583
F interpolated(X const &x, X const &x1, X const &x2, F const &f1, F const &f2)
Linearly interpolated value: f( x )
Histogram(utility::vector1< Y > const &densities, const X first_bin, const X step_size, const bool periodic=false, const BinPlacement bin_placement=left, const Interpolator interp=linear)
Initialize a histogram with the given density distribution.
Definition: Histogram.hh:331
T modulo(T const &x, T const &y)
x(mod y) mathematical modulo returning magnitude < | y | and sign of y
Base class for reference-counted polymorphic classes.
short int min(short int const a, short int const b)
min( short int, short int )
member1 value
Definition: Tag.cc:296
std::string to_string(Interpolator const &interpolator) const
Definition: Histogram.hh:114
short int max(short int const a, short int const b)
max( short int, short int )
Program exit functions and macros.
X min_
the x value of densities_[0]. Not actually the minimum for BinPlacement other than left...
Definition: Histogram.hh:686
utility::pointer::shared_ptr< numeric::interpolation::spline::Interpolator > spline_interpolator_
Definition: Histogram.hh:691
utility::keys::lookup::key< KeyType > const key
platform::SSize bin(X const &x, X const &w, platform::SSize const n)
Periodic interpolation bin number of a value.
X last_bin_right() const
The x-value of the right corner of the last bin.
Definition: Histogram.hh:396
Input file stream wrapper for uncompressed and compressed files.
bool interpolate(X const &x, Y &y) const
Interpolates a density for a given x-value from the histogram.
Definition: Histogram.hh:498
X minimum() const
The smallest value for which we can interpolate.
Definition: Histogram.hh:436
X first_bin() const
The x-value of the left corner of the first bin.
Definition: Histogram.hh:389
bool derivative_linear(X const &x, Y &y) const
The derivative of f(x), linearly interpolated.
Definition: Histogram.hh:655
double Real
Definition: types.hh:39
utility::vector1< Y > densities() const
The densities array.
Definition: Histogram.hh:385
static char * line
Definition: Svm.cc:2683
void set_interpolator(Interpolator interpolator)
Definition: Histogram.hh:413
ReferenceCount()
Default constructor.
vector1: std::vector with 1-based indexing
Numeric functions.
bool interpolate(X const &x, Y &y, Real &dy) const
Interpolates a density for a given x-value from the histogram.
Definition: Histogram.hh:522
bool interpolate_linear(X const &x, Y &y) const
Definition: Histogram.hh:615
utility::vector1< Y > & densities()
Definition: Histogram.hh:386
X step_size() const
Return the distance between two bins.
Definition: Histogram.hh:399
bool interpolate_flat(X const &x, Y &y) const
Returns the density of the bin which x belongs to.
Definition: Histogram.hh:595
def y
bool interpolate_spline(X const &x, Y &y, Real &dy) const
Definition: Histogram.hh:558