Struct 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:

  1. 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.
  2. A cluster with more than one observation has the label N + i, where N is the total number of observations and i corresponds to the the ith step in which the cluster was created. So for example, the very first step in a dendrogram creates a cluster with the label N and the last step in a dendrogram creates a cluster with the label (N + N - 1) - 1 (since there are always N - 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>

Source

pub fn new(observations: usize) -> Dendrogram<T>

Return a new dendrogram with space for the given number of observations.

Source

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.

Source

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.

Source

pub fn steps(&self) -> &[Step<T>]

Returns the steps in the dendrogram.

Source

pub fn steps_mut(&mut self) -> &mut [Step<T>]

Return a mutable slice of the steps in this dendrogram.

Source

pub fn len(&self) -> usize

Return the number of steps in this dendrogram.

Source

pub fn is_empty(&self) -> bool

Return true if and only if this dendrogram has no steps.

Source

pub fn observations(&self) -> usize

Return the number of observations that this dendrogram supports.

Source

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>

Source

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>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Hash> Hash for Dendrogram<T>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T> Index<usize> for Dendrogram<T>

Source§

type Output = Step<T>

The returned type after indexing.
Source§

fn index(&self, i: usize) -> &Step<T>

Performs the indexing (container[index]) operation. Read more
Source§

impl<T> IndexMut<usize> for Dendrogram<T>

Source§

fn index_mut(&mut self, i: usize) -> &mut Step<T>

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<T: PartialEq> PartialEq for Dendrogram<T>

Source§

fn eq(&self, other: &Dendrogram<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: Eq> Eq for Dendrogram<T>

Source§

impl<T> StructuralPartialEq for Dendrogram<T>

Auto Trait Implementations§

§

impl<T> Freeze for Dendrogram<T>

§

impl<T> RefUnwindSafe for Dendrogram<T>
where T: RefUnwindSafe,

§

impl<T> Send for Dendrogram<T>
where T: Send,

§

impl<T> Sync for Dendrogram<T>
where T: Sync,

§

impl<T> Unpin for Dendrogram<T>
where T: Unpin,

§

impl<T> UnwindSafe for Dendrogram<T>
where T: UnwindSafe,

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