Skip to content

eles.effectiveResistance(options?)

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

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

Preview · Collection › Algorithms › Similarity, diffusion and resistance

Read in the complete API reference · All API members

// Effective resistance and commute time — the graph as a resistor network
eles.effectiveResistance(options?: EffectiveResistanceOptions): AlgoRun<EffectiveResistanceResult>

Effective resistance and commute time — the graph as a resistor network. Weights are conductances by default, the convention of the papers that define the weighted measure; weightAs: 'resistance' reads them as resistances, NetworkX's default. resistance(a, b) comes from the Laplacian pseudo-inverse, commuteTime(a, b) the expected round-trip steps of the random walk (component volume × resistance). Pairs in different components answer Infinity. Async: executor ('cpu' | 'gpu' | 'auto', default 'auto') picks between dense f64 elimination on the CPU and Newton–Schulz matmul iteration on the GPU; both are O(n³), so 'auto' takes the GPU on size alone.

Parameters
NameDescription
options: EffectiveResistanceOptions?

{ weight, weightAs, executor }

Fields of options
NameDescription
weight: WeightFn?
weightAs: 'conductance' | 'resistance'?

what weight measures: 'conductance' (default, a heavier edge conducts more) or 'resistance' (a heavier edge resists more — NetworkX's invert_weight=True default)

executor: AlgoExecutor?

where the run executes; see AlgoExecutor (default 'auto')

Returns AlgoRun<EffectiveResistanceResult>

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

Example

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

Example graph and handle setup

Throws

if executor or weightAs is invalid; rejects if an edge weight is not positive or executor: 'gpu' is unavailable