15 #ifndef INCLUDED_numeric_interpolation_Histogram_hh
16 #define INCLUDED_numeric_interpolation_Histogram_hh
38 namespace interpolation {
97 template<
typename X,
typename Y>
115 if ( interpolator ==
flat )
return "flat";
116 if ( interpolator ==
linear )
return "linear";
117 if ( interpolator ==
spline )
return "spline";
118 return "unrecognized";
134 std::map<std::string, std::string> & params)
140 while ( ! db_file.eof() && db_file.good() ) {
141 int nextchar = db_file.peek();
156 if ( ! db_file.good() && ! db_file.eof() ) {
157 cerr << __FILE__ <<
":" << __LINE__ <<
" [ERROR] "
158 <<
"IO Error" << endl;
165 db_file >> key >> ws;
173 energies.push_back(y);
194 void set_params(std::map<std::string, std::string>
const& params)
201 pair<X,bool> step(
step_,
false);
204 param != params.end(); ++param ) {
205 string key( param->first);
206 string value(param->second);
208 transform(key.begin(), key.end(), key.begin(), ::tolower );
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: "
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: "
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: "
243 }
else if (
"periodic" == key ) {
245 transform(value.begin(), value.end(), value.begin(), ::tolower );
246 if (
"true" == value ) {
248 }
else if (
"false" == value ) {
251 cerr << __FILE__ <<
":" << __LINE__ <<
" [WARNING] "
252 <<
"Unrecognized value for @periodic: "
255 }
else if (
"bins" == key ) {
257 transform(value.begin(), value.end(), value.begin(), ::tolower );
258 if (
"left" == value ) {
260 }
else if (
"center" == value ) {
263 cerr << __FILE__ <<
":" << __LINE__ <<
" [WARNING] "
264 <<
"Unrecognized value for @bins: "
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 ) {
276 cerr << __FILE__ <<
":" << __LINE__ <<
" [WARNING] "
277 <<
"Unrecognized value for @interpolator: "
281 cerr << __FILE__ <<
":" << __LINE__ <<
" [WARNING] "
282 <<
"Ignoring unrecognized parameter @" << key << endl;
310 cerr << __FILE__ <<
":" << __LINE__ <<
" [WARNING] "
311 <<
"Range missmatch. Expected range of ["
312 <<
min_ <<
", " << max.first
313 <<
") but densities cover ["
375 map<string,string> params;
549 dy =
static_cast< Y
>(dY);
587 a = x_normalized -
bin;
641 upper = ( lower ==
nbins())?1:lower+1;
677 upper = ( lower ==
nbins())?1:lower+1;
701 #endif //INCLUDED_numeric_Histogram_HH
size_type nbins() const
The number of bins.
ocstream cerr(std::cerr)
Wrapper around std::cerr.
static void read_from_db(std::istream &db_file, utility::vector1< Y > &energies, std::map< std::string, std::string > ¶ms)
Read a score function from the minirosetta_database into an array.
#define utility_exit_with_message(m)
Exit with file + line + message.
Histogram(std::istream &file)
Generate Histogram from a file.
utility::keys::lookup::gen< KeyType > const gen
X maximum() const
The largest value for which we can interpolate.
utility::vector1< Y > densities_
Interpolator interpolator_
X last_bin() const
The x-value of the left corner of the last bin.
Histogram(Histogram const &h)
Copy Constructor.
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.
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.
bool periodic() const
Return whether this histogram is periodic.
NumericTraits: Numeric type traits.
InterpolatorOP get_interpolator()
BinPlacement bin_placement_
A histogram with fixed-width bins.
Interpolator interpolator() const
BinPlacement bin_placement() const
The bin placement.
void set_params(std::map< std::string, std::string > const ¶ms)
Set properties of this histogram from a map of strings.
platform::SSize bin_number(X const &x, X &a) const
get the number of the bin to the left of X.
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.
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 )
std::string to_string(Interpolator const &interpolator) const
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...
utility::pointer::shared_ptr< numeric::interpolation::spline::Interpolator > spline_interpolator_
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.
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.
X minimum() const
The smallest value for which we can interpolate.
X first_bin() const
The x-value of the left corner of the first bin.
bool derivative_linear(X const &x, Y &y) const
The derivative of f(x), linearly interpolated.
utility::vector1< Y > densities() const
The densities array.
void set_interpolator(Interpolator interpolator)
void add_known_value(Real x, Real y)
ReferenceCount()
Default constructor.
vector1: std::vector with 1-based indexing
bool interpolate(X const &x, Y &y, Real &dy) const
Interpolates a density for a given x-value from the histogram.
bool interpolate_linear(X const &x, Y &y) const
utility::vector1< Y > & densities()
Interpolator & interpolator()
X step_size() const
Return the distance between two bins.
BinPlacement & bin_placement()
bool interpolate_flat(X const &x, Y &y) const
Returns the density of the bin which x belongs to.
bool interpolate_spline(X const &x, Y &y, Real &dy) const