pub struct StableMetrics<T> {
pub epsilon: T,
pub max_value: T,
pub clip_values: bool,
pub use_logsumexp: bool,
}Expand description
Numerically stable computation of common operations
Fields§
§epsilon: TMinimum value to avoid division by zero or log of zero
max_value: TMaximum value to clip extreme values
clip_values: boolWhether to clip values
use_logsumexp: boolWhether to use log-sum-exp trick for numerical stability
Implementations§
Source§impl<T: Float + NumCast> StableMetrics<T>
impl<T: Float + NumCast> StableMetrics<T>
Sourcepub fn with_epsilon(self, epsilon: T) -> Self
pub fn with_epsilon(self, epsilon: T) -> Self
Set the epsilon value
Sourcepub fn with_max_value(self, maxvalue: T) -> Self
pub fn with_max_value(self, maxvalue: T) -> Self
Set the maximum value
Sourcepub fn with_clip_values(self, clipvalues: bool) -> Self
pub fn with_clip_values(self, clipvalues: bool) -> Self
Set whether to clip values
Sourcepub fn with_logsumexp(self, uselogsumexp: bool) -> Self
pub fn with_logsumexp(self, uselogsumexp: bool) -> Self
Set whether to use log-sum-exp trick
Sourcepub fn stable_mean(&self, values: &[T]) -> Result<T>
pub fn stable_mean(&self, values: &[T]) -> Result<T>
Sourcepub fn stable_variance(&self, values: &[T], ddof: usize) -> Result<T>
pub fn stable_variance(&self, values: &[T], ddof: usize) -> Result<T>
Numerically stable calculation of variance
Implements Welford’s online algorithm for computing variance, which is more stable for large datasets.
§Arguments
values- Input array of valuesddof- Delta degrees of freedom (0 for population variance, 1 for sample variance)
§Returns
- The variance of the values
Sourcepub fn stable_std(&self, values: &[T], ddof: usize) -> Result<T>
pub fn stable_std(&self, values: &[T], ddof: usize) -> Result<T>
Sourcepub fn cross_entropy(&self, y_true: &[T], ypred: &[T]) -> Result<T>
pub fn cross_entropy(&self, y_true: &[T], ypred: &[T]) -> Result<T>
Sourcepub fn kl_divergence(&self, p: &[T], q: &[T]) -> Result<T>
pub fn kl_divergence(&self, p: &[T], q: &[T]) -> Result<T>
Sourcepub fn js_divergence(&self, p: &[T], q: &[T]) -> Result<T>
pub fn js_divergence(&self, p: &[T], q: &[T]) -> Result<T>
Sourcepub fn wasserstein_distance(&self, u_values: &[T], vvalues: &[T]) -> Result<T>
pub fn wasserstein_distance(&self, u_values: &[T], vvalues: &[T]) -> Result<T>
Sourcepub fn matrix_exp_trace(&self, eigenvalues: &[T]) -> Result<T>
pub fn matrix_exp_trace(&self, eigenvalues: &[T]) -> Result<T>
Sourcepub fn matrix_logdet(&self, eigenvalues: &[T]) -> Result<T>
pub fn matrix_logdet(&self, eigenvalues: &[T]) -> Result<T>
Trait Implementations§
Source§impl<T: Clone> Clone for StableMetrics<T>
impl<T: Clone> Clone for StableMetrics<T>
Source§fn clone(&self) -> StableMetrics<T>
fn clone(&self) -> StableMetrics<T>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<T: Debug> Debug for StableMetrics<T>
impl<T: Debug> Debug for StableMetrics<T>
Auto Trait Implementations§
impl<T> Freeze for StableMetrics<T>where
T: Freeze,
impl<T> RefUnwindSafe for StableMetrics<T>where
T: RefUnwindSafe,
impl<T> Send for StableMetrics<T>where
T: Send,
impl<T> Sync for StableMetrics<T>where
T: Sync,
impl<T> Unpin for StableMetrics<T>where
T: Unpin,
impl<T> UnwindSafe for StableMetrics<T>where
T: UnwindSafe,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
Converts
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>
Converts
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.