[−][src]Trait rstats::Vectors
Implementing basic vector algebra and safe geometric median.
Required methods
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 arcentroid(&self, d: usize) -> Vec<f64>
fn medoid(&self, d: usize) -> Result<(f64, usize)>
fn distsum(&self, d: usize, v: &[f64]) -> f64
fn eccentr(&self, d: usize, indx: usize) -> f64
fn exteccentr(&self, d: usize, thisp: &[f64]) -> f64
fn gmedian(&self, d: usize, eps: f64) -> Result<(f64, Vec<f64>)>
fn nmedian(&self, d: usize, eps: f64) -> Result<(f64, Vec<f64>)>
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 arcentroid(&self, d: usize) -> Vec<f64>
[src]
Centroid = multidimensional arithmetic mean
Example
use rstats::{Vectors,genvec}; let pts = genvec(15,15,255,30); let centre = pts.as_slice().arcentroid(15); let dist = pts.as_slice().distsum(15,¢re); assert_eq!(dist, 4.14556218326653_f64);
fn medoid(&self, d: usize) -> Result<(f64, usize)>
[src]
Medoid is a point in n-dimensional set of points with the least sum of distances to all others.
This method returns an index to the start of medoid within a flat vector of d-dimensional points.
d
is the number of dimensions = length of the slices.
Set of points (slices) is held as one flat buff:&[f64]
.
This is faster than vec of vecs but users have to handle the indices.
Note: medoid
computes each distance twice but it is probably faster than memoizing and looking them up,
unless the dimensionality is somewhat large.
Example
use rstats::{Vectors,genvec}; let pts = genvec(15,15,255,30); let (dist,indx) = pts.as_slice().medoid(15).unwrap(); assert_eq!(dist,4.812334638782327_f64);
fn distsum(&self, d: usize, v: &[f64]) -> f64
[src]
The sum of distances of all points contained in &self to given point v.
v which minimises this objective function is the Geometric Median.
fn eccentr(&self, d: usize, indx: usize) -> f64
[src]
multidimensional eccentricity
of a point within the set
based on geometric median without actually having to find the median
it is a measure of not being a median
. The actual median will have eccentricity zero
and the medoid will have the least ecentricity
fn exteccentr(&self, d: usize, thisp: &[f64]) -> f64
[src]
ecentricity of a point not in the set
fn gmedian(&self, d: usize, eps: f64) -> Result<(f64, Vec<f64>)>
[src]
Geometric Median is the point that minimises the sum of distances to a given set of points.
This is the original Weiszfeld's algorithm (for comparison). It is not recommended for production use.
It has problems with convergence and/or division by zero when the iterative estimate
runs too close to one of the existing points in the set.
See test/tests.rs, where test gmedian
panics, whereas nmedian
finds the correct result.
Example
use rstats::{Vectors,genvec}; let pts = genvec(15,15,255,30); let (ds,gm) = pts.as_slice().gmedian(15, 1e-5).unwrap(); assert_eq!(ds,4.126465898732421_f64);
fn nmedian(&self, d: usize, eps: f64) -> Result<(f64, Vec<f64>)>
[src]
Geometric Median is the point that minimises the sum of distances to a given set of points.
This is an improved algorithm. It dodges any points in the set
which typically cause problems to Weiszfeld. It does so in a more sophisticated way than gmedian.
It maintains convergence even on the difficult data (dense points near the geometric median).
Use nmedian in preference to gmedian on difficult data.
Eps controls the desired accuracy.
Example
use rstats::{Vectors,genvec}; let pts = genvec(15,15,255,30); let (ds,gm) = pts.as_slice().nmedian(15, 1e-5).unwrap(); assert_eq!(ds,4.126465898732421_f64);