Trait rstats::VecVecf64 [−][src]
pub trait VecVecf64 {}Show methods
fn acentroid(self) -> Vec<f64>; fn gcentroid(self) -> Vec<f64>; fn hcentroid(self) -> Vec<f64>; fn trend(self, eps: f64, v: Vec<Vec<f64>>) -> Vec<f64>; fn translate(self, m: &[f64]) -> Vec<Vec<f64>>; fn distsums(self) -> Vec<f64>; fn distsuminset(self, indx: usize) -> f64; fn distsum(self, v: &[f64]) -> f64; fn dists(self, v: &[f64]) -> Vec<f64>; fn medoid(self) -> (f64, usize, f64, usize); fn eccentricities(self) -> Vec<Vec<f64>>; fn exacteccs(self, eps: f64) -> Vec<Vec<f64>>; fn sortedeccs(self, ascending: bool, eps: f64) -> (Vec<f64>, Vec<f64>); fn wsortedeccs(self, ws: &[f64], eps: f64) -> (Vec<f64>, Vec<f64>, Vec<f64>); fn wsortedcos(
self,
medmed: &[f64],
med: &[f64],
ws: &[f64]
) -> (Vec<f64>, Vec<f64>); fn nxmember(self, indx: usize) -> Vec<f64>; fn eccmember(self, indx: usize) -> Vec<f64>; fn nxnonmember(self, p: &[f64]) -> Vec<f64>; fn errorv(self, p: &[f64]) -> Vec<f64>; fn eccnonmember(self, p: &[f64]) -> Vec<f64>; fn wnxnonmember(self, ws: &[f64], p: &[f64]) -> Vec<f64>; fn mags(self) -> Vec<f64>; fn moe(self, eps: f64) -> (MStats, Med); fn emedoid(self, eps: f64) -> (f64, usize, f64, usize); fn firstpoint(self) -> Vec<f64>; fn nmedian(self, eps: f64) -> Vec<f64>; fn gmedian(self, eps: f64) -> Vec<f64>; fn wgmedian(self, ws: &[f64], eps: f64) -> Vec<f64>; fn covar(self, med: &[f64]) -> Vec<f64>;
Expand description
Methods applicable to vector of vectors of
Required methods
Subtract m from all points - e.g. transform to zero median form
fn distsuminset(self, indx: usize) -> f64
fn distsuminset(self, indx: usize) -> f64
Fast sums of distances from each point to all other points
Sum of distances from arbitrary point (v) to all the points in self
Individual distances from any point v (typically not in self) to all the points in self.
fn eccentricities(self) -> Vec<Vec<f64>>
fn eccentricities(self) -> Vec<Vec<f64>>
Eccentricity vectors from each point
Exact eccentricity vectors from all member points by first finding the Geometric Median.
As well as being more accurate, it is usually faster than eccentricities
above,
especially for large numbers of points.
Returns ( gm, sorted eccentricities magnitudes )
( wgm, sorted eccentricities magnitudes, associated cpdf )
Sorted cosines magnitudes and cpdf, needs central median
Next approx median point from this member point given by its indx
Weighted eccentricity vector for a non member point
Median and quartiles of eccentricities (new robust measure of spread of a multivariate sample)
Medoid and Outlier as defined by eccentricities.
fn firstpoint(self) -> Vec<f64>
fn firstpoint(self) -> Vec<f64>
Geometric medians of a set First iteration point for geometric medians
Implementations on Foreign Types
acentroid = simple multidimensional arithmetic mean
Example
use rstats::{Vecf64,VecVecf64,functions::genvec}; let pts = genvec(15,15,255,30); let dist = pts.distsum(&pts.acentroid()); assert_eq!(dist, 4.14556218326653_f64);
gcentroid = multidimensional geometric mean
Example
use rstats::{Vecf64,VecVecf64,functions::genvec}; let pts = genvec(15,15,255,30); let centre = pts.gcentroid(); let dist = pts.distsum(¢re); assert_eq!(dist,4.897594485332543_f64);
hcentroid = multidimensional harmonic mean
Example
use rstats::{Vecf64,VecVecf64,functions::genvec}; let pts = genvec(15,15,255,30); let centre = pts.hcentroid(); let dist = pts.distsum(¢re); assert_eq!(dist, 5.623778191797538_f64);
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.
Translates the whole set by vector -m. Returns Vec of Vecs.
When m is set to the geometric median, this produces the zero median form.
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 each member point, gives its sum of distances to all other points.
The sum of distances from one member point, given by its indx
, to all the other points in self.
For all the points, use more efficient distsums
.
Individual distances from any point v, typically not a member, to all the members of self.
The sum of distances from any single point v, typically not a member, to all the members of self.
Geometric Median is defined as the point which minimises this function.
Medoid is the member point (point belonging to the 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.
In other words, they are the members nearest and furthest from the median.
This function returns a four-tuple:
(medoid_distance, medoid_index, outlier_distance, outlier_index).
Example
use rstats::{Vecf64,VecVecf64,functions::genvec}; let pts = genvec(15,15,255,30); let (dm,_,_,_) = pts.medoid(); assert_eq!(dm,4.812334638782327_f64);
Finds approximate vectors from each member point towards the geometric median. Twice as fast as doing them individually, using symmetry.
Exact eccentricity vectors from all member points by first finding the Geometric Median.
Usually faster than the approximate eccentricities
above, especially when there are many points.
GM and sorted eccentricities magnitudes.
Describing a set of points self
in n dimensions
Weighted geometric median, sorted eccentricities magnitudes, associated cummulative probability density function in [0,1] of the weights.
Sorted cosines magnitudes, associated cummulative probability density function in [0,1] of the weights. Needs central median
Vector eccentricity
or measure of
not being the geometric median
, added to a given member point.
The true geometric median is as yet unknown.
The member point in question is specified by its index indx
.
This function is suitable for a single member point.
Vector eccentricity
or measure of
not being the geometric median
for a member point.
The true geometric median is as yet unknown.
The true geometric median would return zero.
The member point in question is specified by its index indx
.
This function is suitable for a single member point.
When eccentricities of all the points are needed, use exacteccs
above.
Eccentricity vector added to a non member point, while the true geometric median is as yet unknown. This function is suitable for a single non-member point.
Error vector for (usually non-member) point p, i.e. unscaled eccentricity vector. The true geometric median would return zero vector.
Eccentricity vector for a non member point, while the true geometric median is as yet unknown. Returns the eccentricity vector. The true geometric median would return zero vector. This function is suitable for a single non-member point.
Next approximate weighted median, from a non member point.
Mean and Std (in MStats struct), Median and quartiles (in Med struct) of scalar eccentricities of points in self. These are new robust measures of a cloud of multidimensional points (or multivariate sample).
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 nr. 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::{Vecf64,VecVecf64,functions::genvec}; pub const EPS:f64 = 1e-7; let d = 6_usize; let pt = genvec(d,24,7,13); // random test data 5x20 let (_medoideccentricity,medei,_outlierecccentricity,outei) = pt.emedoid(EPS); assert_eq!(medei,10); // index of e-medoid assert_eq!(outei,20); // index of e-outlier
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 gm coincides with one of them.
However, these problems are fixed in my new algorithm here.
There will eventually be a multithreaded version.
Possible first iteration point for geometric medians. Same as eccnonmember(origin), just saving the zero subtractions.
Example
use rstats::{Vecf64,VecVecf64,functions::genvec}; let pts = genvec(15,15,255,30); let dist = pts.distsum(&pts.firstpoint()); assert_eq!(dist,4.132376831171272_f64);
Secant method with recovery from divergence for finding the geometric median
Secant method with recovery for finding the weighted geometric median
Flattened lower triangular part of a covariance matrix for f64 vectors in self. Since covariance matrix is symmetric (positive semi definite), the upper triangular part can be trivially generated 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 here flattened into a single vector in this double loop order: left to right, top to bottom