pub struct MinMaxScaler { /* private fields */ }Expand description
Streaming min-max scaler – incremental feature scaling to a configurable range.
Tracks per-feature running minimum and maximum values, scaling features to a
target range (default [0, 1]). Each call to
update_and_transform incorporates
a new sample in O(n_features) time with zero allocations (after the first
sample initializes internal buffers).
Scaling formula:
scaled = (x - min) / (max - min) * (range_high - range_low) + range_lowWhen max - min < f64::EPSILON for a feature (zero range), the scaler
outputs the midpoint of the target range to avoid division by zero.
§Example
use irithyll::preprocessing::MinMaxScaler;
use irithyll::pipeline::StreamingPreprocessor;
let mut scaler = MinMaxScaler::new();
// Feed samples one at a time.
scaler.update_and_transform(&[0.0, 100.0]);
scaler.update_and_transform(&[10.0, 0.0]);
// Transform a new observation using running min/max.
let scaled = scaler.transform(&[5.0, 50.0]);
assert!((scaled[0] - 0.5).abs() < 1e-9);
assert!((scaled[1] - 0.5).abs() < 1e-9);Implementations§
Source§impl MinMaxScaler
impl MinMaxScaler
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a scaler with the default target range [0, 1].
The number of features is inferred from the first call to
update_and_transform.
use irithyll::preprocessing::MinMaxScaler;
let scaler = MinMaxScaler::new();Sourcepub fn with_range(low: f64, high: f64) -> Self
pub fn with_range(low: f64, high: f64) -> Self
Create a scaler with a custom output range [low, high].
§Panics
Panics if low >= high.
use irithyll::preprocessing::MinMaxScaler;
let scaler = MinMaxScaler::with_range(-1.0, 1.0);Sourcepub fn mins(&self) -> &[f64]
pub fn mins(&self) -> &[f64]
Per-feature running minimums observed so far.
Empty until the first sample has been incorporated.
Trait Implementations§
Source§impl Clone for MinMaxScaler
impl Clone for MinMaxScaler
Source§fn clone(&self) -> MinMaxScaler
fn clone(&self) -> MinMaxScaler
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for MinMaxScaler
impl Debug for MinMaxScaler
Source§impl Default for MinMaxScaler
impl Default for MinMaxScaler
Source§impl StreamingPreprocessor for MinMaxScaler
impl StreamingPreprocessor for MinMaxScaler
Source§fn update_and_transform(&mut self, features: &[f64]) -> Vec<f64>
fn update_and_transform(&mut self, features: &[f64]) -> Vec<f64>
Update running min/max from this sample and return scaled features.
On the first call, initializes internal buffers from the sample. Since
min == max for every feature after a single sample, all outputs will
be the midpoint of the target range.
Source§fn transform(&self, features: &[f64]) -> Vec<f64>
fn transform(&self, features: &[f64]) -> Vec<f64>
Scale features using current min/max without updating statistics.
If no samples have been seen yet (no min/max stats), features pass through unscaled.
Source§fn output_dim(&self) -> Option<usize>
fn output_dim(&self) -> Option<usize>
Number of output features, or None if unknown until the first sample.
Auto Trait Implementations§
impl Freeze for MinMaxScaler
impl RefUnwindSafe for MinMaxScaler
impl Send for MinMaxScaler
impl Sync for MinMaxScaler
impl Unpin for MinMaxScaler
impl UnsafeUnpin for MinMaxScaler
impl UnwindSafe for MinMaxScaler
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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