pub struct Vector<T> { /* private fields */ }Expand description
A 1D vector of floating-point values.
§Examples
use aprender::primitives::Vector;
let v = Vector::from_slice(&[1.0, 2.0, 3.0]);
assert_eq!(v.len(), 3);
assert!((v.sum() - 6.0).abs() < 1e-6);Implementations§
Source§impl<T: Copy> Vector<T>
impl<T: Copy> Vector<T>
Sourcepub fn from_slice(data: &[T]) -> Self
pub fn from_slice(data: &[T]) -> Self
Creates a new vector from a slice.
Sourcepub fn as_mut_slice(&mut self) -> &mut [T]
pub fn as_mut_slice(&mut self) -> &mut [T]
Returns a mutable slice of the underlying data.
Source§impl Vector<f32>
impl Vector<f32>
Sourcepub fn add_scalar(&self, scalar: f32) -> Self
pub fn add_scalar(&self, scalar: f32) -> Self
Adds a scalar to each element.
Sourcepub fn mul_scalar(&self, scalar: f32) -> Self
pub fn mul_scalar(&self, scalar: f32) -> Self
Multiplies each element by a scalar.
Sourcepub fn norm_squared(&self) -> f32
pub fn norm_squared(&self) -> f32
Computes the squared L2 norm.
Sourcepub fn std(&self) -> f32
pub fn std(&self) -> f32
Computes standard deviation of all elements.
Standard deviation is the square root of variance.
§Examples
use aprender::primitives::Vector;
let v = Vector::from_slice(&[1.0, 2.0, 3.0, 4.0, 5.0]);
let std = v.std();
assert!((std - 1.414).abs() < 0.01);Sourcepub fn gini_coefficient(&self) -> f32
pub fn gini_coefficient(&self) -> f32
Computes Gini coefficient (inequality measure).
The Gini coefficient measures inequality in a distribution.
Formula: G = Σ Σ |x_i - x_j| / (2n² * mean)
§Returns
- 0.0: Perfect equality (all values are the same)
- 1.0: Maximum inequality (one value has everything)
§Examples
use aprender::primitives::Vector;
// Perfect equality
let v = Vector::from_slice(&[5.0, 5.0, 5.0]);
assert!((v.gini_coefficient() - 0.0).abs() < 0.01);
// Some inequality
let v = Vector::from_slice(&[1.0, 2.0, 3.0, 4.0, 5.0]);
let gini = v.gini_coefficient();
assert!(gini > 0.0 && gini < 1.0);Trait Implementations§
Source§impl<'de, T> Deserialize<'de> for Vector<T>where
T: Deserialize<'de>,
impl<'de, T> Deserialize<'de> for Vector<T>where
T: Deserialize<'de>,
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl<T> StructuralPartialEq for Vector<T>
Auto Trait Implementations§
impl<T> Freeze for Vector<T>
impl<T> RefUnwindSafe for Vector<T>where
T: RefUnwindSafe,
impl<T> Send for Vector<T>where
T: Send,
impl<T> Sync for Vector<T>where
T: Sync,
impl<T> Unpin for Vector<T>where
T: Unpin,
impl<T> UnwindSafe for Vector<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 more