Skip to content

Clarity-Digital-Twin/nedc-bench

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

396 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🧠⚑ NEDC-BENCH β€” Modern EEG Benchmarking Platform

Tests Coverage Python License Parity Version

Production-ready wrapper and reimplementation of Temple University's NEDC EEG Evaluation v6.0.0

⚠️ Independent Project: This is an open-source contribution, not officially maintained by Temple University, NEDC, or affiliates. We wrap the original NEDC v6.0.0 software unchanged, and provide a modern reimplementation. All algorithmic credit goes to the original authors (Shah et al., 2021).

🎯 What is NEDC-BENCH?

NEDC-BENCH transforms Temple University's NEDC EEG evaluation suite into a production-ready platform. We maintain a dual-pipeline architecture that guarantees scoring parity while offering modern infrastructure for scalable deployment.

The Problem: NEDC's evaluation software is excellent for research but challenging to deploy β€” dependency management, I/O conventions, and operational ergonomics make deployment and usage difficult.

Our Solution: Best of both worlds β€” preserve exact scientific behavior while making it effortless to run in production:

  • 100% algorithmic parity with NEDC v6.0.0 (continuously validated)
  • REST API & WebSockets for programmatic access
  • Docker/Kubernetes ready with Redis caching and Prometheus metrics
  • 92% test coverage with 187 tests

🧱 Architecture β€” Dual Pipeline Design

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    NEDC-BENCH Platform                    β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚   Pipeline Alpha      β”‚    β”‚   Pipeline Beta       β”‚   β”‚
β”‚  β”‚  (Legacy Wrapper)     β”‚    β”‚  (Modern Rewrite)     β”‚   β”‚
β”‚  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€    β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€   β”‚
β”‚  β”‚ β€’ Original NEDC code  β”‚    β”‚ β€’ Clean architecture  β”‚   β”‚
β”‚  β”‚ β€’ Research-grade      β”‚    β”‚ β€’ Type-safe Python    β”‚   β”‚
β”‚  β”‚ β€’ Text-based I/O      β”‚    β”‚ β€’ Async/parallel      β”‚   β”‚
β”‚  β”‚ β€’ 100% fidelity       β”‚    β”‚ β€’ Cloud-native        β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β”‚             ↓                           ↓                 β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”‚
β”‚  β”‚           Unified API & Result Validator         β”‚     β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Five Scoring Algorithms (All Parity-Validated)

  • TAES β€” Time-Aligned Event Scoring
  • DP β€” Dynamic Programming Alignment
  • Overlap β€” Any-overlap detection
  • Epoch β€” 250ms epoch-based sampling
  • IRA β€” Inter-Rater Agreement (Cohen's ΞΊ)

When to Use Which Pipeline

  • Alpha (Legacy Wrapper): When you need bit-exact reproducibility with NEDC v6.0.0
  • Beta (Modern Rewrite): For production deployments requiring speed and modern APIs
  • Dual: To validate parity between pipelines (used in CI/CD)

⚑ Quick Start

Docker Compose (Recommended)

git clone https://github.com/Clarity-Digital-Twin/nedc-bench.git
cd nedc-bench

# Build and start all services (API, Redis, Prometheus, Grafana)
docker compose up -d --build

# Verify health
curl http://localhost:8000/api/v1/health
# Expected: {"status":"healthy"}

# View API documentation
open http://localhost:8000/docs  # Swagger UI
open http://localhost:3000        # Grafana dashboards (admin/admin)

Quick test with sample data:

curl -X POST "http://localhost:8000/api/v1/evaluate" \
  -F "reference=@data/csv_bi_parity/csv_bi_export_clean/ref/aaaaaajy_s001_t000.csv_bi" \
  -F "hypothesis=@data/csv_bi_parity/csv_bi_export_clean/hyp/aaaaaajy_s001_t000.csv_bi" \
  -F "algorithms=all" \
  -F "pipeline=beta"

πŸ’‘ Windows/WSL users: Use docker compose (v2) not docker-compose (v1). See deployment guide for troubleshooting.

From Source (Python 3.10+)

# Using uv (10-100x faster than pip)
curl -LsSf https://astral.sh/uv/install.sh | sh
make dev  # Installs deps + pre-commit hooks

# Or traditional pip
python -m venv .venv && source .venv/bin/activate
pip install -e ".[api]"

# Verify installation
make test  # Run full test suite
make lint  # Check code quality

🧰 Usage Examples

REST API

import requests

# Upload and evaluate EEG annotations
with open("ref.csv_bi", "rb") as ref, open("hyp.csv_bi", "rb") as hyp:
    response = requests.post(
        "http://localhost:8000/api/v1/evaluate",
        files={"reference": ref, "hypothesis": hyp},
        data={"algorithms": ["taes", "epoch", "ira"], "pipeline": "dual"},
    )
    job_id = response.json()["job_id"]

# Get results with parity validation
result = requests.get(f"http://localhost:8000/api/v1/evaluate/{job_id}").json()
print(f"TAES Sensitivity: {result['beta']['taes']['sensitivity']:.2f}%")
print(f"Parity Check: {'βœ… PASS' if result['parity']['match'] else '❌ FAIL'}")

WebSocket Real-time Progress

import asyncio
import websockets


async def monitor_job(job_id):
    async with websockets.connect(f"ws://localhost:8000/ws/{job_id}") as ws:
        async for message in ws:
            print(f"Progress: {message}")

Command Line Interface

# Original NEDC wrapper (preserves exact v6.0.0 behavior)
./run_nedc.sh nedc_eeg_eval/v6.0.0/data/lists/ref.list \
              nedc_eeg_eval/v6.0.0/data/lists/hyp.list

# Python scripts for batch processing
python scripts/run_alpha_complete.py  # Full Alpha pipeline
python scripts/run_beta_batch.py      # All Beta algorithms
python scripts/compare_parity.py      # Compare Alpha vs Beta

πŸ“Š Performance & Validation

Parity Testing

# Verify 100% algorithmic match with NEDC v6.0.0
python scripts/compare_parity.py --verbose

# Expected output (exact values):
# βœ… TAES:    TP=133.84, FP=552.77, Sensitivity=12.45%, FA/24h=30.46
# βœ… Epoch:   TP=33704, FP=18816, Sensitivity=11.86%, FA/24h=259.23
# βœ… Overlap: TP=253, FP=536, Sensitivity=23.53%, FA/24h=29.54
# βœ… DP:      TP=328, FP=966, Sensitivity=30.51%, FA/24h=53.23
# βœ… IRA:     Kappa=0.1887 (multi-class Cohen's ΞΊ)

Performance Metrics

Component Metric Value Notes
API Latency P50 ~250ms With Redis cache
API Latency P99 ~2.5s Cold start
Throughput RPS ~100 4 workers, single node
Cache Hit Rate % >90% After warm-up
Test Coverage % 92% 187 tests
Parity Match 100% All algorithms

πŸ—‚οΈ Project Structure

nedc-bench/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ nedc_bench/           # Modern Beta pipeline (clean-room implementation)
β”‚   β”‚   β”œβ”€β”€ algorithms/       # Reimplemented scoring algorithms
β”‚   β”‚   β”œβ”€β”€ api/              # FastAPI application & endpoints
β”‚   β”‚   β”œβ”€β”€ models/           # Pydantic models for type safety
β”‚   β”‚   β”œβ”€β”€ orchestration/    # Dual-pipeline coordinator
β”‚   β”‚   └── validation/       # Parity checking framework
β”‚   └── alpha/                # Alpha pipeline wrapper
β”‚       └── wrapper/          # Minimal wrapper around NEDC v6.0.0
β”œβ”€β”€ nedc_eeg_eval/            # Original NEDC v6.0.0 (vendored, unchanged)
β”‚   └── v6.0.0/               # DO NOT MODIFY β€” reference implementation
β”œβ”€β”€ scripts/                  # Utility scripts for testing & validation
β”‚   β”œβ”€β”€ compare_parity.py     # Verify algorithmic equivalence
β”‚   └── ultimate_parity_test.py # Full validation suite
β”œβ”€β”€ tests/                    # Comprehensive test suite
β”œβ”€β”€ k8s/                      # Kubernetes manifests
└── docker-compose.yml        # Full stack with Redis & Prometheus

πŸ”¬ Technical Details

Input Formats

  • CSV_BI: Temple's annotation format (included examples)
  • XML: Alternative annotation format
  • List files: Batch processing of multiple files

Caching & Performance

  • Redis caching provides >10x speedup for repeated evaluations
  • Prometheus metrics for production monitoring
  • WebSocket support for real-time progress updates
  • Async processing for parallel execution

πŸ“š Documentation

Core Documentation

Algorithm & Technical Details

  • πŸ”¬ TAES Algorithm β€” Time-Aligned Event Scoring with multi-overlap sequencing
  • πŸ“Š Epoch Algorithm β€” 250ms epoch-based sampling details
  • 🎯 Overlap Algorithm β€” Any-overlap detection
  • πŸ”— DP Alignment β€” Dynamic programming with NULL sentinel design
  • πŸ“ˆ IRA Algorithm β€” Inter-Rater Agreement (Cohen's ΞΊ)

Developer Resources

πŸ”— Background: TUH EEG Corpus

The Temple University Hospital (TUH) EEG Corpus is the world's largest open EEG dataset. To access:

  1. Request access at https://isip.piconepress.com/projects/tuh_eeg/
  2. Email completed form to help@nedcdata.org
  3. Use provided credentials for rsync access

For testing NEDC-BENCH, we include sample data in nedc_eeg_eval/v6.0.0/data/.

Citation

If you use NEDC-BENCH in your research, please cite both:

Original Algorithms (Temple University)

@incollection{shah2021objective,
  title={Objective Evaluation Metrics for Automatic Classification of EEG Events},
  author={Shah, V. and Golmohammadi, M. and Obeid, I. and Picone, J.},
  booktitle={Signal Processing in Medicine and Biology},
  year={2021},
  publisher={Springer},
  doi={10.1007/978-3-030-36844-9_1}
}

This Platform (NEDC-BENCH)

@software{nedc_bench2025,
  title={NEDC-BENCH: A Modern Dual-Pipeline Platform for EEG Evaluation},
  author={{Clarity Digital Twin}},
  year={2025},
  url={https://github.com/Clarity-Digital-Twin/nedc-bench},
  note={Production wrapper and reimplementation with 100% parity validation
        and modern infrastructure}
}

Contributing

We welcome contributions! See CONTRIBUTING.md for guidelines.

License

  • New code (src/nedc_bench/, src/alpha/, tests/): Apache 2.0
  • Original NEDC (nedc_eeg_eval/): No explicit license; Β© Temple University

Support


NEDC-BENCH bridges neuroscience research and production systems β€’ Built on Temple University's foundational algorithms

About

Modern benchmarking platform for EEG event detection systems

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages