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

◆ percentile()

std::vector< double > MayaFlux::Kinesis::Discrete::percentile ( std::span< const double >  data,
size_t  n_windows,
uint32_t  hop_size,
uint32_t  window_size,
double  percentile_value 
)

Arbitrary percentile per window via linear interpolation.

Parameters
percentileValue in [0, 100]

Definition at line 350 of file Analysis.cpp.

351{
352 std::vector<double> out(n_windows);
353 std::vector<size_t> idx(n_windows);
354 std::iota(idx.begin(), idx.end(), 0);
355
356 Parallel::for_each(Parallel::par_unseq, idx.begin(), idx.end(),
357 [&](size_t i) {
358 const size_t start = i * hop_size;
359 auto w = data.subspan(start, std::min<size_t>(window_size, data.size() - start));
360 if (w.empty()) {
361 out[i] = 0.0;
362 return;
363 }
364 std::vector<double> buf(w.begin(), w.end());
365 std::ranges::sort(buf);
366 const double pos = (percentile_value / 100.0) * static_cast<double>(buf.size() - 1);
367 const auto lo = static_cast<size_t>(std::floor(pos));
368 const auto hi = static_cast<size_t>(std::ceil(pos));
369 out[i] = (lo == hi) ? buf[lo] : buf[lo] * (1.0 - (pos - static_cast<double>(lo))) + buf[hi] * (pos - static_cast<double>(lo));
370 });
371
372 return out;
373}

References percentile().

Referenced by percentile().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: