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

◆ compute_percentile_statistic()

std::vector< double > MayaFlux::Yantra::compute_percentile_statistic ( std::span< const double >  data,
const size_t  num_windows,
const uint32_t  hop_size,
const uint32_t  window_size,
double  percentile 
)

Compute percentile statistic using zero-copy processing.

This function computes an arbitrary percentile for a given data span. It finds the specified percentile value in each window.

Parameters
dataInput data span
num_windowsNumber of windows to process
hop_sizeHop size for windowing
window_sizeSize of each window
percentilePercentile value (0-100)
Returns
Vector of percentile values

Definition at line 537 of file AnalysisHelper.cpp.

538{
539 std::vector<double> percentile_values(num_windows);
540
541 if (percentile < 0.0)
542 percentile = 0.0;
543 if (percentile > 100.0)
544 percentile = 100.0;
545
546 std::vector<size_t> indices(num_windows);
547 std::iota(indices.begin(), indices.end(), 0);
548
549 std::for_each(std::execution::par_unseq, indices.begin(), indices.end(),
550 [&](size_t i) {
551 const size_t start_idx = i * hop_size;
552 const size_t end_idx = std::min(start_idx + window_size, data.size());
553 auto window = data.subspan(start_idx, end_idx - start_idx);
554
555 if (window.empty()) {
556 percentile_values[i] = 0.0;
557 return;
558 }
559
560 std::vector<double> sorted_window(window.begin(), window.end());
561 std::ranges::sort(sorted_window);
562
563 if (percentile == 0.0) {
564 percentile_values[i] = sorted_window.front();
565 return;
566 }
567 if (percentile == 100.0) {
568 percentile_values[i] = sorted_window.back();
569 return;
570 }
571
572 double index = (percentile / 100.0) * static_cast<double>(sorted_window.size() - 1);
573 auto lower_idx = static_cast<size_t>(std::floor(index));
574 auto upper_idx = static_cast<size_t>(std::ceil(index));
575
576 if (lower_idx == upper_idx) {
577 percentile_values[i] = sorted_window[lower_idx];
578 } else {
579 double weight = index - static_cast<double>(lower_idx);
580 percentile_values[i] = sorted_window[lower_idx] * (1.0 - weight) + sorted_window[upper_idx] * weight;
581 }
582 });
583
584 return percentile_values;
585}

References compute_percentile_statistic().

Referenced by compute_percentile_statistic(), MayaFlux::Yantra::StatisticalAnalyzer< InputType, OutputType >::compute_statistical_values(), and MayaFlux::Yantra::StatisticalAnalyzer< InputType, OutputType >::create_analysis_result().

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