%pylab nbagg
from tvb.simulator.lab import *
jrm = models.JansenRit(mu=0., v0=6.)
phi_n_scaling = (jrm.a * jrm.A * (jrm.p_max-jrm.p_min) * 0.5 )**2 / 2.
sigma = numpy.zeros(6)
sigma[3] = phi_n_scaling
# the other aspects of the simulator are standard
sim = simulator.Simulator(
model=jrm,
connectivity=connectivity.Connectivity(load_default=True),
coupling=coupling.SigmoidalJansenRit(a=10.0),
integrator=integrators.HeunStochastic(dt=2 ** -4, noise=noise.Additive(nsig=sigma)),
monitors=monitors.TemporalAverage(period=2 ** -2),
simulation_length=1e3,
).configure()
# run it
(time, data), = sim.run()
# visualize time series
figure()
plot(time, data[:, 0, :, 0], 'k', alpha=0.1)
title("Temporal Average")
WARNING File 'hemispheres' not found in ZIP./home/ee213/Desktop/TVB_Distribution/tvb_data/lib/python2.7/site-packages/tvb/simulator/coupling.py:378: RuntimeWarning: overflow encountered in exp pre = self.cmax / (1.0 + numpy.exp(self.r * (self.midpoint - (x_j[:, 0] - x_j[:, 1])))) /home/ee213/Desktop/TVB_Distribution/tvb_data/lib/python2.7/site-packages/tvb/simulator/models/jansen_rit.py:310: RuntimeWarning: overflow encountered in _numba_dfun_jr self.A, self.b, self.B, self.J, self.mu
Le 26 juil. 2016 à 09:35, Toygun Başaklar <tbas...@gmail.com> a écrit :
Hello,
I am working on Jansen Rit model to observe its response to visually evoked potentials. For this purpose, I have started with simulate_region_Jansen_Rit tutorial to practice using TVB. I encountered some RuntimeWarnings when I ran the code. Below I give the code and the corresponding warnings. How can I get rid of these warnings?
WARNING File 'hemispheres' not found in ZIP.
/home/ee213/Desktop/TVB_Distribution/tvb_data/lib/python2.7/site-packages/tvb/simulator/coupling.py:378: RuntimeWarning: overflow encountered in exp pre = self.cmax / (1.0 + numpy.exp(self.r * (self.midpoint - (x_j[:, 0] - x_j[:, 1])))) /home/ee213/Desktop/TVB_Distribution/tvb_data/lib/python2.7/site-packages/tvb/simulator/models/jansen_rit.py:310: RuntimeWarning: overflow encountered in _numba_dfun_jr self.A, self.b, self.B, self.J, self.mu
eqn_t = equations.PulseTrain()
eqn_t.parameters["onset"] = 500.0 # ms
eqn_t.parameters["tau"] = 5.0 # ms
eqn_t.parameters["T"] = 500. # 0.002kHz repetition frequency
stimulus = patterns.StimuliRegion(temporal = eqn_t,
connectivity = conn,
weight = stim_weights)
Le 26 juil. 2016 à 10:39, Toygun Başaklar <tbas...@gmail.com> a écrit :1- So what you are saying is these warnings do not mean the simulation is wrong, am I right? I have implemented Jansen-Rit model in Matlab myself and I would like to compare its response with TVB's response to a flash stimulus, so I want to absolutely make sure this is working as intended.
2- Do I need to generate a stimulus as shown below, or can I add a transient exponential term to the "background activity noise" to account for stimulus as stated in the original paper?
eqn_t = equations.PulseTrain()
eqn_t.parameters["onset"] = 500.0 # ms
eqn_t.parameters["tau"] = 5.0 # ms
eqn_t.parameters["T"] = 500. # 0.002kHz repetition frequency
stimulus = patterns.StimuliRegion(temporal = eqn_t,
connectivity = conn,
weight = stim_weights)
3- On a side note, Jansen's 1995 paper thoroughly discusses about a parameter K. I did not find any parameters related to this in JansenRit class. Does the connectivity matrix account for this K parameter?
--
You received this message because you are subscribed to a topic in the Google Groups "TVB Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tvb-users/PWbmepE4zws/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tvb-users+...@googlegroups.com.
To post to this group, send email to tvb-...@googlegroups.com.
Visit this group at https://groups.google.com/group/tvb-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/tvb-users/3C6E1D9B-4143-4337-B6F7-9C673B7ECF99%40gmail.com.
Le 26 juil. 2016 à 14:11, Toygun Başaklar <tbas...@gmail.com> a écrit :1- Why does sigma have a size of 6? And how do we know 4th index corresponds to model input? Please do correct me if Im wrong.
2- Is there a way to visualize a noise or stimulus object? I couldn't find a number array to plot.
Sigma is the level of noise, and this model requires per state variable dispersion values. (so, it’s not the input, technically speaking)
There’s a demo of visualizing the stimulus pattern, once configured. Please take a look and see if it helps.
Le 27 juil. 2016 à 10:59, Toygun Başaklar <tbas...@gmail.com> a écrit :Sigma is the level of noise, and this model requires per state variable dispersion values. (so, it’s not the input, technically speaking)
But in terms of JR 1995, it is considered as the input to the system, isn't it? ("p(t)" in the below figure is sigma[3] in the code as far as I understood). I'd like to stimulate the model as described in the paper itself. In order to do that, I should add the desired stimulus (flash pulse in this case) to the noise but since the noise is not a data array (it is a noise object), I cannot add the stimulus. Can we somehow obtain access to this noise object's content (time,data) and manipulate it?
Another question that appeared to my mind, is applying a regional stimulus to this model in TVB equivalent to JR's way of applying stimulus (adding exponential onto white noise) in their paper?
In TVB, the noise enters into the integration scheme in proportion to the square root of the time step, but if you still want to do it, you can look at the source for the Noise classes and generate arbitrary data.
Which section of the paper is that? I am looking but don’t see a description of the noise process they used.OTOH, they’re using a RK4-5 scheme, so if you are using the same in MATLAB, this will already be a source of discrepancy with TVB, since this scheme is not implemented.
from pylab import *
from tvb.simulator.lab import *
import numpy
import tvb.datatypes.projections as projections
jrm = models.JansenRit(v0=6.0)
phi_n_scaling = (jrm.a * jrm.A * (jrm.p_max-jrm.p_min) * 0.5 )**2 / 2.
sigma = numpy.zeros(6)
sigma[3] =
phi_n_scaling
conn = connectivity.Connectivity(load_default=True)
weighting = numpy.zeros((76, ))
weighting[[35, 36]] = 3.0
eqn_t = equations.PulseTrain()
eqn_t.parameters["onset"] = 5e3 # ms
eqn_t.parameters["tau"] = 100.0 # ms
eqn_t.parameters["T"] = 5e3 #
eqn_t.parameters["amp"] = 200.0
stim = patterns.StimuliRegion(temporal = eqn_t,
connectivity = conn,
weight = weighting)
stim.configure_space()
stim.configure_time(numpy.arange(0., 1e4, 2**-4))
plot_pattern(stim)
ion()
show()
pr = projections.ProjectionSurfaceEEG(load_default=True)
ss = sensors.SensorsEEG.from_file(source_file="eeg_brainstorm_65.txt")
rm = region_mapping.RegionMapping(load_default=True)
rec = (monitors.EEG(projection=pr, sensors=ss, region_mapping=rm, period=1e3/2048.))
sim = simulator.Simulator(
model=jrm,
connectivity=conn,
coupling=coupling.SigmoidalJansenRit(),
integrator=integrators.HeunStochastic(dt=2 ** -4, noise=noise.Additive(nsig=sigma)),
monitors= rec,
stimulus = stim,
simulation_length=1e4,).configure()
(time, data), = sim.run()
figure()
plot(time, data[:, 0, 31, 0], 'k', alpha=1)
title("EEG")
ioff()
show()
Le 27 juil. 2016 à 15:55, Toygun Başaklar <tbas...@gmail.com> a écrit :It is in section 3.3 Evoked Potentials,
OK, sorry I hadn’t read this paper fully before.Indeed, their stimulation paradigm is more complex (in particular the randomly distributed impulses) than what we have in our tutorials, but you should be able to accomplish this by implementing your own Stimulus subclass. The stimulus is called by the simulator to produce a stimulation pattern on each time step,stimulus[self.model.cvar, :, :] = self.stimulus(stim_step).reshape((1, -1, 1))On each time step, evaluate both the random impulse and transient for the regions you want to stimulate and return a suitable vector.If you need some help with this, let us know.
Le 28 juil. 2016 à 10:23, Toygun Başaklar <tbas...@gmail.com> a écrit :I would like to clarify/ask a few things: (please correct me if I am wrong)
1- I need to use regional stimulus and stimulate occipital areas as I did before.
2- I will create the transient as the temporal pattern of the stimulus (an arbitrary eqn_t in this case).
* I can add the noise onto eqn_t as well. For this I need to create an arbitrary TemporalApplicableEquation subclass in equations.py.
* I can add the random noise onto this stimulus in the simulator, at the line you provided in the above post (in _loop_update_stimulus).
Which one of the above statements are more suitable?
3- Also, I will not use per state variable dispersion, as I already will include noise in my stimulus. This leads to another point, which integrator scheme should I use?
Le 28 juil. 2016 à 10:23, Toygun Başaklar <tbas...@gmail.com> a écrit :I would like to clarify/ask a few things: (please correct me if I am wrong)
1- I need to use regional stimulus and stimulate occipital areas as I did before.
2- I will create the transient as the temporal pattern of the stimulus (an arbitrary eqn_t in this case).
* I can add the noise onto eqn_t as well. For this I need to create an arbitrary TemporalApplicableEquation subclass in equations.py.
* I can add the random noise onto this stimulus in the simulator, at the line you provided in the above post (in _loop_update_stimulus).
Which one of the above statements are more suitable?Maybe I need another coffee, but I didn’t see the conflict among those statements; I think they are all correct.
Heun or Euler deterministic scheme, depending on what you’re using in MATLAB.
Le 28 juil. 2016 à 12:43, Toygun Başaklar <tbas...@gmail.com> a écrit :In the 1st statement, say, I have a regional stimulus with temporal equation eqn_t. I can manipulate this eqn_t to introduce noise to my stimulus.
In the 2nd statement, again say, I have a regional stimulus with temporal equation eqn_t. I can manipulate the function _loop_update_stimulus() of the simulator class to introduce noise at each time step.
I wonder which method will be more feasible/meaningful to implement?
Ah I see. Definitely don’t modify _loop_update_stimulus(), instead use approach (1), provide a stimulus class which returns the desired values.
from pylab import *
from tvb.simulator.lab import *
import numpy
import tvb.datatypes.projections as projections
jrm = models.JansenRit(v0=6.0)
conn = connectivity.Connectivity(load_default=True)
weighting = numpy.zeros((76, ))
weighting[[35,36]] = 3.5
eqn_t = equations.JansenRitExp()
eqn_t.parameters['onset'] = 5000
stim = patterns.StimuliRegion(temporal = eqn_t,
connectivity = conn,
weight = weighting)
pr = projections.ProjectionSurfaceEEG(load_default=True)
ss = sensors.SensorsEEG.from_file(source_file="eeg_brainstorm_65.txt")
rm = region_mapping.RegionMapping(load_default=True)
rec = (monitors.EEG(projection=pr, sensors=ss, region_mapping=rm, period=1))
sim = simulator.Simulator(
model=jrm,
connectivity=conn,
coupling=coupling.SigmoidalJansenRit(),
integrator=integrators.EulerDeterministic(dt=1),
monitors= rec,
stimulus = stim,
simulation_length=1e4).configure()
(time, data), = sim.run()
plot_pattern(sim.stimulus)
ion()
show()
figure()
plot(time, data[:, 0, 60, 0], 'k', alpha=1)
title("EEG")
ioff()
show()
data[:, 0, 60, 0] notation. What do 0, 60 and 0 stand for here? I guessed 60 is for channel selection, but how do I know what channel corresponds to 60?
Is there a flowchart related to how TVB simulator works? I mean I sometimes get confused while tracking the code from one class to another. A generic simulator flowchart (what are initiated inside and with which order, when is integrator used etc.) would be useful.
Thank you.
Le 1 août 2016 à 10:14, Toygun Başaklar <tbas...@gmail.com> a écrit :Is there any way to define dt and time arrays in terms of seconds in TVB?
Also, what we plot in MATLAB is y1-y2 (y_n being the state variables). Can we plot the same in TVB? Do we have access to state variables directly? How is the EEG signal we plot in TVB related to state variables?
Another thing is there are variables in jansen_rit.py named as pmax, pmin and mu. Are these functional? These seem to be used to generate the random input JR talks about.
One last thing, I do not understand thedata[:, 0, 60, 0] notation. What do 0, 60 and 0 stand for here? I guessed 60 is for channel selection, but how do I know what channel corresponds to 60?
Is there a flowchart related to how TVB simulator works? I mean I sometimes get confused while tracking the code from one class to another. A generic simulator flowchart (what are initiated inside and with which order, when is integrator used etc.) would be useful.
Le 1 août 2016 à 16:48, Toygun Başaklar <tbas...@gmail.com> a écrit :What is the difference between using an all-zero weighting matrix in stimulus and not using/giving any stimulus at all? Both of them still produces oscillations (I also would like to learn why/how?), but these oscillations are vastly different.
Can we use different models in different nodes in the same simulator? Why I want to know is because I would like to use two nodes (one in occipital region the other in prefrontal region as JR discussed) and include the connectivity between these two nodes ONLY (is this doable/possible?). At these two nodes JR model will be used but with different C (J in TVB) parameters (135 in occ. 108 in prefrontal). This will be similar to what JR explained in their paper and would also introduce "intercolumn connectivity constants" (K_1 and K_2 in JR-1995).
I’m not sure I understand entirely but send some code so I see what you mean.
weighting = numpy.zeros((76, ))
eqn_t = equations.JansenRitExp()
eqn_t.parameters['onset'] = 5000
eqn_t.parameters['pulse'] = 1
stim = patterns.StimuliRegion(temporal = eqn_t,
connectivity = conn,
weight = weighting).
.
.
.
sim = simulator.Simulator(
model=jrm,
connectivity=conn,
coupling=coupling.SigmoidalJansenRit(),
integrator=integrators.EulerDeterministic(dt=1),
monitors= rec,
stimulus = stim,
simulation_length=1e4).configure()
sim = simulator.Simulator(
model=jrm,
connectivity=conn,
coupling=coupling.SigmoidalJansenRit(),
integrator=integrators.EulerDeterministic(dt=1),
monitors= rec,
stimulus = None,
simulation_length=1e4).configure()
If it is just the parameter values which vary spatially, yes, you just need to make a vector instead of scalar for the parameter.
The first one generates:<Auto Generated Inline Image 1.png>
The second one generates:<Auto Generated Inline Image 2.png>
In MATLAB, when I provide no input at all (no noise or pulse density) I do not see any oscillations. Why is this not the case in TVB?
If it is just the parameter values which vary spatially, yes, you just need to make a vector instead of scalar for the parameter.
This is a part of what I want, yes. I want two different values for J, a and b running in two different JR models on two nodes only. How can I achieve this?
I'm not sure how TVB connectivity really works, but I'm assuming every node is connected with each other with the coupling equation we choose. I would like to have two active nodes (so if there are 76 nodes in TVB, I want only 2 connected nodes and the remaining 74 unconnected/infinite distance) and on these nodes I want the same set of equations but with different parameters. I hope I could make myself clear, I am having a hard time to express myself - I am overwhelmed by the features/functions in TVB.
OK, then maybe you just want to start with a 2 node network? For example,conn = connectivity.Connectivity()conn.weights = numpy.random.randn(2, 2)conn.delays = numpy.zeros((2, 2))jr = JansenRit()jr.J = numpy.r_[J_val_node_1, J_val_node_2]# etc for jr.a, jr.bsim = Simulator(model=jr, connectivity=conn, …)and then configure your simulator as usual. Does this make more sense?
Le 2 août 2016 à 09:39, Toygun Başaklar <tbas...@gmail.com> a écrit :To achieve the same, do we set conn.weights to [[0, 4000],[100,0]]?
Also, JR uses 30s^-1 as delay between nodes. Do I set conn.delays to [[0, 0.03],[0.03, 0]] assuming the delays are all in ms in TVB?
conn = connectivity.Connectivity()
conn.weights = numpy.r_['0,2',[0.0, 4000.0],[100.0,0.0]]
conn.delays = numpy.r_['0,2',[0.0, 0.03],[0.03,0.0]]
conn.weights = numpy.r_['0,2',[0.0, 4000.0],[100.0,0.0]]
conn.delays = numpy.r_['0,2',[0.0, 0.03],[0.03,0.0]]
conn.orientations = numpy.r_['0,2',[-0.17818834, 0.66607632, 0.00588274],[-0.09655664, 0.15027455, -0.04954971]]
conn.centres = numpy.r_['0,2',[-70.449382, -12.870265, -11.423195],[ 59.612735, -2.407101, -0.844581]]
File "/home/ee213/Desktop/TVB_Distribution/tvb_data/lib/python2.7/site-packages/tvb/simulator/simulator.py", line 304, in configure
self._configure_monitors()
File "/home/ee213/Desktop/TVB_Distribution/tvb_data/lib/python2.7/site-packages/tvb/simulator/simulator.py", line 538, in _configure_monitors
monitor.config_for_sim(self)
File "/home/ee213/Desktop/TVB_Distribution/tvb_data/lib/python2.7/site-packages/tvb/simulator/monitors.py", line 586, in config_for_sim
super(EEG, self).config_for_sim(simulator)
File "/home/ee213/Desktop/TVB_Distribution/tvb_data/lib/python2.7/site-packages/tvb/simulator/monitors.py", line 481, in config_for_sim
numpy_add_at(gain.T, self.rmap, self.gain.T)
IndexError: index 36 is out of bounds for axis 0 with size 2
Le 3 août 2016 à 10:15, Toygun Başaklar <tbas...@gmail.com> a écrit :Could you help me to resolve this issue? Are we on the right track?
rec = (monitors.EEG(sensors=sensors.SensorsEEG(load_default=True), region_mapping=rm, period=1))
Le 3 août 2016 à 11:55, Toygun Başaklar <tbas...@gmail.com> a écrit :Without region mapping it didn't work. But with following it worked:
rec = (monitors.EEG(sensors=sensors.SensorsEEG(load_default=True), region_mapping=rm, period=1))
So I omitted the projections object from the monitor. Is there any chance it would cause any problem/error?
--
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 tvb-users+...@googlegroups.com.
To post to this group, send email to tvb-...@googlegroups.com.
Visit this group at https://groups.google.com/group/tvb-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/tvb-users/9743ac19-ef09-4903-b1b4-21b95faee87d%40googlegroups.com.
jrm = models.JansenRit(v0=6.0, variables_of_interest=['y1-y2','y1-y2'])
output1 = data[:, 1, 32, 0]
figure('Visual Cortex Node')
plot(time, output1, 'k', alpha=1)
title("EEG")
ion()
show()
output2 = data[:, 0, 32, 0]
figure('Prefrontal Cortex Node')
plot(time, output2, 'k', alpha=1)
title("EEG")
ion()
show()
--
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 tvb-users+...@googlegroups.com.
To post to this group, send email to tvb-...@googlegroups.com.
Visit this group at https://groups.google.com/group/tvb-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/tvb-users/34a74999-3ffe-44f9-b510-bb8095863a9b%40googlegroups.com.
32 is the index of the sensor here. Also, you’ve made the same variables of interest, so in this case, you’re plotting the same variable of interest (y1 - y2) for the same sensor.You could use a single variable of interest [‘y1 - y2’] and then plot different sensors.
from pylab import *
from tvb.simulator.lab import *
import numpy
import tvb.datatypes.projections as projections
# # Simulate with the Jansen and Rit model.
jrm = models.JansenRit(v0=6.0, variables_of_interest=['y1-y2'])
jrm.J = numpy.r_[108, 135]
jrm.B = numpy.r_[17.6, 22]
conn = connectivity.Connectivity()
conn.weights = numpy.r_['0,2',[0.0, 4000.0],[100.0,0.0]]
conn.delays = numpy.r_['0,2',[0.0, 0.03],[0.03,0.0]]
conn.orientations = numpy.r_['0,2',[ 0.31577083, 0.43790701, -0.34546315],[-0.09655664, 0.15027455, -0.04954971]]
conn.centres = numpy.r_['0,2',[ 59.286775, -2.547348, -21.924281],[ 59.612735, -2.407101, -0.844581]]
weighting = numpy.zeros((2, ))
weighting[[0,1]] = 1
eqn_t = equations.JansenRitExp()
eqn_t.parameters['onset'] = 5000
eqn_t.parameters['pulse'] = 0
stim = patterns.StimuliRegion(temporal = eqn_t,
connectivity = conn,
weight = weighting)
pr = projections.ProjectionSurfaceEEG(load_default=True)
ss = sensors.SensorsEEG.from_file(source_file="eeg_brainstorm_65.txt")
rm = region_mapping.RegionMapping(load_default=True)
rec = (monitors.EEG(sensors=sensors.SensorsEEG(load_default=True), region_mapping=rm, period=1))
# the other aspects of the simulator are standard
sim = simulator.Simulator(
model=jrm,
connectivity=conn,
coupling=coupling.SigmoidalJansenRit(),
integrator=integrators.EulerDeterministic(dt=1),
monitors= rec,
stimulus = stim,
simulation_length=1e4).configure()
# run it
(time, data), = sim.run()
plot_pattern(sim.stimulus)
ion()
show()
output1 = data[:, :, 60, 0]#Oz
figure('Visual Cortex Node')
plot(time[1000:10000], output1[1000:10000], 'k', alpha=1)
title("EEG")
ion()
show()
output2 = data[:, :, 57, 0]#Fpz
figure('Prefrontal Cortex Node')
plot(time[1000:10000], output2[1000:10000], 'k', alpha=1)
Le 3 août 2016 à 16:59, Toygun Başaklar <tbas...@gmail.com> a écrit :So in this case, I will need to plot from two sensors, one from occipital region and one from prefrontal region, to see the outputs from each column/node. I chose regions 60 (Oz) and 57 (Fpz) and plot the results however the results do not coincide with JR's plots. I have two questions:
1- Do conn.weights correspond to K_1 and K_2 (intercolumn connectivity constants) in JR paper? Should their magnitude be the same as in the paper (K_1 = 4000, K_2 = 100) ? I am asking because I cannot think of any other reason for seeing wrong/irrelevant results (you can see the code used below).
2- Can I give two different stimulus to different nodes? I want to apply noise to prefrontal node and noise+pulse to visual node.
From the code I’m not 100% sure where the difference might arise, so I’ll have to take a closer look. If you want to share an excerpt of your MATLAB code and results (by private communication if you prefer), it would accelerate the process.
Not with the current stimuli classes, you’d need a custom one, which knows how to combine these features. I can make an example of this.
hi
Please restate the problem your trying to solve, or quote a more precise section of a previous email.
thanks,
Marmaduke
To view this discussion on the web visit https://groups.google.com/d/msgid/tvb-users/9359f128437b46a1a8fbf69edd523468%40univ-amu.fr.
To unsubscribe from this group and stop receiving emails from it, send an email to tvb-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tvb-users/16fb8f35-bfe2-4a4e-ad04-e063c03bec1b%40googlegroups.com.
--
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 tvb-...@googlegroups.com.
hi
Use a list ['y1 - y2'] instead of just a string 'y1-y2'.
cheers,
Marmaduke