Record Class HierarchicalClustering

java.lang.Object
java.lang.Record
smile.clustering.HierarchicalClustering
Record Components:
tree - the hierarchical cluster tree. An n-1 by 2 matrix of which row i describes the merging of clusters at step i of the clustering. If an element j in the row is less than n, then observation j was merged at this stage. If j >= n then the merge was with the cluster formed at the (earlier) stage j-n of the algorithm.
height - the clustering height. A set of n-1 non-decreasing real values, which are the value of the criterion associated with the clustering method for the particular agglomeration.
All Implemented Interfaces:
Serializable

public record HierarchicalClustering(int[][] tree, double[] height) extends Record implements Serializable
Agglomerative Hierarchical Clustering. Hierarchical agglomerative clustering seeks to build a hierarchy of clusters in a bottom up approach: each observation starts in its own cluster, and pairs of clusters are merged as one moves up the hierarchy. The results of hierarchical clustering are usually presented in a dendrogram.

In general, the merges are determined in a greedy manner. In order to decide which clusters should be combined, a measure of dissimilarity between sets of observations is required. In most methods of hierarchical clustering, this is achieved by use of an appropriate metric, and a linkage criteria which specifies the dissimilarity of sets as a function of the pairwise distances of observations in the sets.

Hierarchical clustering has the distinct advantage that any valid measure of distance can be used. In fact, the observations themselves are not required: all that is used is a matrix of distances.

References

  1. David Eppstein. Fast hierarchical clustering and other applications of dynamic closest pairs. SODA 1998.
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    HierarchicalClustering(int[][] tree, double[] height)
    Creates an instance of a HierarchicalClustering record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    final boolean
    Indicates whether some other object is "equal to" this one.
    fit(Linkage linkage)
    Fits the Agglomerative Hierarchical Clustering with given linkage method, which includes proximity matrix.
    final int
    Returns a hash code value for this object.
    double[]
    Returns the value of the height record component.
    int[]
    partition(double h)
    Cuts a tree into several groups by specifying the cut height.
    int[]
    partition(int k)
    Cuts a tree into several groups by specifying the desired number.
    final String
    Returns a string representation of this record class.
    int[][]
    Returns the value of the tree record component.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • HierarchicalClustering

      public HierarchicalClustering(int[][] tree, double[] height)
      Creates an instance of a HierarchicalClustering record class.
      Parameters:
      tree - the value for the tree record component
      height - the value for the height record component
  • Method Details

    • fit

      public static HierarchicalClustering fit(Linkage linkage)
      Fits the Agglomerative Hierarchical Clustering with given linkage method, which includes proximity matrix.
      Parameters:
      linkage - a linkage method to merge clusters. The linkage object includes the proximity matrix of data.
      Returns:
      the model.
    • partition

      public int[] partition(int k)
      Cuts a tree into several groups by specifying the desired number.
      Parameters:
      k - the number of clusters.
      Returns:
      the cluster label of each sample.
    • partition

      public int[] partition(double h)
      Cuts a tree into several groups by specifying the cut height.
      Parameters:
      h - the cut height.
      Returns:
      the cluster label of each sample.
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • tree

      public int[][] tree()
      Returns the value of the tree record component.
      Returns:
      the value of the tree record component
    • height

      public double[] height()
      Returns the value of the height record component.
      Returns:
      the value of the height record component