Repository navigation
Phase 3: Natural-gradient EM backend (opt-in) - #20
Merged
neuromechanist merged 3 commits intoJul 2, 2026
Merged
neuromechanist merged 3 commits into
neuromechanist merged 3 commits into
Conversation
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.
Closes #12. Part of epic #9.
Summary
New
AMICATorchNGbackend: a vectorized, closed-form natural-gradient EM port of the NumPy/Fortran algorithm (no Adam, no autograd). Exposed opt-in viaAMICA(backend="ng"); the default staysAMICATorch(no change to existing behavior).Proven correct
Per-block sufficient statistics (dgm/dalpha/dmu/dbeta/drho/dA/dc) match the validated NumPy reference to 1e-14 (machine precision) on an identical real-data block (test_sufficient_stats_match_numpy_reference). Direct W (no pinv), block-wise accumulation (block-size-invariant, verified), float64, NumPy-matched init, log|det W|+sldet in the reported LL (init LL ~ -3.5, Fortran range).
Result
End-to-end mean correlation vs Fortran: 0.69 (up from 0.43 for the Adam backend). This does NOT yet meet the epic's >0.95 target, and can't on natural gradient alone — Fortran reaches its solution via Newton. The >0.95 end-to-end test is included as
xfail(strict)and flips to pass when Phase 4 (Newton, #13) lands.Tests
4 fast tests pass (parity, blocking invariance, LL-at-init, finite-W); 1 slow xfail (end-to-end >0.95, gated on Phase 4). Full fast suite green, no regression to the default backend.