MCPcopy Create free account
hub / github.com/OpenMS/OpenMS / quantile

Function quantile

src/openms/include/OpenMS/MATH/MISC/MathFunctions.h:363–378  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

361 @brief Returns the value of the @p q th quantile (0-1) in a sorted non-empty vector @p x
362 */
363 template <typename T1> typename T1::value_type quantile(const T1 &x, double q)
364 {
365 if (x.empty()) throw Exception::InvalidParameter(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION,
366 "Quantile requested from empty container.");
367 if (q < 0.0) q = 0.;
368 if (q > 1.0) q = 1.;
369
370 const auto n = x.size();
371 const auto id = std::max(0., n * q - 1); // -1 for c++ index starting at 0
372 const auto lo = floor(id);
373 const auto hi = ceil(id);
374 const auto qs = x[lo];
375 const auto h = (id - lo);
376
377 return (1.0 - h) * qs + h * x[hi];
378 }
379
380 // portable random shuffle
381 class OPENMS_DLLAPI RandomShuffler

Callers 2

run_Method · 0.85
computeGoodness_Method · 0.85

Calls 2

emptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected