Skip to main content

nexus_stats_detection/
lib.rs

1#![cfg_attr(not(feature = "std"), no_std)]
2#![warn(missing_docs)]
3
4//! Advanced change detection and signal analysis for [`nexus-stats`](https://docs.rs/nexus-stats).
5//!
6//! This crate provides change detection, anomaly detection, signal analysis,
7//! and hypothesis testing types separated from the core `nexus-stats` crate.
8//!
9//! Types are organized into submodules:
10//! - [`detection`] — MOSUM, Shiryaev-Roberts, AdaptiveThreshold, RobustZ, TrendAlert, MultiGate, PageHinkley, ADWIN, DistDrift, BOCPD
11//! - [`signal`] — Autocorrelation, CrossCorrelation, Entropy, TransferEntropy, PredictiveInfoBound
12//! - [`estimation`] — SPRT (Bernoulli, Gaussian)
13
14#[cfg(feature = "alloc")]
15extern crate alloc;
16
17/// Validates that a float value is finite (not NaN, not Inf).
18macro_rules! check_finite {
19    ($val:expr) => {
20        if !$val.is_finite() {
21            return Err(if $val.is_nan() {
22                nexus_stats_core::DataError::NotANumber
23            } else {
24                nexus_stats_core::DataError::Infinite
25            });
26        }
27    };
28}
29
30// Internal modules
31mod multi_gate;
32mod page_hinkley;
33mod robust_z;
34#[cfg(all(feature = "alloc", any(feature = "std", feature = "libm")))]
35mod simd_math;
36mod trend_alert;
37
38#[cfg(any(feature = "std", feature = "libm"))]
39mod adaptive_threshold;
40#[cfg(all(feature = "alloc", any(feature = "std", feature = "libm")))]
41mod adwin;
42#[cfg(all(feature = "alloc", any(feature = "std", feature = "libm")))]
43mod bocpd;
44#[cfg(all(feature = "alloc", any(feature = "std", feature = "libm")))]
45mod dist_drift;
46#[cfg(feature = "alloc")]
47mod mosum;
48#[cfg(any(feature = "std", feature = "libm"))]
49mod shiryaev_roberts;
50#[cfg(any(feature = "std", feature = "libm"))]
51mod sprt;
52
53/// Advanced change detection types.
54pub mod detection {
55    pub use super::multi_gate::*;
56    pub use super::page_hinkley::*;
57    pub use super::robust_z::*;
58    pub use super::trend_alert::*;
59
60    #[cfg(any(feature = "std", feature = "libm"))]
61    pub use super::adaptive_threshold::*;
62    #[cfg(all(feature = "alloc", any(feature = "std", feature = "libm")))]
63    pub use super::adwin::*;
64    #[cfg(all(feature = "alloc", any(feature = "std", feature = "libm")))]
65    pub use super::bocpd::*;
66    #[cfg(all(feature = "alloc", any(feature = "std", feature = "libm")))]
67    pub use super::dist_drift::*;
68    #[cfg(feature = "alloc")]
69    pub use super::mosum::*;
70    #[cfg(any(feature = "std", feature = "libm"))]
71    pub use super::shiryaev_roberts::*;
72}
73
74/// Signal analysis and information theory.
75pub mod signal;
76
77/// Hypothesis testing.
78pub mod estimation {
79    #[cfg(any(feature = "std", feature = "libm"))]
80    pub use super::sprt::*;
81}