Page 1 of 1
Exploring parameter space
Posted: Fri May 20, 2016 11:59 am
by menica
I want to see what happens to the model changing each parameter, having the AP shape fixed.
I don't understand what the sentence means. Changing a parameter will change the shape of the action potential.
I want to change same parameters of the model to define their range values which does not affect the AP.
I would like change some parameters (in this case tau of the synapse between two compartments) and plot on the same plot window, for each run, the membrane potential of the post synaptic compratment. I would like to save in different files the results of each run.
This is my code now
Code: Select all
objref somevarveclist, tveclist, glist
somevarveclist = new List()
tveclist = new List()
glist = new List()
//record data
objref vvec, tvec
tvec = new Vector()
tvec.record(&t) // record time
vvec = new Vector()
vvec.record(&POST.v(0.5))
strdef fname, prefix
prefix = "tau"
objref f1
f1 = new File()
proc savedata() {
sprint(fname, "%s%d.dat",prefix,i)
f1.wopen("fname")
f1.printf("t POST.v(0.5)\n")
f1.printf("%d\n",tvec.size())
for i=0,tvec.size()-1 {
f1.printf("%g %g\n", tvec.x(i), vvec.x(i))
}
f1.close()
print "Save response to file - Done."
}
obfunc newgraph() { localobj xtmp, ytmp, gtmp
ytmp = $o1.c // make copies of the data to be plotted
xtmp = $o2.c
somevarveclist.append(ytmp) // save these copies
tveclist.append(xtmp)
gtmp = new Graph() // plot them
ytmp.plot(gtmp,xtmp)
gtmp.exec_menu("View = plot")
return gtmp
}
proc init(){
forall finitialize(v)
if (cvode.active()) {
cvode.re_init()
} else {
fcurrent()
}
}
proc batrun() { local i, gsaved
access POST
gsaved = synE.tau //but I would like to vary ncle.weight
for i = 1,$1 { //5 run
synE.tau = i*$2 //0.01 incremento
print synE.tau
run()
savedata()
glist.append(newgraph(vvec, tvec))
synE.tau = gsaved // restore original value
}
}
proc myrun() {
init()
batrun(5,0.01)
}
myrun()
First point: I want to create the file for each run, but I get only one fname, I would like to have tau1.dat, tau2.dat...one file for each run containig the vvec and tvec vlaues recorded.
Secpon point: Now I get 5 different windows and only in the first one I have values displayed. How could I save at each run the vvec and hold on the same plot?
Final point:
I tryed to change the NetCon weight ncle.weight so defined:
Code: Select all
objref ncle
ncle=new List()
objectvar synE
POST synE = new ExpSyn(0.5)
PRE ncle.append(new NetCon(&v(1), synE, -40, 0, 0.05))
but I had this Error: weight not a public member of List. How could I solve this?
Thanks for your help
Menica
Re: Exploring parameter space
Posted: Mon May 23, 2016 11:01 am
by ted
I want to create the file for each run, but I get only one fname, I would like to have tau1.dat, tau2.dat...one file for each run containig the vvec and tvec vlaues recorded.
proc savedata() accepts two arguments: a string and a number. Why aren't you using its second argument?
Now I get 5 different windows and only in the first one I have values displayed. How could I save at each run the vvec and hold on the same plot?
If you want to keep results from a previous run, you need to save a copy the contents of vvec. Otherwise Vector recording in the new run will overwrite the contents of vvec with new results. Example:
Code: Select all
objref vsaved
vsaved = new List()
for i=0,3 {
. . . change a parameter . . .
run()
vsaved.append(vvec.c) // append a copy of vvec to vsaved
}
I tryed to change the NetCon weight ncle.weight . . . but I had this Error: weight not a public member of List. How could I solve this?
The error message means exactly what it says: the List class has no member called weight. That's because ncle is a List, not a NetCon. However, the objects that have been appended to ncle are NetCons, and you can refer to those with the List class's .o or .object method. For example if 3 NetCons were appended to ncle, the first NetCon in ncle is ncle.o(0) and its weight is called ncle.o(0).weight.
Re: Exploring parameter space
Posted: Tue May 24, 2016 10:22 am
by menica
Dear Ted,
thanks, now the things are working well, but I still didn't solve the plotting problem.
I substitute the newgraph() function which was creating a new graph at each run with a proc plotdata(). Now I can create 2 windows graph , each one for the quantity that I want to plot at every run on the same graph, but only the last vector of the run is plotted, the others are not plotted.
I inserted the "vsaved.append(vvec.c) // append a copy of vvec to vsaved" in the butrun(), but I guess I need to pass this information to the plotdata().
How could I do this?
Code: Select all
proc plotdata() {
if (ga==nil) ga = new Graph()
vvec.plot(ga,tvec)
ga.size(0,tstop,-90,90)
ga.label(0.05, 0.75, "v ", 2, 1, 0, 0, 1)
ga.exec_menu("View = plot")
gb = new Graph()
NAKp.plot(gb,tvec)
gb.size(0,tstop,-90,90)
// gb.label(0.05, 0.9, "time", 2, 1, 0, 0, 1)
gb.label(0.7, 0.75, "Ipump", 2, 1, 0, 0, 1)
gb.exec_menu("View = plot")
}
proc batrun() { local i, gsaved
access POST
gsaved = ncle.o(0).weight
for i = 1,$1 { //5 run
ncle.o(0).weight = i+$2 //0.01 incremento
print ncle.o(0).weight
run()
vsaved.append(vvec.c)
tsaved.append(tvec.c)
psaved.append(NAKp.c)
savedata(i)
plotdata(i)
//glist.append(newgraph(vvec, tvec))
}
ncle.o(0).weight = gsaved // restore original value
}
Thanks
Re: Exploring parameter space
Posted: Tue May 24, 2016 10:37 am
by menica
Dear Ted,
I solved it! :) just now
Code: Select all
obfunc newgraph() { localobj xtmp, ytmp, ztmp
ytmp = $o1.c // make copies of the data to be plotted
xtmp = $o2.c
ztmp = $o3.c
vsaved.append(ytmp) // save these copies
tsaved.append(xtmp)
psaved.append(ztmp)
ztmp.plot(gb,xtmp)
gb.exec_menu("View = plot")
gb.label(0.7, 0.75, "Ipump", 2, 1, 0, 0, 1)
ytmp.plot(ga,xtmp)
ga.exec_menu("View = plot")
ga.label(0.7, 0.75, "V", 2, 1, 0, 0, 1)
return ga
return gb
}
proc batrun() { local i, gsaved
access POST
gsaved = ncle.o(0).weight
for i = 1,$1 { //5 run
ncle.o(0).weight = i+$2 //0.01 incremento
print ncle.o(0).weight
run()
vsaved.append(vvec.c)
tsaved.append(tvec.c)
psaved.append(NAKp.c)
savedata(i)
glist.append(newgraph(vvec, tvec, NAKp))
}
ncle.o(0).weight = gsaved // restore original value
}
Re: Exploring parameter space
Posted: Wed Oct 26, 2016 7:58 am
by menica
dear Ted,
I tried with the same code (without the newgraph) to change the time between spikes (t_interp) at each run:
Code: Select all
proc batrun() { local i, gsaved
gsaved = t_interp
for i = 1,$1 {
t_interp = i*$2
num_estim=(tstop-stim[0].del)/t_interp //re-calculate the number of stimuli accordin to the new t_interp
run()
print t_interp
print num_estim
savedata(i)
}
t_interp = gsaved // restore original value
}
but in this case, it does not work properly. the loop works fine (it prints the expected values of t_interp and nume_estim for each i) but the saved currents and potential files by savedata contains all the same results from the first 'default' simulation.
Here is the code for the stimuli:
Code: Select all
numeromax_estimulos=200
objref stim[numeromax_estimulos]
for i=0, numeromax_estimulos-1{
psoma stim[i]=new IClamp(0.5)
}
aa=numeromax_estimulos
proc estimulo(){
stim[0].amp=$1
stim[0].dur=$2
stim[0].del=$3
t_interp=$4
num_estim=$5
for i=1,num_estim-1{
stim[i].amp=stim[0].amp
stim[i].dur=stim[0].dur
stim[i].del=stim[0].del+(stim[0].dur+t_interp)*i
}
for i=num_estim,numeromax_estimulos-1{
stim[i].amp=0
}
aa=$5
}
Any suggestion?
Thanks
Re: Exploring parameter space
Posted: Fri Oct 28, 2016 10:37 am
by ted
There are no useful clues in the code snippets in any of the posts in this thread. In fact, from the code that is shown, it is surprising that saving results ever worked at all.
There's no magic to recording and saving simulation results. First, at any point after model specification is complete, but before calling run() (or any func or proc that calls run()), use the Vector class's record() method, as documented in the Programmer's Reference and illustrated in various posts in the NEURON Forum, to set up recording for each variable of interest. Second, write a proc that will write the data of interest into however many files you want, using whatever format you want--very straightforward with the File class's and Vector class's methods. Third, right after calling run(), call that procedure. There is no need to use the Vector class's append() method. Above all, keep the code simple, and after any change be sure to run tests to make sure that it works.