Reuse solver residual in calibrator#231
Open
mrp089 wants to merge 4 commits into
Open
Conversation
The block update_gradient methods previously hand-coded the residual r = E*ydot + F*y + c, duplicating the residual the solver already assembles in SparseSystem::update_residual (r = -C - E*ydot - F*y). Reuse the solver residual during calibration and have update_gradient assemble only the Jacobian of the residual with respect to the parameters. The Jacobian signs are flipped to match the solver's sign convention; the overall sign cancels in the LM normal equations, so the optimization is unchanged. - LevenbergMarquardtOptimizer now sets the model parameters to the current alpha, assembles E/F once, and computes the residual per observation via update_solution + update_residual. - calibrate registers the parameters with the model so the solver's assembly can read their values. - Blocks without calibration parameters (e.g. a normal junction) are skipped in the Jacobian loop, so Junction::update_gradient is removed. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…ndeleev-a7e408 # Conflicts: # src/model/Junction.h # src/optimize/LevenbergMarquardtOptimizer.cpp # src/optimize/calibrate.cpp
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.
Current situation
Closes #153.
Release Notes
The calibrator reuses the code from the solver to calculate the residual, which previously needed to be reimplemented for each block. This makes the code more straightforward and makes calibrating new blocks easier.
Documentation
No change in functionality
Testing
Should work as before
Code of Conduct & Contributing Guidelines