pub struct Adwin { /* private fields */ }Expand description
ADWIN (Adaptive Windowing) drift detector.
Maintains a variable-length window and detects distribution changes by comparing the means of the window’s two halves. See the module documentation for the algorithm.
§Examples
use rill_ml::drift::{Adwin, DriftDetector, DriftLevel};
let mut adwin = Adwin::default();
// Stable stream.
for _ in 0..100 {
adwin.update(0.0).unwrap();
}
assert_eq!(adwin.level(), DriftLevel::None);
// Sudden shift. ADWIN's level is transient: after detecting drift and
// trimming the window, subsequent stable updates reset the level to
// None, so we check the level returned by each update.
let mut detected = false;
for _ in 0..100 {
let level = adwin.update(5.0).unwrap();
if level == DriftLevel::Drift {
detected = true;
break;
}
}
assert!(detected);Implementations§
Source§impl Adwin
impl Adwin
Sourcepub fn new(config: AdwinConfig) -> Result<Self, RillError>
pub fn new(config: AdwinConfig) -> Result<Self, RillError>
Create a new ADWIN detector with the given configuration.
Returns an error if:
deltais not in(0, 1).warning_deltais not in(0, 1)or is less thandelta.max_windowis zero.min_samplesis zero.
Sourcepub fn window_size(&self) -> usize
pub fn window_size(&self) -> usize
The number of values currently in the window.
Sourcepub fn window_mean(&self) -> f64
pub fn window_mean(&self) -> f64
The mean of all values currently in the window, or 0.0 if empty.
Sourcepub const fn config(&self) -> &AdwinConfig
pub const fn config(&self) -> &AdwinConfig
The configuration of this detector.
Trait Implementations§
Source§impl DriftDetector for Adwin
impl DriftDetector for Adwin
Source§fn update(&mut self, value: f64) -> Result<DriftLevel, RillError>
fn update(&mut self, value: f64) -> Result<DriftLevel, RillError>
Update the detector with a new scalar observation. Read more
Source§fn level(&self) -> DriftLevel
fn level(&self) -> DriftLevel
The current drift level.
Source§fn samples_seen(&self) -> u64
fn samples_seen(&self) -> u64
Number of observations incorporated so far.
Source§fn last_value(&self) -> f64
fn last_value(&self) -> f64
The detector-specific statistic value from the last update. Read more
Auto Trait Implementations§
impl Freeze for Adwin
impl RefUnwindSafe for Adwin
impl Send for Adwin
impl Sync for Adwin
impl Unpin for Adwin
impl UnsafeUnpin for Adwin
impl UnwindSafe for Adwin
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
Mutably borrows from an owned value. Read more