Skip to main content

SpaceMatrix

Struct SpaceMatrix 

Source
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

Source

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.
Source

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

Source§

fn dist(&self, x1: &Point, x2: &Point) -> f32

Returns the distance between two points x1 and x2.
Source§

fn color(&self, x: &Point) -> usize

Returns the color of point x.
Source§

fn n(&self) -> PointCount

Return the number of points in the metric space.
Source§

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>

Provides an iterator of all points of the metric space. This is the only way to access the points.
Source§

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.
Source§

fn dist_set(&self, x: &Point, point_set: Vec<&Point>) -> f32

Source§

fn get_closest<'a>( &self, x: &Point, point_set: &Vec<&'a Point>, ) -> (f32, &'a Point)

Source§

fn is_metric(&self) -> bool

Checks whether the dist function satisfy the metric properties in which case true is returned. Care: this need O(n3) time.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V