C

HierarchicalClustering

Partitions the graph into clusters using hierarchical clustering.
Inheritance Hierarchy

Remarks

Hierarchical clustering creates a hierarchy of clusters in a bottom-to-top approach based on some distance metric and linkage.

The clustering is performed using the agglomerative strategy i.e., a bottom-up approach according to which initially each node comprises its own cluster. At each step pairs of clusters are merged while moving up the hierarchy. The dissimilarity between clusters is determined based on the given linkage and the given node distances metric. The algorithm continues until all nodes belong to the same cluster.

Predefined metrics are available as constants on HierarchicalClustering:

Internally the HierarchicalClusteringResult stores a dendrogram which represents the result of the clustering algorithm as a binary tree structure. Based on the dendrogram the graph's nodes are partitioned into clusters according to either clusterCount or cutoff. Since both methods to compute the clusters only require the dendrogram, the HierarchicalClusteringResult offers methods to create a new clustering based on either criterion as long as either the graph or the subgraph specification did not change in between (which would require re-computing the dendrogram).

Other Clustering Algorithms

yFiles for HTML supports a number of other clustering algorithms:

Complexity

O(|V|³)

Examples

Calculating hierarchical clusters of a graph
// prepare the hierarchical clustering algorithm
const algorithm = new HierarchicalClustering()
// run the algorithm
const result = algorithm.run(graph)

// highlight the nodes of the clusters with different styles
for (const node of graph.nodes) {
  const componentId = result.nodeClusterIds.get(node)!
  graph.setStyle(node, clusterStyles.get(componentId)!)
}

See Also

Developer's Guide

Members

No filters for this type

Constructors

Parameters

Properties

Gets or sets the number of clusters.

If set to a negative number or 0, the cutoff value is used to calculate the clusters. If both values are negative, a number of 1 is used (one cluster containing all nodes in the graph).

A new result for a different number of clusters can be obtained efficiently with changeClusterCount on a valid HierarchicalClusteringResult, as long as the graph, linkage, and metric are still the same.

final

See Also

Developer's Guide
Gets or sets the cut-off value.

The clusters are calculated based on the given cut-off value that is used for cutting the hierarchical tree at a point such that the dissimilarity values of the nodes that remain at the dendrogram are less than this value.

This value will only be used if clusterCount is 0 or negative.

This value must be non-negative, otherwise the result will be a single cluster which contains all nodes of the graph.

A new result for a different cut-off value can be obtained efficiently with changeCutoff on a valid HierarchicalClusteringResult, as long as the graph, linkage, and metric are still the same.

final

See Also

Developer's Guide
Gets or sets the method for determining the distance between clusters.
The default is SINGLE.
conversionfinal

See Also

Developer's Guide
Gets or sets a function which returns the distance between any two nodes.

The result of the function must not be negative.

Predefined common metrics are available as constants on HierarchicalClustering:

final

See Also

Developer's Guide
Gets or sets the collection of edges which define a subset of the graph for the algorithms to work on.

If nothing is set, all edges of the graph will be processed.

If only the excludes are set, all edges in the graph except those provided in the excludes are processed.

Note that edges which start or end at nodes which are not in the subgraphNodes are automatically not considered by the algorithm.

ItemCollection<T> instances may be shared among algorithm instances and will be (re-)evaluated upon (re-)execution of the algorithm.

The edges provided here must be part of the graph which is passed to the run method.
conversionfinal

Examples

Calculating hierarchical clusters on a subset of the graph
// prepare the hierarchical clustering algorithm
const algorithm = new HierarchicalClustering({
  // Ignore edges without target arrow heads
  subgraphEdges: {
    excludes: (edge: IEdge): boolean =>
      edge.style instanceof PolylineEdgeStyle &&
      edge.style.targetArrow instanceof Arrow &&
      edge.style.targetArrow.type === ArrowType.NONE,
  },
})
// run the algorithm
const result = algorithm.run(graph)

// highlight the nodes of the clusters with different styles
for (const node of graph.nodes) {
  const componentId = result.nodeClusterIds.get(node)!
  graph.setStyle(node, clusterStyles.get(componentId)!)
}
Gets or sets the collection of nodes which define a subset of the graph for the algorithms to work on.

If nothing is set, all nodes of the graph will be processed.

If only the excludes are set, all nodes in the graph except those provided in the excludes are processed.

ItemCollection<T> instances may be shared among algorithm instances and will be (re-)evaluated upon (re-)execution of the algorithm.

The nodes provided here must be part of the graph which is passed to the run method.
conversionfinal

Examples

Calculating hierarchical on a subset of the graph
// prepare the hierarchical clustering algorithm
const algorithm = new HierarchicalClustering({
  subgraphNodes: {
    // only consider elliptical nodes in the graph
    includes: (node: INode): boolean =>
      node.style instanceof ShapeNodeStyle &&
      node.style.shape === ShapeNodeShape.ELLIPSE,
    // but ignore the first node, regardless of its shape
    excludes: graph.nodes.first()!,
  },
})
// run the algorithm
const result = algorithm.run(graph)

// highlight the nodes of the clusters with different styles
for (const node of graph.nodes) {
  const componentId = result.nodeClusterIds.get(node)!
  graph.setStyle(node, clusterStyles.get(componentId)!)
}

Methods

Partitions the graph into clusters using hierarchical clustering.
The returned HierarchicalClusteringResult can be used to efficiently create different clusterings of the same graph based on the metric and linkage as long as the graph hasn't changed (and would thus invalidate the computed dendrogram.
The result obtained from this algorithm is a snapshot which is no longer valid once the graph has changed, e.g. by adding or removing nodes or edges.
final

Parameters

graph: IGraph
The input graph to run the algorithm on.

Return Value

HierarchicalClusteringResult
A HierarchicalClusteringResult containing the computed clusters and dendrogram.

Throws

Exception ({ name: 'InvalidOperationError' })
If the algorithm can't create a valid result due to an invalid graph structure or wrongly configured properties.

Complexity

O(|V|³)

Constants

A predefined metric for Euclidean distance.
A predefined metric for squared Euclidean distance.
A predefined metric for Manhattan distance.