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
[ICA] runamica writes AMICA input in channel-major order instead of MATLAB column-major #435
data has shape (chans, frames) (see runamica: chans, frames = data.shape), and ndarray.tofile always writes in C order, so the file holds all of channel 1, then all of channel 2, and so on. MATLAB's runamica15 writes the same matrix with fwrite(fid, dat, 'float'), which is column-major. That file holds every channel for frame 1, then every channel for frame 2, which is the data_dim x field_dim layout the AMICA binary reads. The readers in the same file (W, S, comp_list, ...) already use reshape(..., order='F'), so the writer is the odd one out. The docstring even claims it "matches MATLAB's fwrite(fid, dat, 'float') behavior".
If this holds, AMICA trains on scrambled samples, and every runamica/eeg_amica decomposition is wrong. The remaining tests wouldn't notice: test_eeg_amica.py::TestEegAmicaReconstruction and test_runamica.py::TestRunamicaIntegration::test_runamica_ll_decreasing only check self-consistency and that the log-likelihood improves. An earlier round-trip test only pinned the current layout and was removed in #429.
Not yet confirmed against the MATLAB runamica15.m source, which isn't in the bundled EEGLAB copy. Do that first.
Suggested fix, test first:
Failing test: write a small known (chans, frames) array with _write_data_file, then read it back with np.fromfile(path, '<f4').reshape(chans, frames, order='F') and assert equality with the input.
Confirmed against SCCN AMICA revision 2b364cd4a995c057a06409de55f0b8ada8a0f1d8: MATLAB writes columns of the channels-by-frames matrix, and the Fortran reader reads one record of data_dim floats into each frame. NumPy tofile writes C order regardless of the array's memory layout, so EEGPrep sends scrambled channel/frame values; reconstruction and improving likelihood do not establish that the intended data were fitted. No overlapping open PR or separate open issue was found.
eeg_amica → runamica → _write_data_file → AMICA get_data preserves the channels-by-frames shape until serialization changes the ordering. Write the float32 little-endian transpose with tofile so each frame's channels are consecutive; first demonstrate failures with explicit file bytes/Fortran-order readback and the actual binary's recovered channel means, then verify the fix against MATLAB and update the user documentation.
🤖 Fixed in draft PR #436 (3dee66d): frame-contiguous float32 serialization, three file-layout regressions, actual-binary channel-mean validation, and a documentation note to recompute affected decompositions. All 10 local AMICA tests pass; MATLAB comparison evidence shows byte-identical input, identical means/sphere/likelihood, and weights within 2.14e-14.
CI tests passed on Linux Python 3.12/3.13, macOS Python 3.12, and Windows Python 3.12; pre-commit, Ruff/ty, and documentation checks passed. The Claude review job failed immediately after initialization with is_error:true and zero model usage, producing no review findings; this recurrence is recorded in existing Beads issue eegprep-aug. PR remains a draft for review.
Activity
suraj-ranganath commentedon Oct 7, 2026
🤖
Research
Confirmed against SCCN AMICA revision 2b364cd4a995c057a06409de55f0b8ada8a0f1d8: MATLAB writes columns of the channels-by-frames matrix, and the Fortran reader reads one record of data_dim floats into each frame. NumPy tofile writes C order regardless of the array's memory layout, so EEGPrep sends scrambled channel/frame values; reconstruction and improving likelihood do not establish that the intended data were fitted. No overlapping open PR or separate open issue was found.
Relevant code
Proposed Fix
eeg_amica → runamica → _write_data_file → AMICA get_datapreserves the channels-by-frames shape until serialization changes the ordering. Write the float32 little-endian transpose with tofile so each frame's channels are consecutive; first demonstrate failures with explicit file bytes/Fortran-order readback and the actual binary's recovered channel means, then verify the fix against MATLAB and update the user documentation.suraj-ranganath commentedon Oct 7, 2026
🤖 Fixed in draft PR #436 (3dee66d): frame-contiguous float32 serialization, three file-layout regressions, actual-binary channel-mean validation, and a documentation note to recompute affected decompositions. All 10 local AMICA tests pass; MATLAB comparison evidence shows byte-identical input, identical means/sphere/likelihood, and weights within 2.14e-14.
CI tests passed on Linux Python 3.12/3.13, macOS Python 3.12, and Windows Python 3.12; pre-commit, Ruff/ty, and documentation checks passed. The Claude review job failed immediately after initialization with is_error:true and zero model usage, producing no review findings; this recurrence is recorded in existing Beads issue eegprep-aug. PR remains a draft for review.