Class ClusterDistanceMatrix


  • public class ClusterDistanceMatrix
    extends java.lang.Object
    Shared code for algorithms that work on a pairwise cluster distance matrix.

    Note that this requires O(n²) memory (and often O(n³) runtime).

    This class bridges the gap from the relational (indexed by identifiers) and the matrix view (indexed by integers 0...n-1).

    While this will usually store (merge-) distances when clustering, it can store arbitrary doubles.

    Since:
    0.7.5
    Author:
    Erich Schubert
    • Field Summary

      Fields 
      Modifier and Type Field Description
      int[] clustermap
      Mapping from positions to cluster numbers
      double[] matrix
      Distance matrix (modifiable).
      int size
      Number of rows/columns.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      double get​(int x, int y)
      Get a value from the (upper triangular) distance matrix.
      static int triangleSize​(int x)
      Compute the size of a complete x by x triangle (minus diagonal)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • matrix

        public final double[] matrix
        Distance matrix (modifiable).
      • clustermap

        public final int[] clustermap
        Mapping from positions to cluster numbers
      • size

        public final int size
        Number of rows/columns.
    • Constructor Detail

      • ClusterDistanceMatrix

        public ClusterDistanceMatrix​(int size)
        Constructor.
        Parameters:
        size - Size
    • Method Detail

      • triangleSize

        public static int triangleSize​(int x)
        Compute the size of a complete x by x triangle (minus diagonal)
        Parameters:
        x - Offset
        Returns:
        Size of complete triangle
      • get

        public double get​(int x,
                          int y)
        Get a value from the (upper triangular) distance matrix.

        Note: in many cases, linear iteration over the matrix will be faster than repeated calls to this method!

        Parameters:
        x - First object
        y - Second object
        Returns:
        Distance