Skip to content

eles.hierarchicalClustering(options?)

eles.hierarchicalClustering — Collection > Algorithms > Clustering. Cytoscape.js signatures, parameters and return contract.

eles.hierarchicalClustering — Collection › Algorithms › Clustering

Preview · Collection › Algorithms › Clustering

Read in the complete API reference · All API members

// Agglomerative hierarchical clustering
eles.hierarchicalClustering(options?: HierarchicalClusteringOptions): AlgoRun<Collection<NodeData, EdgeData, NodeData>[]>

Agglomerative hierarchical clustering. Async: returns a promise, and executor ('cpu' | 'gpu' | 'auto', default 'auto'; 'workers' runs the reference on one pool worker) picks where the distance matrix is built; the merge chain itself is sequential and runs with the reference — in-thread, or on the pool worker for a named distance and a 'min' / 'max' / 'mean' linkage. A custom distance function or a per-pair linkage consults the metric inside the run, on the calling thread, and 'workers' rejects them. Threshold mode merges every closest pair at most threshold apart, a merge at exactly threshold included, as SciPy's fcluster and R's cutree.

Parameters
NameDescription
options: HierarchicalClusteringOptions?

{ attributes, distance, linkage, mode, threshold, dendrogramDepth, executor }

Fields of options
NameDescription
distance: DistanceMetric?
linkage: string?

linkage criterion: 'min' (single), 'max' (complete), 'mean', or per-pair

mode: 'threshold' | 'dendrogram'?
threshold: number?

threshold mode merges pairs at most this far apart (default Infinity)

addDendrogram: boolean?
dendrogramDepth: number?
attributes: HierarchicalAttributeFn[]?
executor: AlgoExecutor?

where the run executes; see AlgoExecutor (default 'auto')

Returns AlgoRun<Collection<NodeData, EdgeData, NodeData>[]>

a promise of one collection per cluster — with cancel() on it: a pending run rejects with CancelledError, a 'cpu' run has already completed

Example

const run = eles.hierarchicalClustering({ attributes: [node => node.data('score')], executor: 'cpu' });
const result = await run;
console.log(result.reduce((sum, cluster) => sum + cluster.length, 0)); // 3

Example graph and handle setup

Throws

if executor is invalid; rejects if executor: 'gpu' is unavailable in this environment, or executor: 'workers' is given a custom distance function or a per-pair linkage

Also spelled eles.hca.