Skip to content

eles.closenessCentrality(options?)

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

eles.closenessCentrality — Collection › Algorithms › Centrality

Preview · Collection › Algorithms › Centrality

Read in the complete API reference · All API members

// Closeness centrality of one node — how near it is, by shortest path, to the rest of the collection
eles.closenessCentrality(options?: ClosenessCentralityOptions): number

Closeness centrality of one node — how near it is, by shortest path, to the rest of the collection. Harmonic (default): Σ 1/d, an unreachable node contributing 0. harmonic: false: the classic (n − 1)/Σd, and over r reachable nodes the Wasserman–Faust (r/Σd)·(r/(n − 1)) — NetworkX's definition. Directed runs sum distances from the node (direction: 'out', default, as R igraph and graph-tool) or to it ('in', as NetworkX and Neo4j GDS).

Parameters
NameDescription
options: ClosenessCentralityOptions?

{ root, weight, directed, direction, harmonic }

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 number

the closeness score

Example

console.log(eles.closenessCentrality({ root: cy.getElementById('b') })); // 2

Example graph and handle setup

Throws

if root is not a node of the collection, or direction is neither 'out' nor 'in'

Also spelled eles.cc.