PyTorch AMICA: Adaptive Mixture Independent Component Analysis
Project description
pyamica
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dd16d7efc68a9fa4ddb45849923283b6eaa914ab5c92f063aa7d28455bbdda43
|
|
| MD5 |
65ef6e938cd50aeb3c12199952197703
|
|
| BLAKE2b-256 |
f32f6be0dbff5a8f74f0ade44c075eccf8df5c39ff87a1923280c9259dd066d9
|
Provenance
The following attestation bundles were made for pyamica-0.1.0.tar.gz:
Publisher:
release.yml on DerAndereJohannes/pyamica
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyamica-0.1.0.tar.gz -
Subject digest:
dd16d7efc68a9fa4ddb45849923283b6eaa914ab5c92f063aa7d28455bbdda43 - Sigstore transparency entry: 1070672715
- Sigstore integration time:
-
Permalink:
DerAndereJohannes/pyamica@c0d2183cd29a78c1c693048e5f6e1953dbb90b08 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/DerAndereJohannes
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@c0d2183cd29a78c1c693048e5f6e1953dbb90b08 -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a0f48f0541549d4ca26cf34783b4b83e2f4834a57647cb01892999e270e83de7
|
|
| MD5 |
ef04f8ca219061d8c182dc86113dea69
|
|
| BLAKE2b-256 |
cdb7c9ca4b809d69c4cbe07d58e8bc610baec7110317fa287df0fbd009d0d720
|
Provenance
The following attestation bundles were made for pyamica-0.1.0-py3-none-any.whl:
Publisher:
release.yml on DerAndereJohannes/pyamica
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyamica-0.1.0-py3-none-any.whl -
Subject digest:
a0f48f0541549d4ca26cf34783b4b83e2f4834a57647cb01892999e270e83de7 - Sigstore transparency entry: 1070672764
- Sigstore integration time:
-
Permalink:
DerAndereJohannes/pyamica@c0d2183cd29a78c1c693048e5f6e1953dbb90b08 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/DerAndereJohannes
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@c0d2183cd29a78c1c693048e5f6e1953dbb90b08 -
Trigger Event:
push
-
Statement type: