pub trait VecVecg<T, U> {
Show 26 methods
// Required methods
fn scalar_wfn(
self,
ws: &[U],
f: impl Fn(&[T]) -> Result<f64, RE>
) -> Result<(Vec<f64>, f64), RE>;
fn vector_wfn(
self,
v: &[U],
f: impl Fn(&[T]) -> Result<Vec<f64>, RE>
) -> Result<(Vec<Vec<f64>>, f64), RE>;
fn wdvdt(self, ws: &[U], centre: &[f64]) -> Result<Vec<f64>, RE>;
fn divs(self, v: &[U]) -> Result<Vec<f64>, RE>;
fn wdivs(self, ws: &[U], v: &[f64]) -> Result<(Vec<f64>, f64), RE>;
fn wdivsmed(self, ws: &[U], v: &[f64]) -> Result<f64, RE>;
fn wradii(self, ws: &[U], gm: &[f64]) -> Result<(Vec<f64>, f64), RE>;
fn wmadgm(self, ws: &[U], wgm: &[f64]) -> Result<f64, RE>;
fn leftmultv(self, v: &[U]) -> Result<Vec<f64>, RE>;
fn rightmultv(self, v: &[U]) -> Result<Vec<f64>, RE>;
fn matmult(self, m: &[Vec<U>]) -> Result<Vec<Vec<f64>>, RE>;
fn wsumv(self, ws: &[U]) -> Vec<f64>;
fn wacentroid(self, ws: &[U]) -> Vec<f64>;
fn trend(self, eps: f64, v: Vec<Vec<U>>) -> Result<Vec<f64>, RE>;
fn translate(self, m: &[U]) -> Result<Vec<Vec<f64>>, RE>;
fn wsigvec(self, idx: &[usize], ws: &[U]) -> Result<Vec<f64>, RE>;
fn wdepth(
self,
descending_index: &[usize],
ws: &[U],
p: &[f64]
) -> Result<f64, RE>;
fn dependencies(self, m: &[U]) -> Result<Vec<f64>, RE>;
fn distsum(self, v: &[U]) -> Result<f64, RE>;
fn dists(self, v: &[U]) -> Result<Vec<f64>, RE>;
fn wsortedrads(self, ws: &[U], gm: &[f64]) -> Result<Vec<f64>, RE>;
fn wgmedian(self, ws: &[U], eps: f64) -> Result<Vec<f64>, RE>;
fn par_wgmedian(self, ws: &[U], eps: f64) -> Result<Vec<f64>, RE>;
fn wgmparts(self, ws: &[U], eps: f64) -> Result<(Vec<f64>, f64), RE>;
fn wcovar(self, ws: &[U], mid: &[f64]) -> Result<TriangMat, RE>;
fn serial_wcovar(self, ws: &[U], mid: &[f64]) -> Result<TriangMat, RE>;
}
Expand description
Methods applicable to slice of vectors of generic end type, plus one other argument of a similar kind
Required Methods§
sourcefn scalar_wfn(
self,
ws: &[U],
f: impl Fn(&[T]) -> Result<f64, RE>
) -> Result<(Vec<f64>, f64), RE>
fn scalar_wfn( self, ws: &[U], f: impl Fn(&[T]) -> Result<f64, RE> ) -> Result<(Vec<f64>, f64), RE>
Applies scalar valued closure to all vectors in self and multiplies by their weights
sourcefn vector_wfn(
self,
v: &[U],
f: impl Fn(&[T]) -> Result<Vec<f64>, RE>
) -> Result<(Vec<Vec<f64>>, f64), RE>
fn vector_wfn( self, v: &[U], f: impl Fn(&[T]) -> Result<Vec<f64>, RE> ) -> Result<(Vec<Vec<f64>>, f64), RE>
Applies vector valued closure to all vectors in self and multiplies by their weights
sourcefn wdvdt(self, ws: &[U], centre: &[f64]) -> Result<Vec<f64>, RE>
fn wdvdt(self, ws: &[U], centre: &[f64]) -> Result<Vec<f64>, RE>
Individually weighted time series derivative of vectors
sourcefn wdivs(self, ws: &[U], v: &[f64]) -> Result<(Vec<f64>, f64), RE>
fn wdivs(self, ws: &[U], v: &[f64]) -> Result<(Vec<f64>, f64), RE>
weighted 1.0-dotproduct of v, with all in self
sourcefn wdivsmed(self, ws: &[U], v: &[f64]) -> Result<f64, RE>
fn wdivsmed(self, ws: &[U], v: &[f64]) -> Result<f64, RE>
median of weighted cos deviations from v
sourcefn wradii(self, ws: &[U], gm: &[f64]) -> Result<(Vec<f64>, f64), RE>
fn wradii(self, ws: &[U], gm: &[f64]) -> Result<(Vec<f64>, f64), RE>
weighted radii to all points in self
sourcefn wmadgm(self, ws: &[U], wgm: &[f64]) -> Result<f64, RE>
fn wmadgm(self, ws: &[U], wgm: &[f64]) -> Result<f64, RE>
wmadgm median of weighted radii from (weighted) gm: stable nd data spread estimator
sourcefn leftmultv(self, v: &[U]) -> Result<Vec<f64>, RE>
fn leftmultv(self, v: &[U]) -> Result<Vec<f64>, RE>
Leftmultiply (column) vector v by (rows of) matrix self: projects v to new basis self
sourcefn rightmultv(self, v: &[U]) -> Result<Vec<f64>, RE>
fn rightmultv(self, v: &[U]) -> Result<Vec<f64>, RE>
Rightmultiply (row) vector v by (columns of) matrix self
sourcefn wacentroid(self, ws: &[U]) -> Vec<f64>
fn wacentroid(self, ws: &[U]) -> Vec<f64>
Weighted Arithmetic Centre = weighted euclidian mean of a set of points
sourcefn translate(self, m: &[U]) -> Result<Vec<Vec<f64>>, RE>
fn translate(self, m: &[U]) -> Result<Vec<Vec<f64>>, RE>
Subtract m from all points - e.g. transform to zero median form
sourcefn wsigvec(self, idx: &[usize], ws: &[U]) -> Result<Vec<f64>, RE>
fn wsigvec(self, idx: &[usize], ws: &[U]) -> Result<Vec<f64>, RE>
Weighted sums of points in each hemisphere
sourcefn wdepth(
self,
descending_index: &[usize],
ws: &[U],
p: &[f64]
) -> Result<f64, RE>
fn wdepth( self, descending_index: &[usize], ws: &[U], p: &[f64] ) -> Result<f64, RE>
Weighted likelihood of zero median point p belonging to zero median data cloud self
.
sourcefn dependencies(self, m: &[U]) -> Result<Vec<f64>, RE>
fn dependencies(self, m: &[U]) -> Result<Vec<f64>, RE>
Dependencies of vector m on each vector in self
sourcefn distsum(self, v: &[U]) -> Result<f64, RE>
fn distsum(self, v: &[U]) -> Result<f64, RE>
Sum of distances from arbitrary point (v) to all the points in self
sourcefn dists(self, v: &[U]) -> Result<Vec<f64>, RE>
fn dists(self, v: &[U]) -> Result<Vec<f64>, RE>
Individual distances from any point v (typically not in self) to all the points in self.
sourcefn wsortedrads(self, ws: &[U], gm: &[f64]) -> Result<Vec<f64>, RE>
fn wsortedrads(self, ws: &[U], gm: &[f64]) -> Result<Vec<f64>, RE>
Weighted sorted weighted radii magnitudes, normalised
sourcefn wgmedian(self, ws: &[U], eps: f64) -> Result<Vec<f64>, RE>
fn wgmedian(self, ws: &[U], eps: f64) -> Result<Vec<f64>, RE>
The weighted geometric median to accuracy eps
sourcefn par_wgmedian(self, ws: &[U], eps: f64) -> Result<Vec<f64>, RE>
fn par_wgmedian(self, ws: &[U], eps: f64) -> Result<Vec<f64>, RE>
Parallel (multithreaded) implementation of the weighted Geometric Median.
sourcefn wgmparts(self, ws: &[U], eps: f64) -> Result<(Vec<f64>, f64), RE>
fn wgmparts(self, ws: &[U], eps: f64) -> Result<(Vec<f64>, f64), RE>
Like wgmedian
but returns also the sum of reciprocals.
Object Safety§
Implementations on Foreign Types§
source§impl<T, U> VecVecg<T, U> for &[Vec<T>]where
T: Sync + Clone + PartialOrd + Into<f64>,
Vec<Vec<T>>: IntoParallelIterator,
Vec<T>: IntoParallelIterator,
U: Sync + Clone + PartialOrd + Into<f64>,
Vec<Vec<U>>: IntoParallelIterator,
Vec<U>: IntoParallelIterator,
impl<T, U> VecVecg<T, U> for &[Vec<T>]where
T: Sync + Clone + PartialOrd + Into<f64>,
Vec<Vec<T>>: IntoParallelIterator,
Vec<T>: IntoParallelIterator,
U: Sync + Clone + PartialOrd + Into<f64>,
Vec<Vec<U>>: IntoParallelIterator,
Vec<U>: IntoParallelIterator,
source§fn scalar_wfn(
self,
ws: &[U],
f: impl Fn(&[T]) -> Result<f64, RE>
) -> Result<(Vec<f64>, f64), RE>
fn scalar_wfn( self, ws: &[U], f: impl Fn(&[T]) -> Result<f64, RE> ) -> Result<(Vec<f64>, f64), RE>
Applies scalar valued closure to all vectors in self and multiplies by their weights. Returns also the sum of weights.
source§fn vector_wfn(
self,
ws: &[U],
f: impl Fn(&[T]) -> Result<Vec<f64>, RE>
) -> Result<(Vec<Vec<f64>>, f64), RE>
fn vector_wfn( self, ws: &[U], f: impl Fn(&[T]) -> Result<Vec<f64>, RE> ) -> Result<(Vec<Vec<f64>>, f64), RE>
Applies vector valued closure to all vectors in self and multiplies by their weights. Returns also the sum of weights
source§fn wdvdt(self, ws: &[U], centre: &[f64]) -> Result<Vec<f64>, RE>
fn wdvdt(self, ws: &[U], centre: &[f64]) -> Result<Vec<f64>, RE>
Individually time weighted time series derivative of vectors. Weighted arithmetic mean, minus the centre (geometric median).
source§fn wdivs(self, ws: &[U], v: &[f64]) -> Result<(Vec<f64>, f64), RE>
fn wdivs(self, ws: &[U], v: &[f64]) -> Result<(Vec<f64>, f64), RE>
median of weighted 1.0-dotproducts of v, with all in self
source§fn wdivsmed(self, ws: &[U], v: &[f64]) -> Result<f64, RE>
fn wdivsmed(self, ws: &[U], v: &[f64]) -> Result<f64, RE>
median of weighted cos deviations from v
source§fn wradii(self, ws: &[U], gm: &[f64]) -> Result<(Vec<f64>, f64), RE>
fn wradii(self, ws: &[U], gm: &[f64]) -> Result<(Vec<f64>, f64), RE>
weighted radii to all points in self
source§fn wmadgm(self, ws: &[U], gm: &[f64]) -> Result<f64, RE>
fn wmadgm(self, ws: &[U], gm: &[f64]) -> Result<f64, RE>
wmadgm median of weighted deviations from (weighted) gm: stable nd data spread estimator.
source§fn leftmultv(self, v: &[U]) -> Result<Vec<f64>, RE>
fn leftmultv(self, v: &[U]) -> Result<Vec<f64>, RE>
Rows of matrix self multiplying (column) vector v Projects vector v onto the new basis given by self
source§fn rightmultv(self, v: &[U]) -> Result<Vec<f64>, RE>
fn rightmultv(self, v: &[U]) -> Result<Vec<f64>, RE>
Row vector v multipying columns of matrix self
source§fn matmult(self, m: &[Vec<U>]) -> Result<Vec<Vec<f64>>, RE>
fn matmult(self, m: &[Vec<U>]) -> Result<Vec<Vec<f64>>, RE>
Rectangular Matrices multiplication: self * m.
Returns DataError if lengths of rows of self: self[0].len()
and columns of m: m.len()
do not match.
Result dimensions are self.len() x m[0].len()
source§fn wsumv(self, ws: &[U]) -> Vec<f64>
fn wsumv(self, ws: &[U]) -> Vec<f64>
Weighted sum.
Weights are associated with vectors of self, not with coordinates
source§fn trend(self, eps: f64, v: Vec<Vec<U>>) -> Result<Vec<f64>, RE>
fn trend(self, eps: f64, v: Vec<Vec<U>>) -> Result<Vec<f64>, RE>
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 (dimensional) space but can have different numbers of points.
source§fn translate(self, m: &[U]) -> Result<Vec<Vec<f64>>, RE>
fn translate(self, m: &[U]) -> Result<Vec<Vec<f64>>, RE>
Translates the whole set by subtracting vector m.
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 used mean (acentroid
here), or the quasi median,
both of which depend on the choice of axis.
source§fn wsigvec(self, idx: &[usize], ws: &[U]) -> Result<Vec<f64>, RE>
fn wsigvec(self, idx: &[usize], ws: &[U]) -> Result<Vec<f64>, RE>
Weighted sums of points in each hemisphere.
Uses only the points specified in idx (e.g. the convex hull).
Self should normally be zero median vectors, i.e. self.translate(&median)
.
The result is normalized to unit vector.
source§fn wdepth(
self,
descending_index: &[usize],
ws: &[U],
p: &[f64]
) -> Result<f64, RE>
fn wdepth( self, descending_index: &[usize], ws: &[U], p: &[f64] ) -> Result<f64, RE>
Likelihood of zero median point p belonging to zero median data cloud self
,
based on the cloud’s shape outside of normal plane through p.
Returns the weighted sum of unit vectors of its outside points, projected onto unit p.
Index should be in the descending order of magnitudes of self points (for efficiency).
Weights ws are associated 1-1 with the points (vectors) of self.
source§fn dependencies(self, m: &[U]) -> Result<Vec<f64>, RE>
fn dependencies(self, m: &[U]) -> Result<Vec<f64>, RE>
Dependencies of m on each vector in self m is typically a vector of outcomes. Factors out the entropy of m to save repetition of work
source§fn dists(self, v: &[U]) -> Result<Vec<f64>, RE>
fn dists(self, v: &[U]) -> Result<Vec<f64>, RE>
Individual distances from any point v, typically not a member, to all the members of self.
source§fn distsum(self, v: &[U]) -> Result<f64, RE>
fn distsum(self, v: &[U]) -> Result<f64, RE>
Sum of distances from any single point v, typically not a member,
to all members of self.
Geometric Median (gm) is defined as the point which minimises this function.
This is relatively expensive measure to compute.
The radius (distance) from gm is far more efficient, once gm has been found.
source§fn wsortedrads(self, ws: &[U], gm: &[f64]) -> Result<Vec<f64>, RE>
fn wsortedrads(self, ws: &[U], gm: &[f64]) -> Result<Vec<f64>, RE>
Sorted weighted radii to all member points from the Geometric Median.
source§fn wgmedian(self, ws: &[U], eps: f64) -> Result<Vec<f64>, RE>
fn wgmedian(self, ws: &[U], eps: f64) -> Result<Vec<f64>, RE>
Weighted Geometric Median (gm) is the point that minimises the sum of distances to a given set of points.
source§fn par_wgmedian(self, ws: &[U], eps: f64) -> Result<Vec<f64>, RE>
fn par_wgmedian(self, ws: &[U], eps: f64) -> Result<Vec<f64>, RE>
Parallel (multithreaded) implementation of the weighted 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.
source§fn wgmparts(self, ws: &[U], eps: f64) -> Result<(Vec<f64>, f64), RE>
fn wgmparts(self, ws: &[U], eps: f64) -> Result<(Vec<f64>, f64), RE>
Like gmedian
but returns also the sum of unit vecs and the sum of reciprocals.
source§fn wcovar(self, ws: &[U], mid: &[f64]) -> Result<TriangMat, RE>
fn wcovar(self, ws: &[U], mid: &[f64]) -> Result<TriangMat, RE>
Weighted covariance matrix for f64 vectors in self. Becomes comediance when
argument m is the geometric median instead of the centroid.
Since the matrix is symmetric, the missing upper triangular part can be trivially
regenerated for all j>i by: c(j,i) = c(i,j).
The indexing is always in this order: (row,column) (left to right, top to bottom).
The items are flattened into a single vector in this order.
The full 2D matrix can be reconstructed by symmatrix
in the trait Stats
.
source§fn serial_wcovar(self, ws: &[U], mid: &[f64]) -> Result<TriangMat, RE>
fn serial_wcovar(self, ws: &[U], mid: &[f64]) -> Result<TriangMat, RE>
Symmetric covariance matrix for weighted vectors.
Becomes comediance when supplied argument mid
is the geometric median instead of the centroid.
Indexing is always in this order: (row,column) (left to right, top to bottom).