Keep finite-difference residual evaluations within bounds - #3566
Open
yurekami wants to merge 1 commit into
Open
Conversation
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.
jacobian_fdchooses an inward finite-difference direction, but its relative step can still cross the opposite bound when the interval is narrow. For example, with bounds[0, 1e-10], the default perturbation from zero evaluates the residual at about1.49e-8. This can makeleast_squaresfail for residuals defined only inside the supplied bounds.Clip the actual evaluation points to the box and use their actual displacement as the finite-difference denominator. Step inward explicitly at the upper bound, including when an adjacent-float interval's midpoint rounds to that endpoint. Clipping the points themselves also avoids a rounding excursion across zero that can remain after clipping only the displacement.
The regression tests cover lower/interior/upper points, mixed parameter scales, intervals crossing zero, adjacent floating-point bounds, exact linear Jacobians, and a bounded least-squares solve. Before the fix, the nine new helper subcases and the solver regression fail. After the fix, the full minimizer suite passes: 18 tests and 13 subtests.
Validation used the current checkout's Python module and tests on Windows/Python 3.12 with installed MuJoCo 3.12.0 native bindings; no native code was changed or rebuilt. Reproduce that configuration from the repository root with:
Pyink checks pass for the changed regions, isort passes with
mujococlassified as a third-party extension package, and the applicable pre-commit checks pass.