pub struct MinMaxNormalizer { /* private fields */ }Expand description
Rolling min-max normalizer over a sliding window of f64 observations.
§Example
use fin_stream::norm::MinMaxNormalizer;
let mut norm = MinMaxNormalizer::new(4);
norm.update(10.0);
norm.update(20.0);
norm.update(30.0);
norm.update(40.0);
// 40.0 is the current max; 10.0 is the current min
let v = norm.normalize(40.0).unwrap();
assert!((v - 1.0).abs() < 1e-10);Implementations§
Source§impl MinMaxNormalizer
impl MinMaxNormalizer
Sourcepub fn new(window_size: usize) -> Self
pub fn new(window_size: usize) -> Self
Create a new normalizer with the given rolling window size.
window_size must be at least 1. Passing 0 is a programming error;
this function will panic in debug mode and is flagged by the
clippy::panic lint configured in Cargo.toml.
§Panics
Panics if window_size == 0.
Sourcepub fn min_max(&mut self) -> Option<(f64, f64)>
pub fn min_max(&mut self) -> Option<(f64, f64)>
Return the current (min, max) of the window.
Returns None if the window is empty.
§Complexity: O(1) when the cache is clean; O(W) after an eviction.
Sourcepub fn normalize(&mut self, value: f64) -> Result<f64, StreamError>
pub fn normalize(&mut self, value: f64) -> Result<f64, StreamError>
Normalize value into [0.0, 1.0] using the current window.
The value is clamped so that even if value falls outside the window
range the result is always in [0.0, 1.0].
§Errors
Returns NormalizationError if the window is empty (no observations
have been fed yet).
§Complexity: O(1) when cache is clean; O(W) after an eviction.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if no observations have been added since construction or
the last reset.
Sourcepub fn window_size(&self) -> usize
pub fn window_size(&self) -> usize
The configured window size.