Skip to content

Base the default error penalty on the scalar start value - #716

Open
hmgaudecker wants to merge 7 commits into
mainfrom
fix/error-penalty-scalar-default
Open

hmgaudecker wants to merge 7 commits into
mainfrom
fix/error-penalty-scalar-default

Conversation

@hmgaudecker

Copy link
Copy Markdown
Member

Closes #715.

With error_handling="continue", the default error penalty was built from start_criterion.internal_value(solver_type). For least-squares and likelihood solvers that is a vector, so:

  • least squares: the first failing evaluation raised InvalidFunctionError instead of being penalized;
  • likelihood: the penalty landed at the wrong level.

The default constant is now computed from the scalar start value for every aggregation level. The new test checks that, without explicit error_penalty options, the likelihood and least-squares penalties equal the scalar penalty of the same start value. It fails on main for both.

https://claude.ai/code/session_01Hs8mfXPYyEa24KaAp6BwCW

For least-squares and likelihood solvers the default penalty constant was
built from the start criterion's residual or contribution vector, so it
became an array: a least-squares penalty raised InvalidFunctionError and a
likelihood penalty landed at the wrong level. The default now derives from
the scalar start value for every aggregation level.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Hs8mfXPYyEa24KaAp6BwCW
@codecov

codecov Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
src/optimagic/optimization/error_penalty.py 96.29% <100.00%> (ø)
src/optimagic/optimization/optimize.py 92.17% <ø> (ø)

... and 5 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@hmgaudecker
hmgaudecker requested a review from janosg October 16, 2026 16:51
@janosg

janosg commented Oct 19, 2026

Copy link
Copy Markdown
Member

Thanks! This bug was introduced during the major refactor in 2024.

janosg and others added 3 commits October 19, 2026 15:49
The default penalty constant is now always computed from the scalar start
value, so constant and slope are floats for every aggregation level.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Split the explanation of the error penalty out of the how-to guide, state
the two design constraints (finite values, implemented outside the solver)
and add background on hidden constraints from the literature.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Cover all supported combinations of function type, solver type and
direction, with numerical and closed-form derivatives. Extend the penalty
unit tests to maximization and check that the default penalty is worse
than the start value. bhhh cases are marked xfail because bhhh steps
uphill when the derivative is consistent with the objective.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@review-notebook-app

Copy link
Copy Markdown

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

Replace the toy problem by a Poisson regression for scalar and likelihood
functions and a Gaussian nonlinear regression for least-squares functions,
so that bhhh is tested on problems it is designed for.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Drop the tests for maximizing least-squares problems (already covered in
test_function_formats_ls.py) and for incompatible solver types (moved to #720).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@janosg janosg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reviewed the PR and the fix is correct.

I made two follow up changes:

  1. Split the documentation of error handling into How-To and Explanation and improve the explanation section.
  2. Add more comprehensive end-to-end tests for error handling with different solver types (which actually uncovered a few problems in BHHH).

I'm requesting a new review from @timmens. You can focus on the changes in documentation and tests.

@janosg
janosg requested a review from timmens October 19, 2026 17:59

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

error_handling="continue" fails for least-squares objectives: default penalty constant is a vector

2 participants