You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Epic: PyTorch backend parity with Fortran AMICA (natural-gradient EM rewrite) #9
Bring the PyTorch backend to numerical parity with the Fortran reference (amica15mac), and fix the memory/scaling problems that come from the current Adam+autograd framing.
Root cause
The default torch backend reframes AMICA as "minimize NLL with Adam over reparameterized tensors," but AMICA is a fixed-point EM / natural-gradient method with closed-form sufficient-statistic updates. Adam on the reparameterized surface follows a different trajectory and converges to a different fixed point. The NumPy pyAMICA.py is a faithful port and is the spec.
See design review: .context/decisions/0001-torch-backend-natural-gradient-em.md and the "2026-07-02 design review" section of .context/research.md.
Concrete defects
Swapped mixture factorization (amica_torch.py:176-233): sources summed before per-source mixture reduction.
Per-source alpha collapsed to a scalar mean (amica_torch.py:187).
LL normalized by n_samples instead of n_samples * nw (amica_torch.py:205).
Newton double-steps and NaNs at newt_start.
pinv(A.T).T per forward; float32 default; Python loops in the hot path; no sample blocking.
Phases
Validation harness & test repair (foundation gate)
Isolated correctness fixes (3 math bugs)
Natural-gradient EM rewrite (new module, swap at parity)
Newton + adaptive PDF + outlier rejection
Definition of done
Component correlation vs Fortran > 0.95 on the sample EEG data; per-channel LL matching Fortran within tolerance; validation harness green as the parity gate.
Phase 3 merged (PR #20). Natural-gradient EM backend (AMICATorchNG) landed opt-in via backend="ng"; default unchanged. Sufficient statistics proven to match the NumPy reference to 1e-14; end-to-end correlation 0.69 (up from 0.43). The >0.95 target is carried into Phase 4 (Newton) as a strict xfail. Phases 1-3 complete; Phase 4 (#13) is next.
Activity
neuromechanist commentedon Jul 2, 2026
Phase 3 merged (PR #20). Natural-gradient EM backend (
AMICATorchNG) landed opt-in viabackend="ng"; default unchanged. Sufficient statistics proven to match the NumPy reference to 1e-14; end-to-end correlation 0.69 (up from 0.43). The >0.95 target is carried into Phase 4 (Newton) as a strict xfail. Phases 1-3 complete; Phase 4 (#13) is next.