MathUtils

Struct MathUtils 

Source
pub struct MathUtils {}

Implementations§

Source§

impl MathUtils

Source

pub const LOG10_P_OF_ZERO: f64 = -1.0E+6f64

Source

pub fn median_clone<T: PartialOrd + Copy>(numbers: &[T]) -> T

Source

pub fn median<T: Ord + PartialOrd + Copy>(numbers: &mut [T]) -> T

Source

pub fn normalize_pls(pls: &[f64]) -> Vec<f64>

Source

pub fn ebe_add_in_place<T: Send + Sync + Add + Copy + AddAssign>( a: &mut [T], b: &[T], )

Element by elemnt addition of two vectors in place

Source

pub fn ebe_add<T: Send + Sync + Add + Copy + Add<Output = T>>( a: &[T], b: &[T], ) -> Vec<T>

Element by elemnt addition of two vectors

Source

pub fn ebe_subtract<T: Send + Sync + Sub + Copy + Sub<Output = T>>( a: &[T], b: &[T], ) -> Vec<T>

Element by elemnt subtraction of two vectors

Source

pub fn ebe_multiply<T: Send + Sync + Mul + Copy + Mul<Output = T>>( a: &[T], b: &[T], ) -> Vec<T>

Element by elemnt multiplication of two vectors

Source

pub fn dot_product<T: Send + Sync + Mul + Add + Copy + Mul<Output = T> + Add<Output = T> + Sum>( a: &[T], b: &[T], ) -> T

calculates the dot product of two vectors

Source

pub fn log_to_log10(ln: f64) -> f64

Converts LN to LOG10 @param ln log(x) @return log10(x)

Source

pub fn log10_binomial_coeffecient(n: f64, k: f64) -> f64

@see #binomialCoefficient(int, int) with log10 applied to result

Source

pub fn log10_factorial(n: f64) -> f64

Source

pub fn max_element_index(array: &[f64], start: usize, finish: usize) -> usize

Gets the maximum element’s index of an array of f64 values Rather convoluted due to Rust not allowing proper comparisons between floats

Source

pub fn normalize_log10(array: Vec<f64>, take_log10_of_output: bool) -> Vec<f64>

Source

pub fn log10_sum_log10(log10_values: &[f64], start: usize, finish: usize) -> f64

Source

pub fn log10_sum_log10_two_values(a: f64, b: f64) -> f64

Source

pub fn log10_sum_log10_three_values(a: f64, b: f64, c: f64) -> f64

Do the log-sum trick for three double values. @param a @param b @param c @return the sum… perhaps NaN or infinity if it applies.

Source

pub fn scale_log_space_array_for_numeric_stability(array: &[f64]) -> Vec<f64>

Given an array of log space (log or log10) values, subtract all values by the array maximum so that the max element in log space is zero. This is equivalent to dividing by the maximum element in real space and is useful for avoiding underflow/overflow when the array’s values matter only up to an arbitrary normalizing factor, for example, an array of likelihoods.

@param array @return the scaled-in-place array

Source

pub fn normalize_from_log10( array: &[f64], take_log10_of_output: bool, keep_in_log_space: bool, ) -> Vec<f64>

See #normalizeFromLog10 but with the additional option to use an approximation that keeps the calculation always in log-space

@param array @param takeLog10OfOutput @param keepInLogSpace

@return array

Source

pub fn is_valid_log10_probability(result: f64) -> bool

Source

pub fn log10_to_log(log10: f64) -> f64

Source

pub fn log10_one_minus_pow10(a: f64) -> f64

Calculates {@code log10(1-10^a)} without losing precision.

@param a the input exponent. @return {@link Double#NaN NaN} if {@code a > 0}, otherwise the corresponding value.

Source

pub fn approximate_log10_sum_log10(a: f64, b: f64) -> f64

Source

pub fn approximate_log10_sum_log10_vec( vals: &[f64], from_index: usize, to_index: usize, ) -> f64

Calculate the approximate log10 sum of an array range. @param vals the input values. @param fromIndex the first inclusive index in the input array. @param toIndex index following the last element to sum in the input array (exclusive). @return the approximate sum. @throws IllegalArgumentException if {@code vals} is {@code null} or {@code fromIndex} is out of bounds or if {@code toIndex} is larger than the length of the input array or {@code fromIndex} is larger than {@code toIndex}.

Source

pub fn well_formed_f64(val: f64) -> bool

Source

pub fn normal_distribution(mean: f64, sd: f64, x: f64) -> f64

Calculate f(x) = Normal(x | mu = mean, sigma = sd) @param mean the desired mean of the Normal distribution @param sd the desired standard deviation of the Normal distribution @param x the value to evaluate @return a well-formed double

Source

pub fn normalize_sum_to_one(array: Vec<f64>) -> Vec<f64>

normalizes the real-space probability array.

Does not assume anything about the values in the array, beyond that no elements are below 0. It’s ok to have values in the array of > 1, or have the sum go above 0.

@param array the array to be normalized @return a newly allocated array corresponding the normalized values in array

Source

pub fn fast_bernoulli_entropy(p: f64) -> f64

Computes the entropy -p*ln(p) - (1-p)*ln(1-p) of a Bernoulli distribution with success probability p using an extremely fast Pade approximation that is very accurate for all values of 0 <= p <= 1.

See http://www.nezumi.demon.co.uk/consult/logx.htm

Source

pub fn is_valid_probability(result: f64) -> bool

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> 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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

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

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> Ungil for T
where T: Send,