MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ quantile()

MAYAFLUX_API double MayaFlux::Kinesis::Discrete::quantile ( std::span< const double >  window,
std::span< const double >  coefs 
)

Quantile of the whole window, interpolating between ranks.

The per-call counterpart of Discrete::percentile, which is the batch form over every window of a buffer and takes percent.

coefs[0] is the quantile in [0, 1], 0.5 when the array is empty: 0 is the minimum, 1 the maximum. Uses a per-thread scratch vector, so it allocates only the first time a window of a new size is seen.

Definition at line 413 of file Kernels.cpp.

414{
415 const size_t n = window.size();
416 if (n == 0)
417 return 0.0;
418
419 thread_local std::vector<double> scratch;
420 scratch.assign(window.begin(), window.end());
421
422 const double q = std::clamp(coefs.empty() ? 0.5 : coefs.front(), 0.0, 1.0);
423 const double position = q * static_cast<double>(n - 1);
424 const auto lower = static_cast<size_t>(position);
425 const double fraction = position - static_cast<double>(lower);
426
427 const auto nth = scratch.begin() + static_cast<std::ptrdiff_t>(lower);
428 std::nth_element(scratch.begin(), nth, scratch.end());
429 const double low = *nth;
430
431 if (fraction <= 0.0 || lower + 1 >= n)
432 return low;
433
434 const double high = *std::min_element(nth + 1, scratch.end());
435 return low + (high - low) * fraction;
436}
std::optional< glm::vec3 > position
Definition Decoder.cpp:93
std::weak_ptr< Core::Window > window
Definition Picker.cpp:23
double q

References position, q, and window.