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>
impl<DataId: Debug + Clone + Send + Sync, T: Send + Sync + Clone, Dist: Distance<T> + Send + Sync> Facilities<DataId, T, Dist>
pub fn is_empty(&self) -> bool
Sourcepub fn get_weight(&self) -> f64
pub fn get_weight(&self) -> f64
total weight already inserted
pub fn get_distance(&self) -> &Dist
Sourcepub fn match_point(&self, point: &[T], dmax: f32, distance: &Dist) -> bool
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
Sourcepub fn get_facility(
&self,
rank: usize,
) -> Option<&Arc<RwLock<Facility<DataId, T>>>>
pub fn get_facility( &self, rank: usize, ) -> Option<&Arc<RwLock<Facility<DataId, T>>>>
retrieve facility by rank if rank is Ok
Sourcepub fn get_cloned_facility(&self, rank: usize) -> Option<Facility<DataId, T>>
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
Sourcepub fn get_facility_weight(&self, rank: usize) -> Result<f64>
pub fn get_facility_weight(&self, rank: usize) -> Result<f64>
return weight in facility of rank rank, error else
Sourcepub fn get_nearest_facility(
&self,
data: &[T],
parallel: bool,
) -> Result<(usize, f32)>
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
Sourcepub fn compute_weight_cost(&mut self) -> (f64, f64)
pub fn compute_weight_cost(&mut self) -> (f64, f64)
returns (total weight, total cost)
Sourcepub fn log(&self, level: usize)
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.
Sourcepub fn dispatch_data(
&mut self,
data: &[&Vec<T>],
_ids: &[usize],
weights: Option<&Vec<f32>>,
) -> f64
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
Sourcepub 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>>)
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
Sourcepub fn into_weighted_data(&self) -> Vec<(f64, Vec<T>, DataId)>
pub fn into_weighted_data(&self) -> Vec<(f64, Vec<T>, DataId)>
extract facility centers and associated weight for possible other clustering step
Sourcepub fn cross_distances(&self)
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>
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>
fn clone(&self) -> Facilities<DataId, T, Dist>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto 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>
impl<DataId, T, Dist> Sync for Facilities<DataId, T, Dist>
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> 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
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>
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