@graphty/algorithms / index / indexed / closenessCentrality
Function: closenessCentrality() ​
closenessCentrality(
s,options?):ClosenessResult
Defined in: indexed/closeness.ts:235
Closeness centrality of every node: 1 / sum(distance to each reached node) by default, the legacy closenessCentrality (hops) and weightedClosenessCentrality (weighted: true) numbers. The weighted route reads the snapshot's f32 arc weights, so it matches legacy to f32 rounding; pass the f64 weights as weights for the exact legacy sums. As in legacy, a node's distance is final once it is searched from, so a negative weight gives the legacy (not the true shortest) distance and never loops. An unreached node adds nothing, and a node that reaches nothing scores 0.
SAMPLED (sources or k): the searches run from the sampled sources over the IN-arcs, so each search measures every node's distance TO that source, and each node's sums run over the sources it reaches (itself excluded) instead of over every node it reaches. Everything else is unchanged: the same formula is applied to those sums, with the same n - 1 under normalized and no extrapolation to the whole graph -- the UNSCALED rule sampled betweenness follows. So a sample of every node gives exactly the exact scores (up to the order floating-point sums are added in), and on a sample of k sources 1 / score is the summed distance to those k sources: multiply the plain score by k / n for the Eppstein-Wang estimate of the exact one. A harmonic score (normalized or not) sums reciprocal distances, so it needs the inverse, n / k; a normalized plain score divides by the number of sources reached, which already rescales it, so it needs no factor. On an undirected snapshot the in-arcs are the out-arcs. Two corners are measured from the source's side and so differ from an exact run even over a full sample: a weighted cutoff (the node just past it is admitted from the source's end of the path) and a negative weight (the legacy settle rule is not symmetric).
Parameters ​
s ​
GraphSnapshot
The snapshot
options? ​
ClosenessOptions = {}
Normalisation, harmonic form, cutoff, weights and sampling
Returns ​
One score per node index; iterations and sourcesUsed are the number of searches run
Throws ​
RangeError for a bad sources or k