Repository navigation
Fix loadmodout byte order for W/sbeta/rho (#159) - #163
Conversation
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #163 +/- ##
==========================================
+ Coverage 82.68% 82.95% +0.27%
==========================================
Files 19 19
Lines 2420 2435 +15
Branches 408 412 +4
==========================================
+ Hits 2001 2020 +19
+ Misses 306 299 -7
- Partials 113 116 +3
🚀 New features to boost your workflow:
|
PR review (4 Sonnet reviewers: code, tests, comments, silent-failure)All findings addressed. Highlights: Critical (found independently by the comment and code reviewers, empirically confirmed): Test quality (test-analyzer, empirically verified against reconstructed
Silent-failure:
Out of scope, filed separately: #164 (pre-existing MATLAB gate unchanged (writer bytes unchanged): W/A/sbeta/rho agree with |
Summary
loadmodoutread the Fortran/EEGLAB interop filesW,sbetaandrhoin C order while the writer, genuine Fortran output, and EEGLAB'sloadmodout15.mall use column-major (F order). The result:AmicaOutput.Wcame back transposed, silently corrupting genuine Fortran output and everything derived from it (A = pinv(W@S),svar,origord), andsbeta/rhowere scrambled whenevernum_mix > 1(the default). A write-then-read round trip cancels the error, so no self-consistency test could catch it, which is why prior gates (#92, #155) missed it.Closes #159.
What changed
loadmodout):W,sbeta,rhonow readorder="F", matching the writer, genuine Fortran, andloadmodout15.m. This also corrects the derivedA/svar/origord.write_amicaout): the 3DWis written model-axis-slowest (transpose(2, 0, 1)) so multi-model output is genuine Fortran and EEGLAB-readable. Single-model output is byte-identical to before (verified), preserving Drop-in EEGLAB AMICA replacement: equivalent output, no extra interpretation #92.load_results: reads the same genuine-Fortran bytes and transposes back to the internal-backend convention it returns for the NumPy viz helpers (identical output for single-model; fixes latent multi-model breakage).AmicaOutput.sources(X, model=0): new supported accessor (loaded-fit counterpart of the live model'stransform), so downstream source derivation no longer hand-rolls the sphere/unmixing composition, the error class that spawned this issue.compare_with_fortran(uncalled diagnostic): transposes one side so it stays apples-to-apples.Why it is correct (two external oracles)
loadmodoutreads gives -3.4018468 (5 sig figs); the shipped C-order read gave -3.5167 (off by 0.11). LL is not transpose-symmetric, so unlikeA@W==Iit discriminates orientation.loadmodout15.mvs PythonloadmodoutforW/A/sbeta/rho, on the genuine single-model fixture and a pyAMICA 2-model output, agree to <=1.3e-13 (.context/issue-159/matlab_interop_verification.md). This is the only test that pins direction 2 of the interop contract.Test plan
test_loadmodout_reproduces_fortran_reported_ll(LL oracle, real fixture)test_loadmodout_sources_reproduce_live_transform_multimodel(2-model round trip:sourcesmatches livetransformat |corr| > 0.999 per model; was 0/32 before)test_amicaoutput_sources_contract_and_c_subtractiontest_load_results_returns_internal_w_multimodeltest_sample_data_cli(strict xfail, 2000-iter) still xfails (the W flip did not turn it into an XPASS).mkdocs build --strictclean.Follow-up
plot_topo_pdf(deferred out of #136) is now unblocked and can build onAmicaOutput.sources.