Skip to main content

MinMaxNormF32

Struct MinMaxNormF32 

Source
pub struct MinMaxNormF32 { /* private fields */ }
Expand description

Windowed min-max normalizer.

Scales values to [0, 1] using the windowed minimum and maximum over a sliding timestamp window: (sample - min) / (max - min).

When the range is zero (all values equal), returns 0.5.

§Examples

use nexus_stats_core::normalization::MinMaxNormF32;

let mut mm = MinMaxNormF32::builder().window(100).build().unwrap();
let _ = mm.update(0, 10.0 as f32);
let _ = mm.update(1, 20.0 as f32);
let v = mm.update(2, 15.0 as f32).unwrap();
assert!(v.is_some());

Implementations§

Source§

impl MinMaxNormF32

Source

pub fn builder() -> MinMaxNormF32Builder

Creates a builder.

Source

pub fn update( &mut self, timestamp: u64, sample: f32, ) -> Result<Option<f32>, DataError>

Feeds a sample at the given timestamp. Returns normalized value in [0, 1] once at least one sample has been observed.

§Errors

Returns DataError::NotANumber if the sample is NaN, or DataError::Infinite if the sample is infinite.

Source

pub fn normalize(&self, value: f32) -> Option<f32>

Normalizes an arbitrary value against current windowed min/max without updating state.

Returns None if not primed.

Source

pub fn min(&self) -> Option<f32>

Current windowed minimum, or None if empty.

Source

pub fn max(&self) -> Option<f32>

Current windowed maximum, or None if empty.

Source

pub fn range(&self) -> Option<f32>

Current range (max - min), or None if empty.

Source

pub fn count(&self) -> u64

Number of samples processed (minimum of both trackers).

Source

pub fn is_primed(&self) -> bool

Whether at least one sample has been observed.

Source

pub fn reset(&mut self)

Resets accumulated state. Window size preserved.

Trait Implementations§

Source§

impl Clone for MinMaxNormF32

Source§

fn clone(&self) -> MinMaxNormF32

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MinMaxNormF32

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.