Models#

Jansen-Rit#

class whobpyt.models.jansen_rit.JansenRitModel(params: JansenRitParams, node_size=200, TRs_per_window=20, step_size=0.0001, output_size=64, tr=0.001, sc=ones((200, 200)), lm=ones((64, 200)), dist=ones((200, 200)), use_fit_gains=True, use_laplacian=True, use_fit_lfm=False)#

Connectome-based Jansen-Rit neural mass model of M/EEG.

Each brain region is a Jansen-Rit neural mass with pyramidal, excitatory and inhibitory populations. Regions are coupled through the structural connectivity, with conduction delays computed from the distance matrix. A lead field maps the activity of every region onto the M/EEG sensors. The equations are integrated with the forward Euler method in PyTorch, so the simulation is differentiable and its parameters can be fitted by gradient descent.

Parameters:
paramsJansenRitParams

The model parameters.

node_sizeint

Number of brain regions.

TRs_per_windowint

Number of output samples simulated per call to forward(). Training back-propagates through one window at a time.

step_sizefloat

Integration step, in seconds.

output_sizeint

Number of M/EEG channels. Overridden by lm.shape[0].

trfloat

Interval between output samples, in seconds (for example 0.001 for 1000 Hz). Must be a multiple of step_size.

scndarray, shape (node_size, node_size)

Structural connectivity.

lmndarray, shape (output_size, node_size)

Lead field matrix.

distndarray, shape (node_size, node_size)

Distances between regions, used for the conduction delays.

use_fit_gainsbool

If True, learn a separate gain for every connection of the pyramidal-to-pyramidal, -excitatory and -inhibitory connectivity matrices. If False, the gains are fixed.

use_laplacianbool

If True, add a Laplacian (diagonal) term to the long-range coupling.

use_fit_lfmbool

Whether to fit the lead field matrix. To make the lead field learnable, pass lm in params as a learnable Parameter.

Attributes:
state_nameslist of str

The model’s state variables: 'E', 'Ev', 'I', 'Iv', 'P', 'Pv' (each population’s current and its derivative).

output_nameslist of str

['eeg'].

steps_per_TRint

Integration steps per output sample, int(tr / step_size).

Methods

createDelayIC(ver[, delays_max, state_lb, ...])

Create random initial history for the delayed long-range input.

createIC(ver[, state_lb, state_ub])

Create random initial conditions for the model's states.

forward(external, hx, hE)

This function carries out the forward Euler integration method for the JR neural mass model, with time delays, connection gains, and external inputs considered.

setModelSCParameters([small_constant])

Create the connection gains for the long-range coupling.

createDelayIC(ver, delays_max=500, state_lb=-0.5, state_ub=0.5)#

Create random initial history for the delayed long-range input.

Parameters:
verint

Initial condition version. Not used by this model; kept for consistency with other models.

delays_maxint

Length of the history buffer, in output samples. Must be longer than the longest conduction delay.

state_lb, state_ubfloat

Lower and upper bound of the uniform random initial values.

Returns:
torch.Tensor

Tensor of shape (node_size, delays_max) with random values between state_lb and state_ub.

createIC(ver, state_lb=-0.5, state_ub=0.5)#

Create random initial conditions for the model’s states.

Parameters:
verint

Initial condition version. Not used by this model; kept for consistency with other models.

state_lb, state_ubfloat

Lower and upper bound of the uniform random initial values.

Returns:
torch.Tensor

Tensor of shape (node_size, state_size) with random values between state_lb and state_ub.

forward(external, hx, hE)#

This function carries out the forward Euler integration method for the JR neural mass model, with time delays, connection gains, and external inputs considered. Each population (pyramidal, excitatory, inhibitory) in the network is modeled as a nonlinear second order system. The function updates the state of each neural population and computes the EEG signals at each time step.

Parameters:
externaltorch.Tensor, shape (node_size, steps_per_TR, TRs_per_window)

External input (stimulus) for this window.

hxtorch.Tensor, shape (node_size, 6)

Current state of every region.

hEtorch.Tensor, shape (node_size, delays_max)

History of the pyramidal population, used for the delayed long-range input.

Returns:
next_statedict

'current_state' (the state at the end of the window), 'eeg' (shape (output_size, TRs_per_window)) and each state variable (shape (node_size, TRs_per_window)).

hEtorch.Tensor

The updated history of the pyramidal population.

info()#

Return the model’s state names, output names, tracked parameters and commit.

setModelSCParameters(small_constant=0.05)#

Create the connection gains for the long-range coupling.

Parameters:
small_constantfloat

Initial value of every gain (they enter the model as exp(gain)).

class whobpyt.models.jansen_rit.JansenRitParams(**kwargs)#

Parameters of the JansenRitModel.

Every parameter is a Parameter, so it can be fixed or learnable and can carry a prior. Pass any parameter as a keyword argument to override its default, for example JansenRitParams(a=par(100, 100, 2, True)).

The symbols follow Jansen & Rit (1995). In the equations below, P, E and I are the pyramidal, excitatory interneuron and inhibitory interneuron populations of each brain region.

Parameters:
AParameter, default 3.25

Maximum amplitude of the excitatory postsynaptic potential (mV).

aParameter, default 100

Excitatory synaptic rate constant (1/s), the inverse of the excitatory time constant.

BParameter, default 22

Maximum amplitude of the inhibitory postsynaptic potential (mV).

bParameter, default 50

Inhibitory synaptic rate constant (1/s), the inverse of the inhibitory time constant.

c1, c2Parameter, default 135 and 108

Average number of synaptic contacts between the pyramidal cells and the excitatory interneurons. c1 scales the pyramidal input to the excitatory sigmoid and c2 scales the excitatory interneurons’ output.

c3, c4Parameter, default 33.75 and 33.75

Average number of synaptic contacts between the pyramidal cells and the inhibitory interneurons, used in the same way as c1 and c2.

vmaxParameter, default 5

Maximum firing rate of the sigmoid (1/s).

v0Parameter, default 6

Membrane potential at which the sigmoid reaches half its maximum firing rate (mV).

rParameter, default 0.56

Steepness of the sigmoid (1/mV).

gParameter, default 1000

Global coupling gain of the long-range, delayed input from other regions to the pyramidal population.

g_fParameter, default 10

Gain of the long-range input to the excitatory interneurons (“feedforward”).

g_bParameter, default 10

Gain of the long-range input to the inhibitory interneurons (“feedback”).

std_inParameter, default 100

Standard deviation of the Gaussian noise added to the input of each population at every integration step.

muParameter, default 0.5

Conduction velocity used to compute the long-range delays, delay = distance / mu, in output samples.

kParameter, default 5

Gain of the external input (stimulus) to the pyramidal population.

kiParameter, default 1

Weight of the external input for each region, shape (node_size, 1). Set it to zero for regions that should not be stimulated.

cy0Parameter, default 5

Scaling of the simulated M/EEG signal.

y0Parameter, default 2

Constant offset subtracted from the simulated M/EEG signal.

lmParameter

Lead field matrix, shape (output_size, node_size), mapping region activity to sensors. It has no default and must be given. It can be made learnable.

k0Parameter, optional

Accepted for compatibility with older code but not used by the model.

Notes

The simulated M/EEG signal is cy0 * L @ (E - I) - y0, where L is the lead field lm normalised per channel and average-referenced.

References

Jansen BH, Rit VG. Electroencephalogram and visual evoked potential generation in a mathematical model of coupled cortical columns. Biological Cybernetics 73, 357-366 (1995).