Skip to content

Phase 3: Natural-gradient EM backend (opt-in) - #20

Merged
neuromechanist merged 3 commits into
feature/issue-9-epic-torch-parityfrom
feature/issue-12-phase3-ng-rewrite
Jul 2, 2026
Merged

neuromechanist merged 3 commits into
feature/issue-9-epic-torch-parityfrom
feature/issue-12-phase3-ng-rewrite

Conversation

@neuromechanist

Copy link
Copy Markdown
Member

Closes #12. Part of epic #9.

Summary

New AMICATorchNG backend: a vectorized, closed-form natural-gradient EM port of the NumPy/Fortran algorithm (no Adam, no autograd). Exposed opt-in via AMICA(backend="ng"); the default stays AMICATorch (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.

@neuromechanist
neuromechanist merged commit 607ea25 into feature/issue-9-epic-torch-parity Jul 2, 2026
@neuromechanist
neuromechanist deleted the feature/issue-12-phase3-ng-rewrite branch July 2, 2026 22:41
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