pub trait VecVec<T> {
Show 34 methods
// Required methods
fn scalar_fn(
self,
f: impl Fn(&[T]) -> Result<f64, RE>
) -> Result<Vec<f64>, RE>;
fn vector_fn(
self,
f: impl Fn(&[T]) -> Result<Vec<f64>, RE>
) -> Result<Vec<Vec<f64>>, RE>;
fn radii(self, gm: &[f64]) -> Result<Vec<f64>, RE>;
fn column(self, cnum: usize) -> Vec<f64>;
fn transpose(self) -> Vec<Vec<f64>>;
fn normalize(self) -> Result<Vec<Vec<f64>>, RE>;
fn house_ur(self) -> Result<(TriangMat, TriangMat), RE>;
fn jointpdfn(self) -> Result<Vec<f64>, RE>;
fn jointentropyn(self) -> Result<f64, RE>;
fn dependencen(self) -> Result<f64, RE>;
fn crossfeatures(
self,
f: fn(_: &[T], _: &[T]) -> f64
) -> Result<TriangMat, RE>;
fn sumv(self) -> Vec<f64>;
fn acentroid(self) -> Vec<f64>;
fn par_acentroid(self) -> Vec<f64>;
fn gcentroid(self) -> Result<Vec<f64>, RE>;
fn hcentroid(self) -> Result<Vec<f64>, RE>;
fn firstpoint(self) -> Vec<f64>;
fn distsums(self) -> Vec<f64>;
fn medout(self, gm: &[f64]) -> Result<MinMax<f64>, RE>;
fn nxnonmember(self, g: &[f64]) -> (Vec<f64>, Vec<f64>, f64);
fn radius(self, i: usize, gm: &[f64]) -> Result<f64, RE>;
fn eccinfo(self, gm: &[f64]) -> Result<(MStats, MStats, MinMax<f64>), RE>
where Vec<f64>: FromIterator<f64>;
fn quasimedian(self) -> Result<Vec<f64>, RE>;
fn gmerror(self, gm: &[f64]) -> f64;
fn sigvec(self, idx: &[usize]) -> Result<Vec<f64>, RE>;
fn madgm(self, gm: &[f64]) -> Result<f64, RE>;
fn stdgm(self, gm: &[f64]) -> Result<f64, RE>;
fn inner_hull(self, sqrads: &[f64], radindex: &[usize]) -> Vec<usize>;
fn outer_hull(self, sqrads: &[f64], radindex: &[usize]) -> Vec<usize>;
fn insideness(self, p: &[f64]) -> usize;
fn hulls(self) -> (Vec<usize>, Vec<usize>);
fn gmedian(self, eps: f64) -> Vec<f64>;
fn par_gmedian(self, eps: f64) -> Vec<f64>;
fn gmparts(self, eps: f64) -> (Vec<f64>, Vec<f64>, f64);
}
Expand description
Methods applicable to a slice of vectors of generic end type. Operations on a whole set of multidimensional vectors.
Required Methods§
sourcefn scalar_fn(self, f: impl Fn(&[T]) -> Result<f64, RE>) -> Result<Vec<f64>, RE>
fn scalar_fn(self, f: impl Fn(&[T]) -> Result<f64, RE>) -> Result<Vec<f64>, RE>
Maps a scalar valued closure onto all vectors in self
sourcefn vector_fn(
self,
f: impl Fn(&[T]) -> Result<Vec<f64>, RE>
) -> Result<Vec<Vec<f64>>, RE>
fn vector_fn( self, f: impl Fn(&[T]) -> Result<Vec<f64>, RE> ) -> Result<Vec<Vec<f64>>, RE>
Maps vector valued closure onto all vectors in self and collects
sourcefn radii(self, gm: &[f64]) -> Result<Vec<f64>, RE>
fn radii(self, gm: &[f64]) -> Result<Vec<f64>, RE>
Exact radii magnitudes to all member points from the Geometric Median.
sourcefn normalize(self) -> Result<Vec<Vec<f64>>, RE>
fn normalize(self) -> Result<Vec<Vec<f64>>, RE>
Normalize columns, so that they are all unit vectors
sourcefn house_ur(self) -> Result<(TriangMat, TriangMat), RE>
fn house_ur(self) -> Result<(TriangMat, TriangMat), RE>
Householder’s method returning matrices (U,R)
sourcefn jointpdfn(self) -> Result<Vec<f64>, RE>
fn jointpdfn(self) -> Result<Vec<f64>, RE>
Joint probability density function of n matched slices of the same length
sourcefn jointentropyn(self) -> Result<f64, RE>
fn jointentropyn(self) -> Result<f64, RE>
Joint entropy between a set of vectors of the same length
sourcefn dependencen(self) -> Result<f64, RE>
fn dependencen(self) -> Result<f64, RE>
Dependence (component wise) of a set of vectors.
sourcefn crossfeatures(self, f: fn(_: &[T], _: &[T]) -> f64) -> Result<TriangMat, RE>
fn crossfeatures(self, f: fn(_: &[T], _: &[T]) -> f64) -> Result<TriangMat, RE>
Binary relations between columns of self
sourcefn par_acentroid(self) -> Vec<f64>
fn par_acentroid(self) -> Vec<f64>
Multithreaded Arithmetic Centre = euclidian mean of a set of points
sourcefn hcentroid(self) -> Result<Vec<f64>, RE>
fn hcentroid(self) -> Result<Vec<f64>, RE>
Harmonic Centroid = harmonic mean of a set of points
sourcefn firstpoint(self) -> Vec<f64>
fn firstpoint(self) -> Vec<f64>
Possible first iteration point for geometric medians
sourcefn medout(self, gm: &[f64]) -> Result<MinMax<f64>, RE>
fn medout(self, gm: &[f64]) -> Result<MinMax<f64>, RE>
Medoid distance, its index, outlier distance, its index
sourcefn nxnonmember(self, g: &[f64]) -> (Vec<f64>, Vec<f64>, f64)
fn nxnonmember(self, g: &[f64]) -> (Vec<f64>, Vec<f64>, f64)
Like gmparts, except only does one iteration from any non-member point g
sourcefn radius(self, i: usize, gm: &[f64]) -> Result<f64, RE>
fn radius(self, i: usize, gm: &[f64]) -> Result<f64, RE>
Radius of a point specified by its subscript.
sourcefn eccinfo(self, gm: &[f64]) -> Result<(MStats, MStats, MinMax<f64>), RE>where
Vec<f64>: FromIterator<f64>,
fn eccinfo(self, gm: &[f64]) -> Result<(MStats, MStats, MinMax<f64>), RE>where Vec<f64>: FromIterator<f64>,
Arith mean and std (in MStats struct), Median and mad, Medoid and Outlier (in MinMax struct)
sourcefn quasimedian(self) -> Result<Vec<f64>, RE>
fn quasimedian(self) -> Result<Vec<f64>, RE>
Quasi median, recommended only for comparison purposes
sourcefn sigvec(self, idx: &[usize]) -> Result<Vec<f64>, RE>
fn sigvec(self, idx: &[usize]) -> Result<Vec<f64>, RE>
Proportions of points in idx along each +/-axis (hemisphere)
sourcefn madgm(self, gm: &[f64]) -> Result<f64, RE>
fn madgm(self, gm: &[f64]) -> Result<f64, RE>
madgm, median of radii from geometric median: stable nd data spread estimator
sourcefn stdgm(self, gm: &[f64]) -> Result<f64, RE>
fn stdgm(self, gm: &[f64]) -> Result<f64, RE>
stdgm mean of radii from gm: nd data spread estimator
sourcefn inner_hull(self, sqrads: &[f64], radindex: &[usize]) -> Vec<usize>
fn inner_hull(self, sqrads: &[f64], radindex: &[usize]) -> Vec<usize>
Inner hull points from their square radii and their ascending index radindex
sourcefn outer_hull(self, sqrads: &[f64], radindex: &[usize]) -> Vec<usize>
fn outer_hull(self, sqrads: &[f64], radindex: &[usize]) -> Vec<usize>
Outer hull points from their square radii self
and their decending index radindex
sourcefn insideness(self, p: &[f64]) -> usize
fn insideness(self, p: &[f64]) -> usize
Measure of likelihood of zero median point p belonging to a zero median data cloud self
.
sourcefn hulls(self) -> (Vec<usize>, Vec<usize>)
fn hulls(self) -> (Vec<usize>, Vec<usize>)
Collects indices of outer and inner hull points, from zero median data
sourcefn par_gmedian(self, eps: f64) -> Vec<f64>
fn par_gmedian(self, eps: f64) -> Vec<f64>
Parallel (multithreaded) implementation of Geometric Median. Possibly the fastest you will find.
Implementations on Foreign Types§
source§impl<T> VecVec<T> for &[Vec<T>]where
T: Clone + PartialOrd + Sync + Into<f64>,
Vec<Vec<T>>: IntoParallelIterator,
Vec<T>: IntoParallelIterator,
impl<T> VecVec<T> for &[Vec<T>]where T: Clone + PartialOrd + Sync + Into<f64>, Vec<Vec<T>>: IntoParallelIterator, Vec<T>: IntoParallelIterator,
source§fn scalar_fn(self, f: impl Fn(&[T]) -> Result<f64, RE>) -> Result<Vec<f64>, RE>
fn scalar_fn(self, f: impl Fn(&[T]) -> Result<f64, RE>) -> Result<Vec<f64>, RE>
Maps scalar valued closure onto all vectors in self and collects
source§fn vector_fn(
self,
f: impl Fn(&[T]) -> Result<Vec<f64>, RE>
) -> Result<Vec<Vec<f64>>, RE>
fn vector_fn( self, f: impl Fn(&[T]) -> Result<Vec<f64>, RE> ) -> Result<Vec<Vec<f64>>, RE>
Maps vector valued closure onto all vectors in self and collects
source§fn radii(self, gm: &[f64]) -> Result<Vec<f64>, RE>
fn radii(self, gm: &[f64]) -> Result<Vec<f64>, RE>
Exact radii magnitudes to all member points from the Geometric Median.
More accurate and usually faster as well than the approximate eccentricities
above,
especially when there are many points.
source§fn normalize(self) -> Result<Vec<Vec<f64>>, RE>
fn normalize(self) -> Result<Vec<Vec<f64>>, RE>
Normalize columns, so that they become unit row vectors
source§fn house_ur(self) -> Result<(TriangMat, TriangMat), RE>
fn house_ur(self) -> Result<(TriangMat, TriangMat), RE>
Householder’s method returning triangular matrices (U’,R), where U are the reflector generators for use by house_uapply(m). R is the upper triangular decomposition factor. Here both U and R are returned for convenience in their transposed lower triangular forms. Transposed input self for convenience, so that original columns get accessed easily as rows.
source§fn jointpdfn(self) -> Result<Vec<f64>, RE>
fn jointpdfn(self) -> Result<Vec<f64>, RE>
Joint probability density function of n matched slices of the same length
source§fn dependencen(self) -> Result<f64, RE>
fn dependencen(self) -> Result<f64, RE>
Dependence (component wise) of a set of vectors.
i.e. dependencen
returns 0 iff they are statistically independent
bigger values when they are dependentent
source§fn crossfeatures(self, f: fn(_: &[T], _: &[T]) -> f64) -> Result<TriangMat, RE>
fn crossfeatures(self, f: fn(_: &[T], _: &[T]) -> f64) -> Result<TriangMat, RE>
Flattened lower triangular part of a symmetric matrix for vectors in self.
The upper triangular part can be trivially generated for all j>i by: c(j,i) = c(i,j).
Applies closure f to compute a scalar binary relation between all pairs of vector
components of self.
The closure typically invokes one of the methods from Vecg trait (in vecg.rs),
such as dependencies.
Example call: pts.transpose().crossfeatures(|v1,v2| v1.mediancorrf64(v2)?)?
computes median correlations between all column vectors (features) in pts.
source§fn par_acentroid(self) -> Vec<f64>
fn par_acentroid(self) -> Vec<f64>
multithreaded acentroid = multidimensional arithmetic mean
source§fn distsums(self) -> Vec<f64>
fn distsums(self) -> Vec<f64>
For each member point, gives its sum of distances to all other points and their MinMax
source§fn medout(self, gm: &[f64]) -> Result<MinMax<f64>, RE>
fn medout(self, gm: &[f64]) -> Result<MinMax<f64>, RE>
Points nearest and furthest from the geometric median. Returns struct MinMax{min,minindex,max,maxindex}
source§fn radius(self, i: usize, gm: &[f64]) -> Result<f64, RE>
fn radius(self, i: usize, gm: &[f64]) -> Result<f64, RE>
Radius of a point specified by its subscript.
source§fn eccinfo(self, gm: &[f64]) -> Result<(MStats, MStats, MinMax<f64>), RE>where
Vec<f64>: FromIterator<f64>,
fn eccinfo(self, gm: &[f64]) -> Result<(MStats, MStats, MinMax<f64>), RE>where Vec<f64>: FromIterator<f64>,
Arith mean and std (in MStats struct), Median and MAD (in another MStats struct), Medoid and Outlier (in MinMax struct) of scalar radii of points in self. These are new robust measures of a cloud of multidimensional points (or multivariate sample).
source§fn quasimedian(self) -> Result<Vec<f64>, RE>
fn quasimedian(self) -> Result<Vec<f64>, RE>
Quasi median, recommended only for comparison purposes
source§fn sigvec(self, idx: &[usize]) -> Result<Vec<f64>, RE>
fn sigvec(self, idx: &[usize]) -> Result<Vec<f64>, RE>
Proportions of points along each +/-axis (hemisphere)
Points that are perpendicular to axis get included in both +/-ve hemispheres.
Uses only the selected points specified in idx (e.g. the hull).
Self should normally be zero median vectors,
e.g. self.translate(&median)
source§fn madgm(self, gm: &[f64]) -> Result<f64, RE>
fn madgm(self, gm: &[f64]) -> Result<f64, RE>
madgm median of distances from gm: stable nd data spread measure
source§fn stdgm(self, gm: &[f64]) -> Result<f64, RE>
fn stdgm(self, gm: &[f64]) -> Result<f64, RE>
stdgm mean of distances from gm: nd data spread measure, aka nd standard deviation
source§fn inner_hull(self, sqrads: &[f64], radindex: &[usize]) -> Vec<usize>
fn inner_hull(self, sqrads: &[f64], radindex: &[usize]) -> Vec<usize>
Inner hull points from their square radii and
their ascending index radindex
. Returns subset of radindex
.
source§fn outer_hull(self, sqrads: &[f64], radindex: &[usize]) -> Vec<usize>
fn outer_hull(self, sqrads: &[f64], radindex: &[usize]) -> Vec<usize>
Outer hull points from their square radii and
their descending index radindex
. Returns subset of radindex
.
source§fn insideness(self, p: &[f64]) -> usize
fn insideness(self, p: &[f64]) -> usize
Measure of likelihood of zero median point p belonging to a zero median data cloud self
.
This is not nearly as fast as is simple distance of p from gm but it is more sophisticated,
taking into account the local shape of s near p.
Returns the number of points belonging to s falling outside the normal through p.
All outer hull points have by definition insideness = 0
.
Mahalanobis distance has the same goal but is less specific.
When self contains only precomputed outer hull points, the computation will be faster.
source§fn hulls(self) -> (Vec<usize>, Vec<usize>)
fn hulls(self) -> (Vec<usize>, Vec<usize>)
Collects indices of inner (or core) hull and outer hull, from zero median points in self.
Defining plane of a point A goes through A and is normal to the zero median vector a.
B is an inner hull point, when it lies inside all other points’ defining planes.
B is an outer hull point, when there is no other point beyond its own defining plane.
B can belong to both hulls, as when all the points lie on a hyper-sphere around gm.
The testing is done in increasing (decreasing) radius order.
B lies outside the defining plane of a, when its projection onto unit a exceeds |a|
:
|b|cos(θ) > |a| => a*b > |a|^2
,
such B immediately fails as a candidate for the inner hull.
Working with square magnitudes, |a|^2
saves taking square roots and dividing the dot product by |a|.
Similarly for the outer hull, where A and B simply swap roles.
source§fn firstpoint(self) -> Vec<f64>
fn firstpoint(self) -> Vec<f64>
Initial (first) point for geometric medians.
source§fn nxnonmember(self, g: &[f64]) -> (Vec<f64>, Vec<f64>, f64)
fn nxnonmember(self, g: &[f64]) -> (Vec<f64>, Vec<f64>, f64)
Like gmparts, except only does one iteration from any non-member point g
source§fn gmedian(self, eps: f64) -> Vec<f64>
fn gmedian(self, eps: f64) -> Vec<f64>
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 has 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.
The sum of reciprocals is strictly increasing and so is used here as
easy to evaluate termination condition.
source§fn par_gmedian(self, eps: f64) -> Vec<f64>
fn par_gmedian(self, eps: f64) -> Vec<f64>
Parallel (multithreaded) implementation of Geometric Median. Possibly the fastest you will find.
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 hyper space.
Weiszfeld’s fixed point iteration formula has known problems and sometimes fails to converge.
Specifically, when the points are dense in the close proximity of the gm, or gm coincides with one of them.
However, these problems are solved in my new algorithm here.
The sum of reciprocals is strictly increasing and so is used to easily evaluate the termination condition.