Commit 3361fcd
authored
* docs: add true Leiden refinement phase to backlog (ID 103)
Current vendored implementation uses greedy refinement, which is
functionally Louvain with an extra pass. The paper's randomized
refinement (Algorithm 3) is what guarantees well-connected
communities — the defining contribution of Leiden over Louvain.
* fix: mark backlog item #103 as breaking, add deterministic seed note (#552)
The probabilistic Leiden refinement changes community assignments and
introduces non-determinism — both qualify as breaking per the column
definition. Added a note about using a deterministic seed for CI
reproducibility.
* feat: implement true Leiden probabilistic refinement (Algorithm 3)
Replace greedy best-gain selection in refinement phase with Boltzmann
sampling p(v, C) ∝ exp(ΔH/θ) per Traag et al. 2019, Algorithm 3.
This is the defining contribution of Leiden over Louvain — guarantees
γ-connected communities instead of bridge-connected subcommunities.
Deterministic via seeded PRNG (mulberry32) — same seed always produces
identical community assignments. New refinementTheta option (default
0.01) controls temperature: lower → more greedy, higher → exploratory.
Breaking: community assignments will differ from prior greedy refinement
for any graph where multiple candidates have positive quality gain
during the refinement phase.
Impact: 2 functions changed, 4 affected
* docs: remove backlog #103 — ships in this PR, not a breaking change
* fix: align Leiden refinement with Algorithm 3 (Traag et al. 2019)
Three corrections to match the paper:
1. Singleton guard — only nodes still in singleton communities are
candidates for merging. Once merged, a node is locked for the
remainder of the pass. Essential for γ-connectedness guarantee.
2. Single pass — one randomized sweep, not an iterative while-loop.
Iterating until convergence is Louvain behavior, not Leiden.
3. Stay option — the "remain as singleton" choice (ΔH=0) is included
in the Boltzmann distribution, so a node may probabilistically
stay alone even when positive-gain merges exist.
Impact: 1 functions changed, 1 affected
* test: add Algorithm 3 conformance tests for Leiden refinement
Three new tests that would catch deviations from the paper:
- Stay option: high theta preserves singletons because ΔH=0 competes
in the Boltzmann distribution. Without it, all positive-gain nodes
would be forced to merge.
- Singleton guard: ring of triangles stays granular across seeds.
Without the guard, iterative passes would collapse adjacent triangles.
- Single pass: refine=true preserves at least as many communities as
refine=false on a uniform weak-link graph. Iterative convergence
would over-merge.
* feat: post-refinement connectivity split and fix default theta
Three improvements to complete the robust Leiden implementation:
1. Default refinementTheta changed from 0.01 to 1.0. The old default
made exp(ΔH/0.01) extremely peaked, effectively disabling the
probabilistic behavior. θ=1.0 matches the paper's exp(ΔH).
2. Post-refinement split step: after probabilistic refinement, BFS
each community's induced subgraph. If a community has disconnected
components, split them into separate community IDs. O(V+E) total.
This replaces the expensive per-candidate γ-connectedness check
with a cheap post-step using codegraph's existing graph primitives.
3. New connectivity validation test: across multiple seeds, verify
every community is internally connected via BFS on the subgraph.
This directly tests the core Leiden guarantee.
Adds resizeCommunities() to partition API for the split step.
Impact: 6 functions changed, 5 affected
1 parent 4908334 commit 3361fcd
File tree
5 files changed
+461
-30
lines changed- docs/roadmap
- src/graph/algorithms/leiden
- tests/graph/algorithms
5 files changed
+461
-30
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
122 | 122 | | |
123 | 123 | | |
124 | 124 | | |
| 125 | + | |
125 | 126 | | |
126 | 127 | | |
127 | 128 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
167 | 167 | | |
168 | 168 | | |
169 | 169 | | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
170 | 176 | | |
171 | 177 | | |
172 | 178 | | |
| |||
229 | 235 | | |
230 | 236 | | |
231 | 237 | | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
232 | 260 | | |
233 | 261 | | |
234 | 262 | | |
| |||
237 | 265 | | |
238 | 266 | | |
239 | 267 | | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
240 | 271 | | |
241 | 272 | | |
242 | | - | |
243 | | - | |
244 | | - | |
245 | | - | |
246 | | - | |
247 | | - | |
248 | | - | |
249 | | - | |
250 | | - | |
251 | | - | |
252 | | - | |
253 | | - | |
254 | | - | |
255 | | - | |
256 | | - | |
257 | | - | |
258 | | - | |
259 | | - | |
260 | | - | |
261 | | - | |
262 | | - | |
263 | | - | |
264 | | - | |
265 | | - | |
266 | | - | |
267 | | - | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
268 | 295 | | |
269 | | - | |
270 | | - | |
271 | | - | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
272 | 299 | | |
273 | 300 | | |
274 | | - | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
275 | 330 | | |
276 | 331 | | |
277 | 332 | | |
278 | 333 | | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
279 | 406 | | |
280 | 407 | | |
281 | 408 | | |
| |||
329 | 456 | | |
330 | 457 | | |
331 | 458 | | |
| 459 | + | |
| 460 | + | |
332 | 461 | | |
333 | 462 | | |
334 | 463 | | |
| |||
341 | 470 | | |
342 | 471 | | |
343 | 472 | | |
| 473 | + | |
344 | 474 | | |
345 | 475 | | |
346 | 476 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
373 | 373 | | |
374 | 374 | | |
375 | 375 | | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
376 | 380 | | |
377 | 381 | | |
378 | 382 | | |
| |||
0 commit comments