Commit 9bb21f0
authored
* Add per-model bias c update for multi-model AMICA
Port Fortran's update_c (amica17.f90:1423-1429/1899-1901) into AMICATorchNG
and the NumPy oracle: c[i,h] = sum_t v_h*x / sum_t v_h, the per-model
responsibility-weighted data-space mean. The E-step now centers each model's
data before unmixing (b = W(x - c)); transform() does the same. Replaces the
old gradient-style dc = sum(g) accumulator, which was accumulated but never
applied (c was frozen at 0).
Guarded to a no-op for n_models=1: with v==1 the update collapses to the
(zero) mean of mean-removed data, and skipping it keeps single-model parity
bit-exact (issue #24).
Tests: single-model c stays exactly zero after fit; multi-model c equals the
responsibility-weighted data mean and the two models center differently;
existing NG<->NumPy sufficient-stat parity holds with dc renamed to dc_numer.
Controlled 2-model A/B vs the Fortran binary (same config/seed, c toggled):
cross-corr 0.631 -> 0.642 (+0.011), LL unchanged. The c omission was a minor
contributor; the dominant multi-model gap is intrinsic partition ambiguity
(see .context/issue-27/multimodel_c_update.md). Issue #27.
* Address PR review: guard dead-model c, add tests
Review findings (pr-review-toolkit, Sonnet):
- silent-failure: the new c = dc_numer/dgm division could be 0/0 = NaN for a
dead model (dgm[h]==0). Unlike log(gm[h])=-inf (which softmax tolerates), a
NaN c poisons the next iteration's cross-model softmax for every model. Added
a containment guard in both backends: a zero-responsibility model keeps its
prior c, mirroring the existing mu/beta/rho non-finite guards. This also
resolves the NumPy restart-preserves-NaN-c concern.
- tests: added multi-model coverage the change opened up but the first commit
left unexercised -- NumPy backend c update on real data, NG<->NumPy finalized
c parity, transform() with nonzero c (verified vs W(x-c) by hand), the
dead-model containment guard, multi-model dc_numer blocking invariance, and
do_reject + multi-model c finiteness. Strengthened the Newton multi-model test
to assert finite c and full iteration count.
- comments: fixed two pre-existing docstrings this change made stale
(transform()/get_weights() said "X^T @ W", now "(X-c)^T @ W"); corrected the
Fortran citation for wc = W@c (:2178 get_unmixing_matrices); clarified update_c
is a flag not a routine; AGENTS.md "LL unchanged" -> "LL comparable".
All fast suites green (48 passed). Single-model paths unchanged (guard is
n_models>1). Issue #27.
* Add multi-model distributional-equivalence validation
Records the parity confirmation for multi-model AMICA (issue #27). Because
mixture-of-ICA is not partition-identifiable, exact partition parity with
Fortran is the wrong acceptance bar; the right test is whether the two
implementations sample the same distribution over solutions.
On an N=20-each ensemble (real sample EEG, n_models=2, 100 iters), 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; within-Fortran/within-NG/between all ~0.63-0.64). The single-run
~0.64 cross-corr earlier read as a shortfall is just intrinsic estimator spread:
Fortran agrees with itself at 0.63.
Adds:
- .context/issue-27/multimodel_distributional_equivalence.md (method, results,
acceptance criteria)
- multimodel_ensemble.py (reproduction harness) + the figure (PNG/PDF)
- research.md / AGENTS.md pointers; AGENTS.md #27 now reads VALIDATED
Open residual tracked as #51: NG's LL distribution is ~0.02 lower and more
variable than Fortran's (optimizer quality, not a correctness bug -- one M-step
is bit-exact). Issue #27.
1 parent 39ffcf4 commit 9bb21f0
11 files changed
Lines changed: 784 additions & 34 deletions
File tree
- .context
- issue-27
- pyAMICA
- tests/torch_tests
- torch_impl
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
Lines changed: 102 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
0 commit comments