class HClust::Dendrogram
- HClust::Dendrogram
- Reference
- Object
Overview
A step-wise dendrogram that encodes the arrangement of the clusters produced by hierarchical clustering as a binary tree.
A dendrogram consists of a sequence of N - 1 merge steps (see
Step
), where N is the number of elements or observations that
were clustered, and a step corresponds to a merge between two
distinct clusters.
The labeling of the clusters follows the SciPy convention, where new labels start at N:
- If a cluster has a single element, the label would be the index of the element in the original sequence.
- If a cluster has more than one elements (two previous clusters were merged), the label would be N + i, where i is the index of the merge step that created it.
Consequently, the labels of the newly created clusters ranges from N to N + N - 1.
Defined in:
hclust/dendrogram.crConstructors
-
.new(observations : Int32)
Creates a new
Dendrogram
with the given number of original elements or observations.
Instance Method Summary
-
#<<(step : Step) : self
Appends the given merge step.
-
#==(rhs : self) : Bool
Returns
true
if the merge steps are equal torhs
's steps, elsefalse
. -
#add(c_i : Int32, c_j : Int32, distance : Float64) : Step
Creates and appends a merge step between clusters c_i and c_j with the given distance.
-
#flatten(height : Number) : Array(Array(Int32))
Returns flat clusters of the original observations obtained by cutting the dendrogram at height (cophenetic distance).
-
#flatten(*, count : Int) : Array(Array(Int32))
Returns count or fewer flat clusters of the original observations.
-
#observations : Int32
Number of the original elements or observations that were clustered.
-
#relabel(ordered : Bool = false) : self
Returns a new
Dendrogram
with relabeled clusters. -
#steps : Array::View(Step)
Returns a view of the merge steps.
Constructor Detail
Creates a new Dendrogram
with the given number of original
elements or observations.
Instance Method Detail
Appends the given merge step. Raises ArgumentError
if the
dendrogram is already full (contains N - 1
steps).
Creates and appends a merge step between clusters c_i and c_j with the given distance.
Returns flat clusters of the original observations obtained by cutting the dendrogram at height (cophenetic distance).
Returns count or fewer flat clusters of the original
observations. Raises ArgumentError
if count is negative or
zero.
It internally computes the smallest height at which cutting the dendrogram would generate count or fewer clusters, and then flattens the dendrogram at the computed height.
Returns a new Dendrogram
with relabeled clusters. If ordered
is true
, the dendrogram's steps will be sorted by the
dissimilarities first.
Internally, it uses a UnionFind
data structure for creating
merge steps with the new cluster labels efficiently.
NOTE Cluster labels will follow the SciPy convention, where new
clusters start at N
with N
equal to the number of
observations (see UnionFind
).