Skip to content

Next-generation neural mass with theta forcing

The exact neural mass of quadratic integrate-and-fire neurons.

  • Class: NextGenerationNeuralMassSystem
  • Import: from skcomplex.systems.biology.neuroscience import NextGenerationNeuralMassSystem
  • Field: biology/neuroscience
  • Topics: neural mass, next generation, gamma oscillations, theta-gamma, ode
  • References:
    • Montbrió, Pazó, and Roxin 2015
    • Segneri et al. 2020

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 NextGenerationNeuralMassSystem

trajectory = NextGenerationNeuralMassSystem().prepare().simulate()

Parameters

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

Parameter Default
setup 'ping'
H_e 1.3
H_i None
J_ee 8.0
J_ie 10.0
J_ei 10.0
J_ii None
delta None
I0 None
nu 5.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
Randomness deterministic
Domains real
Structure fixed

Class

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

class NextGenerationNeuralMassSystem(BaseSystem):
    """The exact neural mass of quadratic integrate-and-fire neurons.

    Its gamma rhythm nests in a theta drive.

    In the `'ping'` setup an excitatory and an inhibitory population, with membrane time constants of 20 and 10 ms,
    couple through instantaneous synapses, and the theta current drives the excitatory one. In the `'ing'` setup a
    single inhibitory population inhibits itself through exponential synapses of 10 ms, and the current drives it.
    Without forcing the populations rest or oscillate collectively in the gamma band, about 45 Hz for `H_e = 10`, as
    their excitabilities cross a Hopf bifurcation. A slow theta current sweeps them across it, so gamma bursts appear at
    every theta peak, theta-nested gamma oscillations. The defaults are those of Segneri et al. (2020, figure 3). The
    system has the rates `excitatory.r` and `inhibitory.r`, in spikes per millisecond, and the potentials `excitatory.v`
    and `inhibitory.v`, or the inhibitory population alone in `'ing'`.

    Args:
        setup:
            `'ping'` for excitatory and inhibitory populations or `'ing'` for one inhibitory population.

        H_e:
            The median excitability of the excitatory population.

        H_i:
            The median excitability of the inhibitory population, or `None` for -5 in `'ping'` and 2 in `'ing'`.

        J_ee:
            The excitatory self-coupling of `'ping'`.

        J_ie:
            The inhibition of the excitatory population by the inhibitory one in `'ping'`.

        J_ei:
            The excitation of the inhibitory population by the excitatory one in `'ping'`.

        J_ii:
            The inhibitory self-coupling, or `None` for 0 in `'ping'` and 21 in `'ing'`.

        delta:
            The half-width of the excitabilities, or `None` for 1 in `'ping'` and 0.3 in `'ing'`.

        I0:
            The peak theta current, or `None` for 10 in `'ping'` and 9 in `'ing'`.

        nu:
            The theta frequency, in hertz.

        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.

    Raises:
        ValidationError:
            The setup is unknown.

    Examples:
        >>> from skcomplex.systems.biology.neuroscience import NextGenerationNeuralMassSystem
        >>> [element.label for element in NextGenerationNeuralMassSystem('ing').prepare().system_.elements]
        ['inhibitory']
    """

    field = 'biology/neuroscience'
    topics = ('neural mass', 'next generation', 'gamma oscillations', 'theta-gamma', 'ode')
    references = ('Montbrió, Pazó, and Roxin 2015', 'Segneri et al. 2020')
    until = 1000.0
    dt = 0.5

    def __init__(
        self,
        setup: str = 'ping',
        *,
        H_e: float = 1.3,
        H_i: float | None = None,
        J_ee: float = 8.0,
        J_ie: float = 10.0,
        J_ei: float = 10.0,
        J_ii: float | None = None,
        delta: float | None = None,
        I0: float | None = None,
        nu: float = 5.0,
        label: str = 'system',
        solver: BaseSolver | str = 'auto',
        backend: BaseBackend | str = 'auto',
    ) -> None:
        super().__init__(label, solver=solver, backend=backend)
        self.setup = setup
        self.H_e = H_e
        self.H_i = H_i
        self.J_ee = J_ee
        self.J_ie = J_ie
        self.J_ei = J_ei
        self.J_ii = J_ii
        self.delta = delta
        self.I0 = I0
        self.nu = nu

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

        Args:
            context:
                The observables to compile with the problem, or `None` for none.
        """
        super()._prepare(context)
        if self.setup not in SETUPS:
            error_msg = f'The setup must be one of {", ".join(SETUPS)}, not {self.setup!r}.'
            raise ValidationError(error_msg)
        if self.setup == 'ing':
            population = NeuralMassElement(
                'inhibitory',
                tau=10.0,
                delta=0.3 if self.delta is None else self.delta,
                H=2.0 if self.H_i is None else self.H_i,
            )
            self.system_ = System(
                self.label,
                elements=[population],
                interactions=[
                    NeuralMassInteraction('inhibitory_mean_field', target='inhibitory'),
                    SynapticDriveInteraction(
                        'ii',
                        target='inhibitory',
                        source='inhibitory',
                        J=-(21.0 if self.J_ii is None else self.J_ii),
                        field='s',
                    ),
                    ThetaForcingInteraction(
                        'theta',
                        target='inhibitory',
                        I0=9.0 if self.I0 is None else self.I0,
                        nu=self.nu,
                    ),
                ],
            )
            return
        width = 1.0 if self.delta is None else self.delta
        self.system_ = System(
            self.label,
            elements=[
                NeuralMassElement('excitatory', tau=20.0, delta=width, H=self.H_e),
                NeuralMassElement('inhibitory', tau=10.0, delta=width, H=-5.0 if self.H_i is None else self.H_i),
            ],
            interactions=[
                NeuralMassInteraction('excitatory_mean_field', target='excitatory'),
                NeuralMassInteraction('inhibitory_mean_field', target='inhibitory'),
                SynapticDriveInteraction('ee', target='excitatory', source='excitatory', J=self.J_ee),
                SynapticDriveInteraction('ie', target='excitatory', source='inhibitory', J=-self.J_ie),
                SynapticDriveInteraction('ei', target='inhibitory', source='excitatory', J=self.J_ei),
                SynapticDriveInteraction(
                    'ii',
                    target='inhibitory',
                    source='inhibitory',
                    J=-(0.0 if self.J_ii is None else self.J_ii),
                ),
                ThetaForcingInteraction(
                    'theta',
                    target='excitatory',
                    I0=10.0 if self.I0 is None else self.I0,
                    nu=self.nu,
                ),
            ],
        )

Components

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

Elements:

Interactions:

  • NeuralMassInteraction, from Interaction
  • SynapticDriveInteraction, from Interaction
  • ThetaForcingInteraction, from Interaction
class NeuralMassElement(Element):
    """Population of quadratic integrate-and-fire neurons in an exact mean field.

    The mean field is the one of Montbrió, Pazó, and Roxin.

    The excitabilities of the neurons follow a Lorentzian distribution of median `H` and half-width `delta`, so the
    firing rate `r` and the mean membrane potential `v` of the population follow `dr/dt = delta / (tau^2 pi) + 2 r v
    / tau` and `dv/dt = (v^2 + H) / tau - tau (pi r)^2` exactly, with the membrane time constant `tau`. The synaptic
    field `s` filters the rate with exponential synapses, `ds/dt = (r - s) / tau_d`. The element holds the states and
    parameters, a `NeuralMassInteraction` gives these laws, and couplings and inputs add to the rate of `v`.

    Args:
        label:
            The label of the population.

        r:
            The initial firing rate, in spikes per millisecond.

        v:
            The initial mean membrane potential.

        s:
            The initial synaptic field.

        tau:
            The membrane time constant, in milliseconds.

        delta:
            The half-width of the Lorentzian excitabilities.

        H:
            The median of the Lorentzian excitabilities.

        tau_d:
            The decay time of the synapses, in milliseconds.

    Examples:
        >>> from skcomplex.systems.biology.neuroscience import NeuralMassElement
        >>> NeuralMassElement('excitatory', tau=20.0).tau
        20.0
    """

    def __init__(
        self,
        label: str,
        *,
        r: Annotated[float, RealSet.closed_open(0, oo)] = 0.01,
        v: float = -1.0,
        s: Annotated[float, RealSet.closed_open(0, oo)] = 0.0,
        tau: Annotated[float, RealSet.open(0, oo)] = 20.0,
        delta: Annotated[float, RealSet.open(0, oo)] = 1.0,
        H: float = -5.0,
        tau_d: Annotated[float, RealSet.open(0, oo)] = 10.0,
    ) -> None:
        super().__init__(label)
        self.r = r
        self.v = v
        self.s = s
        self.tau = tau
        self.delta = delta
        self.H = H
        self.tau_d = tau_d

class NeuralMassInteraction(Interaction):
    """Exact mean-field dynamics of one population of quadratic integrate-and-fire neurons.

    It gives the population of its target the rate `dr/dt = delta / (tau^2 pi) + 2 r v / tau`, the potential
    `dv/dt = (v^2 + H) / tau - tau (pi r)^2`, and the synaptic field `ds/dt = (r - s) / tau_d`, with the parameters of
    the target.

    Args:
        label:
            The label of the interaction.

        target:
            The path of the population.

    Examples:
        >>> from skcomplex.systems.biology.neuroscience import NeuralMassInteraction
        >>> NeuralMassInteraction('mean_field', target='e').target
        'e'
    """

    law_classes = (RateLaw,)

    def __init__(self, label: str, *, target: Role) -> None:
        super().__init__(label)
        self.target = target

    def _prepare(self, context: SimpleNamespace) -> None:
        """Set the mean-field rate, potential, and synaptic field of the target.

        Args:
            context:
                The namespace of the target, the time `t`, and the parameters.
        """
        super()._prepare(context)
        p = context.target
        self.laws_ = [
            RateLaw(p.r, p.delta / (p.tau**2 * pi) + 2 * p.r * p.v / p.tau),
            RateLaw(p.v, (p.v**2 + p.H) / p.tau - p.tau * (pi * p.r) ** 2),
            RateLaw(p.s, (p.r - p.s) / p.tau_d),
        ]

class SynapticDriveInteraction(Interaction):
    """Synaptic drive of a population by another, `dv/dt += J x`.

    The drive is by the rate or the synaptic field of the other population.

    Instantaneous synapses pass the firing rate `r` of the source, and exponential synapses its synaptic field `s`. A
    negative strength `J` is inhibition.

    Args:
        label:
            The label of the interaction.

        target:
            The path of the driven population.

        source:
            The path of the driving population, which may be the target.

        J:
            The strength of the synapses, negative for inhibition.

        field:
            `'r'` for instantaneous synapses or `'s'` for exponential synapses.

    Raises:
        ValidationError:
            The field is unknown.

    Examples:
        >>> from skcomplex.systems.biology.neuroscience import SynapticDriveInteraction
        >>> SynapticDriveInteraction('ie', target='e', source='i', J=-10.0).J
        -10.0
    """

    law_classes = (RateLaw,)

    def __init__(
        self,
        label: str,
        *,
        target: Role,
        source: Role,
        J: float = 1.0,
        field: str = 'r',
    ) -> None:
        super().__init__(label)
        self.target = target
        self.source = source
        self.J = J
        self.field = field

    def _check_arguments(self) -> None:
        """Raise an error for an argument the interaction cannot take.

        Raises:
            ValidationError:
                The field is unknown.
        """
        super()._check_arguments()
        if self.field not in FIELDS:
            error_msg = f'The field must be one of {", ".join(FIELDS)}, not {self.field!r}.'
            raise ValidationError(error_msg)

    def _prepare(self, context: SimpleNamespace) -> None:
        """Set the drive of the potential of the target.

        Args:
            context:
                The namespace of the target and the source, the time `t`, and the parameters.
        """
        super()._prepare(context)
        s = context
        self.laws_ = [RateLaw(s.target.v, s.J * getattr(s.source, self.field))]

class ThetaForcingInteraction(Interaction):
    """Theta forcing of a population by the current `I0 (1 - cos(2 pi nu t)) / 2`.

    The forcing is as in optogenetic stimulation.

    The current enters the potential of the population as its excitabilities do, `dv/dt += I(t) / tau`. Time is in
    milliseconds and the frequency `nu` in hertz.

    Args:
        label:
            The label of the interaction.

        target:
            The path of the forced population.

        I0:
            The peak current.

        nu:
            The frequency of the forcing, in hertz.

    Examples:
        >>> from skcomplex.systems.biology.neuroscience import ThetaForcingInteraction
        >>> ThetaForcingInteraction('theta', target='e', nu=8.0).nu
        8.0
    """

    law_classes = (RateLaw,)

    def __init__(
        self,
        label: str,
        *,
        target: Role,
        I0: float = 10.0,
        nu: Annotated[float, RealSet.closed_open(0, oo)] = 5.0,
    ) -> None:
        super().__init__(label)
        self.target = target
        self.I0 = I0
        self.nu = nu

    def _prepare(self, context: SimpleNamespace) -> None:
        """Set the forcing current of the potential.

        Args:
            context:
                The namespace of the target, the time `t`, and the parameters.
        """
        super()._prepare(context)
        s = context
        current = s.I0 / 2 * (1 - cos(2 * pi * s.nu * s.t / 1000))
        self.laws_ = [RateLaw(s.target.v, current / s.target.tau)]

Equations

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

excitatory.r: diff(r_excitatory(t), t) == 2*r_excitatory(t)*v_excitatory(t)/tau_excitatory + delta_excitatory/(pi*tau_excitatory^2)
excitatory.v: diff(v_excitatory(t), t) == -pi^2*tau_excitatory*r_excitatory(t)^2 + J_ee*r_excitatory(t) + J_ie*r_inhibitory(t) - 1/2*I0_theta*(cos(1/500*pi*nu_theta*t) - 1)/tau_excitatory + (v_excitatory(t)^2 + H_excitatory)/tau_excitatory
excitatory.s: diff(s_excitatory(t), t) == (r_excitatory(t) - s_excitatory(t))/tau_d_excitatory
inhibitory.r: diff(r_inhibitory(t), t) == 2*r_inhibitory(t)*v_inhibitory(t)/tau_inhibitory + delta_inhibitory/(pi*tau_inhibitory^2)
inhibitory.v: diff(v_inhibitory(t), t) == -pi^2*tau_inhibitory*r_inhibitory(t)^2 + J_ei*r_excitatory(t) + J_ii*r_inhibitory(t) + (v_inhibitory(t)^2 + H_inhibitory)/tau_inhibitory
inhibitory.s: diff(s_inhibitory(t), t) == (r_inhibitory(t) - s_inhibitory(t))/tau_d_inhibitory