Skip to content

Add KADABRA betweenness centrality approximation algorithm - #518

Open
DerSchmachtin wants to merge 1 commit into
JuliaGraphs:masterfrom
DerSchmachtin:master
Open

Add KADABRA betweenness centrality approximation algorithm#518
DerSchmachtin wants to merge 1 commit into
JuliaGraphs:masterfrom
DerSchmachtin:master

Conversation

@DerSchmachtin

@DerSchmachtin DerSchmachtin commented Jul 31, 2026

Copy link
Copy Markdown

Description

This Pull Request introduces the KADABRA (K-ADaptive Approximation of Betweenness centRAlity) algorithm to Graphs.jl.

Computing exact betweenness centrality can be prohibitively expensive on very large graphs. KADABRA provides a fast and highly scalable randomized approximation of the betweenness centrality, as well as an efficient method to find the top-k nodes with the highest betweenness.

The implementation includes two main exported functions:

  • kadabra_centrality: Approximates the betweenness centrality for all vertices.
  • kadabra_top_k: Returns the top k vertices with the highest betweenness centrality.

Reference:

Borassi M., Natale E. (2016) KADABRA is an ADaptive Algorithm for Betweenness via Random Approximation. In: ESA 2016. [https://dl.acm.org/doi/10.1145/3284359]

A note on the top-k allocation

In top-k mode KADABRA sizes each vertex's confidence interval from its rank gaps before sampling begins. Here the implementation follows the paper (Section 5.2) rather than the authors' C++ reference, which NetworKit's KadabraBetweenness also copies — so a reviewer comparing against either will find a deliberate difference rather than a porting bug:

  • The reference pairs the two rank gaps opposite to the way its own stopping test consults them, and leaves lambda_L(v_1) unconstrained — pinning the top vertex's lower budget, the only one its own test uses, at the minimum.
  • Its tie-collapse rule is never applied to the pair (v_k, v_{k+1}), the single pair the external-exclusion test is built around, which deadlocks both vertices once their gap falls below 2*err.

The allocation is a heuristic for where to spend the delta budget, not part of the (err, delta) guarantee, so each variant remains a valid approximation and they differ only in how many samples they need. Measured over 4 SNAP graphs × k ∈ {3, 5, 10, 100} × 3 seeds at err = 1e-4, the paper's allocation needed 0.80 ± 0.18 times as many samples as the reference's, at identical top-k accuracy — the same overlap with the exact ranking and the same Kendall τ over the top k to three decimals. Collapsing the boundary pair additionally removes the cases where a top-k query cost more than computing every centrality. See the number of samples in comparison to 'k=0' below. k = 0 is unaffected: it does not enter this code path.

topk_allocation

I am separately seeking confirmation from the KADABRA authors on whether the reference's ordering was deliberate (I'm pretty sure it was overlooked), and will report back here. In the meantime I am happy to switch to the reference's behaviour instead if you would prefer bug-for-bug compatibility with NetworKit.

Checklist

  • Added kadabra.jl to src/centrality/
  • Added corresponding test suite in test/centrality/kadabra.jl and registered it in runtests.jl
  • Code has been formatted using JuliaFormatter.jl according to BlueStyle
  • Added documentation strings and exported the functions in Graphs.jl
  • Ensured RNG scoping follows Graphs.jl conventions using standard library imports

All tests pass locally. Let me know if there are any changes or further optimizations you would like me to make!

Benchmarks & Performance

To verify the performance, I ran some benchmarks comparing this Julia implementation against the original, highly optimized C++ version from the authors.

Hardware Setup:
All benchmarks were executed on an AMD Ryzen Threadripper 3960X 24-Core Processor (3.80 GHz, 48 threads) with 125 GiB of RAM running Ubuntu 22.04 LTS.

The Julia implementation is competitive compared to the Original C++ Implementation.
Here are the results (using k=0, delta=0.1 and epsilon=0.0001) on a few test instances taken from SNAP:

image

@DerSchmachtin
DerSchmachtin force-pushed the master branch 2 times, most recently from a71b033 to 47fd306 Compare July 31, 2026 18:26
@codecov

codecov Bot commented Jul 31, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.62%. Comparing base (356aa72) to head (f5d137c).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #518      +/-   ##
==========================================
+ Coverage   97.46%   97.62%   +0.16%     
==========================================
  Files         127      129       +2     
  Lines        7766     8340     +574     
==========================================
+ Hits         7569     8142     +573     
- Misses        197      198       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@DerSchmachtin
DerSchmachtin force-pushed the master branch 5 times, most recently from 1b7aaad to 6d1291d Compare August 5, 2026 07:42
@DerSchmachtin
DerSchmachtin force-pushed the master branch 5 times, most recently from 0298521 to e213fd1 Compare August 14, 2026 11:30
@LoveLow-Global

Copy link
Copy Markdown
Member

Hi there, sorry for the delay in responding. I was very busy thoughout the last couple of weeks, and haven't had the time to look into the new PRs. I will try to review this within a week. Thank you!!

Implements the KADABRA approximation algorithm for betweenness
centrality (Borassi & Natale, 2019), including the adaptive
delta-calibration phase, and registers it in the docs, CHANGELOG
and test suite.

The top-k confidence-budget allocation follows the paper rather than the
authors' C++ reference, which transposes the two rank gaps relative to the
stopping test its own Algorithm 2 performs, leaves lambda_L(v_1)
unconstrained, and never applies the tie-collapse rule to the pair
(v_k, v_{k+1}) that the external-exclusion test is built around. The
allocation is a heuristic for where to spend the delta budget, not part of
the (err, delta) guarantee, so both readings are valid approximations and
differ only in cost. Over 4 SNAP graphs x k in {3, 5, 10, 100} x 3 seeds at
err = 1e-4, the paper's allocation needed 0.80 +- 0.18 times as many samples
as the reference's for identical top-k accuracy, and collapsing the boundary
pair additionally removes the cases where a top-k query cost more than
computing every centrality. The rationale is documented at the call sites in
`compute_bet_err!`. k = 0 does not enter this code path.

Also switches the JET testset to `target_modules=(Graphs,)`, since
`target_defined_modules` was removed in JET 0.12 and now raises a
JETConfigError.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants