pub trait Vecg {
Show 39 methods
// Required methods
fn tm_statistic(self, centre: &[f64], spread: f64) -> Result<f64, RE>;
fn columnp<U: Clone + Into<f64>>(self, c: usize, v: &[Vec<U>]) -> f64;
fn sadd<U: Into<f64>>(self, s: U) -> Vec<f64>;
fn smult<U: Into<f64>>(self, s: U) -> Vec<f64>;
fn dotp<U: Clone + Into<f64>>(self, v: &[U]) -> f64;
fn dotsig(self, sig: &[f64]) -> Result<f64, RE>;
fn cosine<U: Clone + Into<f64>>(self, v: &[U]) -> f64;
fn sine<U: Clone + Into<f64>>(self, v: &[U]) -> f64;
fn vsub<U: Clone + Into<f64>>(self, v: &[U]) -> Vec<f64>;
fn vsubunit<U: Clone + Into<f64>>(self, v: &[U]) -> Vec<f64>;
fn vadd<U: Clone + Into<f64>>(self, v: &[U]) -> Vec<f64>;
fn vdist<U: Clone + Into<f64>>(self, v: &[U]) -> f64;
fn wvmean<U: Clone + Into<f64>>(self, ws: &[U]) -> f64;
fn wvdist<U: Clone + Into<f64>, V: Clone + Into<f64>>(
self,
ws: &[U],
v: &[V]
) -> f64;
fn vdistsq<U: Clone + Into<f64>>(self, v: &[U]) -> f64;
fn cityblockd<U: Clone + Into<f64>>(self, v: &[U]) -> f64;
fn varea<U: Clone + PartialOrd + Into<f64>>(self, v: &[U]) -> f64;
fn varc<U: Clone + PartialOrd + Into<f64>>(self, v: &[U]) -> f64;
fn vsim<U: Clone + Into<f64>>(self, v: &[U]) -> f64;
fn vcorrsim(self, v: Self) -> Result<f64, RE>;
fn pdotp<U: Clone + PartialOrd + Into<f64>>(self, v: &[U]) -> f64;
fn vdisim<U: Clone + Into<f64>>(self, v: &[U]) -> f64;
fn covone<U: Clone + Into<f64>>(self, m: &[U]) -> TriangMat;
fn kron<U: Clone + Into<f64>>(self, v: &[U]) -> Vec<f64>;
fn outer<U: Clone + Into<f64>>(self, v: &[U]) -> Vec<Vec<f64>>;
fn wedge<U: Clone + Into<f64>>(self, v: &[U]) -> TriangMat;
fn geometric<U: Clone + Into<f64>>(self, b: &[U]) -> TriangMat;
fn jointpdf<U: Clone + Into<f64>>(self, v: &[U]) -> Result<Vec<f64>, RE>;
fn jointentropy<U: Clone + Into<f64>>(self, v: &[U]) -> Result<f64, RE>;
fn dependence<U: Clone + PartialOrd + Into<f64>>(
self,
v: &[U]
) -> Result<f64, RE>;
fn independence<U: Clone + PartialOrd + Into<f64>>(
self,
v: &[U]
) -> Result<f64, RE>;
fn correlation<U: Clone + Into<f64>>(self, v: &[U]) -> f64;
fn kendalcorr<U: Clone + Into<f64>>(self, v: &[U]) -> f64;
fn spearmancorr<U: PartialOrd + Clone + Into<f64>>(self, v: &[U]) -> f64;
fn contribvec_newpt(self, gm: &[f64], recips: f64) -> Result<Vec<f64>, RE>;
fn contrib_newpt(self, gm: &[f64], recips: f64, nf: f64) -> Result<f64, RE>;
fn contribvec_oldpt(self, gm: &[f64], recips: f64) -> Result<Vec<f64>, RE>;
fn contrib_oldpt(self, gm: &[f64], recips: f64, nf: f64) -> Result<f64, RE>;
fn house_reflect<U: Clone + PartialOrd + Into<f64>>(
self,
x: &[U]
) -> Vec<f64>;
}
Expand description
Vector Algebra on two vectors (represented here as generic slices).
Also included are scalar operations on the self
vector.
Required Methods§
sourcefn tm_statistic(self, centre: &[f64], spread: f64) -> Result<f64, RE>
fn tm_statistic(self, centre: &[f64], spread: f64) -> Result<f64, RE>
nd tm_statistic of self against centre (geometric median) spread (madgm)
sourcefn columnp<U: Clone + Into<f64>>(self, c: usize, v: &[Vec<U>]) -> f64
fn columnp<U: Clone + Into<f64>>(self, c: usize, v: &[Vec<U>]) -> f64
Dot product of vector self with column c of matrix v
sourcefn smult<U: Into<f64>>(self, s: U) -> Vec<f64>
fn smult<U: Into<f64>>(self, s: U) -> Vec<f64>
Scalar multiplication of vector, creates new vec
sourcefn dotsig(self, sig: &[f64]) -> Result<f64, RE>
fn dotsig(self, sig: &[f64]) -> Result<f64, RE>
Sigvec product with (zero median) vector self. Cloud density d in its direction:0 <= d <= |self|
sourcefn sine<U: Clone + Into<f64>>(self, v: &[U]) -> f64
fn sine<U: Clone + Into<f64>>(self, v: &[U]) -> f64
Sine of an angle with correct sign in any number of dimensions
sourcefn vsubunit<U: Clone + Into<f64>>(self, v: &[U]) -> Vec<f64>
fn vsubunit<U: Clone + Into<f64>>(self, v: &[U]) -> Vec<f64>
Vectors difference as unit vector (done together for efficiency)
sourcefn wvmean<U: Clone + Into<f64>>(self, ws: &[U]) -> f64
fn wvmean<U: Clone + Into<f64>>(self, ws: &[U]) -> f64
Weighted arithmetic mean of self:&[T]
, scaled by ws:&[U]
sourcefn wvdist<U: Clone + Into<f64>, V: Clone + Into<f64>>(
self,
ws: &[U],
v: &[V]
) -> f64
fn wvdist<U: Clone + Into<f64>, V: Clone + Into<f64>>( self, ws: &[U], v: &[V] ) -> f64
Weighted distance of self:&[T]
to v:&[V]
, weighted by ws:&[U]
sourcefn varea<U: Clone + PartialOrd + Into<f64>>(self, v: &[U]) -> f64
fn varea<U: Clone + PartialOrd + Into<f64>>(self, v: &[U]) -> f64
Area spanned by two vectors always over their concave angle
sourcefn varc<U: Clone + PartialOrd + Into<f64>>(self, v: &[U]) -> f64
fn varc<U: Clone + PartialOrd + Into<f64>>(self, v: &[U]) -> f64
Area proportional to the swept arc
sourcefn vsim<U: Clone + Into<f64>>(self, v: &[U]) -> f64
fn vsim<U: Clone + Into<f64>>(self, v: &[U]) -> f64
Vector similarity S in the interval [0,1]: S = (1+cos(theta))/2
sourcefn vcorrsim(self, v: Self) -> Result<f64, RE>
fn vcorrsim(self, v: Self) -> Result<f64, RE>
Median correlation similarity of vectors, range [0,1]
sourcefn vdisim<U: Clone + Into<f64>>(self, v: &[U]) -> f64
fn vdisim<U: Clone + Into<f64>>(self, v: &[U]) -> f64
We define vector dissimilarity D in the interval [0,1]: D = 1-S = (1-cos(theta))/2
sourcefn covone<U: Clone + Into<f64>>(self, m: &[U]) -> TriangMat
fn covone<U: Clone + Into<f64>>(self, m: &[U]) -> TriangMat
Lower triangular part of a covariance matrix for a single f64 vector.
sourcefn outer<U: Clone + Into<f64>>(self, v: &[U]) -> Vec<Vec<f64>>
fn outer<U: Clone + Into<f64>>(self, v: &[U]) -> Vec<Vec<f64>>
Outer product: matrix multiplication of column self with row v.
sourcefn wedge<U: Clone + Into<f64>>(self, v: &[U]) -> TriangMat
fn wedge<U: Clone + Into<f64>>(self, v: &[U]) -> TriangMat
Exterior (Grassman) algebra product: produces 2-blade components
sourcefn geometric<U: Clone + Into<f64>>(self, b: &[U]) -> TriangMat
fn geometric<U: Clone + Into<f64>>(self, b: &[U]) -> TriangMat
Geometric (Clifford) algebra product in matrix form: a*b + a∧b
sourcefn jointpdf<U: Clone + Into<f64>>(self, v: &[U]) -> Result<Vec<f64>, RE>
fn jointpdf<U: Clone + Into<f64>>(self, v: &[U]) -> Result<Vec<f64>, RE>
Joint probability density function
sourcefn jointentropy<U: Clone + Into<f64>>(self, v: &[U]) -> Result<f64, RE>
fn jointentropy<U: Clone + Into<f64>>(self, v: &[U]) -> Result<f64, RE>
Joint entropy of &[T],&[U]
in nats (units of e)
sourcefn dependence<U: Clone + PartialOrd + Into<f64>>(
self,
v: &[U]
) -> Result<f64, RE>
fn dependence<U: Clone + PartialOrd + Into<f64>>( self, v: &[U] ) -> Result<f64, RE>
Statistical pairwise dependence of &[T] &[U]
variables in the range [0,1]
sourcefn independence<U: Clone + PartialOrd + Into<f64>>(
self,
v: &[U]
) -> Result<f64, RE>
fn independence<U: Clone + PartialOrd + Into<f64>>( self, v: &[U] ) -> Result<f64, RE>
Statistical pairwise independence in the range [0,1]
based on joint entropy
sourcefn spearmancorr<U: PartialOrd + Clone + Into<f64>>(self, v: &[U]) -> f64
fn spearmancorr<U: PartialOrd + Clone + Into<f64>>(self, v: &[U]) -> f64
Spearman rho correlation.
sourcefn contribvec_newpt(self, gm: &[f64], recips: f64) -> Result<Vec<f64>, RE>
fn contribvec_newpt(self, gm: &[f64], recips: f64) -> Result<Vec<f64>, RE>
Change to gm that adding point self will cause
sourcefn contrib_newpt(self, gm: &[f64], recips: f64, nf: f64) -> Result<f64, RE>
fn contrib_newpt(self, gm: &[f64], recips: f64, nf: f64) -> Result<f64, RE>
Normalized magnitude of change to gm that adding point self will cause
sourcefn contribvec_oldpt(self, gm: &[f64], recips: f64) -> Result<Vec<f64>, RE>
fn contribvec_oldpt(self, gm: &[f64], recips: f64) -> Result<Vec<f64>, RE>
Contribution of removing point self
sourcefn contrib_oldpt(self, gm: &[f64], recips: f64, nf: f64) -> Result<f64, RE>
fn contrib_oldpt(self, gm: &[f64], recips: f64, nf: f64) -> Result<f64, RE>
Normalized contribution of removing point self (as negative scalar)
sourcefn house_reflect<U: Clone + PartialOrd + Into<f64>>(self, x: &[U]) -> Vec<f64>
fn house_reflect<U: Clone + PartialOrd + Into<f64>>(self, x: &[U]) -> Vec<f64>
Householder reflect
Object Safety§
Implementations on Foreign Types§
source§impl<T> Vecg for &[T]
impl<T> Vecg for &[T]
source§fn tm_statistic(self, centre: &[f64], spread: f64) -> Result<f64, RE>
fn tm_statistic(self, centre: &[f64], spread: f64) -> Result<f64, RE>
nd tm_statistic of self against centre and spread.
Unlike in 1d, is always positive.
source§fn columnp<U: Clone + Into<f64>>(self, c: usize, v: &[Vec<U>]) -> f64
fn columnp<U: Clone + Into<f64>>(self, c: usize, v: &[Vec<U>]) -> f64
Dot product of vector self with column c of matrix v
source§fn smult<U: Into<f64>>(self, s: U) -> Vec<f64>
fn smult<U: Into<f64>>(self, s: U) -> Vec<f64>
Scalar multiplication with a vector, creates new vec
source§fn dotp<U: Clone + Into<f64>>(self, v: &[U]) -> f64
fn dotp<U: Clone + Into<f64>>(self, v: &[U]) -> f64
Scalar product.
Must be of the same length - no error checking (for speed)
source§fn dotsig(self, sig: &[f64]) -> Result<f64, RE>
fn dotsig(self, sig: &[f64]) -> Result<f64, RE>
Measure d of cloud density in (zero median) self direction:0 <= d <= |self|
Product with signature vec of axial projections of some cloud.
Similar result can be obtained by projecting all points onto self but that is usually too slow.
source§fn cosine<U: Clone + Into<f64>>(self, v: &[U]) -> f64
fn cosine<U: Clone + Into<f64>>(self, v: &[U]) -> f64
Cosine of angle between the two slices. Done in one iteration for efficiency.
source§fn sine<U: Clone + Into<f64>>(self, v: &[U]) -> f64
fn sine<U: Clone + Into<f64>>(self, v: &[U]) -> f64
Generalized cross product:
Sine of an angle between self and v with correct sign in any number of dimensions
source§fn vsubunit<U: Clone + Into<f64>>(self, v: &[U]) -> Vec<f64>
fn vsubunit<U: Clone + Into<f64>>(self, v: &[U]) -> Vec<f64>
Vectors difference unitised (done together for efficiency)
source§fn wvmean<U: Clone + Into<f64>>(self, ws: &[U]) -> f64
fn wvmean<U: Clone + Into<f64>>(self, ws: &[U]) -> f64
Weighted arithmetic mean of self:&[T]
, scaled by ws:&[U]
source§fn wvdist<U, V>(self, ws: &[U], v: &[V]) -> f64
fn wvdist<U, V>(self, ws: &[U], v: &[V]) -> f64
Weighted distance of self:&[T]
to v:&[V]
, scaled by ws:&[U]
allows all three to be of different types
source§fn varea<U: Clone + PartialOrd + Into<f64>>(self, v: &[U]) -> f64
fn varea<U: Clone + PartialOrd + Into<f64>>(self, v: &[U]) -> f64
Area spanned by two vectors over their concave angle (always >= 0)
|a||b||sin(theta)| == (1-cos2(theta)).sqrt()
Attains maximum |a|.|b|
when the vectors are orthogonal.
source§fn varc<U: Clone + PartialOrd + Into<f64>>(self, v: &[U]) -> f64
fn varc<U: Clone + PartialOrd + Into<f64>>(self, v: &[U]) -> f64
Area of swept arc = |a||b|(1-cos(theta)) = 2|a||b|D
source§fn pdotp<U: Clone + PartialOrd + Into<f64>>(self, v: &[U]) -> f64
fn pdotp<U: Clone + PartialOrd + Into<f64>>(self, v: &[U]) -> f64
Positive dotp in the interval: [0,2|a||b|]
= |a||b|(1+cos(theta)) = 2|a||b|S
source§fn vsim<U: Clone + Into<f64>>(self, v: &[U]) -> f64
fn vsim<U: Clone + Into<f64>>(self, v: &[U]) -> f64
We define vector similarity S in the interval [0,1] as S = (1+cos(theta))/2
source§fn vdisim<U: Clone + Into<f64>>(self, v: &[U]) -> f64
fn vdisim<U: Clone + Into<f64>>(self, v: &[U]) -> f64
We define vector dissimilarity D in the interval [0,1] as D = 1-S = (1-cos(theta))/2
source§fn covone<U: Clone + Into<f64>>(self, m: &[U]) -> TriangMat
fn covone<U: Clone + Into<f64>>(self, m: &[U]) -> TriangMat
Lower triangular covariance matrix for a single vector. Where m is either mean or median vector (to be subtracted). Covariance matrix is symmetric (kind:2) (positive semi definite).
source§fn kron<U: Clone + Into<f64>>(self, v: &[U]) -> Vec<f64>
fn kron<U: Clone + Into<f64>>(self, v: &[U]) -> Vec<f64>
Kronecker product of two vectors.
The indexing is always assumed to be in this order: row,column.
Flat version of outer(wedge) product
source§fn outer<U: Clone + Into<f64>>(self, v: &[U]) -> Vec<Vec<f64>>
fn outer<U: Clone + Into<f64>>(self, v: &[U]) -> Vec<Vec<f64>>
Outer product: matrix multiplication of column self with row v.
source§fn wedge<U: Clone + Into<f64>>(self, b: &[U]) -> TriangMat
fn wedge<U: Clone + Into<f64>>(self, b: &[U]) -> TriangMat
Exterior (Grassman) algebra product: produces components of 2-blade a∧b
source§fn geometric<U: Clone + Into<f64>>(self, b: &[U]) -> TriangMat
fn geometric<U: Clone + Into<f64>>(self, b: &[U]) -> TriangMat
Geometric (Clifford) algebra product: a*b + a∧b in matrix form here the elements of the dot product a*b are placed in their natural positions on the diagonal (can be easily added)
source§fn jointpdf<U: Clone + Into<f64>>(self, v: &[U]) -> Result<Vec<f64>, RE>
fn jointpdf<U: Clone + Into<f64>>(self, v: &[U]) -> Result<Vec<f64>, RE>
Joint probability density function of two pairwise matched slices
source§fn jointentropy<U: Clone + Into<f64>>(self, v: &[U]) -> Result<f64, RE>
fn jointentropy<U: Clone + Into<f64>>(self, v: &[U]) -> Result<f64, RE>
Joint entropy of two sets of the same length
source§fn dependence<U: Clone + PartialOrd + Into<f64>>(
self,
v: &[U]
) -> Result<f64, RE>
fn dependence<U: Clone + PartialOrd + Into<f64>>( self, v: &[U] ) -> Result<f64, RE>
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
source§fn independence<U: Clone + PartialOrd + Into<f64>>(
self,
v: &[U]
) -> Result<f64, RE>
fn independence<U: Clone + PartialOrd + Into<f64>>( self, v: &[U] ) -> Result<f64, RE>
Independence of &[T] &[U] variables in the range [0,1] returns 1 iff they are statistically component wise independent
source§fn correlation<U: Clone + Into<f64>>(self, v: &[U]) -> f64
fn correlation<U: Clone + Into<f64>>(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);
source§fn kendalcorr<U: Clone + Into<f64>>(self, v: &[U]) -> f64
fn kendalcorr<U: Clone + Into<f64>>(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);
source§fn spearmancorr<U: PartialOrd + Clone + Into<f64>>(self, v: &[U]) -> f64
fn spearmancorr<U: PartialOrd + Clone + Into<f64>>(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);
source§fn contribvec_newpt(self, gm: &[f64], recips: f64) -> Result<Vec<f64>, RE>
fn contribvec_newpt(self, gm: &[f64], recips: f64) -> Result<Vec<f64>, RE>
Delta gm that adding a point will cause
source§fn contrib_newpt(self, gm: &[f64], recips: f64, nf: f64) -> Result<f64, RE>
fn contrib_newpt(self, gm: &[f64], recips: f64, nf: f64) -> Result<f64, RE>
Normalized magnitude of change to gm that adding a point will cause
source§fn contribvec_oldpt(self, gm: &[f64], recips: f64) -> Result<Vec<f64>, RE>
fn contribvec_oldpt(self, gm: &[f64], recips: f64) -> Result<Vec<f64>, RE>
Delta gm caused by removing an existing set point self
source§fn contrib_oldpt(self, gm: &[f64], recips: f64, nf: f64) -> Result<f64, RE>
fn contrib_oldpt(self, gm: &[f64], recips: f64, nf: f64) -> Result<f64, RE>
Normalized Contribution that removing an existing set point p will make Is a negative number
source§fn house_reflect<U: Clone + PartialOrd + Into<f64>>(self, x: &[U]) -> Vec<f64>
fn house_reflect<U: Clone + PartialOrd + Into<f64>>(self, x: &[U]) -> Vec<f64>
Householder reflect