Skip to main content

pAMICA: Python implementation of the Adaptive Mixture ICA algorithm

Project description

pAMICA: Adaptive Mixture ICA

CI codecov DOI Docs

Python (PyTorch) implementation of Adaptive Mixture Independent Component Analysis (AMICA) that reproduces the reference Fortran implementation within numerical tolerance, with CPU, NVIDIA GPU (CUDA), and Apple GPU (MLX) support. It targets EEG/EMG blind source separation and is a drop-in replacement for EEGLAB's AMICA: single-model output is byte-identical to the Fortran reference and loads directly in EEGLAB.

Single-model results match the Fortran reference (Hungarian-matched component correlation ~ 0.998 on well-determined data, Newton disabled); see the documentation for validation details and the backend-selection guide.

Overview

AMICA (Adaptive Mixture ICA) is an advanced blind source separation algorithm that uses adaptive mixtures of independent component analyzers. This implementation provides:

  • Multiple source models
  • Different PDF types
  • Newton optimization
  • Component sharing
  • Outlier rejection
  • Data preprocessing (mean removal, sphering)

Installation

The canonical environment is uv:

git clone https://github.com/sccn/pAMICA.git
cd pAMICA
uv sync                     # install dependencies into a managed venv
uv run pytest               # optional: run the tests

The optional Apple-GPU backend (MLX, Apple Silicon only) installs with the mlx extra: uv pip install mlx.

Usage

pamica exposes a scikit-learn-style estimator backed by the PyTorch natural-gradient EM implementation:

import numpy as np
from pamica import AMICA

# X is (n_channels, n_samples) of real EEG/EMG; float64 gives Fortran parity
model = AMICA(n_models=1, n_mix=3).fit(X)

sources = model.transform(X)       # (n_sources, n_samples)
A = model.get_mixing_matrix()      # sensor-space scalp maps
order = model.variance_order()     # EEGLAB IC order (IC1 = highest variance)

Backends and precision

The wrapper auto-selects a device and computes in float64 for Fortran parity.

  • CPU and CUDA (float64) are bit-reproducible; use them for parity runs.
  • float32 (about 7 significant digits, not parity) is required on the Apple GPUs and modestly faster on CPU; it is not a general speedup, since CUDA is overhead-bound (float32 is about as fast as float64).
  • On Apple Silicon the MLX backend is the fastest option; import it explicitly.
AMICA(device="cuda").fit(X)               # NVIDIA GPU, float64
from pamica.mlx_impl import AMICAMLXNG    # Apple GPU (install the mlx extra)

EEGLAB interoperability

pamica writes results in EEGLAB's AMICA output format, so a run drops into an EEGLAB workflow with no manual re-ordering or sign-flipping:

model.write_amica_output("amicaout")   # gm, W, S, mean, c, alpha, mu, sbeta, rho, ...
mod = loadmodout15('amicaout');   % components in EEGLAB variance order

Legacy NumPy CLI

The NumPy reference backend keeps a JSON-driven command-line interface:

python -m pamica.numpy_impl.cli params.json --outdir results

See the documentation for the full API, the parameter reference, and the backend-selection and validation guides.

Citation

If you use pamica, please cite it (see CITATION.cff) and the original AMICA method:

Palmer, J. A., Kreutz-Delgado, K., & Makeig, S. (2012). AMICA: An adaptive mixture of independent component analyzers with shared components. Technical report, Swartz Center for Computational Neuroscience, UC San Diego.

License

This project is licensed under the BSD 3-Clause License - see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pamica-0.3.0.tar.gz (128.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pamica-0.3.0-py3-none-any.whl (136.5 kB view details)

Uploaded Python 3

File details

Details for the file pamica-0.3.0.tar.gz.

File metadata

  • Download URL: pamica-0.3.0.tar.gz
  • Upload date:
  • Size: 128.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pamica-0.3.0.tar.gz
Algorithm Hash digest
SHA256 d16e5108d87be105058e78b15e32d7983e790ee18a3c719ff27f2004b2f5aeb1
MD5 dfcef0c9c6c944476f69e596f3e28893
BLAKE2b-256 c546dc33d9f405c76dfefcde74807b411400ee9eecd5840e48f8e90a6c9f6de3

See more details on using hashes here.

Provenance

The following attestation bundles were made for pamica-0.3.0.tar.gz:

Publisher: publish.yml on sccn/pAMICA

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pamica-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: pamica-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 136.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pamica-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e38382498327484d2a75db8a8f82e1e2d034e42a21978a2b1cbaaa335402c72b
MD5 e280d05f38d8f8462bfd2a5f420c011b
BLAKE2b-256 ac22e12a161a18e25151cba6e96c36703b73c5227a30248d30b2d2bdf666a7e3

See more details on using hashes here.

Provenance

The following attestation bundles were made for pamica-0.3.0-py3-none-any.whl:

Publisher: publish.yml on sccn/pAMICA

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page