Parameter Space Exploration in Python

275 views
Skip to first unread message

Joelle Zimmermann

unread,
Dec 12, 2014, 2:22:39 PM12/12/14
to tvb-...@googlegroups.com
Hello - has anybody done parameter space exploration in Python? I understand that it is basically just like running a simulation but iterating through the parameters. But, an example to look off of for this kind of iterative parameter exploration would be a great help :) I cant seem to find much on github..

Thanks,
Joelle

Marmaduke Woodman

unread,
Dec 15, 2014, 11:34:41 AM12/15/14
to tvb-...@googlegroups.com

Hi Joelle,

In the simplest scenario, I suggest writing a function that does your single simulation, given the varying parameters, then calling it in a for loop:

import numpy as np
import tvb.simulator.lab as tvb

def runsim(a_i):
    mod = tvb.models.Generic2dOscillator(a=a_i)
    sim = tvb.simulator.Simulator(model=mod)
    sim.configure()
    results = []
    for (t, data), in sim(simulation_length=10.0):
        results.append(data)
    return np.array(results)

a = np.array([1.0, 2.0])

for i, a_i in enumerate(a):
    results = runsim(a_i)
    np.save('results_%03d.npy', results)

Multidimensional parameter explorations are slightly more elaborate and can be done in several ways; I do the following

from itertools import product

a = np.r_[-1:2:0.1]
b = np.r_[-0.3:0:0.05]
c = np.r_[-10:20:2]

for i, (ai, bi, ci) in product(a, b, c):
    np.save('results_%06.npy', runsim(ai, bi, ci))

Let us know if you have further questions on this,

cheers,
Marmaduke


--
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.
For more options, visit https://groups.google.com/d/optout.

Joelle Zimmermann

unread,
Dec 16, 2014, 5:33:49 PM12/16/14
to tvb-...@googlegroups.com
Thanks very much Marmaduke :) This is great.

Jan Stasiński

unread,
Jun 12, 2020, 10:40:50 AM6/12/20
to TVB Users
Hi, I am trying to run a similar multiparameter space exploration code in python but a few years later :) 
The sample code that was suggested is throwing "too many values to unpack" error so is tvb my adaptation of that solution.

As this was a few years ago and perhaps there are some improved sample codes for running 3,4 parameter space exploration in python?
I am not a proficient coder so any suggestions will be much appreciated.
Best
Jan
To unsubscribe from this group and stop receiving emails from it, send an email to tvb-...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
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.

WOODMAN Michael

unread,
Jun 12, 2020, 4:27:07 PM6/12/20
to tvb-...@googlegroups.com

hi


which line does the error occur?


Marmaduke Woodman, TVB Engineer, INS AMU; +33 7 67 77 84 72


From: tvb-...@googlegroups.com <tvb-...@googlegroups.com> on behalf of Jan Stasiński <ja.sta...@gmail.com>
Sent: Friday, June 12, 2020 4:40:50 PM
To: TVB Users
Subject: [TVB] Re: Parameter Space Exploration in Python
 
To unsubscribe from this group and stop receiving emails from it, send an email to tvb-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tvb-users/23f0b2de-03fb-4e29-b94b-34ba8a9bdf79o%40googlegroups.com.

Jan Stasiński

unread,
Jun 21, 2020, 2:34:44 PM6/21/20
to TVB Users
Hi Marmaduke, 

My apologies for the late answer. The line occurred in the first line I believe. I have managed to run PSE using a list comprehension with for loops finally.
Thank you for your response.

Best regards
Jan


On Friday, June 12, 2020 at 10:27:07 PM UTC+2, marmaduke.woodman wrote:

hi


which line does the error occur?


Marmaduke Woodman, TVB Engineer, INS AMU; +33 7 67 77 84 72


To unsubscribe from this group and stop receiving emails from it, send an email to tvb-...@googlegroups.com.

Borjan Milinkovic

unread,
Jun 10, 2022, 12:09:12 AM6/10/22
to TVB Users
Hi all,

I know this is a few years off again, but using the same code as above, I am getting the same issue regarding "not enough values to unpack" 

The error is happening in the line:

for (data, time) in sim(simulation_length=2000): 
as sim does not have the two values data and time to unpack. I'm not so sure why this is happening. 

Any help would be much appreciated.

Thanks,
Boki

WOODMAN Michael

unread,
Jun 10, 2022, 3:12:06 AM6/10/22
to TVB Users
hi, 

you are missing the comma:

for (data, time), in sim

The simulator is returning samples from the monitors, so if you have several, then you would have something like 

for (eeg, t), (meg, t) in sim

but in the case of one monitor you still need the comma because of Python syntax for tuples of one element.

cheers,
Marmaduke 

To unsubscribe from this group and stop receiving emails from it, send an email to tvb-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tvb-users/e5d2d93b-cb0f-4c22-a8ba-13a4ef830a9en%40googlegroups.com.

Borjan Milinkovic

unread,
Jun 10, 2022, 11:12:04 PM6/10/22
to TVB Users
Hi Marmaduke,

Ah, thanks so much--of course!

Much appreciated. 

Best,
Boki

Reply all
Reply to author
Forward
0 new messages