Skip to content

MLX backend: support explicit pcakeep/pcadb #323

Description

@neuromechanist

Summary

The MLX backend (pamica.mlx_impl.AMICAMLXNG) has no explicit pcakeep / pcadb constructor parameters, while the torch backend (AMICATorchNG, torch_impl/core.py:619) supports them with Fortran semantics (numeigs = min(pcakeep, count(eigs > mineig))). On MLX, dimensionality reduction happens only through automatic numerical-rank detection (mineig / mineig_rel), as documented in mlx_impl/core.py around lines 2425-2433 and 3244-3246.

Use case

Standard EEGLAB preprocessing produces data whose rank is known exactly but is not always cleanly separable by an eigenvalue threshold: average reference (rank n-1), removed and later interpolated channels, and ASR-corrected segments. EEGLAB pipelines pass that rank explicitly (for example pcakeep = nbchan - 1 after average reference, as in the HBN pipeline), and the rank chosen should be identical across backends so MLX fits are comparable to torch and Fortran fits of the same data. We plan to run per-session AMICA on 64-channel BioSemi EEG (Alljoined1, 13 sessions) on Apple Silicon, where MLX is the fastest backend.

Request

  • Add pcakeep and pcadb to AMICAMLXNG with the same semantics and validation as AMICATorchNG, including the upfront _pca_reduction_requested() gate.
  • Cross-backend test: same data, same pcakeep, torch vs MLX sphere shape and component match within the existing tolerance.
  • Expose it through the AMICA wrapper once backend selection (Backend selection in the AMICA and AMICAICA wrappers #313) lands.

Related: #304 (params-file surface for the NumPy and MLX backends), #322 (restoring the PCA residual with pcakeep).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions