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.2.0.tar.gz (63.2 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.2.0-py3-none-any.whl (33.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pyamica-0.2.0.tar.gz
Algorithm Hash digest
SHA256 1bf01a7f5e897e47879c065736e337420eeb98671ba70c9af8479b04fb30f530
MD5 4aedd7660bf67193a29ad43328b8ca8b
BLAKE2b-256 13b2268df3a4c5f3d6242ae75fabccb48a70cdbfd52b18f1478bccdaade79c48

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pyamica-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 33.1 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 60ff25099f4c3a1e07eadea56bc3e6bcf14d51e0b509ea43834d3cb4bbfa6676
MD5 52f1b92f4f45fc163eb78d47ee359aa0
BLAKE2b-256 6c8558bd243b97a81fd70f54346c5b4a0310f697b2a442498f39c7878b4be304

See more details on using hashes here.

Provenance

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