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 is a pure Python reimplementation of AMICA built on PyTorch, with an MNE-Python wrapper to make it usable in modern EEG pipelines. It runs on CPU and GPU alike and slots in wherever mne.preprocessing.ICA would be used.

It started as a weekend project and a practical test of LLM-assisted code translation from the original Fortran implementation (sccn/amica). 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/
pip install -e ".[mne,dev]"

With uv:

git clone https://github.com/DerAndereJohannes/pyamica
cd pyamica/
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"

Acknowledgements

This repository includes the pre-compiled amica15ub binary and default parameter file from the AMICA project by Jason Palmer and contributors, used here for development and testing only. They are not distributed as part of the installable package. That binary is licensed under the BSD 2-Clause License; see LICENSES/sccn-amica.txt for the full license text.

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.3.0.tar.gz (65.8 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.3.0-py3-none-any.whl (33.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pyamica-0.3.0.tar.gz
Algorithm Hash digest
SHA256 508947247a8963a048f8506f72a3cc54c1f28269fab286f917b9dab597b4e022
MD5 c272d4ce5c2c3f6e1490c062ac4691f0
BLAKE2b-256 0bcff18b03179256131e02723701da53e1a9ce5907426d0c39392922be5a1f17

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyamica-0.3.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.3.0-py3-none-any.whl.

File metadata

  • Download URL: pyamica-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 33.8 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.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fb96ba9c5975fefafaba337a99f8f9780397f0020e71d96bca05e5667799c91c
MD5 3954774daefb4fd01298cd8332bffc66
BLAKE2b-256 d475340505fa807be8d9394287530de1074c80bdbce890d5c692564e11aa3e3a

See more details on using hashes here.

Provenance

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