pub struct MathUtils {}Implementations§
Source§impl MathUtils
impl MathUtils
pub const LOG10_P_OF_ZERO: f64 = -1.0E+6f64
pub fn median_clone<T: PartialOrd + Copy>(numbers: &[T]) -> T
pub fn median<T: Ord + PartialOrd + Copy>(numbers: &mut [T]) -> T
pub fn normalize_pls(pls: &[f64]) -> Vec<f64>
Sourcepub fn ebe_add_in_place<T: Send + Sync + Add + Copy + AddAssign>(
a: &mut [T],
b: &[T],
)
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
Sourcepub fn ebe_add<T: Send + Sync + Add + Copy + Add<Output = T>>(
a: &[T],
b: &[T],
) -> Vec<T>
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
Sourcepub fn ebe_subtract<T: Send + Sync + Sub + Copy + Sub<Output = T>>(
a: &[T],
b: &[T],
) -> Vec<T>
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
Sourcepub fn ebe_multiply<T: Send + Sync + Mul + Copy + Mul<Output = T>>(
a: &[T],
b: &[T],
) -> Vec<T>
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
Sourcepub fn dot_product<T: Send + Sync + Mul + Add + Copy + Mul<Output = T> + Add<Output = T> + Sum>(
a: &[T],
b: &[T],
) -> T
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
Sourcepub fn log_to_log10(ln: f64) -> f64
pub fn log_to_log10(ln: f64) -> f64
Converts LN to LOG10 @param ln log(x) @return log10(x)
Sourcepub fn log10_binomial_coeffecient(n: f64, k: f64) -> f64
pub fn log10_binomial_coeffecient(n: f64, k: f64) -> f64
@see #binomialCoefficient(int, int) with log10 applied to result
pub fn log10_factorial(n: f64) -> f64
Sourcepub fn max_element_index(array: &[f64], start: usize, finish: usize) -> usize
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
pub fn normalize_log10(array: Vec<f64>, take_log10_of_output: bool) -> Vec<f64>
pub fn log10_sum_log10(log10_values: &[f64], start: usize, finish: usize) -> f64
pub fn log10_sum_log10_two_values(a: f64, b: f64) -> f64
Sourcepub fn log10_sum_log10_three_values(a: f64, b: f64, c: f64) -> f64
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.
Sourcepub fn scale_log_space_array_for_numeric_stability(array: &[f64]) -> Vec<f64>
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
Sourcepub fn normalize_from_log10(
array: &[f64],
take_log10_of_output: bool,
keep_in_log_space: bool,
) -> Vec<f64>
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
pub fn is_valid_log10_probability(result: f64) -> bool
pub fn log10_to_log(log10: f64) -> f64
Sourcepub fn log10_one_minus_pow10(a: f64) -> f64
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.
pub fn approximate_log10_sum_log10(a: f64, b: f64) -> f64
Sourcepub fn approximate_log10_sum_log10_vec(
vals: &[f64],
from_index: usize,
to_index: usize,
) -> f64
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}.
pub fn well_formed_f64(val: f64) -> bool
Sourcepub fn normal_distribution(mean: f64, sd: f64, x: f64) -> f64
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
Sourcepub fn normalize_sum_to_one(array: Vec<f64>) -> Vec<f64>
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
Sourcepub fn fast_bernoulli_entropy(p: f64) -> f64
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
pub fn is_valid_probability(result: f64) -> bool
Auto Trait Implementations§
impl Freeze for MathUtils
impl RefUnwindSafe for MathUtils
impl Send for MathUtils
impl Sync for MathUtils
impl Unpin for MathUtils
impl UnwindSafe for MathUtils
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
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>
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>
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>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
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
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.