Statistical Learning analysis for EEG - ZITC computation with LLM-assisted configuration
Project description
autocleaneeg-sl
Statistical Learning EEG analysis package - epoch extraction, configuration wizard, and Z-scored Inter-Trial Coherence (ZITC) computation.
Features
- Configuration Wizard - Infer paradigm parameters from event sequences using heuristics or LLM assistance
- Epoch Extraction - Extract word-locked epochs from continuous EEG with jitter detection
- ZITC Computation - Z-scored ITC using surrogate distributions for statistical validity
- Built-in Presets - Ready-to-use configurations for common SL experiments
Installation
pip install autocleaneeg-sl
Quick Start
Full Pipeline
# 1. Infer configuration from event sequence
autocleaneeg-sl wizard --events-file events.txt --soa 300 --output config.yaml
# 2. Extract epochs using the config
autocleaneeg-sl epoch raw_eeg.set --config config.yaml --output epochs.fif
# 3. Compute ZITC
autocleaneeg-sl zitc epochs.fif --config config.yaml --output results.csv
Python API
from autocleaneeg_sl import (
infer_config,
load_events_from_file,
extract_sl_epochs,
compute_zitc,
)
# Step 1: Infer paradigm configuration
events = load_events_from_file("events.txt")
result = infer_config(events, soa_ms=300.0)
print(f"Word onset codes: {result.word_onset_codes}")
print(f"Words: {result.words}")
# Save validated YAML config
with open("config.yaml", "w") as f:
f.write(result.to_yaml())
# Step 2: Extract epochs
epochs = extract_sl_epochs(
"raw_eeg.set",
word_onset_codes=result.word_onset_codes,
syllable_soa_ms=300.0,
)
# Step 3: Compute ZITC
zitc_result = compute_zitc(epochs, freq_range=(0.5, 5.0), n_surrogates=200)
# Get ZITC at target frequencies
word_zitc = zitc_result.get_zitc_at_freq(1.111) # Word rate
syllable_zitc = zitc_result.get_zitc_at_freq(3.333) # Syllable rate
print(f"Word-rate ZITC: {word_zitc:.2f}")
print(f"Syllable-rate ZITC: {syllable_zitc:.2f}")
Configuration Wizard
The wizard analyzes event sequences to identify word structure in Statistical Learning paradigms.
Heuristic Inference
# From event file
autocleaneeg-sl wizard --events-file events.txt --soa 300
# From string
autocleaneeg-sl wizard --events "11 2 4 8 3 5 9 7 6 1 12 10" --soa 300
# Save to file
autocleaneeg-sl wizard --events-file events.txt --soa 300 --output config.yaml
LLM-Assisted Inference
For complex paradigms with non-sequential syllable codes, LLM assistance provides better accuracy:
# Using OpenCode server (start with: opencode serve)
autocleaneeg-sl wizard --events-file events.txt --provider opencode
# Using Anthropic API
export ANTHROPIC_API_KEY=your-key
autocleaneeg-sl wizard --events-file events.txt --provider anthropic
# Using local Ollama
autocleaneeg-sl wizard --events-file events.txt --provider ollama
Python API
from autocleaneeg_sl import infer_config, run_wizard, load_events_from_file
events = load_events_from_file("events.txt")
# Heuristic only
result = infer_config(events, soa_ms=300.0)
# LLM-assisted
result = run_wizard(events, provider="opencode", soa_ms=300.0)
# Access results
print(result.word_onset_codes) # [11, 8, 9, 1]
print(result.words) # [[11, 2, 4], [8, 3, 5], [9, 7, 6], [1, 12, 10]]
print(result.confidence) # 0.95
# Get config object or YAML
config = result.to_config()
yaml_str = result.to_yaml()
Epoch Extraction
Extract word-locked epochs from continuous EEG:
autocleaneeg-sl epoch raw_eeg.set --config config.yaml --output epochs.fif
autocleaneeg-sl epoch raw_eeg.set --preset adult-sl-2017 --subject 001re
from autocleaneeg_sl import extract_sl_epochs, get_preset
# Using config
epochs, result = extract_sl_epochs(
"raw_eeg.set",
word_onset_codes=[11, 8, 9, 1],
syllable_soa_ms=300.0,
)
# Using preset
config = get_preset("adult-sl-2017")
word_onsets = config.get_word_onset_codes("001re")
epochs, result = extract_sl_epochs("raw_eeg.set", word_onset_codes=word_onsets)
ZITC Computation
Compute Z-scored Inter-Trial Coherence:
autocleaneeg-sl zitc epochs.fif --freq-range 0.5 5.0 --surrogates 200
autocleaneeg-sl zitc epochs.fif --target-freqs 1.111 3.333 --output results.csv
from autocleaneeg_sl import compute_zitc
result = compute_zitc(
epochs,
freq_range=(0.5, 5.0),
n_surrogates=200,
seed=42,
)
# Access results
print(result.frequencies) # Frequency bins
print(result.zitc) # Z-scored ITC values
print(result.raw_itc) # Raw PLV values
# Export
df = result.to_dataframe()
df.to_csv("zitc_results.csv")
Method
ZITC is computed as:
ZITC = (True PLV - Surrogate Mean) / Surrogate Std
Where surrogates are generated by circular time-shifting each epoch, destroying phase-locking while preserving spectral properties.
Configuration Format
paradigm:
name: my-sl-paradigm
syllable_soa_ms: 300.0
syllables_per_epoch: 36
jitter_threshold_ms: 320.0
syllable_codes: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
languages:
stream1:
word_onset_codes: [11, 8, 9, 1]
words:
- "11-2-4"
- "8-3-5"
- "9-7-6"
- "1-12-10"
analysis:
freq_range: [0.5, 10.0]
target_freqs:
word: 1.111
syllable: 3.333
Built-in Presets
from autocleaneeg_sl import list_presets, get_preset
print(list_presets()) # ['adult-sl-2017', 'infant-sl']
config = get_preset("adult-sl-2017")
print(config.paradigm.syllable_soa_ms) # 300.0
CLI Reference
autocleaneeg-sl wizard # Infer config from events
autocleaneeg-sl epoch # Extract epochs from raw EEG
autocleaneeg-sl zitc # Compute ZITC from epochs
autocleaneeg-sl --help # Show help
Requirements
- Python >= 3.9
- NumPy >= 1.20
- MNE-Python >= 1.0
- Pandas >= 1.3
- PyYAML >= 6.0
- requests (for LLM providers)
License
MIT
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 autocleaneeg_sl-0.3.0.tar.gz.
File metadata
- Download URL: autocleaneeg_sl-0.3.0.tar.gz
- Upload date:
- Size: 21.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
294736f11dffac9fb467e21580fe686fc4ef385216b8b06cdc94b9bf33e8c4a9
|
|
| MD5 |
17ab244ecbefcdba304178514aa39401
|
|
| BLAKE2b-256 |
7176c1002be5b6bddc71d7f3e70e38184f06ab9afa5518b579ba73b34bd91c1b
|
File details
Details for the file autocleaneeg_sl-0.3.0-py3-none-any.whl.
File metadata
- Download URL: autocleaneeg_sl-0.3.0-py3-none-any.whl
- Upload date:
- Size: 25.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
680712505f956be754f328e11415f5be87bbd483abe662c45cee9c93fb7f064e
|
|
| MD5 |
65aacdb8de08509de0d18fc8ba5999ec
|
|
| BLAKE2b-256 |
089b2d4c58c9878a04b91127f14e0756ac1b4443da964f59380e50821849356f
|