# 8-channel ConvMAE MI SSL

This package compares ShallowConvNet, matched ConvMAE scratch training, and
ConvMAE self-supervised pretraining for subject-specific left-vs-right motor
imagery classification.

## Fixed input

- Channels: `Fp1 Fp2 Fz C3 C4 Pz O1 O2`
- Events: `41=left`, `61=right`
- Baseline: `-0.5 to 0 s`
- Task: `0 to 2 s`
- Continuous fourth-order Butterworth SOS zero-phase filtering
- 200 Hz output, no ASR, ICA, EA, or causal filtering

## Run

```powershell
python run_convmae.py smoke-test
python run_convmae.py prepare
python run_convmae.py screen --device cuda
python run_convmae.py pretrain --device cuda
python run_convmae.py finetune --device cuda
python run_convmae.py fewshot --device cuda --fewshot-trials-per-class 20
python run_convmae.py report
```

`all` executes the complete sequence. Every pretraining objective has `best.pt`
and `last.pt`; fold CSV files are append-safe and completed folds are skipped.
On the CUDA workstation, `spark_run.sh` runs `screen`, `pretrain`, and
`finetune` without rebuilding the local raw-data cache.

Training augmentation is generated independently for every sample in every
iteration: amplitude `U(0.95,1.05)`, per-channel DC offset
`U(-0.05,0.05) x window SD`, and reflected shift within `+-10` samples.

`fewshot` uses exactly 20 left and 20 right trials from each outer-fold
calibration pool and keeps the complete outer test fold untouched. The primary
analysis trains on all 40 trials with a fixed optimizer-update budget derived
from the locked all-trial validation runs. A sensitivity analysis uses 16+16
for training and 4+4 for inner validation. Both repeat three paired subset and
training seeds for SSL full fine-tuning and ShallowConvNet. Linear probing is
intentionally excluded from this experiment.
