Trait rstats::Vecf64 [−][src]
pub trait Vecf64 {}Show methods
fn smult(self, s: f64) -> Vec<f64>; fn sadd(self, s: f64) -> Vec<f64>; fn dotp(self, v: &[f64]) -> f64; fn vinverse(self) -> Vec<f64>; fn cosine(self, _v: &[f64]) -> f64; fn vsub(self, v: &[f64]) -> Vec<f64>; fn negv(self) -> Vec<f64>; fn vadd(self, v: &[f64]) -> Vec<f64>; fn vmag(self) -> f64; fn vmagsq(self) -> f64; fn vdist(self, v: &[f64]) -> f64; fn vdistsq(self, v: &[f64]) -> f64; fn cityblockd(self, v: &[f64]) -> f64; fn vunit(self) -> Vec<f64>; fn vsubunit(self, v: &[f64]) -> Vec<f64>; fn varea(self, v: &[f64]) -> f64; fn varc(self, v: &[f64]) -> f64; fn vsim(self, v: &[f64]) -> f64; fn vdisim(self, v: &[f64]) -> f64; fn correlation(self, _v: &[f64]) -> f64; fn kendalcorr(self, _v: &[f64]) -> f64; fn spearmancorr(self, _v: &[f64]) -> f64; fn autocorr(self) -> f64; fn covone(self, m: &[f64]) -> Vec<f64>; fn symmatrix(self) -> Vec<Vec<f64>>; fn minmax(self) -> (f64, usize, f64, usize); fn lintrans(self) -> Vec<f64>; fn sortf(self) -> Vec<f64>;
Expand description
Vector algebra on one or two vectors.
Required methods
Unit vector of difference (done together for efficiency)
Area of parallelogram between two vectors (magnitude of cross product)
Lower triangular part of a covariance matrix for a single f64 vector.
Reconstructs the full symmetric matrix from its lower diagonal compact form
Implementations on Foreign Types
Scalar product of two f64 slices.
Must be of the same length - no error checking (for speed)
Cosine of an angle between two vectors.
Example
use rstats::Vecf64; 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.cosine(&v2),0.7517241379310344);
Euclidian distance between two n dimensional points (vectors).
Slightly faster than vsub followed by vmag, as both are done in one loop
Euclidian distance squared between two n dimensional points (vectors).
Slightly faster than vsub followed by vmasq, as both are done in one loop
Same as vdist without taking the square root
Area of a parallelogram between two vectors.
Same as the magnitude of their cross product |a ^ b| = |a||b|sin(theta).
Attains maximum |a|.|b|
when the vectors are othogonal.
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
Area proportional to the swept arc up to angle theta.
Attains maximum of 2|a||b|
when the vectors have opposite orientations.
This is really |a||b|(1-cos(theta)) = 2|a||b|D
Pearson’s correlation coefficient of a sample of two f64 variables.
Example
use rstats::Vecf64; 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 coefficient of a sample of two f64 variables. Defined by: tau = (conc - disc) / sqrt((conc + disc + tiesx) * (conc + disc + tiesy)) This is the simplest implementation with no sorting.
Example
use rstats::Vecf64; 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 coefficient of two f64 variables. This is the simplest implementation with no sorting.
Example
use rstats::Vecf64; 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);
(Auto)correlation coefficient of pairs of successive values of (time series) f64 variable.
Example
use rstats::Vecf64; let v1 = vec![1_f64,2.,3.,4.,5.,6.,7.,8.,9.,10.,11.,12.,13.,14.]; assert_eq!(v1.autocorr(),0.9984603532054123_f64);
Finds minimum, minimum’s first index, maximum, maximum’s first index of &f64
New sorted vector. Immutable sort.
Copies self and then sorts it in place, leaving self unchanged.
Calls mutsortf and that calls the standard self.sort_unstable_by.
Consider using our sortm
instead.
Flattened lower triangular part of a covariance matrix for a single f64 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
Reconstructs the full symmetric square matrix from its lower diagonal compact form, as produced by covar, covone, wcovar