Skip to content

Repository files navigation

Executive Summary: Autonomous Mitigation of Non-Stationary Signal Drift in Brain-Computer Interfaces

Author: Vaibhav Balani (IIT Kanpur)
Project Scope: Autonomous Systems Engineering, Applied Riemannian Geometry, Neuroinformatics
Repository Status: Fully implemented in Python (PhysioNet Validated)


1. The Core Problem: The BCI Deployment Bottleneck

Currently, non-invasive Brain-Computer Interfaces (BCIs), such as EEG headsets used for motor-imagery or assistive prosthetics, fail to transition from the laboratory into commercial, real-world deployment. The fundamental reason is non-stationary signal drift.

In a pristine laboratory, a classifier (like Common Spatial Patterns + SVM) can achieve 90%+ accuracy. However, in the real world, the EEG signal distribution shifts constantly due to physiological changes (sweat, fatigue) and hardware degradation (electrode gel drying). As the underlying data distribution changes, the static classifier rapidly degrades to random guessing (0% accuracy). Historically, the only solution has been to force the user to perform a manual supervised recalibration session every few hours, rendering all-day wearable BCIs commercially unviable.

2. The Proposed Solution

To solve this, I have engineered a fully autonomous, self-healing software architecture. Instead of relying on manual recalibration, this pipeline mathematically monitors the health of the incoming brainwaves and dynamically repairs its own spatial filters in the background without interrupting the user.


3. Technical Pillar 1: Unsupervised Recalibration (Covariance Whitening)

To heal the model without explicit user labels, the system utilizes Euclidean Alignment via Covariance Whitening.

  • By tracking the resting-state covariance of the drifted data, the system calculates a transformation matrix ($R^{-1/2}$).
  • This matrix mathematically aligns the shifted, noisy data back to the pristine calibration distribution.
  • Once aligned, the Common Spatial Pattern (CSP) filters are re-calculated on the fly, instantly restoring the classifier's accuracy.

4. Technical Pillar 2: Geometric Artifact Rejection (Riemannian Geometry)

If the system blindly heals itself on every piece of noisy data, a sudden physical artifact (like the user jaw clenching) would poison the model.

  • To prevent this, the pipeline maps the covariance matrices of the brainwaves onto a Symmetric Positive-Definite (SPD) Manifold.
  • Using the Affine-Invariant Riemannian Metric (AIRM), the system calculates the exact geodesic distance between the incoming brainwave and the healthy baseline.
  • It constructs a "Riemannian Potato" (a dynamic geometric threshold). If an incoming signal falls outside this mathematical boundary, it is immediately flagged as a physical artifact and dropped.

5. Technical Pillar 3: Agentic Systems Control (LangGraph)

Running heavy $O(n^3)$ matrix inversions continuously would instantly drain the battery of a commercial wearable headset.

  • Hysteresis Guards: The system employs a LangGraph "Strike-Counter." It waits until the Riemannian Gate confirms sustained, non-artifact drift over a specific threshold before it takes action.
  • Background Threading: When a heal is justified, the LangGraph node routes the matrix calculations to a background thread. The main loop continues to stream and predict data seamlessly while the background thread repairs the filters and hot-swaps them into the live model.

6. Simulation and Results

The pipeline was validated against the PhysioNet EEG Motor Movement/Imagery Dataset with injected adversarial drift (both variance inflation and subspace rotation).

  • The classifier's initial accuracy of ~75% crashed to 4.0% under extreme drift.
  • The LangGraph state machine autonomously detected the Covariate Shift, blocked extreme noise using the Riemannian Gate, and successfully routed the data to the Unsupervised Whitening node.
  • Result: The spatial filters were healed in the background and the accuracy was completely restored without human intervention.

7. Codebase Architecture (File Mapping)

To ensure modularity and scalability for open-source integration, the Python codebase is strictly segregated into independent mathematical pillars. Below is the mapping of which script serves what piece of the pipeline:

  • bci_selfheal/graph.py: The Agentic State Machine. This file contains the LangGraph node architecture that manages the control loop, the hysteresis guard (strike-counter), and routes heavy calculations to background threads.
  • bci_selfheal/riemannian.py: The Mathematical Core. Contains all Riemannian geometry functions: the Affine-Invariant Riemannian Metric (AIRM), Covariance Whitening (Ledoit-Wolf shrinkage), and the dynamic "Riemannian Potato" boundary for artifact gating.
  • bci_selfheal/adapters.py: The Classifier Bridge. Provides the interface between the live data stream and the machine learning model (e.g., ClassicalCSPSVMAdapter), applying the Whitening matrix ($R^{-1/2}$) to heal the classifier on the fly.
  • bci_selfheal/csp.py: The Signal Processing Module. A custom implementation of the Common Spatial Patterns (CSP) algorithm for extracting motor-imagery features from the EEG signal before classification.
  • bci_selfheal/ledger.py: The State Memory. Defines the BCIState tracking dictionary, which holds the rolling window buffers, accuracy history, and system status across graph ticks.
  • bci_selfheal/data_pipeline.py: The Data Ingestion Engine. Handles downloading and formatting the pristine PhysioNet EEG dataset used for validation.
  • bci_selfheal/drift.py: The Adversarial Simulator. Injects synthetic non-stationary drift (variance inflation and subspace rotation) on top of the live data to rigorously stress-test the healing architecture.
  • bci_selfheal/main.py: The Entry Point. The primary execution script that boots up the LangGraph agent, runs the continuous simulation loop, and logs the accuracy recovery over time.

(For visual proof of the system's efficiency, see the Final report + Final code/Graphs/ directory which contains the Crash & Recovery curve, the Riemannian Geodesic scatter plot, and the Covariance Heatmaps).

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages