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

◆ compute_mad_statistic()

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

Compute MAD (Median Absolute Deviation) statistic using zero-copy processing.

Definition at line 742 of file AnalysisHelper.cpp.

743{
744 std::vector<double> mad_values(num_windows);
745
746 std::vector<size_t> indices(num_windows);
747 std::iota(indices.begin(), indices.end(), 0);
748
749 std::for_each(std::execution::par_unseq, indices.begin(), indices.end(),
750 [&](size_t i) {
751 const size_t start_idx = i * hop_size;
752 const size_t end_idx = std::min(start_idx + window_size, data.size());
753 auto window = data.subspan(start_idx, end_idx - start_idx);
754
755 if (window.empty()) {
756 mad_values[i] = 0.0;
757 return;
758 }
759
760 std::vector<double> sorted_window(window.begin(), window.end());
761 std::ranges::sort(sorted_window);
762
763 double median {};
764 size_t n = sorted_window.size();
765 if (n % 2 == 0) {
766 median = (sorted_window[n / 2 - 1] + sorted_window[n / 2]) / 2.0;
767 } else {
768 median = sorted_window[n / 2];
769 }
770
771 std::vector<double> abs_deviations;
772 abs_deviations.reserve(window.size());
773 for (double val : window) {
774 abs_deviations.push_back(std::abs(val - median));
775 }
776
777 std::ranges::sort(abs_deviations);
778 size_t mad_n = abs_deviations.size();
779 if (mad_n % 2 == 0) {
780 mad_values[i] = (abs_deviations[mad_n / 2 - 1] + abs_deviations[mad_n / 2]) / 2.0;
781 } else {
782 mad_values[i] = abs_deviations[mad_n / 2];
783 }
784 });
785
786 return mad_values;
787}

References compute_mad_statistic().

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

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