Skip to content

Wilson-Cowan

The Wilson-Cowan system of interacting excitatory and inhibitory populations.

  • Class: WilsonCowanSystem
  • Import: from skcomplex.systems.biology.neuroscience import WilsonCowanSystem
  • Field: biology/neuroscience
  • Topics: neural mass, oscillations, excitation-inhibition
  • References:
    • Wilson and Cowan 1972
    • arXiv:2112.12147

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 WilsonCowanSystem

trajectory = WilsonCowanSystem().prepare().simulate()

Parameters

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

Parameter Default
E 0.1
I 0.05
P 1.25
Q 0.0
c1 16.0
c2 12.0
c3 15.0
c4 3.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 WilsonCowanSystem(BaseSystem):
    """The Wilson-Cowan system of interacting excitatory and inhibitory populations.

    The populations are made of neurons.

    With the published couplings, a moderate excitatory input `P = 1.25` gives a limit cycle of population activity, and
    no input lets the activity decay to rest. The system has the activities `cortex.E` and `cortex.I`.

    Args:
        E:
            The initial excitatory activity.

        I:
            The initial inhibitory activity.

        P:
            The external input to the excitatory population.

        Q:
            The external input to the inhibitory population.

        c1:
            The excitatory to excitatory coupling.

        c2:
            The inhibitory to excitatory coupling.

        c3:
            The excitatory to inhibitory coupling.

        c4:
            The inhibitory to inhibitory coupling.

        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 WilsonCowanSystem
        >>> WilsonCowanSystem(P=0.0).prepare().system_.elements[0].P
        0.0
    """

    field = 'biology/neuroscience'
    topics = ('neural mass', 'oscillations', 'excitation-inhibition')
    references = ('Wilson and Cowan 1972', 'arXiv:2112.12147')
    until = 100.0
    dt = 0.2

    def __init__(
        self,
        E: float = 0.1,
        I: float = 0.05,
        *,
        P: float = 1.25,
        Q: float = 0.0,
        c1: float = 16.0,
        c2: float = 12.0,
        c3: float = 15.0,
        c4: float = 3.0,
        label: str = 'system',
        solver: BaseSolver | str = 'auto',
        backend: BaseBackend | str = 'auto',
    ) -> None:
        super().__init__(label, solver=solver, backend=backend)
        self.E = E
        self.I = I
        self.P = P
        self.Q = Q
        self.c1 = c1
        self.c2 = c2
        self.c3 = c3
        self.c4 = c4

    @staticmethod
    def _get_response(x: Expression, gain: Expression, threshold: Expression) -> Expression:
        """Return the response `logistic(x) - logistic(0)` of a sigmoid.

        The sigmoid has a gain and a threshold, and the response is 0 at no input.
        """
        response: Expression = logistic(x, threshold, 1 / gain) - logistic(0, threshold, 1 / gain)
        return response

    @staticmethod
    def _get_saturation(gain: Expression, threshold: Expression) -> Expression:
        """Return the largest value of the response of a sigmoid of a gain and a threshold."""
        saturation: Expression = 1 - logistic(0, threshold, 1 / gain)
        return saturation

    def _get_excitation(self, s: SimpleNamespace) -> Expression:
        """Return the response of the Wilson-Cowan excitatory population to its input."""
        c = s.target
        excitation: Expression = (self._get_saturation(c.a_e, c.theta_e) - c.r_e * c.E) * self._get_response(
            c.c1 * c.E - c.c2 * c.I + c.P,
            c.a_e,
            c.theta_e,
        )
        return excitation

    def _get_inhibition(self, s: SimpleNamespace) -> Expression:
        """Return the response of the Wilson-Cowan inhibitory population to its input."""
        c = s.target
        inhibition: Expression = (self._get_saturation(c.a_i, c.theta_i) - c.r_i * c.I) * self._get_response(
            c.c3 * c.E - c.c4 * c.I + c.Q,
            c.a_i,
            c.theta_i,
        )
        return inhibition

    def _prepare(self, context: Sequence[Observable] | None = None) -> None:
        """Set the Wilson-Cowan system of interacting excitatory and inhibitory populations.

        Args:
            context:
                The observables to compile with the problem, or `None` for none.
        """
        super()._prepare(context)
        cortex = WilsonCowanElement(
            'cortex',
            E=self.E,
            I=self.I,
            P=self.P,
            Q=self.Q,
            c1=self.c1,
            c2=self.c2,
            c3=self.c3,
            c4=self.c4,
        )
        relaxations = [
            LeakyIntegrationInteraction(
                'excitatory_relaxation',
                target='cortex',
                state='E',
                goal=self._get_excitation,
                time=lambda s: s.target.tau_e,
            ),
            LeakyIntegrationInteraction(
                'inhibitory_relaxation',
                target='cortex',
                state='I',
                goal=self._get_inhibition,
                time=lambda s: s.target.tau_i,
            ),
        ]
        self.system_ = System(self.label, elements=[cortex], interactions=relaxations)

Components

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

Elements:

Interactions:

  • LeakyIntegrationInteraction, from Interaction
class WilsonCowanElement(Element):
    """Excitatory and inhibitory populations of Wilson and Cowan.

    The populations are fractions of active cells.

    The excitatory activity follows `tau_e E' = -E + (k_e - r_e E) S_e(c1 E - c2 I + P)` and the inhibitory activity
    `tau_i I' = -I + (k_i - r_i I) S_i(c3 E - c4 I + Q)`, where `S(x) = 1 / (1 + exp(-a (x - theta))) - 1 / (1 +
    exp(a theta))` is a sigmoid shifted to vanish at zero input and `k` is its largest value. The element holds the
    states and parameters and has no laws of its own: the relaxations of `WilsonCowanSystem` read its parameters.

    Args:
        label:
            The label of the populations.

        E:
            The initial excitatory activity.

        I:
            The initial inhibitory activity.

        c1:
            The excitatory to excitatory coupling.

        c2:
            The inhibitory to excitatory coupling.

        c3:
            The excitatory to inhibitory coupling.

        c4:
            The inhibitory to inhibitory coupling.

        a_e:
            The gain of the excitatory response.

        theta_e:
            The threshold of the excitatory response.

        a_i:
            The gain of the inhibitory response.

        theta_i:
            The threshold of the inhibitory response.

        r_e:
            The refractory period of excitatory cells.

        r_i:
            The refractory period of inhibitory cells.

        P:
            The external input to the excitatory population.

        Q:
            The external input to the inhibitory population.

        tau_e:
            The time constant of the excitatory population.

        tau_i:
            The time constant of the inhibitory population.

    Examples:
        >>> from skcomplex.systems.biology.neuroscience import WilsonCowanElement
        >>> WilsonCowanElement('cortex', P=1.25).c1
        16.0
    """

    def __init__(
        self,
        label: str,
        *,
        E: Annotated[float, RealSet.closed_open(0, oo)] = 0.1,
        I: Annotated[float, RealSet.closed_open(0, oo)] = 0.05,
        c1: Annotated[float, RealSet.closed_open(0, oo)] = 16.0,
        c2: Annotated[float, RealSet.closed_open(0, oo)] = 12.0,
        c3: Annotated[float, RealSet.closed_open(0, oo)] = 15.0,
        c4: Annotated[float, RealSet.closed_open(0, oo)] = 3.0,
        a_e: Annotated[float, RealSet.open(0, oo)] = 1.3,
        theta_e: float = 4.0,
        a_i: Annotated[float, RealSet.open(0, oo)] = 2.0,
        theta_i: float = 3.7,
        r_e: Annotated[float, RealSet.closed_open(0, oo)] = 1.0,
        r_i: Annotated[float, RealSet.closed_open(0, oo)] = 1.0,
        P: float = 1.25,
        Q: float = 0.0,
        tau_e: Annotated[float, RealSet.open(0, oo)] = 1.0,
        tau_i: Annotated[float, RealSet.open(0, oo)] = 1.0,
    ) -> None:
        super().__init__(label)
        self.E = E
        self.I = I
        self.c1 = c1
        self.c2 = c2
        self.c3 = c3
        self.c4 = c4
        self.a_e = a_e
        self.theta_e = theta_e
        self.a_i = a_i
        self.theta_i = theta_i
        self.r_e = r_e
        self.r_i = r_i
        self.P = P
        self.Q = Q
        self.tau_e = tau_e
        self.tau_i = tau_i

class LeakyIntegrationInteraction(Interaction):
    """Leaky integration of a potential or an activity towards its input over a time constant.

    Neuroscience names it the leak of a membrane or of a population, as in the Wilson-Cowan and leaky integrate-and-fire
    models. The rate is `(goal(ns) - x) / time(ns)` of a state `x` of a target, with optional noise. With a constant
    goal and time and an additive noise of amplitude `sigma`, the state follows the Ornstein-Uhlenbeck process `dx =
    (goal - x) / time dt + sigma dW`, whose stationary variance is `sigma**2 time / 2`. A goal or a time function takes
    the namespace of the interaction, which reads the target as `ns.target` and the time as `ns.t`, and a number stands
    for a constant. A goal that is a number applies to every component of a vector state.

    Args:
        label:
            The label of the interaction, unique among the components of its system.

        target:
            The path of the element or group whose state relaxes.

        state:
            The name of the state of the target that relaxes.

        goal:
            A function of the namespace that returns the goal, or a number.

        time:
            A function of the namespace that returns the relaxation time, or a positive number.

        noise:
            A function of the namespace that returns the amplitude of the noise, a number, or `None` for no noise.

    Raises:
        ValidationError:
            The state is not a name, or a function is neither callable nor a number.

    Examples:
        >>> from skcomplex.core.components.elements import Element
        >>> from skcomplex.core.systems import System
        >>> from skcomplex.systems.biology.neuroscience import LeakyIntegrationInteraction
        >>> relaxation = LeakyIntegrationInteraction('relaxation', target='stock', goal=10.0, time=0.5)
        >>> system = System(elements=[Element('stock', values={'x': 0.0})], interactions=[relaxation]).prepare()
        >>> round(float(system.simulate(5.0, dt=0.01).get_values('stock.x')[-1]), 3)
        10.0
    """

    law_classes = (RateLaw, NoiseLaw)

    def __init__(
        self,
        label: str,
        *,
        target: Role,
        state: str = 'x',
        goal: Callable[[SimpleNamespace], object] | float = 0.0,
        time: Callable[[SimpleNamespace], object] | float = 1.0,
        noise: Callable[[SimpleNamespace], object] | float | None = None,
    ) -> None:
        super().__init__(label)
        self.target = target
        self.state = state
        self.goal = goal
        self.time = time
        self.noise = noise

    def _get_tags(self) -> Tags:
        """Return the tags of the rate, and of the noise when there is one."""
        return self._get_variant_tags((RateLaw,) if self.noise is None else (RateLaw, NoiseLaw))

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

        Raises:
            ValidationError:
                The state is not a name, or a function is neither callable nor a number.
        """
        super()._check_arguments()
        if not isinstance(self.state, str) or not self.state.isidentifier():
            error_msg = f'The state of {self.label!r} is {self.state!r}. Give the name of a state.'
            raise ValidationError(error_msg)
        for name in ('goal', 'time', 'noise'):
            value = getattr(self, name)
            if not (callable(value) or isinstance(value, int | float) or (name == 'noise' and value is None)):
                error_msg = f'The {name} of {self.label!r} is {value!r}. Give a function of the namespace or a number.'
                raise ValidationError(error_msg)

    def _prepare(self, context: SimpleNamespace) -> None:
        """Set the relaxation `(goal - x) / time` of the state, and its noise.

        Args:
            context:
                The namespace of the target.
        """
        super()._prepare(context)
        state = getattr(context.target, self.state)
        goal = self._broadcast(self._evaluate('goal', context), state)
        laws: list[BaseLaw] = [RateLaw(state, (goal - state) / self._evaluate('time', context))]
        if self.noise is not None:
            laws.append(NoiseLaw(state, self._evaluate('noise', context)))
        self.laws_ = laws

    def _evaluate(self, name: str, context: SimpleNamespace) -> object:
        """Return the value of a function of the namespace, or the symbol of a number."""
        value = getattr(self, name)
        return value(context) if callable(value) else getattr(context, name)

    @staticmethod
    def _broadcast(value: object, state: object) -> object:
        """Return a value with one component per component of a vector state, repeating a number."""
        if isinstance(state, FreeModuleElement) and not isinstance(value, FreeModuleElement | list | tuple):
            return vector(SR, [value] * len(state))
        return value

Equations

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

cortex.E: diff(E_cortex(t), t) == -1/4*((2*r_e_cortex*E_cortex(t) + tanh(-1/2*a_e_cortex*theta_e_cortex) - 1)*(tanh(1/2*(c1_cortex*E_cortex(t) - c2_cortex*I_cortex(t) + P_cortex - theta_e_cortex)*a_e_cortex) - tanh(-1/2*a_e_cortex*theta_e_cortex)) + 4*E_cortex(t))/tau_e_cortex
cortex.I: diff(I_cortex(t), t) == -1/4*((2*r_i_cortex*I_cortex(t) + tanh(-1/2*a_i_cortex*theta_i_cortex) - 1)*(tanh(1/2*(c3_cortex*E_cortex(t) - c4_cortex*I_cortex(t) + Q_cortex - theta_i_cortex)*a_i_cortex) - tanh(-1/2*a_i_cortex*theta_i_cortex)) + 4*I_cortex(t))/tau_i_cortex