Trait rstats::Median

source ·
pub trait Median<'a, T> {
    // Required methods
    fn qmedian_by(
        self,
        c: &mut impl FnMut(&T, &T) -> Ordering,
        q: impl Fn(&T) -> f64
    ) -> Result<f64, MedError<String>>;
    fn median_by(
        self,
        c: &mut impl FnMut(&T, &T) -> Ordering
    ) -> Result<Medians<'a, T>, MedError<String>>;
    fn zeroed(
        self,
        centre: f64,
        quantify: impl Fn(&T) -> f64
    ) -> Result<Vec<f64>, MedError<String>>;
    fn med_correlation(
        self,
        v: Self,
        c: &mut impl FnMut(&T, &T) -> Ordering,
        q: impl Fn(&T) -> f64
    ) -> Result<f64, MedError<String>>;
    fn mad(self, centre: f64, quantify: impl Fn(&T) -> f64) -> f64;
}
Expand description

Fast 1D generic medians, plus related methods

Required Methods§

source

fn qmedian_by( self, c: &mut impl FnMut(&T, &T) -> Ordering, q: impl Fn(&T) -> f64 ) -> Result<f64, MedError<String>>

Median by comparison c, at the end quantified to a single f64 by q

source

fn median_by( self, c: &mut impl FnMut(&T, &T) -> Ordering ) -> Result<Medians<'a, T>, MedError<String>>

Median by comparison c, returns odd/even result

source

fn zeroed( self, centre: f64, quantify: impl Fn(&T) -> f64 ) -> Result<Vec<f64>, MedError<String>>

Zero mean/median data, produced by subtracting the centre

source

fn med_correlation( self, v: Self, c: &mut impl FnMut(&T, &T) -> Ordering, q: impl Fn(&T) -> f64 ) -> Result<f64, MedError<String>>

Median correlation = cosine of an angle between two zero median Vecs

source

fn mad(self, centre: f64, quantify: impl Fn(&T) -> f64) -> f64

Median of absolute differences (MAD).

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl<'a, T> Median<'a, T> for &'a [T]

Medians of &[T]

source§

fn qmedian_by( self, c: &mut impl FnMut(&T, &T) -> Ordering, q: impl Fn(&T) -> f64 ) -> Result<f64, MedError<String>>

Median of &[T] by comparison c, quantified to a single f64 by q. When T is a primitive type directly convertible to f64, pass in as f64 for q. When f64:From is implemented, pass in |x| x.into() for q. When T is Ord, use |a,b| a.cmp(b) as the comparator closure. In all other cases, use custom closures c and q. When T is not quantifiable at all, use the ultimate median_by method.

source§

fn median_by( self, c: &mut impl FnMut(&T, &T) -> Ordering ) -> Result<Medians<'a, T>, MedError<String>>

Median(s) of unquantifiable type by general comparison closure

source§

fn zeroed( self, centre: f64, q: impl Fn(&T) -> f64 ) -> Result<Vec<f64>, MedError<String>>

Zero mean/median data produced by subtracting the centre

source§

fn med_correlation( self, v: &'a [T], c: &mut impl FnMut(&T, &T) -> Ordering, q: impl Fn(&T) -> f64 ) -> Result<f64, MedError<String>>

We define median based correlation as cosine of an angle between two zero median vectors (analogously to Pearson’s zero mean vectors)

§Example
use medians::{Medianf64,Median};
use core::convert::identity;
use core::cmp::Ordering::*;
let v1 = vec![1_f64,2.,3.,4.,5.,6.,7.,8.,9.,10.,11.,12.,13.,14.];
let v2 = vec![14_f64,1.,13.,2.,12.,3.,11.,4.,10.,5.,9.,6.,8.,7.];
assert_eq!(v1.medf_correlation(&v2).unwrap(),-0.1076923076923077);
assert_eq!(v1.med_correlation(&v2,&mut |a,b| a.total_cmp(b),|&a| identity(a)).unwrap(),-0.1076923076923077);
source§

fn mad(self, centre: f64, q: impl Fn(&T) -> f64) -> f64

Data dispersion estimator MAD (Median of Absolute Differences). MAD is more stable than standard deviation and more general than quartiles. When argument centre is the median, it is the most stable measure of data dispersion.

Implementors§