Skip to main content

Crate nexus_stats

Crate nexus_stats 

Source
Expand description

Fixed-memory, zero-allocation streaming statistics for real-time systems.

65+ algorithms, all O(1) per update (or O(d) for d-dimensional filters), fixed memory. Core types are no_std compatible; types marked (std) require the std feature, (alloc) require alloc, and (std|libm) require either std or libm.

§Usage

Import from the category module you need:

use nexus_stats::smoothing::EmaF64;
use nexus_stats::detection::CusumF64;
use nexus_stats::statistics::WelfordF64;
use nexus_stats::{DataError, ConfigError, Direction};

With the full feature (or individual subcrate features), advanced types are available through the same module paths:

// Requires `smoothing` feature
use nexus_stats::smoothing::KamaF64;
// Requires `regression` feature
use nexus_stats::regression::LinearRegressionF64;
// Requires `detection` feature
use nexus_stats::signal::AutocorrelationF64;

§Data Quality & Error Policy

nexus-stats distinguishes two failure categories:

Data errors — NaN or Inf values reaching a streaming update. These indicate upstream data quality problems (broken feeds, failed computations, missing values). All update methods that accept float inputs return Result<_, DataError>. The library rejects the input and leaves internal state unchanged. The caller declares the policy:

  • .unwrap() to crash on bad data (testing, strict systems)
  • Log and continue (monitoring, degraded-mode operation)
  • Increment a counter and trigger a circuit breaker (production)

Programmer errors — wrong dimensions, out-of-range indices, type misuse. These are bugs in the calling code. The library panics via assert!. Fix the code.

§Internal State Invariant

Given only finite (non-NaN, non-Inf) inputs, all internal accumulators remain finite for typical workloads. Extreme value ranges (>1e150) or very long-running instances (billions of updates) can cause internal accumulator overflow through summation. For long-running systems: call reset() periodically, use exponentially-weighted variants (EW*) which naturally bound growth, or use .max_covariance() on RLS filters to auto-reset when the covariance matrix diverges.

§Categories

§Core (always available)

ModuleContents
smoothingEMA, AsymEma, Slew
detectionCUSUM
statisticsWelford, Moments, EwmaVar, Covariance, HarmonicMean, Percentile
monitoringDrawdown, Windowed Min/Max, CoDel, Liveness, EventRate, Jitter, ErrorRate, Saturation
controlDeadBand, Hysteresis, Debounce, LevelCrossing, Diff

§Advanced (feature-gated, re-exported from subcrates)

FeatureModuleContents
smoothingsmoothing+ Holt, KAMA, Spring, Kalman1d, WindowedMedian
detectiondetection+ MOSUM, Shiryaev-Roberts, AdaptiveThreshold, RobustZ, TrendAlert, MultiGate
detectionsignalAutocorrelation, CrossCorrelation, Entropy, TransferEntropy
detectionestimation+ SPRT
regressionregressionLinear, Polynomial, EW variants, Transformed, LogisticRegression
regressionlearningLMS, NLMS, RLS, OnlineKMeans, GD, AdaGrad, Adam
regressionestimation+ Kalman 2d/3d, BetaBinomial, GammaPoisson
controlcontrol+ PeakDetector, BoolWindow
controlfrequencyTopK, FlexProportion, DecayAccum
fullallEverything above

§Features

FeatureDefaultEnables
stdyesInstant-based windowed/CoDel/liveness/event-rate types, sqrt/exp intrinsics
allocwith stdMOSUM, KAMA, WindowedMedian, BoolWindow, adaptive filters, optimizers
libmnoPure Rust sqrt/exp fallback for no_std (enables Shiryaev-Roberts, etc.)
smoothingnoAdvanced smoothing types (Holt, KAMA, Spring, Kalman1d, WindowedMedian)
detectionnoAdvanced detection + signal analysis (implies smoothing)
regressionnoRegression, learning, estimation types
controlnoAdvanced control + frequency types
fullnoAll subcrates

Modules§

control
Control, thresholding, and differencing.
detection
Change detection and anomaly detection.
estimation
State estimation, Bayesian inference, and hypothesis testing.
frequency
Frequency counting and scoring.
learning
Adaptive filters, online learning, and optimization.
monitoring
Monitoring and health tracking. Monitoring and health tracking. System monitoring and operational health.
regression
Regression and classification.
signal
Signal analysis and information theory.
smoothing
Smoothing and filtering primitives.
statistics
Core streaming statistics. Core streaming statistics. Core streaming statistics.

Macros§

feature_vector
Generates a named feature vector struct where every field is f64.

Enums§

Condition
System condition state.
ConfigError
Configuration error from building a stats primitive.
DataError
Error returned when a streaming update receives invalid data.
Direction
Directional change or anomaly direction.