Class Util

java.lang.Object
com.chemaxon.clustering.util.Util

@Beta @PublicAPI public final class Util extends Object
Clustering related utility methods.

Please note that this class is marked with Beta annotation, so it can be subject of incompatible changes or removal in later releases.

  • Method Details

    • toMultilineString

      public static String toMultilineString(IDBasedHierarchicClustering clustering, String prefix)
    • toJsonMixed

      public static String toJsonMixed(IDBasedHierarchicClustering clustering)
      Provide a JSON-like representation for Web GUI widget display.

      Please note that the provided representation is not defined, it can be changed in future releases.

      Parameters:
      clustering - Clustering to JSonify
      Returns:
      JSON representation
    • countNumberOfClusters

      public static int countNumberOfClusters(HierarchicClustering<?,? extends HierarchicCluster<?>> c)
      Count the number of clusters in a clustering.
      Parameters:
      c - A clustering
      Returns:
      Total number of clusters, including singletons
    • maxDepth

      public static int maxDepth(HierarchicClustering<?,? extends HierarchicCluster<?>> c)
      Find max depth.
      Parameters:
      c - A clustering
      Returns:
      Max parent-children steps required to reach every leaf
    • hierarchicIndexOf

      public static <T> String hierarchicIndexOf(T member, HierarchicClustering<T,? extends HierarchicCluster<T>> clustering)
      Consruct a hierarchic index for a given member of a clustering.

      Hierarchic index is a comma (,) separated list of 1-based indexes of the path leading to the given member from the roots. In a clustering, hierarchic index "2,3,4" means that the given member is accessible from the second root's third child cluster, as its fourth element. The previous elements can be further clusters or leaf nodes.

      This implementation orders child clusters before immediate leaves.

      Type Parameters:
      T - Type of clustered members
      Parameters:
      member - A member
      clustering - Associated clustering
      Returns:
      1-based, comma separated compact (no whitespaces) hierarchic index string of the given member
      Throws:
      IllegalArgumentException - when the given member is not part of the given clustering
    • traverseSimplePreOrderDfs

      public static void traverseSimplePreOrderDfs(IDBasedHierarchicClustering h, SimpleDfsVisitor preOrderVisitor)
      Parameters:
      h - Hierarchy to traverse
      preOrderVisitor - A non-null visitor to invoke
    • traverseSimplePostOrderDfs

      public static void traverseSimplePostOrderDfs(IDBasedHierarchicClustering h, SimpleDfsVisitor postOrderVisitor)
      Parameters:
      h - Hierarchy to traverse
      postOrderVisitor - A non-null visitor to invoke
    • traverseSimpleDfs

      public static void traverseSimpleDfs(IDBasedHierarchicClustering h, SimpleDfsVisitor preorderVisitorOrNull, SimpleDfsVisitor postorderVisitorOrNull)
      Simple DFS traversal.

      Non recursive DFS traversal of all (intermediate included) clusters with a List based stack. Leaves and members must be handled by the visitor implementation.

      For the following tree (only clusters shown, no leaves/members considered)

         C-0
         C-1 -+- C-2 --- C-3
              +- C-4
         C-5
         C-6 --- C-7 --- C-8
       

      The following invocation order is expected (<PATH> / <VISITED>) for the preorder callback:

       "C-0"               / "C-0"
       "C-1"               / "C-1"
       "C-1", "C-2"        / "C-2"
       "C-1", "C-2", "C-3" / "C-3"
       "C-1", "C-4"        / "C-4"
       "C-5"               / "C-5"
       "C-6"               / "C-6"
       "C-6", "C-7"        / "C-7"
       "C-6", "C-7", "C-8" / "C-8"
       

      The following invocation order is expected (<PATH> / <VISITED>) for the postorder callback:

       "C-0"               / "C-0"
       "C-1", "C-2", "C-3" / "C-3"
       "C-1", "C-2"        / "C-2"
       "C-1", "C-4"        / "C-4"
       "C-1"               / "C-1"
       "C-5"               / "C-5"
       "C-6", "C-7", "C-8" / "C-8"
       "C-6", "C-7"        / "C-7"
       "C-6"               / "C-6"
       
      Parameters:
      h - Clustering
      preorderVisitorOrNull - Visitor to be invoked before a descend step or null
      postorderVisitorOrNull - Visitor to be invoked after an ascend or side step or null
    • linearEuclideanDissimilarityInput

      public static DissimilarityInput linearEuclideanDissimilarityInput(double[] values)
      Construct a DissimilarityInput over a set of 1D values.
      Parameters:
      values - Values to consider
      Returns:
      Dissimilarity input representing their euclidean distances
    • traversePostOrderDFS

      public static <T> List<T> traversePostOrderDFS(PostOrderDfsVisitor<T> visitor, IDBasedHierarchicClustering clustering)
      Invoke recursive DFS post order traversal on a hierarchy.
      Type Parameters:
      T - Traversal result type
      Parameters:
      visitor - Callback interface for traversal/skipping
      clustering - Clustering to traverse
      Returns:
      Result list of traversal associated to roots
    • hierarchyToString

      public static String hierarchyToString(IDBasedHierarchicClustering clustering, IDBasedAssigner levels, List<String> labels, int cols)
      Render a minimalist dendrogram from a String.
      Parameters:
      clustering - Source clustering to use
      levels - Level assignemnt to use
      labels - Leaf labels for leaf IDs
      cols - Total columns
      Returns:
      String representation of the given clustering