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

◆ median()

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

Median per window via nth_element partial sort.

Definition at line 325 of file Analysis.cpp.

326{
327 std::vector<double> out(n_windows);
328 std::vector<size_t> idx(n_windows);
329 std::iota(idx.begin(), idx.end(), 0);
330
331 Parallel::for_each(Parallel::par_unseq, idx.begin(), idx.end(),
332 [&](size_t i) {
333 const size_t start = i * hop_size;
334 auto w = data.subspan(start, std::min<size_t>(window_size, data.size() - start));
335 std::vector<double> buf(w.begin(), w.end());
336 const size_t mid = buf.size() / 2;
337 std::nth_element(buf.begin(), buf.begin() + static_cast<ptrdiff_t>(mid), buf.end());
338 if (buf.size() % 2 != 0) {
339 out[i] = buf[mid];
340 } else {
341 const double upper = buf[mid];
342 std::nth_element(buf.begin(), buf.begin() + static_cast<ptrdiff_t>(mid - 1), buf.begin() + static_cast<ptrdiff_t>(mid));
343 out[i] = (buf[mid - 1] + upper) / 2.0;
344 }
345 });
346
347 return out;
348}

References median().

Referenced by median().

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