pub struct FeatureDriftDetector<const D: usize> { /* private fields */ }Expand description
Per-dim histogram-driven feature drift detector.
D pins the feature-vector dimensionality at compile time,
mirroring the rest of the crate. The detector is std-only
because it ships its observability plumbing.
Implementations§
Source§impl<const D: usize> FeatureDriftDetector<D>
impl<const D: usize> FeatureDriftDetector<D>
Sourcepub fn new(num_bins: usize) -> RcfResult<Self>
pub fn new(num_bins: usize) -> RcfResult<Self>
Build a fresh detector with num_bins equal-width bins per
dimension. Uses DEFAULT_SMOOTHING for Laplace smoothing.
§Errors
Returns RcfError::InvalidConfig when num_bins < 2 or
D == 0.
Sourcepub fn with_smoothing(num_bins: usize, smoothing: f64) -> RcfResult<Self>
pub fn with_smoothing(num_bins: usize, smoothing: f64) -> RcfResult<Self>
Like Self::new but with a caller-chosen smoothing
epsilon in (0, 1].
§Errors
Returns RcfError::InvalidConfig on any out-of-range
argument.
Sourcepub fn with_metrics_sink(self, sink: Arc<dyn MetricsSink>) -> Self
pub fn with_metrics_sink(self, sink: Arc<dyn MetricsSink>) -> Self
Install a metrics sink — every observe / psi call emits
counters/gauges into it.
Sourcepub fn metrics_sink(&self) -> &Arc<dyn MetricsSink>
pub fn metrics_sink(&self) -> &Arc<dyn MetricsSink>
Read-only handle to the installed sink.
Sourcepub fn is_baseline_frozen(&self) -> bool
pub fn is_baseline_frozen(&self) -> bool
Whether Self::freeze_baseline has been called.
Sourcepub fn observations_total(&self) -> u64
pub fn observations_total(&self) -> u64
Lifetime count of Self::observe calls.
Sourcepub fn bin_edges(&self) -> Option<&[(f64, f64); D]>
pub fn bin_edges(&self) -> Option<&[(f64, f64); D]>
Per-dim (min, max) range pinned at baseline time — None
before Self::freeze_baseline.
Sourcepub fn observe(&mut self, point: &[f64; D]) -> RcfResult<()>
pub fn observe(&mut self, point: &[f64; D]) -> RcfResult<()>
Fold point into the production histogram (or the pre-
freeze buffer when the baseline has not yet been frozen).
§Errors
RcfError::NaNValuewhenpointcontains a non-finite component.
Sourcepub fn freeze_baseline(&mut self) -> RcfResult<()>
pub fn freeze_baseline(&mut self) -> RcfResult<()>
Freeze the current production histogram as the baseline.
Computes per-dim (min, max) from the collected samples,
rebuilds the histogram with equal-width bins, then clones it
into the baseline slot. Subsequent Self::observe calls
feed the production histogram only.
§Errors
Returns RcfError::EmptyForest when no points have been
observed yet (nothing to bin).
Sourcepub fn reset_production(&mut self)
pub fn reset_production(&mut self)
Drop the production histogram; keep the baseline. Call between monitoring windows.
Sourcepub fn psi(&self) -> RcfResult<Vec<f64>>
pub fn psi(&self) -> RcfResult<Vec<f64>>
Per-dim Population Stability Index against the baseline.
Returns a Vec of length D; entry d is
Σ_i (Q_i − P_i) · ln(Q_i / P_i) with Laplace smoothing.
§Errors
Returns RcfError::EmptyForest when the baseline has not
been frozen.
Sourcepub fn kl_divergence(&self) -> RcfResult<Vec<f64>>
pub fn kl_divergence(&self) -> RcfResult<Vec<f64>>
Per-dim KL divergence D_KL(Q || P) against the baseline —
Σ_i Q_i · ln(Q_i / P_i). Asymmetric; see module docs.
§Errors
Returns RcfError::EmptyForest when the baseline has not
been frozen.
Trait Implementations§
Auto Trait Implementations§
impl<const D: usize> Freeze for FeatureDriftDetector<D>
impl<const D: usize> !RefUnwindSafe for FeatureDriftDetector<D>
impl<const D: usize> Send for FeatureDriftDetector<D>
impl<const D: usize> Sync for FeatureDriftDetector<D>
impl<const D: usize> Unpin for FeatureDriftDetector<D>
impl<const D: usize> UnsafeUnpin for FeatureDriftDetector<D>
impl<const D: usize> !UnwindSafe for FeatureDriftDetector<D>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more