Skip to content

eles.closenessCentralityNormalized(options?)

eles.closenessCentralityNormalized — Collection > Algorithms > Centrality. Cytoscape.js signatures, parameters and return contract.

eles.closenessCentralityNormalized — Collection › Algorithms › Centrality

Preview · Collection › Algorithms › Centrality

Read in the complete API reference · All API members

// Closeness centrality for every node, normalized to [0, 1]
eles.closenessCentralityNormalized(options?: ClosenessCentralityOptions): AlgoRun<ClosenessCentralityNormalizedResult>

Closeness centrality for every node, normalized to [0, 1]. Async: the whole-collection form is the all-pairs tier, so like floydWarshall it returns a promise and executor ('cpu' | 'gpu' | 'workers' | 'auto', default 'auto') picks where it runs; 'cpu' is the reproducible reference. Unweighted runs walk a BFS per source, O(n·(n+E)) — on the worker pool too (one source range per worker, bit-identical to 'cpu'; under 'auto' a sparse graph takes the pool first from 512 nodes, using workers for sparse graphs, and a dense one the GPU first); weighted runs relax Floyd–Warshall, O(n³), and take the offload lane (one pool worker). The single-root closenessCentrality stays synchronous.

Each score is closenessCentrality's for that node (the same harmonic and direction), divided by the largest.

normalization: 'size' divides a harmonic score by n − 1 instead, igraph's and graph-tool's normalized harmonic centrality, and leaves a classic score, which already carries n − 1, as is.

Parameters
NameDescription
options: ClosenessCentralityOptions?

{ weight, directed, direction, harmonic, normalization, executor }

Fields of options
NameDescription
root: Collection | null?
weight: WeightFn?
directed: boolean?
direction: 'out' | 'in'?

which distances a directed run sums: 'out' (default) from the node to the others — R igraph's mode = "out" and graph-tool's — or 'in', from the others to the node — NetworkX's, Neo4j GDS's and Boldi–Vigna's. Ignored when undirected.

harmonic: boolean?

Σ 1/d (default, tolerates disconnection), or the classic (n − 1)/Σd with the Wasserman–Faust correction: over the r nodes reachable, (r/Σd)·(r/(n − 1)), 0 when none is

normalization: 'max' | 'size'?

read by closenessCentralityNormalized only: 'max' (default) divides by the largest score; 'size' divides a harmonic score by n − 1 (igraph's and graph-tool's normalized harmonic centrality) and leaves a classic one as is, (n − 1) already being in its formula

executor: AlgoExecutor?

where the run executes; see AlgoExecutor (default 'auto'). Read by the whole-collection closenessCentralityNormalized only — the single-root closenessCentrality is a cheap Dijkstra walk and stays synchronous on the CPU. Unweighted runs walk a BFS per source on either executor (72.3); weighted runs relax Floyd–Warshall.

Returns AlgoRun<ClosenessCentralityNormalizedResult>

a promise of a closeness accessor — with cancel() on it: a pending run rejects with CancelledError, a 'cpu' run has already completed

Example

const run = eles.closenessCentralityNormalized({ executor: 'cpu' });
const result = await run;
console.log(result.closeness(cy.getElementById('b')) > 0); // true

Example graph and handle setup

Throws

if executor, direction or normalization is invalid; rejects if executor: 'gpu' or 'workers' is unavailable in this environment, or 'workers' is asked of a weighted run

Also spelled eles.ccn, eles.closenessCentralityNormalised.