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

◆ flag_outliers()

std::vector< size_t > MayaFlux::Kinesis::Stochastic::Estimate::flag_outliers ( std::span< const double >  samples,
double  threshold_mad = 3.0 
)
staticnoexcept

Flags samples whose deviation from the median exceeds a threshold.

Parameters
samplesValues to analyze
threshold_madNumber of scaled-MAD units beyond which a sample is flagged, typically 2.5 to 3.5 for physical sensor data
Returns
Indices into samples considered outliers

Shape-aware in the sense that a single wild sample and a run of several consistent high samples are distinguished by the caller inspecting which indices come back, not by this function alone: an isolated flagged index surrounded by unflagged ones reads differently from several consecutive flagged indices, and that read is left to the caller since the correct interpretation depends on domain (a genuine fast transition vs. a dropout burst).

Definition at line 247 of file Estimate.cpp.

248{
249 std::vector<size_t> result;
250 if (samples.size() < 2)
251 return result;
252
253 std::vector<double> sorted(samples.begin(), samples.end());
254 std::ranges::sort(sorted);
255 const double median = sorted[sorted.size() / 2];
256 const double scaled_mad = median_absolute_deviation(samples);
257
258 if (scaled_mad < 1e-12)
259 return result;
260
261 for (size_t i = 0; i < samples.size(); ++i) {
262 const double dev = std::abs(samples[i] - median) / scaled_mad;
263 if (dev > threshold_mad)
264 result.push_back(i);
265 }
266
267 return result;
268}
static double median_absolute_deviation(std::span< const double > samples) noexcept
Median absolute deviation of a span.
Definition Estimate.cpp:229
std::vector< double > 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 Analysis.cpp:325