Repository navigation
Keep length-one dimensions in second_derivative - #755
Open
anshurajbisoyi98-ctrl wants to merge 1 commit into
Open
anshurajbisoyi98-ctrl wants to merge 1 commit into
anshurajbisoyi98-ctrl wants to merge 1 commit into
Conversation
hessian_to_block_tree dropped every dimension of length one, so the Hessian of a function of one parameter came back with shape () instead of (1, 1). estimate_ml then failed with an IndexError whenever a single parameter was estimated. Keep the full block shape, as matrix_to_block_tree already does for first derivatives. Closes optimagic-dev#752 Signed-off-by: anshurajbisoyi98-ctrl <anshurajbisoyi98@gmail.com>
Codecov Report✅ All modified and coverable lines are covered by tests.
... and 2 files with indirect coverage changes 🚀 New features to boost your workflow:
|
This branch has not been deployed
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.
What problem do you want to solve?
Closes #752, reported by janosg.
I used the fix proposed in the issue:
hessian_to_block_treenow keeps the full(*s0, *s1, *s2)shape instead of dropping every dimension of length one. All theexamples from the issue now give the expected shapes, and
estimate_mlworks with asingle parameter.
One side effect worth pointing out: a one-row DataFrame with a
valuecolumn used toget a bare scalar block back. It now gets a one-by-one DataFrame, the same as DataFrames
with more rows.
Tests: a parametrized shape test for the cases in the issue, and an
estimate_mltestwith one float parameter that checks the Hessian covariance against
1 / n. Both fail onmain. I rantests-fastand the slow tests intests/estimagic,tests/optimagic/differentiationandtests/optimagic/parameters. I didn't touch thejax comparison tests. Their helper uses
assert_array_almost_equal, which treats a 0-darray as equal to a
(1, 1)one, so they wouldn't have caught this.Checklist
Closes #XXXX.I used Claude Code to help check the fix and write the tests. I reviewed the change,
checked that the new tests fail without it, and ran the test suites above and ty
locally.