⚙️ Core: Refactor Newton-Raphson Solver #443
Closed
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.
🔧 The Violation:
The
calculate_final_sizefunction inmath_explorer/src/epidemiology/analytics.rscontained a hardcoded implementation of the Newton-Raphson method, violating DRY (logic duplication of a standard algorithm) and SRP (mixing domain logic with numerical solving). It also used string-based error handling.🛠️ The Fix:
NewtonRaphsonsolver inmath_explorer/src/pure_math/analysis/roots.rs. This struct implements the existingRootFindertrait (using numerical differentiation) and exposes a specializedfind_root_with_derivativemethod for high-precision use cases.calculate_final_sizeto use the newNewtonRaphsoncomponent, injecting the analytical derivative of the final size equation.EpidemiologyErrorto wrapAnalysisError, moving away from stringly-typed errors.📉 Debt Reduction:
🧪 Integrity:
NewtonRaphsoncovering linear, quadratic, and bounded scenarios.test_final_size_high_r0passes with the new implementation.PR created automatically by Jules for task 18224543845005302773 started by @fderuiter