14 #ifndef INCLUDED_numeric_util_hh 
   15 #define INCLUDED_numeric_util_hh 
   29 template<
typename Number>
 
   30 Number 
clamp(Number 
value, Number lower_bound, Number upper_bound) {
 
   31   if ( value < lower_bound ) {
 
   33   } 
else if ( upper_bound < value ) {
 
   41 inline double log(
double x, 
double base) {
 
   42   return std::log10(x) / std::log10(base);
 
   46 template < 
typename T >
 
   48   return value != 
value;
 
   51 template < 
typename T >
 
   53   return std::numeric_limits< T >::has_infinity &&
 
   54     value == std::numeric_limits< T >::infinity();
 
   70     value1 <= value2 + epsilon &&
 
   71     value1 >= value2 - epsilon
 
   81 template < 
typename T >
 
   83   assert(values.size());
 
   86     retval = 
max(retval, values[
ii]);
 
   91 template < 
typename T >
 
   93   assert(values.size());
 
   96     retval = 
min(retval, values[
ii]);
 
  107   Real const score_before,
 
  108   Real const score_after,
 
  109   Real const temperature
 
  111   Real const boltz_factor( ( score_before - score_after ) / temperature );
 
  112   Real const probability (
 
  120 template < 
typename T >
 
  124   if ( (max_index - min_index) == 1 ) {
 
  126     T max_distance = 
std::abs(input_list[max_index] - key);
 
  127     T min_distance = 
std::abs(input_list[min_index] - key);
 
  128     if ( max_distance < min_distance ) {
 
  129       return input_list[max_index];
 
  131       return input_list[min_index];
 
  137   if ( input_list[mid_index] > key ) {
 
  138     return find_nearest_value<T>(input_list,
key,min_index,mid_index-1);
 
  139   } 
else if ( input_list[mid_index] < key ) {
 
  140     return find_nearest_value<T>(input_list,
key,mid_index+1, max_index);
 
  142     return input_list[mid_index];
 
  148 template < 
typename T >
 
  152   std::sort(temp_list.begin(),temp_list.end());
 
  157   return find_nearest_value<T>(temp_list,
key,initial_minimum,initial_maximum);
 
bool isnan(T value)
portable check to see if a value is NaN. 
Real boltzmann_accept_probability(Real const score_before, Real const score_after, Real const temperature)
Calculates the acceptance probability of a given score-change at the given temperature, generally used in simulated annealing algorithms. Returns a value in the range (0-1). 
bool equal_by_epsilon(numeric::Real value1, numeric::Real value2, numeric::Real epsilon)
are two Real values are equal up to some epsilon 
numeric::Real median(utility::vector1< numeric::Real > const &values)
Returns the median from a vector1 of Real values. 
double log(double x, double base)
Computes log(x) in the given base. 
numeric::Real mean(utility::vector1< numeric::Real > const &values)
short int min(short int const a, short int const b)
min( short int, short int ) 
short int max(short int const a, short int const b)
max( short int, short int ) 
Number clamp(Number value, Number lower_bound, Number upper_bound)
Clamps to the closed interval [lower_bound, upper_bound]. Templated type must implement operator<...
utility::keys::lookup::key< KeyType > const key
T abs(T const &x)
std::abs( x ) == | x | 
std::vector with 1-based indexing 
rosetta project type declarations. Should be kept updated with core/types.hh. This exists because num...
vector1: std::vector with 1-based indexing 
T find_nearest_value(typename utility::vector1< T > const &input_list, T key, platform::Size min_index, platform::Size max_index)
recursive binary search that finds the value closest to key. Call find_nearest_value(input_list,value) instead. It's the driver function for this function. This fails miserably (and silently!) on a non-sorted vector, so don't do that!.