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/pyAMICA.git
cd pyAMICA
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.2.1.tar.gz (117.2 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.2.1-py3-none-any.whl (125.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pamica-0.2.1.tar.gz
Algorithm Hash digest
SHA256 f28b01d42ed5fd019b740420a40b193f633b9950194c9d40643dc2bf4633c913
MD5 026ad7b7bf0682703cb21c3a932c04dd
BLAKE2b-256 6279e4ae8b1751bbda145287fe3a641c745331d6d52013b471c1152cc27c0f7e

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pamica-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 125.2 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.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a68c01080423a6650bb89f7c6edde913fa56f94a690f5943564f216c7f6224b8
MD5 bb58e09752f225925c0553a100d91186
BLAKE2b-256 b8d7dc311ddebf7cd79c34983c8f42e626663ab1535bcb2384b44613fba39dca

See more details on using hashes here.

Provenance

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