Python Package: DA4BCI
Published:
Package: DA4BCI (Python) Title: A Unified Framework for Domain Adaptation in EEG-based Brain-Computer Interfaces Version: 0.1.0 Authors: Yiming Shen, David Degras License: MIT
Overview
Python port of the DA4BCI R package, providing a comprehensive suite of domain adaptation methods tailored for EEG-based BCI applications with a unified interface, evaluation metrics, and visualization tools.
Available Methods
| Method | Description |
|---|---|
| TCA | Transfer Component Analysis |
| SA | Subspace Alignment |
| CORAL | Correlation Alignment |
| GFK | Geodesic Flow Kernel |
| MIDA | Maximum Independence Domain Adaptation |
| RD | Riemannian Distance Alignment |
| ART | Aligned Riemannian Transport |
| PT | Parallel Transport |
| OT | Entropy-regularized Optimal Transport (Sinkhorn) |
| M3D | Manifold-based Multi-step Domain Adaptation |
Evaluation Tools
Built-in distribution alignment metrics: MMD, Energy Distance, Wasserstein Distance, and Mahalanobis Distance. Includes evaluate_shift() for before/after comparison and PCA/t-SNE visualization.
Python vs R Performance
Benchmarked on the same data (500 × 50), median of 5 runs:
| Method | R (ms) | Python (ms) | Speedup |
|---|---|---|---|
| MIDA | 3567.9 | 173.1 | 20.6× |
| M3D | 1750.6 | 158.2 | 11.1× |
| TCA | 192.1 | 29.7 | 6.5× |
| CORAL | 1.7 | 0.3 | 6.0× |
Python is faster across all 15 benchmarked operations, with speedups from 1.1× to 20.6×.
Key Benchmark Findings
Full benchmark: 10 DA methods × 10 distribution-shift scenarios = 100 experiments (1500 samples × 50 features each).
- TCA has the most robust Energy reduction across all 10 distributions (73–97%).
- ART and PT achieve perfect Mahalanobis alignment (100%) on most distributions.
- CORAL and PT are the fastest (< 1 ms), suitable for real-time BCI applications.
- Cauchy distributions are the hardest scenario — only TCA and MIDA maintain positive Energy reduction.
Installation & Usage
pip install git+https://github.com/Yiming-S/DA4BCI-Python.git
from da4bci import domain_adaptation
source, target = ... # EEG feature matrices
result = domain_adaptation(source, target, method="sa", control={"k": 10})
adapted_source = result["weighted_source_data"]