pub struct SpaceMatrix { /* private fields */ }Expand description
A general finite metric space with color classes.
- Distances are given by a symmetric distance matrix of size nxn,
- Colors are given by a list of size n,
- Implements the ColoredMetric trait.
Implementations§
Source§impl SpaceMatrix
impl SpaceMatrix
Sourcepub fn new(distances: Vec<Vec<f32>>, colors: Vec<usize>) -> SpaceMatrix
pub fn new(distances: Vec<Vec<f32>>, colors: Vec<usize>) -> SpaceMatrix
Creates a new SpaceMatrix.
§Input
- distances has to be a 2D-vector that represents a quadratic matrix satisfying the metric properties (symmetry, non-negativity, identity of indiscernibles and the triangle inequality),
- colors is a vector that stores the color of each point.
The running time of asserting the metric properties is O(n3).
§Panics
- Panics, if distances is not a quadratic matrix.
- Panics, if the length of the color classes does not match the number of points given by distances.
- Panics, if distances does not satisfy the metric properties.
Sourcepub fn new_by_array<const N: PointCount>(
distances: [[f32; N]; N],
colors: [usize; N],
) -> SpaceMatrix
pub fn new_by_array<const N: PointCount>( distances: [[f32; N]; N], colors: [usize; N], ) -> SpaceMatrix
Creates a new SpaceMatrix as in new but the distances and color data are received by arrays.
§Example
use ff_k_center::{Point,SpaceMatrix,ColoredMetric};
let space = SpaceMatrix::new_by_array(
[[0.0, 2.0, 1.5],
[2.0, 0.0, 0.6],
[1.5, 0.6, 0.0]], [0, 0, 1]);
let points : Vec<&Point> = space.point_iter().collect();
assert!(space.is_metric());
assert_eq!(space.dist(points[1],points[2]),0.6);
assert_eq!(space.color(points[2]),1);
assert_eq!(space.n(),3);Trait Implementations§
Source§impl ColoredMetric for SpaceMatrix
impl ColoredMetric for SpaceMatrix
Source§fn dist(&self, x1: &Point, x2: &Point) -> f32
fn dist(&self, x1: &Point, x2: &Point) -> f32
Returns the distance between two points
x1 and x2.Source§fn n(&self) -> PointCount
fn n(&self) -> PointCount
Return the number of points in the metric space.
Source§fn get_point(&self, idx: usize) -> Option<&Point>
fn get_point(&self, idx: usize) -> Option<&Point>
Return a reference (wrapped in
Some) to the point with provided index.
If there is not point with this index, return None.Source§fn point_iter(&self) -> Iter<'_, Point>
fn point_iter(&self) -> Iter<'_, Point>
Provides an iterator of all points of the metric space. This is the only way to access the
points.
Source§fn gamma(&self) -> ColorCount
fn gamma(&self) -> ColorCount
Returns the number of color classes that are present in the metric space. More precesely it
return the highest color value + 1.
fn dist_set(&self, x: &Point, point_set: Vec<&Point>) -> f32
fn get_closest<'a>( &self, x: &Point, point_set: &Vec<&'a Point>, ) -> (f32, &'a Point)
Auto Trait Implementations§
impl Freeze for SpaceMatrix
impl RefUnwindSafe for SpaceMatrix
impl Send for SpaceMatrix
impl Sync for SpaceMatrix
impl Unpin for SpaceMatrix
impl UnsafeUnpin for SpaceMatrix
impl UnwindSafe for SpaceMatrix
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more