DWCM Phase 4: fix bad-seed convergence via θ-space coordinate Newton solver#12
Merged
fabiosaracco merged 3 commits intomainfrom Mar 13, 2026
Merged
Conversation
Co-authored-by: fabiosaracco <43313433+fabiosaracco@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] [PHASE-4] Modify tests for convergence performance on networks
DWCM Phase 4: fix bad-seed convergence via θ-space coordinate Newton solver
Mar 13, 2026
There was a problem hiding this comment.
Pull request overview
This PR adds a "theta-newton" variant to the DWCM fixed-point solver to address convergence failures (period-3 oscillations) that occur with high-strength hub nodes in power-law networks at N≥5k. The new solver works in θ-space using coordinate-wise Newton steps, avoiding the β>1 clamping instability of the existing β-space fixed-point iteration.
Changes:
- New
"theta-newton"variant insolve_fixed_point_dwcmwith Gauss-Seidel ordering and per-node Newton step clamping - Two new helper functions:
_theta_newton_step_dense()for small N and_theta_newton_step_chunked()for large N (memory-efficient) - Anderson mixing extended with a residual-norm filter to prevent extreme theta-newton iterates from contaminating mixing history
Comment on lines
+192
to
+197
| if effective_chunk > 0: | ||
| fp_raw = _theta_newton_step_chunked( | ||
| theta, s_out, s_in, effective_chunk, damping | ||
| ) | ||
| else: | ||
| fp_raw = _theta_newton_step_dense(theta, s_out, s_in, damping) |
Comment on lines
+137
to
+140
| if variant not in ("jacobi", "gauss-seidel", "theta-newton"): | ||
| raise ValueError( | ||
| f"Unknown variant {variant!r}. Choose 'jacobi', 'gauss-seidel', or 'theta-newton'." | ||
| ) |
| _and_g.append(theta_fp.clone()) | ||
| _and_r.append(r_k.clone()) | ||
| r_k_norm = r_k.abs().max().item() | ||
| _ANDERSON_MAX_NORM = 1e6 |
Comment on lines
+185
to
+197
| if variant == "theta-newton": | ||
| # θ-space coordinate Newton step (avoids β>1 clamping oscillations). | ||
| # For each node i: Δθ_i = −F_i / F′_i where | ||
| # F_i = Σ_{j≠i} W_ij − s_i (expected − observed strength) | ||
| # F′_i = −Σ_{j≠i} W_ij(1+W_ij) (diagonal Hessian entry, ≤ 0) | ||
| # W_ij = 1/expm1(θ_out_i + θ_in_j) | ||
| # Step is clipped to [−damping, +damping] to prevent overshooting. | ||
| if effective_chunk > 0: | ||
| fp_raw = _theta_newton_step_chunked( | ||
| theta, s_out, s_in, effective_chunk, damping | ||
| ) | ||
| else: | ||
| fp_raw = _theta_newton_step_dense(theta, s_out, s_in, damping) |
Owner
|
@copilot apply changes based on the comments in this thread. Then, go on with the remaining tasks. |
…tant, add tests, converged-only stats, bad-seed tracking, FP-GS α=0.3, theta-newton solver, --phase4 CLI Co-authored-by: fabiosaracco <43313433+fabiosaracco@users.noreply.github.com>
Contributor
Author
Done in commit 6949321. Applied all four review comments and completed the remaining tasks:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
For power-law networks at N≥5k, a handful of super-hub nodes (e.g. s_out=419, s_in=520) cause the β-space fixed-point to request β>1 on the very first update. Clamping to β≈1 creates a period-3 oscillation (residuals cycling 1.5×10¹⁰ → 420 → 520 → …) that no amount of Anderson mixing or damping can escape.
Root cause
The β-space FP update
β_i^new = s_i / D_i(β^old)can yield β>1 whenD_i < s_i, i.e. when a hub's observed strength exceeds what the current multipliers can produce. Clamping to the boundary poisons downstream updates for all other nodes.Fix: θ-space coordinate Newton (
"theta-newton"variant)Rewriting the DWCM equation as:
gives a monotone, always-feasible 1-D equation in θ_i ∈ (0, ∞). The exact per-node Newton step is:
This step is always finite and moves monotonically toward the solution — no β>1 state is ever produced.
Changes
src/solvers/fixed_point_dwcm.py"theta-newton"variant accepted bysolve_fixed_point_dwcm; Gauss-Seidel ordering (θ_out updated first, θ_in uses fresh values); zero-strength nodes pinned to_ETA_MAXand never updatedmax_step: float = 1.0parameter controls per-node Newton step clipping for"theta-newton";dampingis now exclusively the β-space blend factor and is skipped for theta-newton (no double attenuation)_theta_newton_step_dense()— full N×N path for N ≤_LARGE_N_THRESHOLD_theta_newton_step_chunked()— memory-efficient chunked path for large N (same O(chunk×N) budget as existing chunked β-FP)_ANDERSON_MAX_NORM = 1e6promoted to module-level constant (was re-assigned on every loop iteration)‖r_k‖∞ < _ANDERSON_MAX_NORM) that prevents extreme theta-newton iterates from contaminating the mixing historyvariant,damping, andmax_stepparams fully documentedtests/test_dwcm.pyTestThetaNewtonDWCMclass with 5 tests: convergence on N=4 and N=10, convergence with Anderson acceleration, zero-strength node pinning (θ = _ETA_MAX), chunked==dense step consistency, result fields (elapsed_time, peak_ram_bytes, residuals)src/benchmarks/dwcm_comparison.py—in the tablerun_multi_seed_comparisonreturns(agg, bad_seeds)— seeds where no method converged are collected, printed, and (in--phase4mode) saved tobad_seeds_phase4.txt--phase4CLI flag: N=5k, 5 seeds, all key methods; bad seeds saved tobad_seeds_phase4.txtBenchmark Results: N=5,000, seeds 0–4, TOL=1e-6, timeout=60 s/solver
Per-seed results
Aggregate table (converged runs only)
Key findings
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.