Skip to content

eles.katzCentrality(options?)

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

eles.katzCentrality — Collection › Algorithms › Centrality

Preview · Collection › Algorithms › Centrality

Read in the complete API reference · All API members

// Katz centrality — attenuated walk counting, where a node is central when many short walks end at it and a walk of length k is worth alphaᵏ
eles.katzCentrality(options?: KatzCentralityOptions): AlgoRun<KatzCentralityResult>

Katz centrality — attenuated walk counting, where a node is central when many short walks end at it and a walk of length k is worth alphaᵏ. Async: returns a promise, and executor ('cpu' | 'gpu' | 'auto', default 'auto'; 'workers' runs the reference on one pool worker) picks where the iteration runs; like pageRank, 'auto' always uses the sparse CPU iteration and the GPU path serves an explicit 'gpu'. katzNormalized divides by the largest score, or by the scores' Euclidean norm under normalization: 'l2' — NetworkX's normalized=True.

Parameters
NameDescription
options: KatzCentralityOptions?

{ alpha, beta, maxIterations, tolerance, directed, weight, normalization, executor }

Fields of options
NameDescription
alpha: number?

the walk attenuation per step (default 0.1); must be positive, and under 1/λ_max of the adjacency for the iteration to converge

beta: number?

the baseline every node starts each step with (default 1)

maxIterations: number?

iteration cap when the tolerance is never met (default 200)

tolerance: number?

stop once Σ|Δx| < n · tolerance (default 1e-6)

directed: boolean?

count incoming walks only

weight: WeightFn?
normalization: 'max' | 'l2'?

how katzNormalized scales: 'max' (default) divides by the largest score, 'l2' by the scores' Euclidean norm — NetworkX's katz_centrality(normalized=True)

executor: AlgoExecutor?

where the run executes; see AlgoExecutor (default 'auto'). Like pageRank, 'auto' stays on the sparse CPU iteration at every measured size (KATZ_GPU_MIN_N); the GPU path serves an explicit 'gpu'.

Returns AlgoRun<KatzCentralityResult>

a promise of the { katz, katzNormalized } accessors — with cancel() on it: a pending run rejects with CancelledError, a 'cpu' run has already completed

Example

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

Example graph and handle setup

Throws

if executor, alpha, beta or normalization is invalid; rejects if executor: 'gpu' is unavailable in this environment