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
Multi-model NG partition matching vs Fortran (>0.95 cross-corr) #27
The multi-model (n_models>1) M-step in AMICATorchNG is proven bit-exact vs Fortran: one seeded 2-model step matches per-model unmixing to ~1e-15 and gm exactly, the sphere matches to ~1e-13, and NG<->NumPy multi-model sufficient-stat parity holds to 1e-8 (suite test test_multimodel_sufficient_stats_match_numpy_reference).
However, a full 2-model fit reaches a comparable LL (NG -3.355 vs Fortran -3.345) but only ~0.77 Hungarian cross-correlation, because multi-model AMICA has many near-degenerate partitions (unlike single-model's unique solution). NG is self-consistent (cross-corr 1.0 across block sizes), so this is intrinsic partition ambiguity, not a code defect.
Open question (may be unachievable): can NG be made to converge to Fortran's exact partition (>0.95 cross-corr)? Candidate levers:
Exact fit-loop-schedule parity with Fortran (lrate ratchet / numdecs / Newton ramp) for multi-model.
Seeded, sphere-matched runs to reduce transient divergence.
Note: this is speculative; the algorithmic correctness is already validated. Document outcome even if it stays partition-limited.
PR #25 review (code-reviewer) surfaced a concrete, fixable contributor to the multi-model gap that is NOT partition ambiguity: the per-model bias c update is omitted.
Fortran's update_c defaults on: c[i,h] = dc_numer[i,h]/dc_denom[i,h], dc_numer[i,h] = sum_t v_h(t)*data(i,t), dc_denom[i,h] = sum_t v_h(t) (amica17.f90:1423-1429, 1899-1901). It is a per-model, per-channel (data-space) responsibility-weighted mean, subtracted before W.
For n_models=1, v_h ≡ 1, so dc_numer = sum(data) = 0 on mean-removed data -> c stays 0 -> single-model parity exact (unaffected).
For n_models>1, v_h is non-uniform, so Fortran moves c per model; both Python backends freeze c at 0. This diverges the multi-model trajectory.
The currently-retained dc accumulator (g.sum(0)) is the OLD gradient-based bias, NOT Fortran's dc_numer = sum(v*data); a correct fix needs a new data-space accumulator + the pre-W subtraction convention (careful data-vs-source-space).
Scope for this issue: add the c update (new dc_numer/dc_denom accumulators) to both AMICATorchNG and pyAMICA.py, guarded to no-op for n_models=1, and re-measure the 2-model NG-vs-Fortran cross-correlation to see how much of the ~0.77 is c-omission vs genuine partition ambiguity. AGENTS.md updated to stop attributing the gap 'entirely' to partition ambiguity.
Outcome: the multi-model NG backend is validated against Fortran by distributional equivalence — the correct acceptance bar for a non-partition-identifiable estimator (the original >0.95 single-run cross-corr target asked the algorithm to be more identifiable than it mathematically is).
Ported the missing per-model bias c update (Fortran update_c) to both backends, guarded to a bit-exact no-op for n_models=1.
N=20-each ensemble on real sample EEG (n_models=2): the NG-vs-Fortran partition cross-corr distribution is statistically equivalent to Fortran's own run-to-run distribution (Mann-Whitney p=0.97; TOST equivalent within ±0.05). The ~0.64 single-run cross-corr is intrinsic estimator spread — Fortran agrees with itself at 0.63.
Open residual → #51: NG's log-likelihood distribution is ~0.02 lower and more variable than Fortran's (optimizer quality, not a correctness bug; one M-step is bit-exact).
Activity
neuromechanist commentedon Jul 3, 2026
PR #25 review (code-reviewer) surfaced a concrete, fixable contributor to the multi-model gap that is NOT partition ambiguity: the per-model bias
cupdate is omitted.update_cdefaults on:c[i,h] = dc_numer[i,h]/dc_denom[i,h],dc_numer[i,h] = sum_t v_h(t)*data(i,t),dc_denom[i,h] = sum_t v_h(t)(amica17.f90:1423-1429, 1899-1901). It is a per-model, per-channel (data-space) responsibility-weighted mean, subtracted before W.n_models=1,v_h ≡ 1, sodc_numer = sum(data) = 0on mean-removed data -> c stays 0 -> single-model parity exact (unaffected).n_models>1,v_his non-uniform, so Fortran moves c per model; both Python backends freeze c at 0. This diverges the multi-model trajectory.dcaccumulator (g.sum(0)) is the OLD gradient-based bias, NOT Fortran'sdc_numer = sum(v*data); a correct fix needs a new data-space accumulator + the pre-W subtraction convention (careful data-vs-source-space).Scope for this issue: add the
cupdate (newdc_numer/dc_denomaccumulators) to bothAMICATorchNGandpyAMICA.py, guarded to no-op forn_models=1, and re-measure the 2-model NG-vs-Fortran cross-correlation to see how much of the ~0.77 is c-omission vs genuine partition ambiguity. AGENTS.md updated to stop attributing the gap 'entirely' to partition ambiguity.Address PR #25 review: Newton mu, guards, tests
Address PR #40 review: final write, value asserts, CLI test
Compress Known Issues section in AGENTS.md
AGENTS.md: squash-merge policy + refresh Known Issues (#47)
Add per-model bias c update for multi-model AMICA
Address PR review: guard dead-model c, add tests
Add multi-model distributional-equivalence validation
Add per-model bias c update for multi-model AMICA (#27) (#49)
neuromechanist commentedon Jul 6, 2026
Resolved by PR #49 (merged as 9bb21f0).
Outcome: the multi-model NG backend is validated against Fortran by distributional equivalence — the correct acceptance bar for a non-partition-identifiable estimator (the original
>0.95single-run cross-corr target asked the algorithm to be more identifiable than it mathematically is).cupdate (Fortranupdate_c) to both backends, guarded to a bit-exact no-op forn_models=1.n_models=2): the NG-vs-Fortran partition cross-corr distribution is statistically equivalent to Fortran's own run-to-run distribution (Mann-Whitney p=0.97; TOST equivalent within ±0.05). The ~0.64 single-run cross-corr is intrinsic estimator spread — Fortran agrees with itself at 0.63..context/issue-27/multimodel_distributional_equivalence.md.Open residual → #51: NG's log-likelihood distribution is ~0.02 lower and more variable than Fortran's (optimizer quality, not a correctness bug; one M-step is bit-exact).
docs: consolidate dev docs into .context
docs: consolidate dev docs into .context (#58)
feat: component sharing in AMICATorchNG (#60)
feat: component sharing (share_comps) in AMICATorchNG (#68)
Add Amari distance metric and Fortran/Apple-CPU perf rows
Add Amari distance metric and Fortran/Apple-CPU perf rows (#120)