Skip to content

Multi-model NG partition matching vs Fortran (>0.95 cross-corr) #27

Closed

Description

@neuromechanist

Follow-up from #24 (parity PR #25).

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.

Activity

  1. added
    enhancement
    on Jul 3, 2026
  2. neuromechanist commented on Jul 3, 2026

    @neuromechanist
    MemberAuthor

    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.

  3. neuromechanist commented on Jul 6, 2026

    @neuromechanist
    MemberAuthor

    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.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.
    • Method/figure/acceptance criteria: .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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions