← Research

Brain-implant drift10 min read

The Fix That Can't Ship: Making r_norm Causal for Real-Time BCI

This post is part of an earlier series and is no longer updated. The current answer is on Can a brain implant work without daily re-tuning?.

A follow-on to the 3-part SBP drift series. Parts 1–3 found the drift, fixed it with r_norm, and mapped where the fix breaks. This post audits a flaw hiding inside the fix itself: it isn't causal, so it can't run on a device.

Correction (2026-10-25): the conclusion of this post has reversed. The decoder shared across the series predicted finger velocity 60 ms ahead of the newest SBP bin. Checked against the LINK authors' own ridge baseline, that lead cost about 0.08 R² on every feature that cannot see the future, causal r_norm included, while the acausal version's two-sided smoothing hid most of it. With the decoder predicting velocity at the current bin, going causal costs nothing measurable: same-day R² is 95 % of the acausal value, and cross-session transfer is better, not worse. Every number below is re-stated from that run, with 95 % confidence intervals (session bootstrap). The earlier "cost of causality" was the decoder's lead, not causality.

Correction (2026-10-23): the first version scored each session's warm-up bins and reported a cost of causality of ΔR² −0.0037. With the warm-up excluded, the same evaluation gave Δ +0.0015. Updated again the same day: the series now uses one decoder spec everywhere (Ridge on 100 ms of SBP history instead of the current bin only). Under it, going causal does cost something: mean cross-session R² 0.0258 acausal vs 0.0198 causal (Δ −0.0061). The numbers, the α sweep and the conclusion below are re-stated from that run. Session labels in the overlay figures were also wrong (the second session is day 9, not day 4), and several figure captions described decoded velocity when the figures show normalized SBP. All fixed below.


Interactive notebook

Open notebook in your browser


The uncomfortable admission

Every R² number in Parts 1–3 was computed with an algorithm that cheats.

Not on purpose, and not in a way that's wrong for offline analysis. But in a way that matters the moment you imagine this running on an actual implant. Here is the normalization at the heart of r_norm:

zi,d(t)=SBPi,d(t)−μi,dσi,dz_{i,d}(t) = \frac{\mathrm{SBP}_{i,d}(t) - \mu_{i,d}}{\sigma_{i,d}}

Look at μi,d\mu_{i,d} and σi,d\sigma_{i,d}. They are the mean and standard deviation of channel ii over the entire session dd: every time bin, start to finish. To normalize the sample at t=0t = 0, I used statistics computed from samples at t=1,2,…,Tt = 1, 2, \dots, T that, in a live system, have not happened yet.

The Gaussian smoothing step has the same problem: a symmetric kernel centered on tt pulls in samples from t+1,t+2,…t+1, t+2, \dots to produce the output at tt.

Both operations are acausal. They look into the future. That's free in a saved .nwb file. It's impossible on a brain.


Why this is the post that matters

A chronic BCI does not get the whole session up front. It gets one sample, then the next, then the next, forever, in real time. And it has to produce an output now, using only what it has already seen.

So the real question isn't "does r_norm improve cross-day transfer?" (Part 2 answered that). The real question is:

How much of that improvement survives when the algorithm is only allowed to look at the past?

The gap between the acausal number I reported and the causal number a device could actually achieve is the difference between a notebook result and an engineering result.


What "live data" means when you don't have an implant

I don't have a brain to stream from. So I simulate the stream.

I take the same LINK SBP sessions from Parts 1–3 and replay each one bin-by-bin: at step tt, the algorithm is handed only sbp[t] and whatever state it has accumulated from steps 0…t−10 \dots t-1. It is never allowed to index forward. This replay harness is the honest stand-in for an implant's real-time feed: same data, strictly causal access.

Nothing about the data changes. What changes is what the algorithm is allowed to see.


The fix: replace whole-session statistics with running statistics

Causal normalization needs μ\mu and σ\sigma estimated from the past only, updated as each sample arrives. The natural choice, and the one that quietly does extra work for us, is an exponentially-weighted moving mean and variance:

μt=(1−α) μt−1+α xt,vt=(1−α) vt−1+α (xt−μt)2\mu_t = (1-\alpha)\,\mu_{t-1} + \alpha\, x_t, \qquad v_t = (1-\alpha)\,v_{t-1} + \alpha\,(x_t - \mu_t)^2 z^t=xt−μtvt+ε\hat{z}_t = \frac{x_t - \mu_t}{\sqrt{v_t} + \varepsilon}

One knob: α\alpha, the update rate. It sets how fast the normalizer forgets old data. Small α\alpha tracks slowly and stably, large α\alpha adapts fast but jitters. Crucially, because it forgets, an EWMA normalizer doesn't just go causal. It begins to track drift on its own, which is the seed of the next post.

The smoother gets the same treatment: the symmetric Gaussian becomes a one-sided (causal) filter, which buys causality at the price of a phase delay: the output lags the input by a few bins.


Three things this post measures

1. The cost of causality

Re-run the Part 2 pairwise cross-session R² evaluation with causal r_norm vs. the acausal version, scoring every feature set on the bins after each session's 300-bin (6 s) warm-up. The headline is the R² lost by being honest, and it comes out negative: acausal off-diagonal R² = 0.030 (95 % CI −0.012 to +0.079), causal (EWMA) = 0.049 (CI +0.008 to +0.097), so ΔR² = +0.019 (CI +0.011 to +0.027). Causal transfers better. A trailing-window causal variant gives 0.048, indistinguishable from the EWMA (−0.0015, CI −0.005 to +0.002). The likely reason is in Part 2: the acausal version's 50 ms two-sided smoothing lowers transfer (z-score alone reaches 0.051), and the causal version uses a much lighter one-pole smoother.

Pairwise cross-session decoder R² matrices: acausal Gold r_norm (left) versus the causal EWMA version (center) and a causal sliding-window version (right). Each cell is the R² of a decoder trained on session i and tested on session j, scored after the warm-up. The three panels look alike; on average the causal ones are slightly warmer off the diagonal (0.049 and 0.048 against 0.030).

Read this relatively, not absolutely. The absolute cross-session R² here (~0.03–0.05) is low because it averages every pair of sessions, including pairs more than a year apart, where nothing transfers. What matters is the gap between acausal and causal on the same data. The scoreboard, which has confidence intervals, splits it further: causal r_norm reaches 95 % of the acausal same-day R² (0.263 vs 0.276), and it keeps a similar share of it from day to day (81 % vs 79 % within a week, 80 % vs 76 % at 8–30 days; neither difference is distinguishable from zero). The earlier version of this post reported a large within-session gap (0.183 vs 0.270); that gap was the decoder's 60 ms lead, which the acausal smoother partly compensated for.

2. The warm-up transient

At t=0t=0 there are no statistics. The running mean/variance need time to converge before the normalized output is trustworthy, and every real session start pays this cost. In practice the running std reaches its steady-state (acausal) value within a few hundred bins (the warmup = 300 marker below), after which causal and acausal normalization agree. Scoring through that window inflated the cost of causality in the first version of this post; the R² numbers above exclude it.

Running EWMA standard-deviation estimate for the three highest-variance channels over the first ~1200 time bins of one session. Each solid line converges toward its acausal full-session std (dashed). The dotted vertical line marks the warm-up cutoff of 300 bins.

3. The α\alpha sweep

The forgetting rate α\alpha has a sweet spot: too slow (α≤0.003\alpha \le 0.003) and the normalizer can't track drift; too fast (α≥0.1\alpha \ge 0.1) and it chases noise. Mean transfer R² (decoder trained on Day 0, scored on every later session, warm-up excluded) rises from 0.0005 at α = 0.001 to 0.038 at α = 0.03, with 0.01 at 0.025, then drops to 0.002 at 0.1 and below zero at 0.3: an inverted U. For this one Day-0 decoder, 0.03 beats 0.01 (by 0.013, CI 0.002 to 0.026). I keep α = 0.01 anyway: chosen across every decoder of the 17 earliest sessions, 0.01 wins (mean transfer 0.194 vs 0.179 for 0.03), and on the 13 later sessions 0.01 and 0.003 tie (0.031 and 0.032) while 0.03 trails (0.013). The values are small because most later sessions are months away, where nothing transfers; the shape is the point.

Mean cross-session transfer R² as a function of the EWMA update rate α (log x-axis), decoder trained on Day 0. The curve rises from about zero at α=0.001 to a peak at α=0.03, then falls to about zero at α=0.1 and below zero at α=0.3, an inverted U.

And, because this is an engineering post, one more: per-sample latency. The causal update takes ≈ 5.4 µs/bin at 96 channels in Python. That number mostly measures the Python interpreter, not the algorithm, so it says little about a device. The honest version is an operation count and a fixed-point implementation, which is a follow-up.


Multi-day replay stability

Beyond the aggregate R² and the α sweep, I streamed all 30 sessions back to back through one causal normalizer to check that its running statistics stay bounded across day boundaries.

Running EWMA mean (top) and standard deviation (bottom) for three high-variance channels while all 30 sessions are streamed back to back through one causal normalizer. Dotted lines mark session boundaries; the statistics jump at boundaries and settle, without diverging.

A closer look at one channel within two sessions, day 0 (2020-01-27) and day 9 (2020-02-05): after the warm-up, the causal z-score tracks the acausal one closely. Because the causal state resets every session, this shows within-session agreement only. It says nothing about decay across days; that is what the pairwise R² above measures.

Causal versus acausal z-score for one channel over the first 1,200 bins of day 0 and day 9, with their difference below. After the 300-bin warm-up (dotted line) the two traces overlap and the error stays small.

The rolling correlation between the two z-scores, computed over 300-bin windows through each session, makes the same point in one line per session.

Correlation between causal and acausal z-scores for one channel, in consecutive 300-bin windows through day 0 and day 9. After the first window the correlation sits near 0.99, with a few dips to about 0.9.


What I found (the prior mostly held)

My prior was that causal r_norm would lose some R² versus the acausal version (the acausal one had a free look at the future), but that most of the benefit would survive, because the dominant drift correction (per-channel gain/variance, established in Part 2) doesn't require seeing the future, only a reasonable estimate of the recent past. With the decoder fixed, it loses nothing measurable. Causal r_norm reaches 95 % of the acausal same-day R², transfers across sessions slightly better (+0.019, CI +0.011 to +0.027), and on the scoreboard holds at least half of its same-day R² for 52 days (95 % CI 42–82). The cost of going real-time is the first seconds of each session, while the running statistics converge. The first two versions of this post said otherwise; both times the cost came from how I scored it (warm-up bins, then a decoder predicting 60 ms ahead), not from causality.


Why an engineer should care

Two reasons this is more than a footnote:

  • It's the deployability gate. A drift fix that needs the whole session is a data-analysis trick. A drift fix that runs on a one-sample-at-a-time stream is a piece of a real decoder. This post is what moves r_norm across that line.
  • It sets up online adaptation. The EWMA's forgetting factor is a primitive version of continual recalibration. The next post, on unsupervised latent alignment for the month-scale residual, is where that adaptation gets real.

References

  1. Jarosiewicz, B., et al. (2015). Virtual typing by people with tetraplegia using a self-calibrating intracortical brain–computer interface. Science Translational Medicine, 7(313), 313ra179. https://doi.org/10.1126/scitranslmed.aac7328
  2. Gilja, V., et al. (2012). A high-performance neural prosthesis enabled by control algorithm design (ReFIT). Nature Neuroscience, 15, 1752–1757. https://doi.org/10.1038/nn.3265

Code: github.com/radhakrishnanrishaban/ephys-signal-atlas | neurosignal