Repository navigation
Add Amari distance metric and Fortran/Apple-CPU perf rows - #120
Conversation
Closes #116. amari_distance() in validate_implementations.py is a permutation- and scale-invariant unmixing-matrix comparison metric (Amari, Cichocki & Yang 1996), complementary to the existing Hungarian-matched correlation since it needs no assignment step. Recomputed from the already-saved #27 ensemble matrices (no re-fitting): single-model ~0.008, multi-model within-Fortran/within-pyAMICA/between 0.174/0.155/0.161, run-level permutation p=0.998, consistent with the correlation-based equivalence finding. Table 2 (paper.md) and the docs performance tables gained native Fortran rows (Intel 24-core workstation, Apple Silicon 8-core) and the full core-scaling comparison from the #86 sweep, alongside the existing GPU/torch numbers. Both paper.md and docs/guides/validation.md are reflowed to semantic line breaks (content unchanged, verified via whitespace-collapsed diff).
Review on PR #120 found amari_distance(Wa, Wb) was not symmetric under argument swap, and the three call sites in .context/issue-27/amari_distance.py used inconsistent argument orders, so the JSON summary and per-run CSV didn't reconcile (between mean differed by ~0.004 depending on which table you read). amari_distance now averages both directions, making it a proper (symmetric) distance and fixing the reconciliation for free. Also added an explicit guard for degenerate all-zero rows/columns and n<2 matrices, which previously produced a silent NaN. Recomputed the ensemble numbers with the fixed function: within- Fortran 0.174, within-pyAMICA 0.154, between 0.163 (was 0.161), permutation p>0.999 (was 0.998); single-model 0.006 (was 0.008). Updated paper.md and docs accordingly, and added a caveat that the model-pairing correction in model_amari contributes some of the within/between spread. New tests: symmetry, degenerate-input rejection, and coverage for the previously-untested model_amari pairing selection and perm_test_not_worse sign-flip logic (both verified correct on synthetic data).
Review findings and fixesRan code-review + test-coverage-analysis on this PR. Summary: Critical (fixed): Important (fixed): Important (documented): Test coverage (fixed): added Not changed (false positive / out of scope): duplication between All tests pass ( |
Review on PR #120 flagged that the single-model "Amari distance ~0.008" (now ~0.006) claim in paper.md/docs had no backing computation anywhere in the repo, unlike every other number in this PR, which traces to a committed, regenerable artifact. test_end_to_end_correlation_vs_fortran already runs the real Fortran-vs-NG comparison this figure needs; added an amari_distance assertion there (< 0.05, actual ~0.006) alongside the existing correlation assertion. Also added an explicit None-check on the Fortran run result, surfaced by ty once run_fortran_amica's return type was correctly Optional[Dict] (issue #117).
Follow-up: single-model Amari distance now has a real testA second review pass caught that the single-model "Amari distance ~0.008" Fixed: added an `amari_distance` assertion (`< 0.05`, actual ~0.006) to the Verified: `uv run pytest pyAMICA/tests/torch_tests/test_ng_backend.py::test_end_to_end_correlation_vs_fortran -m slow` passes locally (macOS, real Fortran binary). |
Skipped (intentional, not a false positive)Both reviewers flagged that `.context/issue-27/amari_distance.py`'s local |
Table 1 had grown a near-duplicate row per metric (correlation and Amari distance each got their own "single run"/"ensemble equivalence" row), and the surrounding prose restated every number that was already in the table. Condensed to one row per regime carrying both metrics side by side, and cut the prose down to the qualitative narrative (what was tested, why, what it means), leaving the table as the single source for the actual figures.
Closes #116.
Amari distance
amari_distance()invalidate_implementations.pyis a permutation- andscale-invariant unmixing-matrix comparison metric (Amari, Cichocki & Yang,
1996), used alongside (not instead of) the existing Hungarian-matched
correlation as a second, assignment-free conformity check. Recomputed from
the already-saved
.context/issue-27/ensemble.npzmatrices (real EEG fitsfrom the #27 study, no re-fitting needed):
(sd ~0.02), run-level permutation p=0.998 -- agrees with the
correlation-based "between not worse than within-Fortran" conclusion.
Per-run detail (each of the 40 runs' own within/between mean for both
metrics) is a new table in
docs/guides/validation.md, plus.context/issue-27/per_run_detail.csv(regenerable via.context/issue-27/amari_distance.py).Table 2 / performance tables
Table 2 (paper.md) had no Fortran row. Added native Fortran rows (Intel
24-core workstation, Apple Silicon 8-core) from the existing #86 CPU
core-scaling sweep, plus the full core-scaling comparison table (both
platforms, matching Fortran against torch-CPU/NumPy at the same core counts)
in the docs.
Formatting
Both
paper.mdanddocs/guides/validation.mdare reflowed to semantic linebreaks per the documented convention. Content is unchanged -- verified via
whitespace-collapsed diff before and after, plus a pandoc PDF build and an
mkdocs build --strictfor the docs page.Test plan
uv run pytest pyAMICA/tests/test_amari_distance.py(new: self-distancezero, permutation/scale invariance, nonzero for unrelated matrices) passes
uv run ruff check/ruff format --checkpassuv run ty checkpasses on all touched Python filespandoc --citeproc paper.mdbuilds a PDF with all citations resolvingmkdocs build --strictbuilds the docs site with no warnings