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.1.tar.gz (129.1 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.1-py3-none-any.whl (137.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pamica-0.3.1.tar.gz
Algorithm Hash digest
SHA256 f26be4212c0623123380812d82d01f2299099b23d696f8debea5a145fc8cffe1
MD5 91a832e0e11833e9085c8886d4ce2723
BLAKE2b-256 d3efb4ea5e4c56fd6fb628b9bf7b1a270e67c1262b2a4235c81cb7bf421a5095

See more details on using hashes here.

Provenance

The following attestation bundles were made for pamica-0.3.1.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.1-py3-none-any.whl.

File metadata

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

File hashes

Hashes for pamica-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 165756a4fc9ae426f9917463391940bbaaa4df211c5dc08ef487e2a6536b92d8
MD5 ca92870e71fed03b9e7b2a48018153bd
BLAKE2b-256 c2c875f434f81797fb34a293698a92c45b099417bfc4bcaf2001128184c80b17

See more details on using hashes here.

Provenance

The following attestation bundles were made for pamica-0.3.1-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