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:
- params
JansenRitParams The model parameters.
- node_size
int Number of brain regions.
- TRs_per_window
int Number of output samples simulated per call to
forward(). Training back-propagates through one window at a time.- step_size
float Integration step, in seconds.
- output_size
int Number of M/EEG channels. Overridden by
lm.shape[0].- tr
float Interval between output samples, in seconds (for example 0.001 for 1000 Hz). Must be a multiple of
step_size.- sc
ndarray, shape (node_size, node_size) Structural connectivity.
- lm
ndarray, shape (output_size, node_size) Lead field matrix.
- dist
ndarray, 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
lminparamsas a learnable Parameter.
- params
- Attributes:
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:
- Returns:
torch.TensorTensor of shape (node_size, delays_max) with random values between
state_lbandstate_ub.
- createIC(ver, state_lb=-0.5, state_ub=0.5)#
Create random initial conditions for the model’s states.
- Parameters:
- Returns:
torch.TensorTensor of shape (node_size, state_size) with random values between
state_lbandstate_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:
- external
torch.Tensor, shape (node_size, steps_per_TR, TRs_per_window) External input (stimulus) for this window.
- hx
torch.Tensor, shape (node_size, 6) Current state of every region.
- hE
torch.Tensor, shape (node_size, delays_max) History of the pyramidal population, used for the delayed long-range input.
- external
- Returns:
- next_state
dict '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)).- hE
torch.Tensor The updated history of the pyramidal population.
- next_state
- info()#
Return the model’s state names, output names, tracked parameters and commit.
- 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 exampleJansenRitParams(a=par(100, 100, 2, True)).The symbols follow Jansen & Rit (1995). In the equations below,
P,EandIare the pyramidal, excitatory interneuron and inhibitory interneuron populations of each brain region.- Parameters:
- A
Parameter, default 3.25 Maximum amplitude of the excitatory postsynaptic potential (mV).
- a
Parameter, default 100 Excitatory synaptic rate constant (1/s), the inverse of the excitatory time constant.
- B
Parameter, default 22 Maximum amplitude of the inhibitory postsynaptic potential (mV).
- b
Parameter, default 50 Inhibitory synaptic rate constant (1/s), the inverse of the inhibitory time constant.
- c1, c2
Parameter, default 135 and 108 Average number of synaptic contacts between the pyramidal cells and the excitatory interneurons.
c1scales the pyramidal input to the excitatory sigmoid andc2scales the excitatory interneurons’ output.- c3, c4
Parameter, 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
c1andc2.- vmax
Parameter, default 5 Maximum firing rate of the sigmoid (1/s).
- v0
Parameter, default 6 Membrane potential at which the sigmoid reaches half its maximum firing rate (mV).
- r
Parameter, default 0.56 Steepness of the sigmoid (1/mV).
- g
Parameter, default 1000 Global coupling gain of the long-range, delayed input from other regions to the pyramidal population.
- g_f
Parameter, default 10 Gain of the long-range input to the excitatory interneurons (“feedforward”).
- g_b
Parameter, default 10 Gain of the long-range input to the inhibitory interneurons (“feedback”).
- std_in
Parameter, default 100 Standard deviation of the Gaussian noise added to the input of each population at every integration step.
- mu
Parameter, default 0.5 Conduction velocity used to compute the long-range delays,
delay = distance / mu, in output samples.- k
Parameter, default 5 Gain of the external input (stimulus) to the pyramidal population.
- ki
Parameter, 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.- cy0
Parameter, default 5 Scaling of the simulated M/EEG signal.
- y0
Parameter, default 2 Constant offset subtracted from the simulated M/EEG signal.
- lm
Parameter 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.- k0
Parameter, optional Accepted for compatibility with older code but not used by the model.
- A
Notes
The simulated M/EEG signal is
cy0 * L @ (E - I) - y0, whereLis the lead fieldlmnormalised 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).