1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
//! Fixed-memory, zero-allocation streaming statistics for real-time systems.
//!
//! 60+ 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:
//!
//! ```rust
//! 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:
//!
//! ```rust,ignore
//! // 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)
//!
//! | Module | Contents |
//! |--------|----------|
//! | [`smoothing`] | EMA, AsymEma, Slew |
//! | [`detection`] | CUSUM |
//! | [`statistics`] | Welford, Moments, EwmaVar, Covariance, HarmonicMean, Percentile, BipowerVariation, RollSpread *(std\|libm)*, TwoScaleRv *(alloc, std\|libm)* |
//! | [`monitoring`] | Drawdown, Windowed Min/Max, CoDel, Liveness, EventRate, Jitter, ErrorRate, Saturation, HawkesIntensity *(std\|libm)* |
//! | [`control`] | DeadBand, Hysteresis, Debounce, LevelCrossing, Diff |
//!
//! ## Advanced (feature-gated, re-exported from subcrates)
//!
//! | Feature | Module | Contents |
//! |---------|--------|----------|
//! | `smoothing` | `smoothing` | + Holt, KAMA, Spring, Kalman1d, WindowedMedian |
//! | `detection` | `detection` | + MOSUM, Shiryaev-Roberts, AdaptiveThreshold, RobustZ, TrendAlert, MultiGate, PageHinkley, ADWIN |
//! | `detection` | `signal` | Autocorrelation, CrossCorrelation, Entropy, TransferEntropy, PredictiveInfoBound |
//! | `detection` | `estimation` | + SPRT |
//! | `regression` | `regression` | Linear, Polynomial, EW variants, Transformed, LogisticRegression |
//! | `regression` | `learning` | LMS, NLMS, RLS, OnlineKMeans, GD, AdaGrad, Adam, UCB1, ThompsonBeta, ThompsonGamma, EpsilonGreedy, EXP3 |
//! | `regression` | `estimation` | + Kalman 2d/3d, BetaBinomial, GammaPoisson |
//! | `control` | `control` | + PeakDetector, BoolWindow |
//! | `control` | `frequency` | TopK, FlexProportion, DecayAccum |
//! | `full` | all | Everything above |
//!
//! # Features
//!
//! | Feature | Default | Enables |
//! |---------|---------|---------|
//! | `std` | yes | `WallClock`, `sqrt`/`exp` intrinsics |
//! | `alloc` | with `std` | MOSUM, KAMA, WindowedMedian, BoolWindow, adaptive filters, optimizers |
//! | `libm` | no | Pure Rust `sqrt`/`exp` fallback for `no_std` (enables Shiryaev-Roberts, etc.) |
//! | `smoothing` | no | Advanced smoothing types (Holt, KAMA, Spring, Kalman1d, WindowedMedian) |
//! | `detection` | no | Advanced detection + signal analysis (implies `smoothing`) |
//! | `regression` | no | Regression, learning, estimation types |
//! | `control` | no | Advanced control + frequency types |
//! | `full` | no | All subcrates |
// Re-export core types at crate root
pub use ;
/// Clock trait and implementations for time-aware stats types.
pub use clock;
// Re-export the math module (doc-hidden, for subcrate use)
pub use math;
// Re-export the feature_vector macro
pub use feature_vector;
// ---- Core modules (always available, from nexus-stats-core) ----
/// Smoothing and filtering primitives.
///
/// Core types (EMA, AsymEma, Slew) are always available. Advanced types
/// (Holt, KAMA, Spring, Kalman1d, WindowedMedian) require the `smoothing`
/// feature.
/// Change detection and anomaly detection.
///
/// CUSUM is always available. Advanced types (MOSUM, Shiryaev-Roberts,
/// AdaptiveThreshold, RobustZ, TrendAlert, MultiGate) require the
/// `detection` feature.
/// Online feature normalization.
pub use normalization;
/// Core streaming statistics.
pub use statistics;
/// Monitoring and health tracking.
pub use monitoring;
/// Control, thresholding, and differencing.
///
/// Core types (DeadBand, Hysteresis, Debounce, LevelCrossing, Diff) are
/// always available. PeakDetector and BoolWindow require the `control` feature.
// ---- Advanced modules (from subcrates, feature-gated) ----
/// Signal analysis and information theory.
///
/// Requires the `detection` feature.
/// State estimation, Bayesian inference, and hypothesis testing.
///
/// Kalman1d is available via [`smoothing`] with the `smoothing` feature.
/// Kalman2d/3d, BetaBinomial, GammaPoisson require the `regression` feature.
/// SPRT requires the `detection` feature.
/// Regression and classification.
///
/// Requires the `regression` feature.
/// Adaptive filters, online learning, and optimization.
///
/// Requires the `regression` feature.
/// Frequency counting and scoring.
///
/// Requires the `control` feature.