Repository navigation
Run fit_scipy with L-BFGS-B, as its docstring says - #840
Open
sandeshbagmare wants to merge 2 commits into
Open
sandeshbagmare wants to merge 2 commits into
sandeshbagmare wants to merge 2 commits into
Conversation
minimize was called without method or bounds, so SciPy picked BFGS while the docstring promised L-BFGS-B. Name the method, drop the disp option that L-BFGS-B does not accept (it was reaching BFGS), print the outcome when verbose, and warn when SciPy reports that it did not converge, so a fit that gave up is not mistaken for one that converged. The crazy-mean case in test_fit_scipy_error_raises relied on BFGS's precision-loss warning, which L-BFGS-B does not emit; that half of the test is replaced by a test asserting the method that reaches SciPy. Fixes QuantClimate#837
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.
Fixes #837
fit_scipycalledminimizewith nomethod, no bounds and no constraints, so SciPy picked BFGS while the docstring promised L-BFGS-B. Two consequences, both from the report: a well-scaled regression diverges toobs_stddev ≈ 1.8e7with ananobjective and no signal, and BFGS holds a dense inverse Hessian, which does not scale to a variational family with many inducing points.Proposed Changes
method="L-BFGS-B".dispfromoptions: L-BFGS-B does not accept it (it was only accepted because the call reached BFGS), andverbosenow reports the iteration count, the final objective and SciPy's own message.OptimizeWarningwhen SciPy reportssuccess=False, so a solver that gave up is not read as a converged fit. This is the "can diverge without an error" half of the report.Tests
test_fit_scipy_uses_lbfgsbrecords the keyword argumentsfit_scipyhands toscipy.optimize.minimizeand asserts the method isL-BFGS-B.test_fit_scipy_error_raiseskept its iteration-limit case (max_iters=1still warns) and lost the crazy-mean case, which only ever warned because of BFGS's "precision loss"OptimizeWarning; L-BFGS-B converges there instead of warning.pytest tests/test_fit.pypasses (106 tests) andruff check/ruff format --checkare clean on both files.