Class Util
Please note that this class is marked with Beta
annotation, so it can be subject of incompatible changes
or removal in later releases.
-
Nested Class Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic int
countNumberOfClusters
(HierarchicClustering<?, ? extends HierarchicCluster<?>> c) Count the number of clusters in a clustering.static <T> String
hierarchicIndexOf
(T member, HierarchicClustering<T, ? extends HierarchicCluster<T>> clustering) Consruct a hierarchic index for a given member of a clustering.static String
hierarchyToString
(IDBasedHierarchicClustering clustering, IDBasedAssigner levels, List<String> labels, int cols) Render a minimalist dendrogram from a String.static DissimilarityInput
linearEuclideanDissimilarityInput
(double[] values) Construct aDissimilarityInput
over a set of 1D values.static int
maxDepth
(HierarchicClustering<?, ? extends HierarchicCluster<?>> c) Find max depth.static String
toJsonMixed
(IDBasedHierarchicClustering clustering) Provide a JSON-like representation for Web GUI widget display.static String
toMultilineString
(IDBasedHierarchicClustering clustering, String prefix) static <T> List<T>
traversePostOrderDFS
(PostOrderDfsVisitor<T> visitor, IDBasedHierarchicClustering clustering) Invoke recursive DFS post order traversal on a hierarchy.static void
traverseSimpleDfs
(IDBasedHierarchicClustering h, SimpleDfsVisitor preorderVisitorOrNull, SimpleDfsVisitor postorderVisitorOrNull) Simple DFS traversal.static void
traverseSimplePostOrderDfs
(IDBasedHierarchicClustering h, SimpleDfsVisitor postOrderVisitor) Simple postorder DFS traversal.static void
traverseSimplePreOrderDfs
(IDBasedHierarchicClustering h, SimpleDfsVisitor preOrderVisitor) Simple preorder DFS traversal.
-
Method Details
-
toMultilineString
-
toJsonMixed
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
Count the number of clusters in a clustering.- Parameters:
c
- A clustering- Returns:
- Total number of clusters, including singletons
-
maxDepth
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 memberclustering
- 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) Simple preorder DFS traversal.This is a convenience method delegating to
traverseSimpleDfs(com.chemaxon.clustering.common.IDBasedHierarchicClustering, com.chemaxon.clustering.util.SimpleDfsVisitor, com.chemaxon.clustering.util.SimpleDfsVisitor)
.- Parameters:
h
- Hierarchy to traversepreOrderVisitor
- A non-null
visitor to invoke
-
traverseSimplePostOrderDfs
public static void traverseSimplePostOrderDfs(IDBasedHierarchicClustering h, SimpleDfsVisitor postOrderVisitor) Simple postorder DFS traversal.This is a convenience method delegating to
traverseSimpleDfs(com.chemaxon.clustering.common.IDBasedHierarchicClustering, com.chemaxon.clustering.util.SimpleDfsVisitor, com.chemaxon.clustering.util.SimpleDfsVisitor)
.- Parameters:
h
- Hierarchy to traversepostOrderVisitor
- 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
- ClusteringpreorderVisitorOrNull
- Visitor to be invoked before a descend step ornull
postorderVisitorOrNull
- Visitor to be invoked after an ascend or side step ornull
-
linearEuclideanDissimilarityInput
Construct aDissimilarityInput
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/skippingclustering
- 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 uselevels
- Level assignemnt to uselabels
- Leaf labels for leaf IDscols
- Total columns- Returns:
- String representation of the given clustering
-