Leaky Integrate-and-Fire (LIF)

The LIF model treats the heart's sinoatrial node as a biological pacemaker neuron. Each heartbeat corresponds to a membrane voltage threshold crossing, producing an inter-beat interval (IBI) directly in physiological time (milliseconds).

Theory

The sinoatrial node drives cardiac rhythm by spontaneously depolarizing and then resetting after each beat. The leaky integrate-and-fire model captures this with a single first-order ODE:

\[\tau \frac{dV}{dt} = -(V - V_{rest}) + R \cdot I\]

The membrane potential $V$ rises toward the fixed point $V^* = V_{rest} + R \cdot I$. When $V$ crosses $V_{threshold}$ (upward), a spike (heartbeat) is recorded and $V$ is immediately reset to $V_{reset}$.

Analytical Period Formula

For constant current $I$ with $V^* > V_{threshold}$ (a necessary condition for repetitive firing), the inter-spike period has a closed form:

\[T = \tau \cdot \ln\!\left(\frac{R \cdot I}{R \cdot I - \Delta V}\right), \quad \Delta V = V_{threshold} - V_{rest}\]

Inverting for the current that produces a target period $T$:

\[I(T) = \frac{\Delta V}{R \cdot \left(1 - e^{-T/\tau}\right)}\]

This inverse formula is the basis of the :analytical fitting method, which applies it to each measured IBI individually.

Parameters

Fixed Physiological Parameters

These are set at construction and are not fitted. They reflect biologically plausible values for the human sinoatrial node.

ParameterDefaultUnitDescription
τ200.0msMembrane time constant
V_rest−65.0mVResting potential
V_reset−65.0mVPost-spike reset potential (equals V_rest)
V_threshold−60.0mVSpike threshold
R10.0MΩMembrane resistance

Fitted Parameter

ParameterRangeDefaultDescription
I1.48 – 1.561.52Input current; encodes autonomic drive and target heart rate

The bounds on I are set in parameter_space(::LIF). Higher I values drive faster firing; lower values produce slower rhythms. Use fit to determine the I that best matches a measured IBI series.

Fitting Methods

MethodSpeedOutputNotes
:analyticalInstantPer-beat $I$ seriesNo simulation needed; exact inversion
:gradientFastScalar $I$Brent univariate optimization; minimizes RMSE
:bayesianSlowPosterior over $I$NUTS MCMC (Turing.jl); provides uncertainty

Examples

Create and Simulate

using HeartRateLab

# Create model with physiological defaults
lif = LIF()

# Simulate 500 inter-beat intervals
params = (I = 1.52,)
ibis = simulate(lif, params, 500)

using Statistics
println("Mean IBI: ", round(mean(ibis); digits=1), " ms")
println("Heart rate: ", round(60000 / mean(ibis)), " bpm")

Fit with Analytical Method

The analytical method is the fastest option. It returns a per-beat current series capturing how autonomic drive varies across the recording.

using HeartRateLab

lif = LIF()
ibis = read_txt("data.txt")

result = fit(lif, ibis; method=:analytical)

println("Mean I:  ", round(result.params.I; digits=4))
println("Std(I):  ", round(result.diagnostics["I_std"]; digits=4))

# Per-beat current series: same length as ibis
I_series = parameter_series(result, :I)
println("I range: ", round.(extrema(I_series); digits=4))

# Simulate from the mean fitted I
synthetic = simulate(result.model, result.params, length(ibis))

Fit with Gradient Method

using HeartRateLab

lif = LIF()
ibis = read_txt("data.txt")

result = fit(lif, ibis; method=:gradient)

println("Fitted I:    ", round(result.params.I; digits=4))
println("Converged:   ", result.diagnostics["converged"])
println("Final RMSE:  ", round(result.diagnostics["loss_final"]; digits=2), " ms")

# Generate synthetic IBIs
synthetic = simulate(result.model, result.params, length(ibis))

API Reference

HeartRateLab.Models.LIF — Type
LIF <: AbstractHRVModel

Leaky Integrate-and-Fire cardiac pacemaker model for HRV simulation. Models the heart's sinoatrial node as a pacemaker neuron.

Parameters

  • τ: Membrane time constant (ms) — sets the intrinsic inter-beat timescale
  • V_rest: Resting potential (mV)
  • V_reset: Reset potential (mV) after each spike (typically equals V_rest)
  • V_threshold: Spike threshold (mV)
  • R: Membrane resistance — scales input current to voltage units

Fitted Parameter

  • I: Input current — sole free parameter; encodes autonomic drive and heart rate

Model Equation

τ dV/dt = -(V - V_rest) + R*I

When V crosses Vthreshold (upward), a spike occurs and V resets to Vreset. The inter-beat interval (IBI) is the time between consecutive spikes, directly in milliseconds — no post-hoc scaling is applied.

Period Formula (analytical)

With ΔV = Vthreshold - Vrest and nullcline V* = Vrest + R·I (requires V* > Vthreshold): T = τ · ln(R·I / (R·I - ΔV)) Inverse (desired period → required I): I = ΔV / (R · (1 - exp(-T/τ)))

source
HeartRateLab.Models.parameter_space — Method
parameter_space(model::LIF) -> NamedTuple

Return the parameter space for LIF model (only I is fitted).

Bounds are derived analytically from the model's own parameters using I(T) = ΔV / (R · (1 - exp(-T/τ))) so they automatically adapt when τ, R, or the voltage parameters change.

Derived bounds

  • lower ↔ T_max = 3000 ms (very slow heart rate, ~20 bpm)
  • upper ↔ T_min = 300 ms (very fast heart rate, ~200 bpm)
  • center ↔ T_center = 800 ms (~75 bpm, normal resting)
source
HeartRateLab.Models.simulate — Method
simulate(model::LIF, params::NamedTuple, n_beats::Int) -> Vector{Float64}

Simulate IBI time series using LIF cardiac pacemaker with DifferentialEquations.jl.

Uses callback-based spike detection for accurate IBI measurement.

Parameters

  • I: Input current (from params or model default)

Model

Leaky Integrate-and-Fire ODE: τ dV/dt = -(V - V_rest) + R·I

When V crosses Vthreshold (upward), a spike occurs and V resets to Vreset.

Returns

Vector of n_beats inter-beat intervals in milliseconds (spike-time differences, no rescaling applied — model time IS physiological time).

source
HeartRateLab.Models.fit — Method
fit(model::LIF, data::Vector{Float64}; method=:bayesian, kwargs...) -> ModelFitResult

Fit LIF model to IBI data using Bayesian inference, gradient-based optimization, or the closed-form analytical solution.

Only the I parameter is fitted; physiological parameters (τ, Vrest, R, Vthreshold) are fixed.

Methods

  • :analytical — Inverts the period formula T = τ·ln(R·I / (R·I - ΔV)) for every IBI individually, yielding a per-beat I series. params.I is the mean; the full series is stored in result.posterior["I"]. Instantaneous, no simulation required.
  • :gradient — Brent univariate optimisation minimising RMSE of simulated IBIs.
  • :bayesian — NUTS sampler via Turing.jl.
source