[][src]Trait rstats::Vectors

pub trait Vectors {
    fn point(&self, d: usize, i: usize) -> &[f64];
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 eccentrinset(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>>;
fn trend(self, d: usize, eps: f64, v: &[f64]) -> Vec<f64>;
fn setsub(self, d: usize, m: &[f64]) -> Vec<f64>; }

Implementing basic vector algebra and safe geometric median.

Required methods

fn point(&self, d: usize, i: usize) -> &[f64]

Utility method to retrieve a sub-slice from multidimensional flat slice.

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 eccentrinset(self, d: usize, indx: usize) -> f64

Ecentricity scalar measure of an internal point given by indx

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

Eccentricity scalar measure and vector of any point

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

Eccentricity scalar measure only, of any point

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

Median and quartiles of eccentricities (new robust measure of spread of a multivariate sample)

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

Medoid and Outlier as defined by eccentricities.

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

Geometric median of the set

fn trend(self, d: usize, eps: f64, v: &[f64]) -> Vec<f64>

Trend between two sets

fn setsub(self, d: usize, m: &[f64]) -> Vec<f64>

Transform to zero median form. or subtract any other vector m

Loading content...

Implementations on Foreign Types

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

fn point(&self, d: usize, i: usize) -> &[f64][src]

Retrieves from flat slice 'self' the (address of) sub-slice at index i, where the length of each sub-slice is d. Utility method for multidimensional flat vectors

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,functions::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 a set point given by its indx to all the other points in self. This method is suitable for a single point. For all the points, use more efficient distances.

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

The sum of distances from any point v (typically not in self) to all the points in self.
Geometric Median is defined as the point 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,functions::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 eccentrinset(self, d: usize, indx: usize) -> f64[src]

Scalar positive measure of not being a median for a point belonging to the set. The point is specified by its index indx. The median does not have to be known. The perfect median would return zero. This is suitable for a single point. When eccentricities of all the points are needed, use more efficient eccentricities.

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

Returns (Measure, Eccentricity-Vector) of any point (typically one not belonging to the set). The first (scalar) part of the result is a positive measure of not being a median. The second part is the eccentricity vector, which always points towards the median. The vector is of particular value and interest. This function has no prior knowledge of the actual median.
This is suitable for a single point. When eccentricities of all the points are needed, use more efficient eccentricities.

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

This convenience wrapper calls veccentr and extracts just the eccentricity (residual error for median). Thus this method is the equivalent of eccentr but suited for any explicitly given point, typically not belonging to the set.
When the eccentricity vector is needed, use veccentr

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

Median of eccentricities measures (MOE). This is a new robust measure of spread of multidimensional points (or multivariate sample).

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

Eccentricity defined Medoid and Outlier. This can give different results to medoid above, defined by sums of distances, especially for the outliers. See tests.rs.
Consider some point c and some other points, bunched up at a distance r from c. The sum of their distances will be n*r. Now, spread those points around a circle of radius r from c. The sum of their distances from c will remain the same but the eccentricity of c will be much reduced.

Example

use rstats::{Vectors,functions::genvec};
let d = 6_usize;
let pt = genvec(d,24,7,13); // random test data 5x20
let (_medoideccentricity,medei,_outlierecccentricity,outei) = pt.emedoid(d);
assert_eq!(medei,10); // index of e-medoid
assert_eq!(outei,9);  // index of e-outlier

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. Search 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 new algorithm here.
There will eventually be a multithreaded version of nmedian.

Example

use rstats::{Vectors,functions::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);

fn trend(self, d: usize, eps: f64, v: &[f64]) -> Vec<f64>[src]

Trend computes the vector connecting the geometric medians of two sets of multidimensional points. This is a robust relationship between two unordered multidimensional sets. The two sets have to be in the same space but can have different numbers of points.

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

Generate a new set of vectors of dimensions d in zero (geometric) median form. Or subtract from them all any other vector m The geometric median is invariant with respect to rotation, unlike the often misguidedly used mean (acentroid here), or the quasi median, both of which depend on the choice of axis. For safety, the quasi-median is not even implemented by rstats. Returns the zero medianized vectors as one flat vector.

Loading content...

Implementors

Loading content...