shape of data - EEG JR model

Skip to first unread message

Deepa Tilwani

May 25, 2023, 5:06:36 PM5/25/23
to TVB Users
Hello TVB Community,

I am trying to simulate EEG from Jansen Rit model as below:

C = 135

# 'A', 'B', 'a', 'b', 'v0', 'nu_max', 'r', 'J', 'a_1', 'a_2', 'a_3', 'a_4', 'p_min', 'p_max', 'mu'
pars = { 'A' : np.array(3.25),
                    'B' : np.array(22),
                    'a' : np.array(100),
                    'b' : np.array(50),
                    'a_1' : np.array(C),
                    'a_2' : np.array(0.8 * C),
                    'a_3' : np.array(0.25 * C),
                    'a_4' : np.array(0.25 * C)}

oscillator = models.JansenRit(**pars)

white_matter = connectivity.Connectivity().from_file()
white_matter.speed = np.array([4.0])
white_matter_coupling = coupling.Linear(a=np.array([0.033]))

nodes = [35]
stim_weights = np.zeros((white_matter.number_of_regions, 1))
stim_weights[nodes] = np.array([3.5])[:, np.newaxis] #Just 1 region
eqn_t = equations.PulseTrain()
eqn_t.parameters["onset"] = 100 # ms
eqn_t.parameters["tau"]   = 100  # ms
eqn_t.parameters["T"]     = 500.  # 2 Hz repetition frequency

stimulus = patterns.StimuliRegion(temporal = eqn_t,
                                  connectivity = white_matter,
                                  weight = stim_weights)

sfreq = 100 #Hz
sim_duration = 16 #seconds

#Initialise an Integrator
hiss = noise.Additive(nsig=np.array([2 ** -10, ]))
heunint = integrators.HeunStochastic(dt=0.01, noise=hiss) #dt for simulation (integration) frequency
pr = projections.ProjectionSurfaceEEG.from_file()
ss = sensors.SensorsEEG.from_file(source_file="eeg_brainstorm_65.txt")
rm = region_mapping.RegionMapping.from_file() #Region Mapping

#Initialise a Monitor with period in physical time
what_to_watch = [monitors.EEG(projection=pr, sensors=ss, region_mapping=rm, period=1/sfreq*1000)]     # period for EEG frequency, 2048Hz => period=1000.0/2048.0

#Initialise a Simulator -- Model, Connectivity, Integrator, and Monitors.
sim = simulator.Simulator(model=oscillator, connectivity=white_matter,
                          integrator=heunint, monitors=what_to_watch, stimulus = stimulus)


#Perform the simulation

tt ,data =*1000)[0]


This code is giving me a  data shape of (1600, 4, 65, 1) as output.

My question is what are these 4 states for EEG ?
As I know JR have 6 states but why simulation of EEG have 4 states?
Example show that 0 is EEG signals what are other 3??

Can some one explain the logic to me?


May 25, 2023, 5:26:20 PM5/25/23
to TVB Users

I believe the default variable of interest for the JR model are y0 to y3, which would result in a model simulation time series with 4 states. You can change the variables of interest inside the model object if I remember correctly. Though, I am not sure how the EEG forward model works or operate on the JR model simulation time series, so I am not sure how this translates to what you end up getting after running the combination. Perhaps someone else can answer that part.

Hope this helps.
Dominic Boutet

Deepa Tilwani

May 26, 2023, 10:10:49 AM5/26/23
to TVB Users
Yes, I was confused because JR I know about states but why it is giving for EEG 4 states and in tutorials there are no explanation. But tutorials explained have EEG genrated and using second axis as 0 for plotting the EEG (

I want to simulate EEG for my analysis. Please help me to understand this.

Also, One more thing I was doing this  :

ss = sensors.SensorsEEG.from_file(source_file="eeg_brainstorm_65.txt")

Sensors shows 0, that is not correct.
Screenshot 2023-05-26 at 10.09.53 AM.png


May 26, 2023, 10:34:27 AM5/26/23
to TVB Users


the models in TVB have a notion of variables of interest, to avoid keep too much data in memory for long simulations with large models.  For JR, this is the first four state variables,

which you can change when you instantiate the model.



From: <> on behalf of Deepa Tilwani <>
Sent: Friday, May 26, 2023 16:10
To: TVB Users
Subject: [RESEAUX SOCIAUX] [TVB] Re: shape of data - EEG JR model
You received this message because you are subscribed to the Google Groups "TVB Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit

Deepa Tilwani

May 27, 2023, 1:25:12 PM5/27/23

I'm a bit unsure about something and could use some clarification. My goal is to obtain simulated EEG signals specifically generated for stimuli. The code mentioned in the previous email simulates EEG signals using the Jansen-Rit model, which involves four states. While I understand that, on a regional level, there are typically four states due for generating temporal averaging, I'm aware that EEG signals themselves do not inherently have four states.

I'm seeking resources that can help me understand the simulation process and how the forward model is utilized to generate EEG signals. I feel a bit confused and would like to find a way to simulate EEG signals that are responsive to stimuli, allowing me to perform Event-Related Potentials (ERPs) analysis. If you have any guidance on obtaining simulated ERPs for a given stimulus, I would greatly appreciate it.

You received this message because you are subscribed to a topic in the Google Groups "TVB Users" group.
To unsubscribe from this topic, visit
To unsubscribe from this group and all its topics, send an email to
To view this discussion on the web visit


May 30, 2023, 3:58:31 AM5/30/23
Sent: Saturday, May 27, 2023 7:24:34 PM
Subject: [RESEAUX SOCIAUX] Re: [RESEAUX SOCIAUX] [TVB] Re: shape of data - EEG JR model
Reply all
Reply to author
0 new messages