Decoding a memory in 1.04 milliseconds
A spike arrives at the input stage of the recording rig. The system pulls a four-channel waveform snippet, projects it into a feature vector, looks up the likelihood of seeing that feature under each environment’s waking statistics, and updates the running posterior over which environment the rat’s hippocampus is currently rehearsing. If the posterior over the target environment crosses threshold, a TTL pulse fires and the laser is on. The median latency from spike onset to laser TTL, in the closed-loop system Igor built, was roughly one millisecond.
By Chapter 5 we had a fast trigger. An HSE detector tells the system that something is happening, tens of milliseconds before the LFP shows it. The trigger fires roughly once a second through a long sleep. Most of those bursts have nothing to do with the memory we want to disrupt. Some are wakeful arousals. Many are replays of other things — the lab, the hallway, this morning, last week. Of the ones that are actually replays of one of our two arenas, only about half are of the target arena. Firing the laser indiscriminately would erase the wrong memories along with the right ones, and the experiment would say nothing.
The decoder’s job is to look at each burst, in real time, and decide whether it represents the target environment. If it does, fire. If it represents the control environment, hold. If it is ambiguous, also hold. Three states, decided in under a hundred milliseconds, on an animal whose brain is moving on at thirty kilohertz.
Why sorting was the wrong move
Chapter 2 ended on a tease. The classical pipeline — detect spike, extract features, cluster the features into single units, decode position from the firing rates of those units — cannot run in real time, because the clustering step is offline by hours. You have a choice: spend the hours, or skip the step.
The way to skip the step, due to Kloosterman and colleagues in 2014, is to do the inference directly on the unsorted spike features. Treat each spike as a point in a high-dimensional feature space — the mark. During waking, you record where the rat is and which marks fire there; this gives you, for each environment, a joint density over (mark, position) pairs. You never commit to cluster identities. During replay, you treat the new spike train as a marked point process and ask, given the marks I just saw, which environment’s waking density makes them most likely?
The math is a Bayesian update. Each new spike contributes a log-likelihood ratio in favor of one environment or the other, depending on whether the spike’s mark falls in a region of feature space that, during waking, was more typical of A or of B. Multiple spikes in a burst accumulate evidence multiplicatively (additively in log-odds). With perhaps thirty unsorted spikes inside a sharp-wave ripple, the posterior usually saturates well before the burst ends.
The playground
The interactive below is the conceptual core, simplified to two feature dimensions. The background shading is a preference field: regions tinted petrol are A-typical (during waking, marks here came from cells with fields in Room A); regions tinted gold are B-typical. As spikes arrive over the two-hundred-millisecond window, each one contributes to the running posterior, and the curves on the right track P(A) and P(B) as they accumulate. If P(A) crosses the confidence threshold first, the laser fires; if P(B) crosses first, the system holds; if neither crosses, also hold.
Try the four scenarios. Replay A is what the experiment is targeting — the decoder rips toward P(A) ≈ 1 within a few dozen spikes and the laser fires. Replay B is the control: same speed of accumulation, opposite direction, no laser. Mixed and noise are the two ways the burst can fail to be a clean replay; in both, the posterior dithers around 0.5 and the threshold never gets crossed. The slider lets you tune how aggressive the decoder is. Push it down to 0.6 and you start firing on uncertain bursts. Push it up to 0.95 and the system gets pickier — you miss a few real Room A events on a bad draw, but the false-positive rate on noise drops to nearly zero.
What the threshold is buying you
The threshold is the only knob the experimenter actually has. Everything upstream of it — the place maps, the marked-point-process likelihoods, the HSE detector — was fixed at the start of the recording. The downstream consequence is binary: laser on, laser off. The trade is the standard signal-detection one. Lower thresholds mean more interventions per session, which would in principle mean more memory disruption per night, but each intervention is less specific. Higher thresholds mean fewer interventions, all of them very confident, but you risk under-treating the target memory.
For the experiments in the paper Igor settled the threshold using a held-out validation set drawn from each animal’s own waking activity. The threshold ended up around 0.85 in most sessions; high enough that the false-fire rate on bursts decoded as Room B sat at a few percent, low enough that roughly half of the genuine Room A replays got disrupted. That half-of-replays figure is, importantly, plenty: this was a content-specific consolidation experiment, not a complete-replay-blockade experiment, and the goal was to remove enough Room A events to bias the consolidation outcome rather than to silence them entirely.
The closed loop, end-to-end
Stitch the chapters together and the closed-loop pipeline reads like this:
(1) Spike streams in on each channel of each tetrode. (2) Feature extraction projects the four-channel snippet to a low-dimensional mark. (3) Multi-unit firing rate is updated in a sliding window; if it crosses the dynamic threshold, the system enters HSE mode. (4) While in HSE mode, every new spike’s mark is fed into the marked-point-process likelihoods to update the posterior over environments. (5) If the posterior on the target environment crosses the confidence threshold, a TTL pulse fires, the laser turns on, and the ArchT-bearing pyramidals in CA1 are silenced for the duration of the pulse. (6) When the HSE window closes, the system resets and goes back to waiting.
All of that lives in lfp_online, which is the C++ project that runs on a real-time Linux kernel during recording. The 1.04-ms median latency, from spike electrode pickup to laser TTL, is the figure of merit for the whole system; it is also the answer to the question “how fast does this all have to be to actually catch a replay?”
We now have a closed loop that can detect a replay event, identify which memory it represents, and fire a laser onto the cells responsible for producing it — all inside the window during which that replay is still happening. The next chapter is what happens biologically when the laser actually fires: how ArchT silences pyramidal cells, the surprising disinhibition that follows, and why this matters for whether the manipulation counts as disrupting the replay or simply annotating it.