Skip to main content

FeatureDriftDetector

Struct FeatureDriftDetector 

Source
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>

Source

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.

Source

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.

Source

pub fn with_metrics_sink(self, sink: Arc<dyn MetricsSink>) -> Self

Install a metrics sink — every observe / psi call emits counters/gauges into it.

Source

pub fn metrics_sink(&self) -> &Arc<dyn MetricsSink>

Read-only handle to the installed sink.

Source

pub fn is_baseline_frozen(&self) -> bool

Whether Self::freeze_baseline has been called.

Source

pub fn observations_total(&self) -> u64

Lifetime count of Self::observe calls.

Source

pub fn num_bins(&self) -> usize

Number of equal-width bins per dimension.

Source

pub fn bin_edges(&self) -> Option<&[(f64, f64); D]>

Per-dim (min, max) range pinned at baseline time — None before Self::freeze_baseline.

Source

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
Source

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).

Source

pub fn reset_production(&mut self)

Drop the production histogram; keep the baseline. Call between monitoring windows.

Source

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.

Source

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.

Source

pub fn max_psi(&self) -> RcfResult<f64>

Maximum PSI across every dimension — the single number SOC dashboards usually alert on.

§Errors

Same as Self::psi.

Source

pub fn argmax_psi(&self) -> RcfResult<Option<usize>>

Dim index with the largest PSI — useful for root-causing “which feature moved?”.

§Errors

Same as Self::psi. Returns Ok(None) when every PSI is exactly zero.

Trait Implementations§

Source§

impl<const D: usize> Debug for FeatureDriftDetector<D>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V