Facilities

Struct Facilities 

Source
pub struct Facilities<DataId, T: Send + Sync + Clone, Dist: Distance<T>> { /* private fields */ }
Expand description

Describes the list of facility (or centers created).

The structure maintains the list of open facilities (or cluster) and their centers. It computes and store (see compute_weight_cost) total weight dispatched into facilities and maintain global facility cost assignment as : $ \sum_{p \in P} \medspace w(p) * dist(p, cf_{p})$. where $ cf_{p}$ is the center of facility assigned to $p$

Implementations§

Source§

impl<DataId: Debug + Clone + Send + Sync, T: Send + Sync + Clone, Dist: Distance<T> + Send + Sync> Facilities<DataId, T, Dist>

Source

pub fn new(size: usize, distance: Dist) -> Self

to be allocated , size should be log(nb_data)

Source

pub fn len(&self) -> usize

return number of facility

Source

pub fn is_empty(&self) -> bool

Source

pub fn get_weight(&self) -> f64

total weight already inserted

Source

pub fn get_distance(&self) -> &Dist

Source

pub fn get_cost(&self) -> f64

returns sum of costs dispatched into facilities.

Source

pub fn match_point(&self, point: &[T], dmax: f32, distance: &Dist) -> bool

return true if there is a facility around point at distance less than dmax

Source

pub fn get_facility( &self, rank: usize, ) -> Option<&Arc<RwLock<Facility<DataId, T>>>>

retrieve facility by rank if rank is Ok

Source

pub fn get_cloned_facility(&self, rank: usize) -> Option<Facility<DataId, T>>

retrieve facility of given rank , and returns a clone (to avoid synchro stuff) useful for easy final analysis

Source

pub fn get_facility_weight(&self, rank: usize) -> Result<f64>

return weight in facility of rank rank, error else

Source

pub fn get_nearest_facility( &self, data: &[T], parallel: bool, ) -> Result<(usize, f32)>

return rank of nearest facility and distance to it If there are many facilities to search (thousands), setting the parallel flag to true is useful

Source

pub fn compute_weight_cost(&mut self) -> (f64, f64)

returns (total weight, total cost)

Source

pub fn log(&self, level: usize)

a function to log info on dist and cost inside facilities

  • level = 0, will log total weight and total cost summed over facilities
  • level = 1 it will log weight and cost of each facility.
Source

pub fn dispatch_data( &mut self, data: &[&Vec<T>], _ids: &[usize], weights: Option<&Vec<f32>>, ) -> f64

This function affects each point to its nearest facility and compute cost of each facility and returns global cost and vector of weight by facility arguments are data vectors, data ids and optional weights.

Not all algos maintain weight and cost consistently all the way, sometimes facilities are created without searching all points in it. So we need to be able do the dispatch afterwards.
Bmor algorithm dispatch points on the fly so it computes an upper bound of the cost
The function can nevertheless be called a posteriori to get a tighter bound on cost

Source

pub fn dispatch_labels<L: PartialEq + Eq + Copy + Hash + Sync + Send>( &mut self, data: &[Vec<T>], labels: &[L], weights: Option<&Vec<f32>>, ) -> (Vec<f64>, Vec<HashMap<L, u32>>)

If we have labelled data we can store labels counts affected to each facility.
This function dispatch data and labels into facilities and returns total cost and a vector of counts for each label occuring in a Facility.
It computes for each facililty: - label distribution, - entropy of distribution/
This can be used to check clustering. These methods can be called after processing all the data.

The function takes as input: - Vectors of data - Vectors of labels associated to data - weights of data.

the function returns:
- Vector of entropy of label distribution by facility.
- A vector of label distribution entropy and distribution in a HashMap

Source

pub fn into_weighted_data(&self) -> Vec<(f64, Vec<T>, DataId)>

extract facility centers and associated weight for possible other clustering step

Source

pub fn cross_distances(&self)

computes distances between facility

Trait Implementations§

Source§

impl<DataId: Clone, T: Clone + Send + Sync + Clone, Dist: Clone + Distance<T>> Clone for Facilities<DataId, T, Dist>

Source§

fn clone(&self) -> Facilities<DataId, T, Dist>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<DataId, T, Dist> Freeze for Facilities<DataId, T, Dist>
where Dist: Freeze,

§

impl<DataId, T, Dist> !RefUnwindSafe for Facilities<DataId, T, Dist>

§

impl<DataId, T, Dist> Send for Facilities<DataId, T, Dist>
where Dist: Send, DataId: Send + Sync,

§

impl<DataId, T, Dist> Sync for Facilities<DataId, T, Dist>
where Dist: Sync, DataId: Send + Sync,

§

impl<DataId, T, Dist> Unpin for Facilities<DataId, T, Dist>
where Dist: Unpin,

§

impl<DataId, T, Dist> !UnwindSafe for Facilities<DataId, T, Dist>

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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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