Skip to main content

PyTorch AMICA: Adaptive Mixture Independent Component Analysis

Project description

pyamica

PyPI versions PyPI version Tests

PyTorch implementation of AMICA (Adaptive Mixture Independent Component Analysis).

AMICA fits a mixture of ICA models to multi-channel time-series data. Each model has its own unmixing matrix and source densities; a per-sample posterior indicates which model most likely generated each data point. This makes it well-suited for EEG recordings where different experimental conditions have different source statistics.

Install

pip install pyamica            # core (no MNE)
pip install "pyamica[mne]"     # with MNE-Python integration

With uv:

uv add pyamica
uv add "pyamica[mne]"

Quick start

import torch
from pyamica import AMICA, AmicaICA

# Low-level PyTorch API - X shape: (T, n_channels), float64
model = AMICA(n_models=2, max_iter=200, device="cuda")
model.fit(X)
print(model.gm_)           # global model weights
print(model.posteriors_)   # (n_models, T) per-sample posteriors

# MNE-Python wrapper
ica = AmicaICA(n_models=2, max_iter=200, device="cuda")
ica.fit(raw, picks="eeg")
ica.plot_model_dominance(smooth_s=1.0)
for m in range(ica.n_models):
    ica.review(raw, model_idx=m, eog_ch=["HEOG", "VEOG"], ecg_ch="ECG")
ica.apply(raw)

Background

pyamica started as a weekend project: a translation of the original Fortran AMICA implementation (sccn/amica) into PyTorch, with an MNE-Python wrapper to make it usable in modern EEG pipelines. It was also used as a practical test of LLM-assisted code translation. The translation was supported by Claude Sonnet 4.6 with a lot of back-and-forth, and turned out good enough (I think) to publish.

All credit for the algorithm, theory, and original implementation goes to Jason A. Palmer and the SCCN team. The canonical reference is:

Palmer, J. A., Kreutz-Delgado, K., & Makeig, S. (2012). AMICA: An Adaptive Mixture of Independent Component Analyzers with Shared Components. Technical Report, UC San Diego. [PDF]

The AMICA introduction on their wiki covers what it does, why it works, and how to interpret multi-model fits.

Development install

git clone https://github.com/DerAndereJohannes/pyamica
cd pyamica/python-package
pip install -e ".[mne,dev]"

With uv:

git clone https://github.com/DerAndereJohannes/pyamica
cd pyamica/python-package
uv sync --extra mne --extra dev

Tests

# fast tests (synthetic data only)
pytest tests/ -v -m "not slow and not gpu"

# with coverage
pytest tests/ -v -m "not slow and not gpu" --cov=pyamica

# Fortran comparison (requires data/ directory)
pytest tests/ -v -m slow

With uv:

uv run pytest tests/ -v -m "not slow and not gpu"

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

pyamica-0.1.0.tar.gz (47.5 kB view details)

Uploaded Source

Built Distribution

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

pyamica-0.1.0-py3-none-any.whl (28.2 kB view details)

Uploaded Python 3

File details

Details for the file pyamica-0.1.0.tar.gz.

File metadata

  • Download URL: pyamica-0.1.0.tar.gz
  • Upload date:
  • Size: 47.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pyamica-0.1.0.tar.gz
Algorithm Hash digest
SHA256 dd16d7efc68a9fa4ddb45849923283b6eaa914ab5c92f063aa7d28455bbdda43
MD5 65ef6e938cd50aeb3c12199952197703
BLAKE2b-256 f32f6be0dbff5a8f74f0ade44c075eccf8df5c39ff87a1923280c9259dd066d9

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyamica-0.1.0.tar.gz:

Publisher: release.yml on DerAndereJohannes/pyamica

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

File details

Details for the file pyamica-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pyamica-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 28.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pyamica-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a0f48f0541549d4ca26cf34783b4b83e2f4834a57647cb01892999e270e83de7
MD5 ef04f8ca219061d8c182dc86113dea69
BLAKE2b-256 cdb7c9ca4b809d69c4cbe07d58e8bc610baec7110317fa287df0fbd009d0d720

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyamica-0.1.0-py3-none-any.whl:

Publisher: release.yml on DerAndereJohannes/pyamica

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