// k-means clustering in attribute space
eles.kMeans(options?: KClusteringOptions): AlgoRun<Collection<NodeData, EdgeData, NodeData>[]>k-means clustering in attribute space. Works on handles and attributes accessors rather than on graph structure.
Async: returns a promise, and executor ('cpu' | 'gpu' | 'auto', default 'auto'; 'workers' runs the reference on one pool worker for a named distance) picks where the iteration runs; 'cpu' is the reproducible reference. A custom distance function is called inside the iteration, so it runs on the calling thread under 'cpu' and 'auto', and 'workers' rejects it.
| Name | Description |
|---|---|
options: KClusteringOptions? |
|
Fields of options
| Name | Description |
|---|---|
k: number? | |
m: number? | |
sensitivityThreshold: number? | |
distance: DistanceMetric? | |
maxIterations: number? | |
attributes: KAttributeFn[]? | |
testMode: boolean? | |
testCentroids: number | FeatureCentroid[] | Collection[] | null? | |
executor: AlgoExecutor? | where the run executes; see |
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.kMeans({ k: 2, attributes: [node => node.data('score')], executor: 'cpu' });const result = await run;console.log(result.reduce((sum, cluster) => sum + cluster.length, 0)); // 3if executor is invalid; rejects if executor: 'gpu' is unavailable in this environment, or executor: 'workers' is given a custom distance function