pub trait Vecg<T, U> {
Show 23 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 correlation(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 dependence based on joint entropy
fn correlation(self, v: &[U]) -> f64
fn correlation(self, v: &[U]) -> f64
Pearson’s 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
Scalar product.
Must be of the same length - no error checking (for speed)
Cosine of angle between the two slices. Done in one iteration for efficiency.
Vectors difference unitised (done together for efficiency)
cityblock distance
Magnitude of the cross product |a x b| = |a||b|sin(theta).
Attains maximum |a|.|b|
when the vectors are orthogonal.
We define vector similarity S in the interval [0,1] as S = (1+cos(theta))/2
We define vector dissimilarity D in the interval [0,1] as D = 1-S = (1-cos(theta))/2
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
Kronecker product of two vectors.
The indexing is always assumed to be in this order: row,column.
Outer product of two vectors.
The indexing is always assumed to be in this order: row,column.
Joint probability density function of two pairwise matched slices
Joint entropy of two sets of the same length
Dependence of &[T] &[U] variables.
i.e. dependence
returns 0 iff they are statistically independent
and 1 when they are identical
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);
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);
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);