Where Should a Spiking Network Keep the Past?

I study delayed-feedback learning in a compact spiking neural network (SNN) for scalp EEG. The central question is which representation of a past observation should be retained until its label becomes available. I compare input replay, synaptic eligibility storage, and spike replay under simulated delays of 5–60 minutes.

302–595×
Less buffer payload for binary L1 spike replay (13.2 KiB) vs. LIF e-prop (3.98 MiB) and approx RLeaky e-prop (7.84 MiB)
0.849
Post-1st-seizure ROC from 65.4 KiB multiply-free 2-bit delta spikes (227× smaller than theoretical full-network e-prop)
99.5%
Energy of 64×64 Layer-2 eligibility Ē in σ₁ (98.5% for Layer 1); chb01/21 ΔW₁ cosine achieves 0.631
0.477
SNN forecasting ROC-AUC on 24 time-of-day-matched seizures (27 evaluated overall)

Overview

The model processes a 30-second EEG window every 5 seconds. In the retrospective evaluation, labels arrive after a delay in 5-minute review batches of approximately 60 windows. Delays of 15 and 60 minutes require retaining up to 241 and 781 pending decisions, respectively. I measure the buffer payload needed to support delayed adaptation in a 15,811-parameter SNN.

The initial proposal focused on seizure forecasting. Following proposal feedback, I expanded the comparison to direct gradient storage, several eligibility compression schemes, and explicit retention policies. I also audited the forecasting baseline before evaluating the delayed-learning methods on continual seizure detection.

1. Three places an SNN can keep the past

Eligibility-based online learning rules maintain synaptic traces that can be combined with a learning signal (Bellec et al., 2020). Here I consider a different constraint: each decision receives its own label after a simulated delay of 5–60 minutes.

The experiments use SHA-256-verified CHB-MIT scalp EEG from 12 CHB-MIT case records (11 unique individuals) studied in FGL (369 EDF files, 456.3 hours, 73 seizures). CHB-MIT file numbering is not always chronological, so I rebuilt absolute timelines directly from EDF header timestamps. Every 5-second frame extracts 10 causal features across 18 bipolar channels (D = 180): six log band powers (δ, θ, α, β, γ, high-γ skipping 60/120 Hz), forward-only 0.5–45 Hz log variance and line length, plus Hjorth mobility and complexity. Six frames form a 30-second window fed into a compact 2-layer snnTorch LIF network (SNNForecaster, 15,811 parameters, Eshraghian et al., 2023): fc1(180→64) → LIF1 → fc2(64→64) → LIF2 → rate h → σ(w·h + b).

Data example A. Ten Minutes of CHB-MIT chb13 Scalp EEG Across a Seizure Onset
Real CHB-MIT chb13 band-power features and causal 2-bit delta front-end spikes across a seizure onset

Top: Channel-averaged causal delta power, beta power, and line length around chb13's first seizure. Bottom: The causal 2-bit delta spike raster (ON = +1 green, OFF = −1 red, silent = 0 cream) that feeds our SNN with binary/ternary synaptic accumulation in Section 6.

When the model scores window j at time t_j, the label y_j ∈ {0, 1} is not yet available. Under binary cross-entropy, the gradient for any parameter θ is linear in y_j: ∇_θ L_j = (p_j - y_j) ∇_θ z_j. Because snnTorch detaches the reset term and Layer 2 has no lateral recurrence in the feedforward version, backprop through time for W_2 factors exactly (checked against PyTorch autograd to <10−6 in tests/test_plasticity.py):

∂Lj / ∂W2,ki = (pj − yj) · wk · Ēj,ki,     Ēj = (1/T) ∑t=1..T ψj(t) εj(t)⊤,     εj(t) = β2εj(t−1) + s1,j(t) In detached-reset feedforward LIF, exact Layer-2 e-prop eligibility Ē_j equals direct weight sensitivity ∂z_j/∂W_2 up to readout weights w_k.

For a backlog of B_delay pending decisions, dense eligibility storage scales as O(B_delay · N_in · N_out) floating-point values. The complete payload is 16,908 bytes per decision. Packed binary Layer-1 activity scales as O(B_delay · N_in · T) bits; with a timestamp, this is 56 bytes per decision. Replaying the retained spikes reconstructs the Layer-2 gradient at the current weights, reducing the buffer payload by a factor of 302.

Figure 1. Streaming Delayed Credit Across Input, Weight, and Spike Space
Tap any block, switch the memory space above, or step through stages to compare how each space stores 15 minutes of pending EEG decisions.

Every learner sees the exact same chronological EEG stream and label arrival timestamps. Toggle the four buttons above to compare stored payload, peak buffer payload at D = 15 min (backlog 241), and plastic layers.

Data example B. One chb13 Seizure Window Across All Three Memory Spaces
Real chb13 ictal window in Input Space (6x180), Weight Space (64x64 E_bar), and Spike Space (6x64 binary spikes)

Left: Real causal z-scored EEG window X (4,328 B). Middle: Exact 64×64 Layer-2 eligibility |E_bar| (16,908 B). Look at the plaid stripes in the middle plot: every active vertical column matches the green Layer-1 spikes on the right (56 B), showing straight away why E_bar collapses to rank 1.

Memory Space & Method Stored Payload per Pending Decision B / dec Peak (15m) Peak (60m) vs. e-prop
Weight: Full L1+L2 e-prop (theory) fp32 E_1 (64×180) + E_2 (64×64) + biases + h, p, t 63,244 14.88 MiB 48.24 MiB 0.27×
Weight: Recurrent RLeaky e-prop fp32 E_in + E_rec (two 64×64) + E_b, h, p, t (approx) 33,292 7.84 MiB 25.39 MiB 0.51×
Weight: Exact LIF L2 e-prop (E_bar) fp32 E_bar (64×64) + E_b + h + p + t 16,908 3.98 MiB 12.89 MiB 1.0×
Input: Full-Net BPTT (fp32) fp32 causal window X (6×180) + t 4,328 0.995 MiB 3.30 MiB 3.9×
Weight: Block-10 (L=10) Per-block sums ΣE_bar, ΣpE_bar (skip mixed) 3,380 825 KiB 2.64 MiB 4.8×
Weight: SVD Rank-1 (fp16) Top singular triplet u_1, σ_1, v_1 + E_b, h (fp16) 526 123.8 KiB 401.0 KiB 32.1×
Spike: E2E 2-bit Delta / Bipolar Bit-packed ON/OFF spikes (270 B) + t (add/sub synapses, all layers) 278 65.4 KiB 212.0 KiB 227× full
Spike: E2E 1-bit Sign Bit-packed binary spikes (135 B) + t (add/sub synapses, all layers) 143 33.7 KiB 109.1 KiB 442× full
Weight: Unaligned Trace (O(1)) Single decaying E_run, pE_run (τ=15m) — 33.0 KiB 33.0 KiB 120×
Spike: Binary L1 Replay (L2+H) Bit-packed Layer-1 spikes s_1 (48 B) + t (8 B) 56 13.2 KiB 42.7 KiB 302–595×
Control: Bias-Only (1 param) Scalar p_j + t_j (global risk offset only) 12 2.8 KiB 9.1 KiB 1,409×
Packed feedback-buffer payload for the 5-second stream (5-minute review bursts; backlog 241 at 15 min and 781 at 60 min). Model parameters and working memory are excluded. Values use binary units (1 KiB = 1024 bytes; 1 MiB = 1024 KiB).
Gradient timing and memory accounting Stored eligibility represents prediction-time sensitivity: Gstored = ∇θL(θj; xj, yj). Replay recomputes Greplay = ∇θL(θarrival; xj, yj) for the retained representation (Layer-1 spikes for Layer-2 replay, with Layer 1 frozen). These gradients need not agree if weights change during the delay. Exactness refers to the corresponding objective, initial state and detached-reset model. Memory figures describe packed feedback-buffer payload, excluding model parameters, working memory and runtime overhead. Full-network e-prop memory is theoretical; no performance score is assigned to it.

2. Low-rank eligibility compression

To compare replay against compressed eligibility, I use the factorization E_bar = (1/T) Σ_t ψ(t) ε(t)ᵀ. Since T = 6, the rank is at most six. Thin QR decompositions of the two 64×6 factors reduce the SVD to a 6×6 matrix. The implementation reports approximately 20× faster decomposition and agreement with the dense SVD to 10⁻¹¹.

Across 328,041 EEG windows, the mean singular values are σ₁ = 7.758, σ₂ = 0.452 and σ₆ = 0.048. Rank 1 accounts for 99.50% of the Layer-2 Frobenius energy and 98.52% for Layer 1. Temporal integration of presynaptic activity is a possible explanation for the concentration.

Figure 2. Exact Singular Value Spectrum & Rank-r Weight-Space Compaction
Select a compression rank above or hover any singular value bar to inspect real 12-case Frobenius energy, ictal gradient cosine fidelity, and memory savings.

Left: Exact singular values of 64×64 Layer-2 eligibility Ē_j averaged across 12 CHB-MIT patients (328k windows; σ_7..σ_64 are algebraically zero). Right: Rank-1 fp16 SVD cuts weight RAM 32× at 0.976 cosine, yet binary spikes are still 9.4× smaller and exact.

Rank-1 fp16 SVD (S2_weight_svd_r1) tracks exact 3.98 MiB e-prop to four decimal places across the whole stream (0.75930 vs. 0.75935 ROC-AUC, 0.06836 vs. 0.06837 Brier, 0.1262 vs. 0.1261 Frobenius drift). Even on heavily shifted chb13 at η = 0.03, rank-1 SVD lifts ROC from 0.430 to 0.654, close to exact e-prop (0.654). Even so, saving the 48-byte binary spike train that generated E_bar_j beats rank-1 weight compression by 9.4× and keeps gradient fidelity at 1.000.

3. Auditing forecasting first (and why I moved to detection)

Before running the continual learning sweeps, I cloned the unmodified Future-Guided Learning repository (SkyeGunasekaran/FutureGuidedLearning, commit 5fa24ea) into a pinned Python 3.11 environment and ran all 12 case records using their exact README commands.

With α = 0.5 across 3 unseeded trials, the CNN-LSTM baseline averaged 0.546 (published: 0.581), while FGL distillation averaged 0.497 (published: 0.844). Sweeping all 11 values of α on the test set topped out at 0.588 on chb05 and 0.625 on chb21, with substantial variation across unseeded runs (chb13 ranged from 0.525 to 1.000 across 17 runs of identical code).

Comparing features and models on the same windows indicated that the evaluation protocol explained much of the performance difference. On FGL's curated windows (Protocol A), plain logistic regression on our 10 band-power features achieves 0.931 AUC (11/12 case records ≥ 0.9), our band-power SNN achieves 0.935, and our compact STFT SNN achieves 0.912 with 29× fewer parameters (0.32M vs. 9.34M) and 21× lower peak inference memory (2.1 vs. 44.7 MB) than FGL's CNN-LSTM (0.556 per-sample). Under chronological streaming (Protocol B: continuous 30-s grid, hard negatives 35 min to 3 h from seizures, censoring, validation thresholds), every EEG model dropped to 0.40–0.54 against 0.518 for a 5-parameter clock-only baseline.

Figure 3. Forecasting Audit: Protocol A vs. B, 27-Seizure Check & Code Findings
Hover or tap any bar pair. Models scoring 0.91–0.94 on curated Protocol A drop to 0.40–0.54 under chronological Protocol B.

I evaluated 27 seizures using rolling-origin splits and training-only normalization. Overall ROC-AUC was 0.577 for logistic regression, 0.553 for the SNN and 0.414 for the clock control. For the 24 seizures with negatives matched within ±1 hour, logistic regression reached 0.516 (95% clustered CI for the difference from clock: [−0.128, +0.342], p = 0.41) and the SNN reached 0.477 (CI [−0.179, +0.299], p = 0.64). A burst-normalized bias-only update reproduced the Brier improvement. I therefore evaluated delayed adaptation on seizure detection.

4. Continual seizure detection: depth vs. memory

For each target patient p, I trained a 3-seed population SNNForecaster on the other patients' ictal vs. interictal 30-second windows, mutually excluding chb01 and chb21 and fitting z-score stats strictly on the training patients. Dropping a population SNN cold onto a new patient's chronological 5-second stream (328,041 windows, 73 seizures) creates real distribution shift: frozen post-1st-seizure ROC averages 0.759, spanning from 0.375 (chb20), 0.399 (chb01), and 0.419 (chb13) all the way up to 0.980 (chb09).

Data example C. Live LOPO Training Loss vs. Cold-Start Unseen chb13 Loss & ROC
Live 15-epoch snnTorch LOPO training loss dropping while held-out unseen chb13 test loss rises before online adaptation

Generated live in our Colab demo notebook. Training loss falls smoothly from 1.10 to 0.18 on the 11 training patients, while unseen chb13 loss climbs and cold-start ROC sits below 0.45. You can see right away why a frozen population SNN struggles on a shifted patient, and also why 2-bit delta spikes already generalize better cold than raw fp32.

During deployment, labels arrive 15–20 minutes late in 5-minute review bursts (60 windows per burst, backlog B_delay = 241, pos_w = 20). Every metric is scored strictly prequentially after each patient's first seizure feedback arrives (covering 61 unseen future seizures across 12 case records), with η selected strictly leave-one-patient-out.

Figure 4. Three-Space Frontier, Delay Scaling & Per-Patient Adaptation
Hover or tap any point or curve to inspect 12-case ROC-AUC, PR-AUC, Brier score, and exact retained buffer payload.

Strictly prequential scores across the 61 unseen seizures after each patient's first confirmed seizure, averaged across 3 seeds with LOPO η selection (initial η grid up to 1e-2).

Method Space (Plastic) Peak buffer payload ROC ΔROC vs Bias PR Brier FPR@80%
A_frozen Control (None) 0 KiB 0.7587 −0.0018 0.2522 0.1477 37.0%
C0_bias_only Control (1-param b) 2.8 KiB 0.7605 0.0000 0.2530 0.1194 37.0%
S1_input_full_bptt Input (L1 + L2 + Head) 1,019 KiB 0.8198 +0.0592* 0.3023† 0.0154 28.6%
S2_weight_eprop_exact Weight (L2 + Head) 3,979 KiB 0.7593 −0.0012 0.2176 0.0684 36.8%
S2_weight_svd_r1 Weight (L2 + Head, r=1) 123.8 KiB 0.7593 −0.0012 0.2175 0.0684 36.8%
S2_weight_block_L10 Weight (L2 + Head, L=10) 825.2 KiB 0.7609 +0.0003 0.2326 0.0965 36.3%
S2_weight_trace_unaligned Weight (O(1) trace) 33.0 KiB 0.7641 +0.0035 0.2590 0.1065 36.1%
S3_spike_l2_replay Spike (L2 + Head, exact) 13.2 KiB 0.7596 −0.0009 0.2173 0.0685 36.8%
S3_head_uint8 Spike (Head, lossless) 17.9 KiB 0.7606 +0.0001 0.2545 0.1221 36.8%
S3_head_block_L20 Spike (Head, L=20) 6.6 KiB 0.7607 +0.0002 0.2546 0.1215 36.7%
12-case means (3 seeds, D=15m, strict LOPO η). *Wilcoxon p=0.016 vs. both frozen and bias-only; †PR-AUC Wilcoxon p=0.034 vs. bias-only. Unaligned trace ROC p=0.042 vs. bias-only.
Why Layer-2-only looked flat under LOPO Two things happened at the same time. Cross-patient EEG shift enters at fc1 (180→64), so full-net BPTT lifted 10 of 12 case records (+6.1% ROC, 9.6× lower Brier). Meanwhile, high-baseline chb09 (0.980 frozen) pulled LOPO PR selection down to a tiny η = 3e-4 for Layer-2 methods. Check Tab 4 of Figure 4 for shifted chb13 (seed 1) at η = 0.03: 13.2 KiB Spike L2 Replay jumps from 0.430 to 0.640 ROC (+0.201 over bias-only) and tracks 3.98 MiB e-prop (0.654) closely. That naturally raised the next question: what happens if we turn Layer 1's inputs into spikes too?

5. Retention under limited memory and noisy feedback

I evaluate two additional constraints: a buffer smaller than the feedback backlog (B < 240) and simulated feedback errors consisting of missed seizures and brief false-positive events.

To define the feedback gate g_t independently of FGL teacher logits, let c_j be the number of consecutive reported positive 5-second frames in the cluster around decision j inside the arrived batch. Real CHB-MIT seizures last 37 to 112 seconds (7 to 22 frames), while brief artifacts last 5 to 10 seconds (1 to 2 frames). I use the following gate:

gj = min(1,  cj / 3)   if ỹj = 1,      gj = 1   if ỹj = 0 Soft gating scales updates smoothly by g_j; hard gating requires c_j ≥ 3 (at least 15 seconds sustained).
Figure 5. Sub-Backlog Retention (B < 240) & Explicit Consistency Gate gt
Hover or tap any budget point. Below the 240-decision backlog, FIFO loses 97.6%–99.7% of labels; Top-Risk and Uncertainty beat both FIFO and Reservoir at 0.88–1.75 KiB.

Two lessons stood out. First, retention depends on how rare your target events are. On dense forecasting streams (Round 2), uniform reservoir beat FIFO, uncertainty, and a learned keep/drop model. On rare-event seizure detection (only 0.28% ictal frames), Top-Risk and Uncertainty beat both FIFO and reservoir in 0.88 to 1.75 KiB by holding onto rare seizure and boundary frames (pushing chb18 from 0.670 FIFO to 0.703 ROC and 0.043 to 0.077 PR in 0.88 KiB). Second, The noise experiments show that false alarms need not substantially degrade adaptation. Averaging updates across each review burst already absorbs 1.0 FA/h plus 50% missed seizures with under 0.001 ROC drift, and hard cluster gating (c_j ≥ 3) reduces the residual Brier error (0.1064 down to 0.1031) with no observed degradation under the tested missed-seizure condition.

6. End-to-end spike replay, recurrence and weight adaptation

Layer-2 spike replay freezes the input projection, whereas full-network input replay requires 0.995 MiB. The feedforward eligibility identity also does not extend directly to recurrent networks. I evaluate these constraints using three additional experiments with the same subject-grouped protocol, three seeds and 61 subsequent seizures, expanding the learning-rate grid to 3×10⁻².

Figure 6. End-to-End Spike Replay, Recurrent LIF & Weight-Space ΔW1 Similarity
Switch tabs above or hover any point or heatmap cell. 65.4 KiB multiply-free 2-bit delta spike replay reaches 0.8493 ROC (24.9% FPR@80%), matching 0.995 MiB fp32 BPTT at 15.6× less RAM.

Same 12-case subject-grouped LOPO protocol (chb01 & chb21 mutually excluded, 3 seeds, strict LOPO η up to 3e-2, 61 unseen post-1st-seizure events). Bit-exact pack/unpack roundtrips are checked on every patient.

Data example D. Recurrent LIF (snn.RLeaky) 12-Patient Detection & Measured e-prop Approximation Gap
12-case RLeaky continual detection ROC bars and histogram of measured ictal gradient cosine of recurrent e-prop vs exact R-BPTT

Left: 12-case RLeaky continual detection scores; 65.4 KiB 2-bit bipolar E2E (0.836 ROC, p=0.027) closely tracks 0.995 MiB fp32 BPTT (0.842 ROC). Right: Across all 36 patient-seed runs, local recurrent e-prop (7.84 MiB) falls short of exact recurrent BPTT (mean ictal cosine 0.9952, min 0.991), while 13.2 KiB binary spike replay achieves a cosine of 1.000.

Architecture & Spike Front-End Peak buffer payload vs. Full e-prop ROC PR Brier FPR@80% ΔROC (p)
FF: fp32 Frozen / Bias-Only 0 / 2.8 KiB — 0.767 / 0.768 0.292 / 0.290 0.113 / 0.093 35.5% baseline
FF: fp32 Full-Net BPTT 1,019 KiB 14.6× 0.8558 0.3836 0.0116 23.7% +0.088 (.005)
FF: 1bit_sign E2E (add/sub synapses) 33.7 KiB 442× 0.8419 0.2259 0.0142 24.3% +0.035 (PR .034)
FF: 2bit_delta E2E (add/sub synapses) 65.4 KiB 227× 0.8493 0.3160 0.0143 24.9% +0.053 (.042)
FF: 2bit_bipolar E2E (add/sub synapses) 65.4 KiB 227× 0.8409 0.2914 0.0160 26.8% +0.081 (.016)
FF: Spiking LoRA r=2 (2bit / fp32) 65.4 / 1,019 KiB — 0.795 / 0.809 0.184 / 0.275 0.020 / 0.020 34.1 / 31.9% +0.035 / +0.041
RLeaky: fp32 Full-Net BPTT 1,019 KiB 18.4× 0.8417 0.3706 0.0143 27.0% +0.068 (.012)
RLeaky: 2bit_bipolar E2E (add/sub synapses) 65.4 KiB 287× 0.8363 0.2715 0.0183 26.7% +0.070 (.027)
12-case means (3 seeds, D=15m, strict LOPO η up to 3e-2). Full-net weight e-prop costs 14.88 MiB (FF) and 18.74 MiB (RLeaky). ΔROC and Wilcoxon p-values are paired against each encoder's own matched bias-only control.
Layer-1 weight-space similarity At η = 3e-3, each patient's cumulative Layer-1 shift ΔW_1 puts 82–92% of its energy in rank 1 (98–99.6% in rank 4). Yet across different patients, those shifts are nearly perpendicular: mean off-diagonal cosine is 0.004 on both 2bit_delta and fp32. I observed that across all four encoder configurations, the #1 highest cosine pair out of all 66 pairs was chb01 ↔ chb21, the same patient recorded 1.5 years apart (0.631 on 2-bit delta vs. 0.357 for the #2 pair; 0.512 on fp32; 0.546 on 1-bit sign). chb01 and chb21 share the same 10-patient LOPO initialization because we mutually excluded them, though the other 65 pairs also share about 90% of their training patients and still average 0.004. This geometry may help explain why Online Spiking LoRA (r=1,2,4) lagged at 0.795: a frozen random A basis simply cannot line up fast enough with each patient's orthogonal focal channels.

Limitations

This study is a retrospective replay on 12 pediatric CHB-MIT recordings (11 unique people from one hospital), and subject-level grouping should also be verified for hyperparameter selection and statistical tests. Checking multi-center datasets like TUSZ or Siena is a direction for further validation. All memory numbers are exact packed bytes and parameter counts, while the multiply-free synaptic accumulation claim is analytical; total compute and energy on physical hardware were not measured. For the recurrent layer, I benchmarked against local recurrent e-prop (O(N²), 7.84 MiB at D = 15 min) rather than full RTRL (O(N³), which would require hundreds of megabytes across 241 pending windows and is infeasible on wearable SRAM); binary Layer-1 spike replay (O(N·T) at 13.2 KiB) recomputes the current-weight recurrent BPTT gradient for the retained spikes, using 594.5× less buffer payload than local recurrent e-prop. Full RTRL was not benchmarked. Finally, my recurrent e-prop approximation check (0.9955 cosine) used 6-step windows with detached reset; longer windows may widen the approximation gap; this was not tested.

7. Core code

The project logs report 40 passing automated unit tests (pytest tests -q). Here are the three main primitives behind the experiments.

A. Exact Layer-2 e-prop & fast T×T QR+SVD

1. src/plasticity/three_space.py — eligibility_svd_fast()
def eligibility_svd_fast(s1, psi, beta2, rank):
    """Exact rank-r SVD of E_bar = (1/T) psi.T @ Eps via T x T QR+SVD (rank <= T)."""
    T, n_in = s1.shape
    eps = np.zeros((T, n_in), dtype=np.float64)
    eps_b = np.zeros(T, dtype=np.float64)
    cur, cb = np.zeros(n_in), 0.0
    for t in range(T):
        cur = beta2 * cur + s1[t]
        cb = beta2 * cb + 1.0
        eps[t], eps_b[t] = cur, cb
    Eb = (psi.T @ eps_b) / T

    # Thin QR reduces 64x64 SVD to an exact 6x6 SVD (~20x faster, error < 1e-11)
    Q1, R1 = np.linalg.qr(psi.T, mode="reduced")
    Q2, R2 = np.linalg.qr(eps.T, mode="reduced")
    u_m, s_all, vt_m = np.linalg.svd((R1 @ R2.T) / T, full_matrices=False)
    r = min(rank, len(s_all))
    return Q1 @ u_m[:, :r], s_all[:r], vt_m[:r, :] @ Q2.T, Eb, s_all

B. 56-byte binary spike replay with burst normalisation

2. src/plasticity/three_space.py — Spike-Space Layer-2 Replay
# At decision time t_i: store only bit-packed binary Layer-1 spikes (48 B + 8 B ts)
store[i] = np.packbits(S1[i])

# At arrival time r_j <= t_i: unpack spikes & regenerate exact current-weight gradient
for j in arrivals:
    packed = store.pop(j, None)
    if packed is None or not usable[j]:
        continue
    s1_j = np.unpackbits(packed)[: T * n_in].reshape(T, n_in).astype(np.float64)
    _, psi_j, hj = layer2(s1_j, W2, b2, beta2)
    E_j, Eb_j = eligibility(s1_j, psi_j, beta2)
    pj = sigmoid(hj @ w + b)
    err = float(g[j]) * (pos_w if y[j] == 1 else 1.0) * (pj - y[j])
    gw += err * hj;  gb += err
    gW2 += err * (w[:, None] * E_j);  gb2 += err * (w * Eb_j)
    n_eff += 1

# Burst normalisation: average simultaneous arrivals to prevent ~60-label blowup
if n_eff > 0 and burst_norm:
    gw /= n_eff; gb /= n_eff; gW2 /= n_eff; gb2 /= n_eff

C. Causal 2-bit delta spike encoder (add/sub synapses, 65.4 KiB)

3. src/plasticity/spike_frontend.py — encode_spikes_2bit_delta()
def encode_spikes_2bit_delta(X_norm, thr_lvl=0.75, thr_del=0.5):
    """Strictly causal 2-bit ON/OFF level + temporal-delta encoder ((-1, 0, 1))."""
    dx = np.zeros_like(X_norm, dtype=np.float32)
    dx[:, 1:, :] = X_norm[:, 1:, :] - X_norm[:, :-1, :]
    on  = ((X_norm > thr_lvl) | (dx > thr_del)).astype(np.uint8)
    off = ((X_norm < -thr_lvl) | (dx < -thr_del)).astype(np.uint8)
    both = (on == 1) & (off == 1)
    on  = np.where(both, (X_norm >= 0).astype(np.uint8), on)
    off = np.where(both, (X_norm < 0).astype(np.uint8), off)
    return on, off  # Packed into 270 B + 8 B timestamp = 278 B/decision (65.4 KiB @ 15m)

Interactive Live Demo Notebook

Open Demo in Google Colab →

References

  1. Gunasekaran, S. et al. (2025). Future-Guided Learning for Seizure Prediction. Nature Communications.
  2. Bellec, G., Scherr, F., Subramoney, A., Hajek, E., Salaj, D., Legenstein, R., & Maass, W. (2020). A solution to the learning dilemma for recurrent networks of spiking neurons (e-prop). Nature Communications.
  3. Eshraghian, J. K., Ward, M., Neftci, E., Wang, X., Lenz, G., Dwivedi, G., Bennamoun, M., Jeong, D. S., & Lu, W. D. (2023). Training Spiking Neural Networks Using Lessons From Deep Learning (snnTorch). Proceedings of the IEEE.
  4. Shoeb, A. H. (2009). Application of Machine Learning to Epileptic Seizure Onset Detection and Treatment (CHB-MIT Scalp EEG Database). MIT PhD Thesis / PhysioNet.