pub trait Cluster<U: Number>: Serialize + for<'a> Deserialize<'a> + PartialEq + Eq + PartialOrd + Ord + Debug + Hash + Display + Send + Sync + Clone {
Show 26 methods
// Required methods
fn new_root<I: Instance, D: Dataset<I, U>>(
data: &D,
seed: Option<u64>,
) -> Self;
fn partition<I, D, P>(
self,
data: &mut D,
criteria: &P,
seed: Option<u64>,
) -> Self
where I: Instance,
D: Dataset<I, U>,
P: PartitionCriterion<U>;
fn offset(&self) -> usize;
fn cardinality(&self) -> usize;
fn depth(&self) -> usize;
fn arg_center(&self) -> usize;
fn radius(&self) -> U;
fn arg_radial(&self) -> usize;
fn lfd(&self) -> f64;
fn children(&self) -> Option<[&Self; 2]>;
fn polar_distance(&self) -> Option<U>;
fn arg_poles(&self) -> Option<[usize; 2]>;
// Provided methods
fn name(&self) -> String { ... }
fn descend_to(&self, offset: usize, cardinality: usize) -> Option<&Self> { ... }
fn is_ancestor_of(&self, other: &Self) -> bool { ... }
fn is_descendant_of(&self, other: &Self) -> bool { ... }
fn is_leaf(&self) -> bool { ... }
fn is_singleton(&self) -> bool { ... }
fn indices(&self) -> Range<usize> { ... }
fn subtree(&self) -> Vec<&Self> { ... }
fn max_leaf_depth(&self) -> usize { ... }
fn distance_to_instance<I: Instance, D: Dataset<I, U>>(
&self,
data: &D,
instance: &I,
) -> U { ... }
fn distance_to_other<I: Instance, D: Dataset<I, U>>(
&self,
data: &D,
other: &Self,
) -> U { ... }
fn overlapping_children<I: Instance, D: Dataset<I, U>>(
&self,
data: &D,
query: &I,
radius: U,
) -> Vec<&Self> { ... }
fn save(&self, path: &Path) -> Result<(), String> { ... }
fn load(path: &Path) -> Result<Self, String> { ... }
}
Expand description
A Cluster
represents a set of “similar” instances under some distance
function.
Required Methods§
sourcefn new_root<I: Instance, D: Dataset<I, U>>(data: &D, seed: Option<u64>) -> Self
fn new_root<I: Instance, D: Dataset<I, U>>(data: &D, seed: Option<u64>) -> Self
Creates a new Cluster
from a given dataset.
sourcefn partition<I, D, P>(
self,
data: &mut D,
criteria: &P,
seed: Option<u64>,
) -> Self
fn partition<I, D, P>( self, data: &mut D, criteria: &P, seed: Option<u64>, ) -> Self
Recursively partitions the Cluster
until the PartitionCriteria
are met.
sourcefn cardinality(&self) -> usize
fn cardinality(&self) -> usize
The number of points in the cluster.
sourcefn arg_center(&self) -> usize
fn arg_center(&self) -> usize
The index of the instance at the center
of the Cluster
.
TODO: Remove this method when we have “center-less” clusters.
sourcefn arg_radial(&self) -> usize
fn arg_radial(&self) -> usize
The index of the instance with the maximum distance from the center
sourcefn polar_distance(&self) -> Option<U>
fn polar_distance(&self) -> Option<U>
The distance between the two poles of the Cluster
used for partitioning.
Provided Methods§
sourcefn name(&self) -> String
fn name(&self) -> String
The name
of the Cluster
String.
This is a human-readable representation of the Cluster
’s offset
and
cardinality
. It is a unique identifier in the tree. It may be used to
store the Cluster
in a database, or to identify the Cluster
in a
visualization.
sourcefn descend_to(&self, offset: usize, cardinality: usize) -> Option<&Self>
fn descend_to(&self, offset: usize, cardinality: usize) -> Option<&Self>
Descends to the Cluster
with the given offset
and cardinality
.
If such a Cluster
does not exist, None
is returned.
§Arguments
offset
: The offset of theCluster
’s instances in the dataset.cardinality
: The number of instances in theCluster
.
sourcefn is_ancestor_of(&self, other: &Self) -> bool
fn is_ancestor_of(&self, other: &Self) -> bool
Whether the Cluster
is an ancestor of another Cluster
.
sourcefn is_descendant_of(&self, other: &Self) -> bool
fn is_descendant_of(&self, other: &Self) -> bool
Whether the Cluster
is a descendant of another Cluster
.
sourcefn is_singleton(&self) -> bool
fn is_singleton(&self) -> bool
Whether the Cluster
is a singleton, i.e. it contains only one instance or has a radius of zero.
sourcefn indices(&self) -> Range<usize>
fn indices(&self) -> Range<usize>
The indices of the instances in the Cluster
after the dataset has been reordered.
sourcefn max_leaf_depth(&self) -> usize
fn max_leaf_depth(&self) -> usize
The maximum depth of and leaf in the subtree of the Cluster
.
If this Cluster
is a leaf, the maximum depth is the depth of the Cluster
.
sourcefn distance_to_instance<I: Instance, D: Dataset<I, U>>(
&self,
data: &D,
instance: &I,
) -> U
fn distance_to_instance<I: Instance, D: Dataset<I, U>>( &self, data: &D, instance: &I, ) -> U
Distance from the center
to the given instance.
sourcefn distance_to_other<I: Instance, D: Dataset<I, U>>(
&self,
data: &D,
other: &Self,
) -> U
fn distance_to_other<I: Instance, D: Dataset<I, U>>( &self, data: &D, other: &Self, ) -> U
Distance from the center
of this Cluster
to the center of the
other
Cluster
.
sourcefn overlapping_children<I: Instance, D: Dataset<I, U>>(
&self,
data: &D,
query: &I,
radius: U,
) -> Vec<&Self>
fn overlapping_children<I: Instance, D: Dataset<I, U>>( &self, data: &D, query: &I, radius: U, ) -> Vec<&Self>
Assuming the Cluster
overlaps with the query ball, we return only
those children that also overlap with the query ball.