Skip to content

Fix optimizer bugs and preserve original figures - #1

Merged
wyli merged 4 commits into
masterfrom
agent/fix-optimizers-and-figures
Jul 13, 2026
Merged

Fix optimizer bugs and preserve original figures#1
wyli merged 4 commits into
masterfrom
agent/fix-optimizers-and-figures

Conversation

@wyli

@wyli wyli commented Jul 12, 2026

Copy link
Copy Markdown
Owner

Scope

Fix correctness and reproducibility bugs while preserving the repository's original figure layout and Matplotlib style.

The regenerated assets retain:

  • labeled black contour lines for quadratic.png
  • the original Newton / modified-Newton / rank-one overlay for quasi_newton.png
  • the single filled YlGnBu Rosenbrock contour with every method overlaid for cg.png
  • the original legend labels, start/optimum annotations, and output sizes

Bugs fixed

  • return the backtracking step that actually satisfied Armijo instead of contracting it once more
  • replace the unsafe interpolating line search with safeguarded quadratic interpolation
  • record the accepted SR1 iterate instead of duplicating the previous point
  • stop BFGS and SR1 using the actual gradient norm rather than an unchanged variable
  • skip numerically unsafe SR1 updates instead of dividing by an arbitrary epsilon
  • restart quasi-Newton/CG directions if numerical error makes them point uphill
  • solve Newton systems directly instead of explicitly forming matrix inverses
  • reject nonsymmetric quadratic matrices whose declared gradient would be mathematically incorrect
  • support current NumPy arrays without deprecated numpy.matrix assumptions

Figure regeneration

MPLBACKEND=Agg python main.py regenerates the same three original-style figures. Repeated runs in the pinned environment produce byte-identical PNGs.

Validation

  • MPLBACKEND=Agg pytest -q — 13 passed
  • finite-difference Rosenbrock derivative check
  • Newton one-step quadratic check
  • BFGS/SR1 convergence checks
  • accepted-step checks for both line searches
  • SR1 trajectory regression for the duplicated-point bug
  • Rosenbrock convergence checks from the figure start
  • figure smoke test locking the original output dimensions
  • GitHub Actions on Python 3.9

@wyli wyli changed the title Fix optimizer convergence and regenerate figures Build a comprehensive optimization path tutorial Jul 12, 2026
@wyli wyli changed the title Build a comprehensive optimization path tutorial Fix optimizer bugs and preserve original figures Jul 12, 2026
@wyli
wyli marked this pull request as ready for review July 13, 2026 05:48
@wyli
wyli merged commit baccf9d into master Jul 13, 2026
2 checks passed
@wyli
wyli deleted the agent/fix-optimizers-and-figures branch July 13, 2026 05:56
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.

1 participant