40 #include <boost/random/mersenne_twister.hpp> 41 #include <boost/random/uniform_int.hpp> 89 return min <= value && value <= max;
106 return (ceil(x / pow(10.0, decPow))) * pow(10.0, decPow);
122 return (floor(0.5 + x / pow(10.0, decPow))) * pow(10.0, decPow);
124 return -((floor(0.5 + fabs(x) / pow(10.0, decPow))) * pow(10.0, decPow));
134 return left2 + (x - left1) * (right2 - left2) / (right1 - left1);
158 return pow(10, x) - 1;
176 template <
typename T>
181 return T(floor(x + T(0.5)));
185 return T(ceil(x - T(0.5)));
196 return std::fabs(a - b) <= tol;
207 template <
typename T>
232 template <
typename T>
233 T
gcd(T a, T b, T & u1, T & u2)
271 template <
typename T>
274 return (mz_obs - mz_ref) / mz_ref * 1e6;
286 template <
typename T>
289 return std::fabs(
getPPM(mz_obs, mz_ref));
301 template <
typename T>
304 return (ppm / 1e6) * mz_ref;
316 template <
typename T>
319 return std::fabs(
ppmToMass(ppm, mz_ref));
335 inline static std::pair<double, double>
getTolWindow(
double val,
double tol,
bool ppm)
341 left = val - val * tol * 1e-6;
342 right = val / (1.0 - tol * 1e-6);
350 return std::make_pair(left, right);
356 template <
typename T1>
typename T1::value_type
quantile(
const T1 &x,
double q)
359 "Quantile requested from empty container.");
363 const auto n = x.size();
364 const auto id = std::max(0., n * q - 1);
365 const auto lo = floor(
id);
366 const auto hi = ceil(
id);
367 const auto qs = x[lo];
368 const auto h = (
id - lo);
370 return (1.0 -
h) * qs +
h * x[hi];
378 rng_(boost::mt19937_64(seed))
389 template <
class RandomAccessIterator>
392 for (
auto i = (last-first)-1; i > 0; --i)
394 boost::uniform_int<decltype(i)> d(0, i);
395 std::swap(first[i], first[d(rng_)]);
bool isOdd(UInt x)
Returns true if the given integer is odd.
Definition: MathFunctions.h:166
static std::pair< double, double > getTolWindow(double val, double tol, bool ppm)
Return tolerance window around val given tolerance tol.
Definition: MathFunctions.h:335
unsigned int UInt
Unsigned integer type.
Definition: Types.h:94
T getPPM(T mz_obs, T mz_ref)
Compute parts-per-million of two m/z values.
Definition: MathFunctions.h:272
const double c
Definition: Constants.h:209
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
static double intervalTransformation(double x, double left1, double right1, double left2, double right2)
transforms point x of interval [left1,right1] into interval [left2,right2]
Definition: MathFunctions.h:132
T round(T x)
Rounds the value.
Definition: MathFunctions.h:177
static double ceilDecimal(double x, int decPow)
rounds x up to the next decimal power 10 ^ decPow
Definition: MathFunctions.h:104
void portable_random_shuffle(RandomAccessIterator first, RandomAccessIterator last)
Definition: MathFunctions.h:390
T1::value_type quantile(const T1 &x, double q)
Returns the value of the q th quantile (0-1) in a sorted non-empty vector x.
Definition: MathFunctions.h:356
bool extendRange(T &min, T &max, const T &value)
Given an interval/range and a new value, extend the range to include the new value if needed...
Definition: MathFunctions.h:66
T ppmToMassAbs(T ppm, T mz_ref)
Definition: MathFunctions.h:317
T gcd(T a, T b)
Returns the greatest common divisor (gcd) of two numbers by applying the Euclidean algorithm...
Definition: MathFunctions.h:208
const double h
Definition: Constants.h:162
Exception indicating that an invalid parameter was handed over to an algorithm.
Definition: Exception.h:339
RandomShuffler(const boost::mt19937_64 &mt_rng)
Definition: MathFunctions.h:381
static bool approximatelyEqual(double a, double b, double tol)
Returns if a is approximately equal b , allowing a tolerance of tol.
Definition: MathFunctions.h:194
Definition: MathFunctions.h:374
double log2linear(double x)
Transforms a number from log10 to to linear scale. Subtracts the 1 added by linear2log(double) ...
Definition: MathFunctions.h:156
boost::mt19937_64 rng_
Definition: MathFunctions.h:388
static double roundDecimal(double x, int decPow)
rounds x to the next decimal power 10 ^ decPow
Definition: MathFunctions.h:119
double linear2log(double x)
Transforms a number from linear to log10 scale. Avoids negative logarithms by adding 1...
Definition: MathFunctions.h:144
bool contains(T value, T min, T max)
Is a value contained in [min, max] ?
Definition: MathFunctions.h:87
T getPPMAbs(T mz_obs, T mz_ref)
Compute absolute parts-per-million of two m/z values.
Definition: MathFunctions.h:287
void seed(uint64_t val)
Definition: MathFunctions.h:399
T ppmToMass(T ppm, T mz_ref)
Compute the mass diff in [Th], given a ppm value and a reference point.
Definition: MathFunctions.h:302
RandomShuffler(int seed)
Definition: MathFunctions.h:377