Repository navigation
feat(adr-001 #3): adaptive Neumann depth from coherence + tolerance - #37
Merged
Merged
Conversation
Today callers of solve_on_change_sublinear / solve_single_entry_neumann
pick `max_terms` blindly. The closure size scales with depth, so an
over-pick wastes work; an under-pick silently misses the tolerance
bound. This lands the math-driven helper:
optimal_neumann_terms(coherence, b_inf_norm, min_diag, tolerance)
→ Option<usize>
For strict-DD A = D - O with coherence c, ‖y_k‖ ≤ ρ^k · ‖y_0‖ with
ρ ≤ 1 - c. To hit tolerance:
k ≥ log(‖b‖_∞ / (min_diag · tolerance)) / log(1 / (1 - c))
Returned k is clamped to [1, 64] (caller-protective floor / cap).
Composition:
- Cache (coherence, min_diag) once at matrix-build time.
- For each event, compute auto_terms = optimal_neumann_terms(...)
instead of guessing.
- Pass auto_terms as max_terms to solve_on_change_sublinear.
Example update (examples/event_driven_anomaly.rs):
- Computes auto_terms from coherence + b_inf + tolerance at startup.
- Uses it as max_terms in every event-handling call.
- Header line now shows the chosen value alongside coherence /
min_diag for transparency.
The example's previous hand-picked max_terms=24 was *under-tuned* for
the test matrix's coherence (0.2): the math-driven helper picks 64
(clamped) for the same tolerance. Per-event latency goes from ~2 ms
to ~12 ms — that's correctness paying its real cost. Higher-coherence
matrices (≥ 0.5) would pick lower term counts, pulling the bench
crossover lower.
Tests: 8 new optimal_neumann_terms tests in coherence::tests.
31/31 coherence tests pass.
Co-Authored-By: claude-flow <ruv@ruv.net>
2 of 3 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.
Summary
Today callers of `solve_on_change_sublinear` / `solve_single_entry_neumann` pick `max_terms` blindly. The closure size scales with depth, so an over-pick wastes work; an under-pick silently misses the tolerance bound. This PR lands the math-driven helper:
```rust
optimal_neumann_terms(coherence, b_inf_norm, min_diag, tolerance) -> Option
```
For strict-DD `A = D - O` with coherence `c`, the Neumann series satisfies `‖y_k‖ ≤ ρ^k · ‖y_0‖` with `ρ ≤ 1 - c`. To hit tolerance:
```
k ≥ log(‖b‖_∞ / (min_diag · tolerance)) / log(1 / (1 - c))
```
Returned `k` is clamped to `[1, 64]` (caller-protective floor + cap).
Composition
Example update
The event-driven example (PR #33, #35) now picks `max_terms` adaptively from the matrix's coherence at startup, removing the last hand-tuned magic number from the canonical inner loop.
Discovery: the prior hand-picked `max_terms=24` was under-tuned for the test matrix's coherence (0.2). The math-driven helper picks 64 (clamped) for the same tolerance. Per-event latency goes from ~2 ms to ~12 ms — that's correctness paying its real cost. Higher-coherence matrices (≥ 0.5) would pick lower term counts, pulling the bench crossover lower.
Test plan
🤖 Generated with claude-flow