Skip to content

eles.neighborhoodSimilarity(options?)

eles.neighborhoodSimilarity — Collection > Algorithms > Similarity, diffusion and resistance. Cytoscape.js signatures, parameters and return contract.

eles.neighborhoodSimilarity — Collection › Algorithms › Similarity, diffusion and resistance

Preview · Collection › Algorithms › Similarity, diffusion and resistance

Read in the complete API reference · All API members

// Neighborhood similarity — pairwise Jaccard, cosine or overlap coefficients over neighbor sets (deduped; loops excluded; directed: true compares out-neighborhoods)
eles.neighborhoodSimilarity(options?: NeighborhoodSimilarityOptions): AlgoRun<NeighborhoodSimilarityResult>

Neighborhood similarity — pairwise Jaccard, cosine or overlap coefficients over neighbor sets (deduped; loops excluded; directed: true compares out-neighborhoods). The result is all-pairs, so it holds O(n²) counts like floydWarshall. Async: returns a promise, and executor ('cpu' | 'gpu' | 'auto', default 'auto') picks where the shared-neighbor counts are computed — under 'auto' the GPU's A·Aᵀ matmul is used only on graphs dense enough to beat the CPU's wedge walk (a mean degree of 64).

Parameters
NameDescription
options: NeighborhoodSimilarityOptions?

{ metric, directed, executor }

Fields of options
NameDescription
metric: SimilarityMetric?

the normalization (default 'jaccard')

directed: boolean?

compare out-neighborhoods instead of undirected ones

executor: AlgoExecutor?

where the run executes; see AlgoExecutor (default 'auto'). 'auto' routes to the GPU only on graphs dense enough that the O(n³) matmul beats the CPU's O(n² + Σ deg²) wedge walk.

Returns AlgoRun<NeighborhoodSimilarityResult>

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

Example

const run = eles.neighborhoodSimilarity({ executor: 'cpu' });
const result = await run;
console.log(result.similarity(cy.getElementById('a'), cy.getElementById('a'))); // 1

Example graph and handle setup

Throws

if executor or metric is invalid; rejects if executor: 'gpu' is unavailable in this environment