Commit d59f6ab
committed
Fix pagerank convergence threshold for large sparse graphs
The previous convergence check `norm < n * tol` scaled the L1 tolerance
by graph size, which made it a useless threshold once N > 2/tol (since
L1 distance between probability vectors is bounded by 2). On large
sparse graphs, the first power-iteration step's L1 diff from the uniform
starting vector could trivially fall below `n * tol`, causing `pagerank`
to return the initial uniform 1/N distribution without any indication of
failure.
Minimal reproduction: a 2000-node graph with 2 edges (path 0->1->2)
returns `pr[2] = 0.0005` (uniform) instead of the correct `pr[2] =
0.00128` (2.6x above uniform).
This patch changes the check to `norm < tol` (absolute L1 tolerance,
matching the docstring semantics) and adds a regression test.
Fixes #15751 parent 3a64257 commit d59f6ab
3 files changed
Lines changed: 52 additions & 1 deletion
File tree
- releasenotes/notes
- src
- tests/digraph
Lines changed: 13 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
199 | 199 | | |
200 | 200 | | |
201 | 201 | | |
202 | | - | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
203 | 210 | | |
204 | 211 | | |
205 | 212 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
321 | 321 | | |
322 | 322 | | |
323 | 323 | | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
0 commit comments