pub struct StandardScaler { /* private fields */ }Expand description
Online standard scaler that standardizes features to approximately zero mean and unit variance.
- When
with_mean = false, the mean subtraction is skipped. - When
with_std = false, the scaling is skipped. - When a feature has seen zero samples, its mean is
0and scale is1, so the original value is returned unchanged. - When a feature’s variance is below
epsilon, the scale is1to avoid NaN or Infinity.
transform does not update state; only update does.
Implementations§
Source§impl StandardScaler
impl StandardScaler
Sourcepub fn new(feature_count: usize) -> Result<Self, RillError>
pub fn new(feature_count: usize) -> Result<Self, RillError>
Create a new scaler for feature_count features with default config.
Sourcepub fn with_config(
feature_count: usize,
config: StandardScalerConfig,
) -> Result<Self, RillError>
pub fn with_config( feature_count: usize, config: StandardScalerConfig, ) -> Result<Self, RillError>
Create a new scaler with a custom configuration.
Sourcepub fn validate(&self) -> Result<(), RillError>
pub fn validate(&self) -> Result<(), RillError>
Validate all configuration and persisted-state invariants.
This is run automatically during deserialization and before operations
that index per-feature state. The hot path (transform_into /
transform) relies on the invariants established here and by the
private constructor, and only re-checks them under debug_assert!.
Sourcepub fn transform_into(
&self,
features: &[f64],
output: &mut Vec<f64>,
) -> Result<(), RillError>
pub fn transform_into( &self, features: &[f64], output: &mut Vec<f64>, ) -> Result<(), RillError>
Transform features into the provided output buffer, reusing its
allocation instead of allocating a fresh Vec on every call.
This is the hot-path entry point. Compared to transform
it avoids two temporary allocations (the variances() and scales()
vectors) by fusing the scale computation into the single output loop.
The trust-boundary checks (dimension validation and finite-output
enforcement) are preserved; the internal-state invariants established
by validate and the private constructor are only
re-checked under debug_assert! because they are guaranteed by the
private fields and the validated deserialization path.
output is truncated to the feature count and then filled; callers
that reuse the same buffer across iterations avoid allocation
entirely after the first call.
Trait Implementations§
Source§impl Clone for StandardScaler
impl Clone for StandardScaler
Source§fn clone(&self) -> StandardScaler
fn clone(&self) -> StandardScaler
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for StandardScaler
impl Debug for StandardScaler
Source§impl Transformer for StandardScaler
impl Transformer for StandardScaler
Source§fn output_dim(&self) -> usize
fn output_dim(&self) -> usize
transform.