Skip to content

AyushGarg76/Spatiotemporal-EEG-Graph-Decoding

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

EEG Autoresearch

Autonomous AI-driven hyperparameter and architecture search for imagined speech classification from multichannel EEG.

Paper: "Spatiotemporal Brain Network Decomposition with Deep Graph Fusion for Decoding Covert Speech from Multichannel EEG"


Quick Start

Step 1 — Install dependencies

pip install -r requirements.txt

Step 2 — Run prepare.py ONCE (data prep)

# Point --data_dir at your "Experimental Cleaned" folder
python prepare.py --data_dir "D:/Dev/Coding/Research_paper/Dataset/Imagined Speech Datasets Applying Traditional and Gamified Acquisition Paradigms/Experimental Cleaned"

This takes ~5–10 minutes. It will:

  • Load all 15 subjects
  • Epoch imagined speech trials (0–2s)
  • Apply 4-band filtering (theta/alpha/beta/gamma)
  • Build electrode graph adjacency
  • Apply sliding window augmentation (250 samples, 50% overlap)
  • Normalize per subject
  • Save everything to ./data/processed/
  • Generate 3 visualization plots

Step 3 — Run a single experiment manually (sanity check)

python train.py

You should see training logs and a final val_accuracy. If this works, your setup is good.

Step 4 — Run autonomous research with Claude Code

# Install Claude Code if you haven't
npm install -g @anthropic-ai/claude-code

# Open this directory in Claude Code
cd eeg-autoresearch
claude

Then paste this opening prompt:

Hi! Please read program.md carefully. Then:
1. Read prepare.py to understand the data format
2. Read train.py to understand the current baseline model
3. Check that ./data/processed/ contains X_train.npy (if not, tell me)
4. Create a branch autoresearch/apr23
5. Initialize results.tsv with header only
6. Run the baseline: python train.py > run.log 2>&1
7. Log the result in results.tsv
8. Then begin the autonomous experiment loop

Your goal is to improve val_accuracy from ~0.50 toward 0.60+
by modifying only train.py. Focus first on GCN depth and fusion strategy.

Overnight run prompt (paste this before you sleep)

Continue the autoresearch loop indefinitely.
Run at least 20 more experiments.
Priority order for hypotheses:
1. Increase GCN hidden dim (64→128→256)
2. Try 3 GCN layers instead of 2
3. Experiment with learning rate (try 5e-4, 2e-3)
4. Try focal loss instead of cross entropy
5. Add residual connections in BandEncoder
6. Try OneCycleLR scheduler
Log everything. NEVER STOP until I interrupt you.

File Structure

eeg-autoresearch/
├── prepare.py          ← Run once. Fixed. DO NOT MODIFY.
├── train.py            ← Agent modifies this.
├── program.md          ← Agent reads this for instructions.
├── requirements.txt
├── results.tsv         ← Auto-generated by agent (not committed to git)
├── run.log             ← Latest experiment log
└── data/
    └── processed/
        ├── X_train.npy          (n_windows, 4, 22, 250)
        ├── y_train.npy          (n_windows,)
        ├── X_val.npy
        ├── y_val.npy
        ├── X_test.npy
        ├── y_test.npy
        ├── adjacency.npy        (22, 22)
        ├── meta.json
        ├── signal_comparison.png
        ├── adjacency_matrix.png
        └── class_distribution.png

What the Agent Can Change in train.py

All hyperparameters are at the top of train.py, clearly labeled:

# Architecture
TEMPORAL_CHANNELS = 32     # filters per band
TEMPORAL_KERNEL   = 25     # temporal conv kernel
GCN_HIDDEN        = 64     # GCN hidden dim
GCN_LAYERS        = 2      # GCN depth
FUSION_TYPE       = "attention"  # how bands are fused

# Optimization
BATCH_SIZE     = 64
LR             = 1e-3
WEIGHT_DECAY   = 1e-4

# Augmentation
AUGMENT        = True
GAUSSIAN_NOISE = 0.05
TIME_SHIFT_MAX = 25

The agent can also modify the model classes themselves.


Expected Accuracy Progression

What Expected val_accuracy
EEGNet, single subject ~0.48 (your notebook)
Baseline GCN (train.py) ~0.52–0.55
After 20 experiments ~0.58–0.62
After 100 experiments ~0.62–0.68

Understanding the Notebook vs This Pipeline

Your notebook (final_try.ipynb):

  • Loaded 1 subject only (s1)
  • Filtered 8–40Hz (missing theta 4–8Hz)
  • No graph structure
  • No sliding window augmentation
  • Best val_accuracy: 0.48

This pipeline:

  • All 15 subjects
  • 4-band decomposition (theta + alpha + beta + gamma)
  • Graph convolution over electrode adjacency
  • 7 windows per trial (augmentation via sliding window)
  • Spatiotemporal deep learning
  • Expected: 0.60+

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages