pub trait Vecg<T, U> {
Show 25 methods
fn sadd(self, s: U) -> Vec<f64>;
fn smult(self, s: U) -> Vec<f64>;
fn dotp(self, v: &[U]) -> f64;
fn cosine(self, v: &[U]) -> f64;
fn vsub(self, v: &[U]) -> Vec<f64>;
fn vsubunit(self, v: &[U]) -> Vec<f64>;
fn vadd(self, v: &[U]) -> Vec<f64>;
fn vdist(self, v: &[U]) -> f64;
fn vdistsq(self, v: &[U]) -> f64;
fn cityblockd(self, v: &[U]) -> f64;
fn varea(self, v: &[U]) -> f64;
fn varc(self, v: &[U]) -> f64;
fn vsim(self, v: &[U]) -> f64;
fn vdisim(self, v: &[U]) -> f64;
fn covone(self, m: &[U]) -> Vec<f64>;
fn kron(self, m: &[U]) -> Vec<f64>;
fn outer(self, m: &[U]) -> Vec<Vec<f64>>;
fn jointpdf(self, v: &[U]) -> Vec<f64>;
fn jointentropy(self, v: &[U]) -> f64;
fn dependence(self, v: &[U]) -> f64;
fn independence(self, v: &[U]) -> f64;
fn correlation(self, v: &[U]) -> f64;
fn mediancorr(self, v: &[U]) -> f64;
fn kendalcorr(self, v: &[U]) -> f64;
fn spearmancorr(self, v: &[U]) -> f64;
}
Expand description
Vector Algebra on two vectors (represented here as generic slices).
Also included are scalar operations on the self
vector.
Required methods
Vectors difference as unit vector (done together for efficiency)
fn cityblockd(self, v: &[U]) -> f64
fn cityblockd(self, v: &[U]) -> f64
cityblock distance
Magnitude of the cross product |a x b| = |a||b|sin(theta).
Attains maximum |a|.|b|
when the vectors are othogonal.
We define vector dissimilarity D in the interval [0,1]: D = 1-S = (1-cos(theta))/2
Lower triangular part of a covariance matrix for a single f64 vector.
fn jointentropy(self, v: &[U]) -> f64
fn jointentropy(self, v: &[U]) -> f64
Joint entropy of &[T],&[U] in nats (units of e)
fn dependence(self, v: &[U]) -> f64
fn dependence(self, v: &[U]) -> f64
Statistical pairwise dependence of &[T] &[U] variables in the range [0,1]
fn independence(self, v: &[U]) -> f64
fn independence(self, v: &[U]) -> f64
Statistical pairwise independence in the range [1,2] based on joint entropy
fn correlation(self, v: &[U]) -> f64
fn correlation(self, v: &[U]) -> f64
Cholesky decomposition of positive definite matrix into LLt Pearson’s correlation.
fn mediancorr(self, v: &[U]) -> f64
fn mediancorr(self, v: &[U]) -> f64
Median based correlation
fn kendalcorr(self, v: &[U]) -> f64
fn kendalcorr(self, v: &[U]) -> f64
Kendall Tau-B correlation.
fn spearmancorr(self, v: &[U]) -> f64
fn spearmancorr(self, v: &[U]) -> f64
Spearman rho correlation.
Implementations on Foreign Types
sourceimpl<T, U> Vecg<T, U> for &[T] where
T: Copy + PartialOrd + Display,
U: Copy + PartialOrd + Display,
f64: From<T>,
f64: From<U>,
impl<T, U> Vecg<T, U> for &[T] where
T: Copy + PartialOrd + Display,
U: Copy + PartialOrd + Display,
f64: From<T>,
f64: From<U>,
sourcefn dotp(self, v: &[U]) -> f64
fn dotp(self, v: &[U]) -> f64
Scalar product.
Must be of the same length - no error checking (for speed)
sourcefn cosine(self, v: &[U]) -> f64
fn cosine(self, v: &[U]) -> f64
Cosine of angle between the two slices. Done in one iteration for efficiency.
sourcefn vsubunit(self, v: &[U]) -> Vec<f64>
fn vsubunit(self, v: &[U]) -> Vec<f64>
Vectors difference unitised (done together for efficiency)
sourcefn cityblockd(self, v: &[U]) -> f64
fn cityblockd(self, v: &[U]) -> f64
cityblock distance
sourcefn varea(self, v: &[U]) -> f64
fn varea(self, v: &[U]) -> f64
Magnitude of the cross product |a x b| = |a||b|sin(theta).
Attains maximum |a|.|b|
when the vectors are orthogonal.
sourcefn vsim(self, v: &[U]) -> f64
fn vsim(self, v: &[U]) -> f64
We define vector similarity S in the interval [0,1] as S = (1+cos(theta))/2
sourcefn vdisim(self, v: &[U]) -> f64
fn vdisim(self, v: &[U]) -> f64
We define vector dissimilarity D in the interval [0,1] as D = 1-S = (1-cos(theta))/2
sourcefn covone(self, m: &[U]) -> Vec<f64>
fn covone(self, m: &[U]) -> Vec<f64>
Flattened lower triangular part of a covariance matrix. m can be either mean or median vector. Since covariance matrix is symmetric (positive semi definite), the upper triangular part can be trivially added for all j>i by: c(j,i) = c(i,j). N.b. the indexing is always assumed to be in this order: row,column. The items of the resulting lower triangular array c[i][j] are pushed flat into a single vector in this double loop order: left to right, top to bottom
sourcefn kron(self, m: &[U]) -> Vec<f64>
fn kron(self, m: &[U]) -> Vec<f64>
Kronecker product of two vectors.
The indexing is always assumed to be in this order: row,column.
sourcefn outer(self, m: &[U]) -> Vec<Vec<f64>>
fn outer(self, m: &[U]) -> Vec<Vec<f64>>
Outer product of two vectors.
The indexing is always assumed to be in this order: row,column.
sourcefn jointpdf(self, v: &[U]) -> Vec<f64>
fn jointpdf(self, v: &[U]) -> Vec<f64>
Joint probability density function of two pairwise matched slices
sourcefn jointentropy(self, v: &[U]) -> f64
fn jointentropy(self, v: &[U]) -> f64
Joint entropy of two sets of the same length
sourcefn dependence(self, v: &[U]) -> f64
fn dependence(self, v: &[U]) -> f64
Dependence of &[T] &[U] variables in the range [0,1] returns 0 iff they are statistically component wise independent returns 1 when they are identical or all their values are unique
sourcefn independence(self, v: &[U]) -> f64
fn independence(self, v: &[U]) -> f64
Independence of &[T] &[U] variables in the range [1,2] returns 2 iff they are statistically component wise independent
sourcefn mediancorr(self, v: &[U]) -> f64
fn mediancorr(self, v: &[U]) -> f64
We define median based correlation as cosine of an angle between two zero median vectors (analogously to Pearson’s zero mean vectors)
Example
use rstats::Vecg;
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.correlation(&v2),-0.1076923076923077);
sourcefn correlation(self, v: &[U]) -> f64
fn correlation(self, v: &[U]) -> f64
Pearson’s (most common) correlation.
Example
use rstats::Vecg;
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.correlation(&v2),-0.1076923076923077);
sourcefn kendalcorr(self, v: &[U]) -> f64
fn kendalcorr(self, v: &[U]) -> f64
Kendall Tau-B correlation. Defined by: tau = (conc - disc) / sqrt((conc + disc + tiesx) * (conc + disc + tiesy)) This is the simplest implementation with no sorting.
Example
use rstats::Vecg;
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.kendalcorr(&v2),-0.07692307692307693);
sourcefn spearmancorr(self, v: &[U]) -> f64
fn spearmancorr(self, v: &[U]) -> f64
Spearman rho correlation. This is the simplest implementation with no sorting.
Example
use rstats::Vecg;
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.spearmancorr(&v2),-0.1076923076923077);