pub struct Dendrogram {
pub points: usize,
pub merges: Vec<Merge>,
}Expand description
The full merge tree.
Fields§
§points: usize§merges: Vec<Merge>Implementations§
Source§impl Dendrogram
impl Dendrogram
Sourcepub fn cut_clusters(&self, k: usize) -> Result<Vec<usize>, ErrorsJSL>
pub fn cut_clusters(&self, k: usize) -> Result<Vec<usize>, ErrorsJSL>
Cuts the tree into exactly k clusters (1 <= k <= points), returning a label per point.
Sourcepub fn cut_distance(&self, height: f64) -> Vec<usize>
pub fn cut_distance(&self, height: f64) -> Vec<usize>
Cuts the tree at height: merges at distance <= height are applied.
Sourcepub fn cophenetic_distances(&self) -> R2D
pub fn cophenetic_distances(&self) -> R2D
The cophenetic distance matrix: the height at which each pair of points first joins.
Source§impl Dendrogram
impl Dendrogram
Sourcepub fn to_linkage_matrix(&self) -> R2D
pub fn to_linkage_matrix(&self) -> R2D
The linkage matrix in SciPy’s format: row i is [a, b, distance, size] for the merge
that creates cluster points + i. The two ids are in the dendrogram’s left-to-right
order, which for trees from agglomerate need not have the smaller
id first as SciPy’s linkage does; the tree is the same.
Sourcepub fn from_linkage_matrix(z: VR2D<'_>) -> Result<Dendrogram, ErrorsJSL>
pub fn from_linkage_matrix(z: VR2D<'_>) -> Result<Dendrogram, ErrorsJSL>
A dendrogram from a linkage matrix in SciPy’s format (n − 1 rows of
[a, b, distance, size]), checking that each row joins two existing, unused clusters
and that the sizes add up.
Sourcepub fn leaves(&self) -> Vec<usize>
pub fn leaves(&self) -> Vec<usize>
The points in the order the dendrogram draws them, left to right (SciPy’s leaves_list).
Sourcepub fn inconsistent(&self, depth: usize) -> Result<R2D, ErrorsJSL>
pub fn inconsistent(&self, depth: usize) -> Result<R2D, ErrorsJSL>
The inconsistency statistics of every merge (SciPy’s inconsistent(Z, d)): row i holds
the mean and standard deviation of the heights of the merges at most depth − 1 levels
below merge i (itself included), their number, and the inconsistency coefficient
(h_i − mean) / std (0 when the deviation is 0). A large coefficient marks a merge much
higher than those beneath it: a natural place to cut.
Sourcepub fn optimal_leaf_ordering(
&self,
distances: VR2D<'_>,
) -> Result<Dendrogram, ErrorsJSL>
pub fn optimal_leaf_ordering( &self, distances: VR2D<'_>, ) -> Result<Dendrogram, ErrorsJSL>
The same tree with the two children of each merge swapped where needed so that the sum
of the distances between neighbouring leaves is as small as possible (SciPy’s
optimal_leaf_ordering; Bar-Joseph, Gifford and Jaakkola’s dynamic programme, O(n³)
time and O(n²) memory). distances is the full matrix the tree was built from.
Sourcepub fn leaf_path_length(&self, distances: VR2D<'_>) -> f64
pub fn leaf_path_length(&self, distances: VR2D<'_>) -> f64
The sum of the distances between neighbouring leaves in leaves order,
the quantity optimal_leaf_ordering minimises.