[][src]Trait rstats::Vectors

pub trait Vectors {
    fn dotp(self, v: &[f64]) -> f64;
fn vsub(self, v: &[f64]) -> Vec<f64>;
fn vadd(self, v: &[f64]) -> Vec<f64>;
fn vmag(self) -> f64;
fn vdist(self, v: &[f64]) -> f64;
fn smult(self, s: f64) -> Vec<f64>;
fn vunit(self) -> Vec<f64>;
fn correlation(self, v: &[f64]) -> Result<f64>;
fn kendalcorr(self, v: &[f64]) -> Result<f64>;
fn spearmancorr(self, v: &[f64]) -> Result<f64>;
fn autocorr(self) -> Result<f64>;
fn minmax(self) -> (f64, usize, f64, usize);
fn acentroid(self, d: usize) -> Vec<f64>;
fn distances(self, d: usize) -> Result<Vec<f64>>;
fn distsuminset(self, d: usize, indx: usize) -> f64;
fn distsum(self, d: usize, v: &[f64]) -> f64;
fn medoid(self, d: usize) -> (f64, usize, f64, usize);
fn eccentricities(self, d: usize) -> Result<Vec<Vec<f64>>>;
fn eccentr(self, d: usize, indx: usize) -> f64;
fn veccentr(self, d: usize, thisp: &[f64]) -> Result<(f64, Vec<f64>)>;
fn ecc(self, d: usize, v: &[f64]) -> f64;
fn moe(self, d: usize) -> Med;
fn emedoid(self, d: usize) -> (f64, usize, f64, usize);
fn nmedian(self, d: usize, eps: f64) -> Result<Vec<f64>>; }

Implementing basic vector algebra and safe geometric median.

Required methods

fn dotp(self, v: &[f64]) -> f64

Scalar product of two vectors

fn vsub(self, v: &[f64]) -> Vec<f64>

Vector subtraction

fn vadd(self, v: &[f64]) -> Vec<f64>

Vector addition

fn vmag(self) -> f64

Vector magnitude

fn vdist(self, v: &[f64]) -> f64

Euclidian distance between two points

fn smult(self, s: f64) -> Vec<f64>

Scalar multiplication

fn vunit(self) -> Vec<f64>

Unit vector

fn correlation(self, v: &[f64]) -> Result<f64>

Correlation

fn kendalcorr(self, v: &[f64]) -> Result<f64>

Kendall's tau-b (rank order) correlation

fn spearmancorr(self, v: &[f64]) -> Result<f64>

Spearman's rho (rank differences) correlation

fn autocorr(self) -> Result<f64>

Autocorrelation

fn minmax(self) -> (f64, usize, f64, usize)

Minimum, minimum's index, maximum, maximum's index.

fn acentroid(self, d: usize) -> Vec<f64>

Centroid = euclidian mean of a set of points

fn distances(self, d: usize) -> Result<Vec<f64>>

Sums of distances from each point to all other points

fn distsuminset(self, d: usize, indx: usize) -> f64

Sum of distances from one point given by indx

fn distsum(self, d: usize, v: &[f64]) -> f64

Sum of distances from arbitrary point (v) to all the points in self

fn medoid(self, d: usize) -> (f64, usize, f64, usize)

Medoid and Outlier (by distance) of a set of points

fn eccentricities(self, d: usize) -> Result<Vec<Vec<f64>>>

Eccentricity vectors from each point

fn eccentr(self, d: usize, indx: usize) -> f64

Ecentricity measure (0,1) of an internal point given by indx

fn veccentr(self, d: usize, thisp: &[f64]) -> Result<(f64, Vec<f64>)>

Eccentricity measure and vector of any point

fn ecc(self, d: usize, v: &[f64]) -> f64

Eccentricity measure only, of any point

fn moe(self, d: usize) -> Med

Median of eccentricities (measure of spread of multivariate sample)

fn emedoid(self, d: usize) -> (f64, usize, f64, usize)

Medoid and Outlier defined by eccentricities

fn nmedian(self, d: usize, eps: f64) -> Result<Vec<f64>>

Geometric median of the set

Loading content...

Implementations on Foreign Types

impl<'_> Vectors for &'_ [f64][src]

fn smult(self, s: f64) -> Vec<f64>[src]

Scalar multiplication of a vector, creates new vec

fn dotp(self, v: &[f64]) -> f64[src]

Scalar product of two f64 slices.
Must be of the same length - no error checking for speed

fn vsub(self, v: &[f64]) -> Vec<f64>[src]

Vector subtraction, creates a new Vec result

fn vadd(self, v: &[f64]) -> Vec<f64>[src]

Vector addition, creates a new Vec result

fn vdist(self, v: &[f64]) -> f64[src]

Euclidian distance between two n dimensional points (vectors).
Slightly faster than vsub followed by vmag, as both are done in one loop

fn vmag(self) -> f64[src]

Vector magnitude

fn vunit(self) -> Vec<f64>[src]

Unit vector - creates a new one

fn correlation(self, v: &[f64]) -> Result<f64>[src]

Correlation coefficient of a sample of two f64 variables.

Example

use rstats::Vectors;
let v1 = vec![1_f64,2.,3.,4.,5.,6.,7.,8.,9.,10.,11.,12.,13.,14.];
let v2 = vec![14_f64,13.,12.,11.,10.,9.,8.,7.,6.,5.,4.,3.,2.,1.];
assert_eq!(v1.correlation(&v2).unwrap(),-1_f64);

fn kendalcorr(self, v: &[f64]) -> Result<f64>[src]

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::Vectors;
let v1 = vec![1_f64,2.,3.,4.,5.,6.,7.,8.,9.,10.,11.,12.,13.,14.];
let v2 = vec![14_f64,13.,12.,11.,10.,9.,8.,7.,6.,5.,4.,3.,2.,1.];
assert_eq!(v1.kendalcorr(&v2).unwrap(),-1_f64);

fn spearmancorr(self, v: &[f64]) -> Result<f64>[src]

Spearman rho correlation coefficient of a sample of two f64 variables. This is the simplest implementation with no sorting.

Example

use rstats::Vectors;
let v1 = vec![1_f64,2.,3.,4.,5.,6.,7.,8.,9.,10.,11.,12.,13.,14.];
let v2 = vec![14_f64,13.,12.,11.,10.,9.,8.,7.,6.,5.,4.,3.,2.,1.];
assert_eq!(v1.spearmancorr(&v2).unwrap(),-1_f64);

fn autocorr(self) -> Result<f64>[src]

(Auto)correlation coefficient of pairs of successive values of (time series) f64 variable.

Example

use rstats::Vectors;
let v1 = vec![1_f64,2.,3.,4.,5.,6.,7.,8.,9.,10.,11.,12.,13.,14.];
assert_eq!(v1.autocorr().unwrap(),0.9984603532054123_f64);

fn acentroid(self, d: usize) -> Vec<f64>[src]

Centroid = simple multidimensional arithmetic mean

Example

use rstats::{Vectors,vimpls::genvec};
let pts = genvec(15,15,255,30);
let centre = pts.acentroid(15);
let dist = pts.distsum(15,&centre);
assert_eq!(dist, 4.14556218326653_f64);

fn minmax(self) -> (f64, usize, f64, usize)[src]

Finds minimum, minimum's index, maximum, maximum's index of &f64 Here self is usually some data, rather than a vector

fn distances(self, d: usize) -> Result<Vec<f64>>[src]

For each point, gives its sum of distances to all other points This is the efficient workhorse of distances based analysis

fn distsuminset(self, d: usize, indx: usize) -> f64[src]

The sum of distances from within-set point given by indx to all points in self.
Geometric Median is defined as v which minimises this function.

fn distsum(self, d: usize, v: &[f64]) -> f64[src]

The sum of distances from any point v to all points in self.
Geometric Median is defined as v which minimises this function.

fn medoid(self, d: usize) -> (f64, usize, f64, usize)[src]

Medoid is the point belonging to set of points self, which has the least sum of distances to all other points. Outlier is the point with the greatest sum of distances. This function returns a four-tuple:
(medoid_distance, medoid_index, outlier_distance, outlier_index). d is the number of dimensions = length of the point sub-slices. The entire set of points is held in one flat &[f64].
This is faster than vec of vecs but we have to handle the indices.

Example

use rstats::{Vectors,vimpls::genvec};
let pts = genvec(15,15,255,30);
let (dm,_,_,_) = pts.medoid(15);
assert_eq!(dm,4.812334638782327_f64);

fn eccentricities(self, d: usize) -> Result<Vec<Vec<f64>>>[src]

Eccentricity vector for each point This is the efficient workhorse of eccentrities analysis

fn eccentr(self, d: usize, indx: usize) -> f64[src]

Eccentricity of a d-dimensional point belonging to the set self, specified by its indx.
Eccentricity is a scalar measure between 0.0 and 1.0 of a point not being a median of the given set. It does not need the median. The perfect median has eccentricity zero.

fn veccentr(self, d: usize, thisp: &[f64]) -> Result<(f64, Vec<f64>)>[src]

Ecentricity measure and the eccentricity vector of any point (typically one not belonging to the set). It is a measure between 0.0 and 1.0 of not being a median but it does not need the median. The eccentricity vector points towards the median and has the maximum possible magnitude of n, by which the scalar measure is normalised.

fn ecc(self, d: usize, v: &[f64]) -> f64[src]

This convenience wrapper calls veccentr and extracts just the eccentricity (residual error for median).

fn moe(self, d: usize) -> Med[src]

We now define MOE (median of ecentricities), a new measure of spread of multidimensional points (or multivariate sample)

fn nmedian(self, d: usize, eps: f64) -> Result<Vec<f64>>[src]

Geometric Median (gm) is the point that minimises the sum of distances to a given set of points. It has (provably) only vector iterative solutions. Searching methods are slow and difficult in highly dimensional space. Weiszfeld's fixed point iteration formula had known problems with sometimes failing to converge. Especially, when the points are dense in the close proximity of the gm, or it coincides with one of them.
However, these problems are fixed in my improved algorithm here.
There is eventually going to be a multithreaded version of nmedian.

Example

use rstats::{Vectors,vimpls::genvec};
let pt = genvec(15,15,255,30);
let gm = pt.nmedian(15, 1e-5).unwrap();
let error = pt.ecc(15,&gm);
assert_eq!(error,0.000004826966175302838_f64);
Loading content...

Implementors

Loading content...