Struct kodama::Dendrogram
source · pub struct Dendrogram<T> { /* private fields */ }
Expand description
A step-wise dendrogram that represents a hierarchical clustering as a binary tree.
A dendrogram consists of a series of N - 1
steps, where N
is the number
of observations that were clustered. Each step corresponds to a merge
between two other clusters (where a cluster might consist of one or more
observations). Each step includes the labels for the pair of clusters that
were merged, the number of total observations in the new merged cluster
and the dissimilarity between the two merged clusters.
The labels of clusters are assigned as follows:
- A cluster that corresponds to a single observation is assigned a label that corresponds to the given observation’s index in the pairwise dissimilarity matrix.
- A cluster with more than one observation has the label
N + i
, whereN
is the total number of observations andi
corresponds to the thei
th step in which the cluster was created. So for example, the very first step in a dendrogram creates a cluster with the labelN
and the last step in a dendrogram creates a cluster with the label(N + N - 1) - 1
(since there are alwaysN - 1
steps in a dendrogram).
This labeling scheme corresponds to the same labeling scheme used by SciPy.
The type parameter T
refers to the type of dissimilarity used in the
steps. In practice, T
is a floating point type.
Implementations§
source§impl<T> Dendrogram<T>
impl<T> Dendrogram<T>
sourcepub fn new(observations: usize) -> Dendrogram<T>
pub fn new(observations: usize) -> Dendrogram<T>
Return a new dendrogram with space for the given number of observations.
sourcepub fn reset(&mut self, observations: usize)
pub fn reset(&mut self, observations: usize)
Clear this dendrogram and ensure there is space for the given number of observations.
This method is useful for reusing a dendrogram’s allocation.
Note that this method does not need to be called before passing it to one of the clustering functions. The clustering functions will reset the dendrogram for you.
sourcepub fn push(&mut self, step: Step<T>)
pub fn push(&mut self, step: Step<T>)
Push a new step on to this dendrogram.
Panics
This method panics if the dendrogram has N - 1
steps, where N
is
the number of observations supported by this dendrogram.
sourcepub fn steps_mut(&mut self) -> &mut [Step<T>]
pub fn steps_mut(&mut self) -> &mut [Step<T>]
Return a mutable slice of the steps in this dendrogram.
sourcepub fn observations(&self) -> usize
pub fn observations(&self) -> usize
Return the number of observations that this dendrogram supports.
sourcepub fn cluster_size(&self, label: usize) -> usize
pub fn cluster_size(&self, label: usize) -> usize
Returns the total number of observations in the cluster identified by the following label.
The label may be any value in the half-open interval
[0, N + N - 1)
, where N
is the total number of observations.
source§impl<T: Float> Dendrogram<T>
impl<T: Float> Dendrogram<T>
sourcepub fn eq_with_epsilon(&self, other: &Dendrogram<T>, epsilon: T) -> bool
pub fn eq_with_epsilon(&self, other: &Dendrogram<T>, epsilon: T) -> bool
Compare two dendrograms for approximate equality.
Approximate equality in this case refers to the dissimilarities in each
step. In particular, two dissimilarities are considered equal if and
only if the absolute value of their difference is less than or equal to
the given epsilon
value.
Trait Implementations§
source§impl<T: Debug> Debug for Dendrogram<T>
impl<T: Debug> Debug for Dendrogram<T>
source§impl<T: Hash> Hash for Dendrogram<T>
impl<T: Hash> Hash for Dendrogram<T>
source§impl<T> Index<usize> for Dendrogram<T>
impl<T> Index<usize> for Dendrogram<T>
source§impl<T> IndexMut<usize> for Dendrogram<T>
impl<T> IndexMut<usize> for Dendrogram<T>
source§impl<T: PartialEq> PartialEq<Dendrogram<T>> for Dendrogram<T>
impl<T: PartialEq> PartialEq<Dendrogram<T>> for Dendrogram<T>
source§fn eq(&self, other: &Dendrogram<T>) -> bool
fn eq(&self, other: &Dendrogram<T>) -> bool
self
and other
values to be equal, and is used
by ==
.