Repository navigation
Ratchet the learning rate on LL decrease (#41) - #43
Merged
neuromechanist merged 2 commits intoJul 5, 2026
Conversation
The NumPy long fit degraded past ~150 iters (LL decreasing, component match dropping) because the convergence handling diverged from Fortran: - numdecs/numincs were incremented inside _check_convergence but never returned, so the caller's counters never accumulated -- the decrease handling effectively reset every iteration. - On numdecs >= max_decs pyAMICA STOPPED, whereas Fortran (amica17.f90:1062-1108) lowers the learning-rate CEILING (lrate0, plus newtrate/rholrate0 under Newton), resets numdecs, and CONTINUES. Without the ceiling ratchet, lrate kept ramping back up and the fit oscillated/drifted. Rewrote _check_convergence to match Fortran: thread numdecs/numincs back to the loop, ratchet lrate0/newtrate/rholrate0 down at max_decs and continue (only a lrate/gradient floor stops on a decrease), stop after maxincs small increases (new maxincs param, Fortran default 5), and reset numdecs when Newton starts. Effect (seed=0): the LL now improves over the long run (-3.399 at 2000 iters vs the pre-fix -3.409 and the ~150-iter -3.404), no longer degrades. The 150-iter NumPy-vs-Fortran mean-corr parity test still passes. Note: the strict all-32-components CLI gate stays xfail on a residual solution-basin difference (pyAMICA reaches a comparable/better-LL but different-partition solution on a few ill-determined components); the LL-degradation drift itself is fixed.
- Compute the weight-gradient norm every iteration (was gated on use_grad_norm), matching Fortran's always-computed ndtmpsum. The decrease-stop gradient floor now applies regardless of use_grad_norm (Fortran's `ndtmpsum <= min_nd` is unconditional; the flag only gates the separate final gradient-norm stop), closing a parity gap for use_grad_norm=False. - Add test_check_convergence_ratchets_lrate_on_decrease: drives the convergence handler directly and asserts the lrate0/newtrate ceilings ratchet down and numdecs resets after max_decs decreases (not a stop). Tested: non-slow suite 37 passed, 1 xfailed.
Member
Author
Review (code-reviewer, Sonnet) + resolutionsThe reviewer confirmed the ratchet logic matches Fortran ( Addressed in the follow-up commit:
Non-slow suite: 37 passed, 1 xfailed (the CLI integration test, on the residual partition-basin difference documented in its xfail reason). |
neuromechanist
deleted the
41-amica_numpy-long-fit-driftsdegrades-past-150-iters-ll-decreases-component-match-drops
branch
July 5, 2026 03:57
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.
Summary
The NumPy long fit degraded past ~150 iters (LL decreasing, component match dropping) because pyAMICA's convergence handling diverged from Fortran in two ways:
numdecs/numincsnever accumulated._check_convergenceincremented them locally but never returned them, so the caller's counters stayed at their initial values — the decrease handling effectively reset every iteration.numdecs >= max_decspyAMICA stopped, whereas Fortran (amica17.f90:1062-1108) lowers the learning-rate ceiling (lrate0, plusnewtrate/rholrate0under Newton), resetsnumdecs, and continues. Without the ceiling ratchet,lratekept ramping back up (it's raised each iter in_update_parameters) and the fit oscillated/drifted.Changes
_check_convergenceto match Fortran: threadnumdecs/numincsback into the loop, ratchetlrate0/newtrate/rholrate0down atmax_decsand continue (only a lrate/gradient floor terminates on a decrease), stop aftermaxincsconsecutive small increases (newmaxincsparam, Fortran default 5), and resetnumdecswhen Newton starts.Effect
test_sample_data_numpy_vs_fortran(mean-corr > 0.9) still passes — no parity regression.Honest status on
test_sample_data_cliStill xfail. The #41 LL-degradation drift is fixed, but the test's strict all-32-components > 0.8 gate still fails (~27/32): at full convergence pyAMICA reaches a comparable/slightly-better-LL but different-partition solution than the Fortran reference on a few ill-determined components — a solution-basin difference (the single-model tail of #27's partition theme), not the drift. The project's other parity test uses the more appropriate
mean > 0.9bar and passes. The xfail reason documents this.Related