Simulation-Based Inference for LIF Neurons
Training an amortized neural posterior estimator (CNN + GRU summary network and CouplingFlow) in BayesFlow 2 to infer six biophysical Leaky Integrate-and-Fire neuron parameters directly from 50 ms voltage traces without an explicit likelihood.
Held-out test recovery (400 traces, 1,000 posterior draws each): E_L = 1.000, V_res = 1.000, t_ref = 0.999, V_th = 0.998.
8,000 train / 2,000 validation plus 400 unseen test traces (50 ms window at 0.1 ms step = 501 voltage samples).
Trained 100 epochs (Adam, batch 64, ReduceLROnPlateau) on an RTX 3070 Laptop GPU with clean convergence and no overfitting.
Passive parameters drop to r = 0.491 and r = 0.046 with near-zero contraction, exposing structural confounding via tau_m = Cm/g_L.
Why this mattered
Mechanistic neuron models like Leaky Integrate-and-Fire (LIF) are straightforward to simulate forward, but discrete spike thresholds, voltage resets, refractory holdouts, and stochastic colored synaptic currents make the analytical likelihood intractable for standard MCMC. Simulation-based inference (SBI) bypasses the likelihood by learning a neural posterior directly from simulated parameter-trace pairs, while also showing which biophysical parameters are genuinely identifiable from voltage recordings alone.
What I built and owned
Completed in a 3-person M.Sc. Data Science group (with Harsh Rana and Siddhartha Karki) in Prof. Dr. Paul Bürkner's Simulation-Based Inference course at TU Dortmund (Aug 2025). I authored and ran the full Python pipeline in the repository: implementing the LIF Euler integrator, ordered biophysical prior sampler (V_res < E_L < V_th), colored synaptic current generator, BayesFlow 2 TimeSeriesNetwork + CouplingFlow training script on GPU, and all recovery, SBC, contraction, and predictive check diagnostics.
Simulator, Amortized Estimator & Diagnostics
6 Biophysical Priors & Colored Input
Simulated 10,000 single-compartment LIF voltage traces over 50 ms (dt = 0.1 ms, 501 time steps) with explicit Euler integration. Sampled six uniform biophysical priors (Cm, g_L, E_L, V_th, V_res, t_ref) under an enforced V_res < E_L < V_th ordering constraint, driven by an exponentially filtered colored synaptic current (tau = 10 ms, 10 Hz modulation) with random per-trial amplitude A in [0.3, 3.0] nA.
CNN + GRU Encoder & CouplingFlow
Wrapped the batched simulator in BayesFlow 2 BasicWorkflow with float32 casting and z-score standardization via Adapter. Coupled a TimeSeriesNetwork (1D CNN + GRU) to summarize each 501-step voltage trace with a conditional CouplingFlow normalizing flow. Trained offline on an 8,000/2,000 split for 100 epochs (Adam lr = 1e-3, batch 64, ReduceLROnPlateau, ModelCheckpoint), reaching best validation loss -8.1362 at epoch 95.
Recovery, SBC, Contraction & PPC
Evaluated amortized posteriors on 400 unseen test traces (1,000 posterior draws per trace) plus BayesFlow default diagnostics on the 2,000-trace validation set (500 draws). Audited point recovery (Pearson r), rank-based Simulation-Based Calibration (SBC) ECDFs against 95% uniformity bands, posterior z-score vs. contraction plots, and posterior predictive voltage overlays re-simulated through the full stochastic LIF model.
Six-Parameter Biophysical Prior Ranges & Posterior Diagnostics
Test recovery measured on 400 held-out traces (1,000 posterior draws each); posterior contraction and SBC measured on 2,000 validation traces (500 draws each).
| Parameter | Prior Support | Test Pearson r | Posterior Contraction | Identifiability & Calibration |
|---|---|---|---|---|
| E_L (Resting potential) | [-80, -65] mV | 1.000 | ~1.00 (Sharp) | Near-exact recovery; slight positive SBC rank shift |
| V_res (Reset potential) | [-80, -70] mV (< E_L) | 1.000 | ~1.00 (Sharp) | Near-exact recovery; SBC shift linked to -80 mV clip boundary |
| t_ref (Refractory period) | [1, 5] ms | 0.999 | ~1.00 (Sharp) | Sharp recovery; rank ECDF well inside 95% band |
| V_th (Spike threshold) | [-60, -50] mV | 0.998 | ~1.00 (Sharp) | Sharp recovery; rank ECDF well inside 95% band |
| Cm (Membrane capacitance) | [100, 200] pF | 0.491 | Low (0.0 to 0.5) | Weakly identified; confounded through tau_m = Cm / g_L |
| g_L (Leak conductance) | [5, 15] nS | 0.046 | Near 0 (Prior-like) | Unidentifiable under unobserved varying input amplitude A |
Ordering V_res < E_L < V_th is enforced by shifting violating draws by 2 to 5 mV and clipping back to prior bounds. Validation recovery (2,000 traces, 500 draws) closely mirrors test recovery (Cm = 0.432, g_L = 0.066, E_L = 1.000, V_th = 0.998, V_res = 1.000, t_ref = 0.999).
Posterior Diagnostics & Simulator Checks
Plots exported directly from main.ipynb and BayesFlow 2 diagnostic routines. Click any figure to inspect full resolution.
Key Takeaways
- Once trained (~12 minutes on an RTX 3070 Laptop GPU), the amortized CouplingFlow generates 1,000 posterior draws per voltage trace in seconds without deriving or evaluating an explicit likelihood.
- Weak recovery on Cm (r = 0.491) and g_L (r = 0.046) reflects a structural identifiability limit, not failed optimization: when per-trial input amplitude A varies unobserved, subthreshold voltage mainly depends on the ratios tau_m = Cm/g_L and R_m = 1/g_L.
- Reading SBC rank ECDFs alongside point recovery exposed subtle sub-millivolt calibration shifts on E_L and V_res that Pearson r = 1.000 hides, partly tied to clipping V_res at -80 mV when enforcing V_res < E_L.
- Practical next steps to unlock passive parameters: reparameterize inference to (tau_m, R_m) or record/fix input current amplitude A, extend recording windows from 50 ms to 200-500 ms using multi-level step and chirp stimuli, and replace boundary clipping with rejection sampling for V_res < E_L.