Skip to content

Integrate-and-fire

The leaky integrate-and-fire neuron, tau v' = -(v - rest) + R I.

  • Class: IntegrateAndFireSystem
  • Import: from skcomplex.systems.biology.neuroscience import IntegrateAndFireSystem
  • Field: biology/neuroscience
  • Topics: neuron, spiking, events
  • References:
    • Lapicque 1907
    • Gerstner et al. 2014

Use this system

The block imports the class and simulates the system with its default parameters and its tuned run settings.

from skcomplex.systems.biology.neuroscience import IntegrateAndFireSystem

trajectory = IntegrateAndFireSystem().prepare().simulate()

Parameters

The model parameters take these defaults, and set_params changes them.

Parameter Default
v -65.0
rest -65.0
threshold -50.0
reset -65.0
resistance 10.0
tau 10.0
I 2.0
solver 'auto'
backend 'auto'

Tags

The system with its default parameters has these capability tags, which solvers and analyses check.

Tag Values
Time continuous
Space none
Laws rate, update
Randomness deterministic
Domains real
Structure fixed

Class

The source of the class shows how it builds its components from its model parameters.

class IntegrateAndFireSystem(BaseSystem):
    """The leaky integrate-and-fire neuron, `tau v' = -(v - rest) + R I`.

    It spikes and resets at a threshold.

    With `R I` above `threshold - rest` it fires periodically with period `tau ln(R I / (R I - threshold + rest))` when
    `reset = rest`. The system has the membrane potential `neuron.v` and its spikes recorded as `spike` events.

    Args:
        v:
            The initial membrane potential in mV.

        rest:
            The resting potential in mV.

        threshold:
            The potential at which the neuron spikes in mV.

        reset:
            The potential after a spike in mV.

        resistance:
            The membrane resistance in MΩ.

        tau:
            The membrane time constant in ms.

        I:
            The input current in nA.

        label:
            The label of the system, which names it when it is nested in another one.

        solver:
            The solver of the problem, or `'auto'` for the one the system chooses.

        backend:
            The backend that evaluates the compiled functions, or `'auto'` for the one the system chooses.

    Examples:
        >>> from skcomplex.systems.biology.neuroscience import IntegrateAndFireSystem
        >>> trajectory = IntegrateAndFireSystem().prepare().simulate(until=50.0, dt=0.1)
        >>> round(trajectory.events[0].time, 2)
        13.86
    """

    field = 'biology/neuroscience'
    topics = ('neuron', 'spiking', 'events')
    references = ('Lapicque 1907', 'Gerstner et al. 2014')
    until = 100.0
    dt = 0.1

    def __init__(
        self,
        v: float = -65.0,
        *,
        rest: float = -65.0,
        threshold: float = -50.0,
        reset: float = -65.0,
        resistance: float = 10.0,
        tau: float = 10.0,
        I: float = 2.0,
        label: str = 'system',
        solver: BaseSolver | str = 'auto',
        backend: BaseBackend | str = 'auto',
    ) -> None:
        super().__init__(label, solver=solver, backend=backend)
        self.v = v
        self.rest = rest
        self.threshold = threshold
        self.reset = reset
        self.resistance = resistance
        self.tau = tau
        self.I = I

    def _prepare(self, context: Sequence[Observable] | None = None) -> None:
        """Set the system of the leaky integrate-and-fire neuron.

        Args:
            context:
                The observables to compile with the problem, or `None` for none.
        """
        super()._prepare(context)
        neuron = LeakyIntegrateAndFireElement('neuron', v=self.v)
        membrane = LeakyIntegrateAndFireInteraction(
            'membrane',
            target='neuron',
            rest=self.rest,
            resistance=self.resistance,
            tau=self.tau,
            I=self.I,
        )
        spike = SpikeResetInteraction('spike', target='neuron', threshold=self.threshold, after=self.reset)
        self.system_ = System(self.label, elements=[neuron], interactions=[membrane, spike])

Components

The system uses these element and interaction classes, each with its nearest class of the core.

Elements:

  • LeakyIntegrateAndFireElement, from Element

Interactions:

  • LeakyIntegrateAndFireInteraction, from Interaction
  • SpikeResetInteraction, from Interaction
class LeakyIntegrateAndFireElement(Element):
    """Leaky integrate-and-fire neuron with the potential `v`.

    Args:
        label:
            The label of the neuron.

        v:
            The initial potential.

    Examples:
        >>> from skcomplex.systems.biology.neuroscience import LeakyIntegrateAndFireElement
        >>> LeakyIntegrateAndFireElement('neuron').v
        -65.0
    """

    def __init__(self, label: str, *, v: float = -65.0) -> None:
        super().__init__(label)
        self.v = v

class LeakyIntegrateAndFireInteraction(Interaction):
    """Leak of the potential of a neuron towards `rest + resistance I` over the time `tau`.

    The potential follows `tau v' = -(v - rest) + resistance I`. A spike reset fires the neuron. Units are mV, ms, MΩ,
    and nA.

    Args:
        label:
            The label of the interaction.

        target:
            The path of the neuron, with the potential `v`.

        rest:
            The resting potential.

        resistance:
            The membrane resistance.

        tau:
            The membrane time constant.

        I:
            The input current.

    Examples:
        >>> from skcomplex.systems.biology.neuroscience import LeakyIntegrateAndFireInteraction
        >>> LeakyIntegrateAndFireInteraction('membrane', target='neuron').tau
        10.0
    """

    law_classes = (RateLaw,)

    def __init__(
        self,
        label: str,
        *,
        target: Role,
        rest: float = -65.0,
        resistance: Annotated[float, RealSet.open(0, oo)] = 10.0,
        tau: Annotated[float, RealSet.open(0, oo)] = 10.0,
        I: float = 2.0,
    ) -> None:
        super().__init__(label)
        self.target = target
        self.rest = rest
        self.resistance = resistance
        self.tau = tau
        self.I = I

    def _prepare(self, context: SimpleNamespace) -> None:
        """Set the leaky integration of the input current.

        Args:
            context:
                The namespace of the neuron, the time `t`, and the parameters.
        """
        super()._prepare(context)
        s = context
        v = s.target.v
        self.laws_ = [RateLaw(v, (-(v - s.rest) + s.resistance * s.I) / s.tau)]

class SpikeResetInteraction(Interaction):
    """Spike of a neuron that resets its potential when it crosses a threshold upwards.

    When the potential `v` rises through `threshold`, it is set to `after`, and the state `kicked`, such as a recovery
    variable or a synaptic trace, grows by `kick`. Every spike is an event labelled by the interaction.

    Args:
        label:
            The label of the interaction and of its events.

        target:
            The path of the neuron.

        state:
            The name of the potential.

        threshold:
            The potential of a spike.

        after:
            The potential after a spike.

        kicked:
            The name of the state a spike increments, or `None` for none.

        kick:
            The increment of the kicked state at a spike.

    Raises:
        ValidationError:
            The direction is not -1, 0, or 1, or the guard or a new value is not a function.

    Examples:
        >>> from skcomplex.core.components.elements import Element
        >>> from skcomplex.core.systems import System
        >>> from skcomplex.systems.biology.common.pharmacokinetics import DosingInteraction
        >>> from skcomplex.systems.biology.neuroscience import SpikeResetInteraction
        >>> drive = DosingInteraction('drive', target='neuron', state='x', dose=1.0)
        >>> spike = SpikeResetInteraction('spike', target='neuron', state='x', threshold=1.0, after=0.0)
        >>> system = System(elements=[Element('neuron', values={'x': 0.0})], interactions=[drive, spike])
        >>> trajectory = system.prepare().simulate(until=2.1, dt=0.25)
        >>> [round(event.time, 6) for event in trajectory.events]
        [1.0, 2.0]
    """

    law_classes = (EventLaw,)

    def __init__(
        self,
        label: str,
        *,
        target: Role,
        state: str = 'v',
        threshold: float = 1.0,
        after: float = 0.0,
        kicked: str | None = None,
        kick: float = 0.0,
    ) -> None:
        super().__init__(label)
        self.target = target
        self.state = state
        self.threshold = threshold
        self.after = after
        self.kicked = kicked
        self.kick = kick

    def _prepare(self, context: SimpleNamespace) -> None:
        """Set the spike, an event when the potential rises through the threshold.

        Args:
            context:
                The namespace of the neuron, the threshold, the potential after a spike, and the kick.
        """
        super()._prepare(context)
        neuron = context.target
        potential = getattr(neuron, self.state)
        reset = {potential: context.after}
        if self.kicked is not None:
            kicked = getattr(neuron, self.kicked)
            reset[kicked] = kicked + context.kick
        self.laws_: list[BaseLaw] = [EventLaw(potential - context.threshold, reset, 1, label=self.label)]

Equations

The equations are those that symbolic returns for the system with its default parameters.

neuron.v: diff(v_neuron(t), t) == (I_membrane*resistance_membrane + rest_membrane - v_neuron(t))/tau_membrane