why these initializations produce different results?

Using the Multiple Run Fitter, praxis, etc..
Post Reply
OJAG
Posts: 34
Joined: Wed Nov 14, 2007 4:46 am
Location: Bogota

why these initializations produce different results?

Post by OJAG » Mon Mar 08, 2010 3:25 pm

Hi all,

I am writing a code to record one variable starting at tmin and stopping at tmax

the basic configuration is this piece of code
variables definition and creation

Code: Select all

objref word,word1,wrd2,cvd, fih0
 strdef end,end1
 fih0=new List()
 word=new string("")
 word1=new string("")
 wrd2=new string("")
 cvd=new CVode()      
  
  //Creation of file to save the vectors
  //======================================
        objref traces_file         
        traces_file = new File("./volt_time_ww_90msXXX.m")  
  //====================================== 
                 
for(Cell_type=0;Cell_type<n_types;Cell_type+=1){
if(Cell_type==0){NL=n_layerP end="P" n_cells=n_P}else{if(Cell_type==1){NL=n_layerFS end="FS" n_cells=n_FS}}
for(c_idx=0;c_idx<NL;c_idx+=1){                        
 sprint(word.str, "objref rec_list_t_%s%g,rec_list_v_%s%g,fihL%s%g",end,c_idx,end,c_idx,end,c_idx)
 execute(word.str)  //this for cycle creates the  objets to be used  
                 }               
              }
The for cycle just creates four lists called rec_list_t_P0 and rec_list_v_P0 to append vectors and measure t and v respectively for population 1 and rec_list_t_FS0 and rec_list_v_FS0 for population 2
Mean Block

Code: Select all

 load_file("./Spk_rec_post_trial1.hoc")
      fih0.append(new FInitializeHandler(1,"Start_record()"))
        //fih0.append(new FInitializeHandler(1,"cvd.event(tmin,\"Start_record()\")"))


Code: Select all

 
proc Start_record(){local n_lyr1, n_cels localobj wrd

print "time is ", t

wrd=word          
for(Cell_type=0;Cell_type<n_types;Cell_type+=1){                
if(Cell_type==0){NL=n_layerP end="P" n_cells=n_P}else{if(Cell_type==1){NL=n_layerFS end="FS" n_cells=n_FS}}
for(n_lyr1=0;n_lyr1<NL;n_lyr1+=1){
sprint(wrd.str,"rec_list_t_%s%g=new List() rec_list_v_%s%g=new List()",end,n_lyr1,end,n_lyr1)execute(wrd.str)
sprint(wrd.str,"n_cel=layer%s[%g].count()",end,n_lyr1)execute(wrd.str)                                                                

for n_cels=0,n_cel-1{
sprint(wrd.str,"rec_list_t_%s%g.append(new Vector()) ",end,n_lyr1)execute(wrd.str)
sprint(wrd.str,"rec_list_v_%s%g.append(new Vector())",end,n_lyr1)execute(wrd.str)
sprint(wrd.str,"layer%s[%g].o(%g).soma cvd.record(&v(0.5),rec_list_v_%s%g.o(%g),rec_list_t_%s%g(%g))",end,n_lyr1,n_cels,end,n_lyr1,n_cels,end,n_lyr1,n_cels)
print wrd.str 
execute(wrd.str)
                  }
                }      
              }
          cvd.event(tmax,"prt2file(word,wrd2)")      
        } 
The procedure Start_record defines the arrays and variables to record from, appends respective vectors to the already created lists and sets up the record procedure, i.e. something like this
layerP[0].o(0).soma cvd.record(&v(0.5),rec_list_v_P0.o(0),rec_list_t_P0.o(0))
The important think here is that at certain time point tmax one event should be delivered to print data to a file using
cvd.event(tmax,"prt2file(word,wrd2)")
if you look at what I called the mean block,
fih0.append(new FInitializeHandler(1,"Start_record()"))
//fih0.append(new FInitializeHandler(1,"cvd.event(tmin,\"Start_record()\")"))

the result of running one or the other is quite different,the first works perfectly but the second seem to not initialize the procedure Start_record...


I will show here two short examples with only one object

FIRST CASE
fih0.append(new FInitializeHandler(1,"Start_record()"))
result: prints all my vectors from t=0 till t=tmax
time is 0 (t initial)
first instance of n_cel
layerP[0].o(0).soma cvd.record(&v(0.5),rec_list_v_P0.o(0),rec_list_t_P0.o(0))

first instance of size_v
first instance of t_v
0 -70
0.20309252 -69.93921
0.40618503 -69.87959
0.93772227 -69.728674
1.4692595 -69.58437
in this case I started recording data at t=0 and then one event is delivered saying that at tmax=150 data should be written to a file and it works fine !!!
now I would want to start the recording of the data at tmin>0 so what I try t do is to use
fih0.append(new FInitializeHandler(1,"cvd.event(tmin,\"Start_record()\")"))
and the result is this
oc>time is 82 (t initial)
first instance of n_cel
layerP[0].o(0).soma cvd.record(&v(0.5),rec_list_v_P0.o(0),rec_list_t_P0.o(0))
It doesn't print anything because the vectors are not initialized and when I look at the vector.size() it says -1

So, does somebody know what is wrong here??
what is the problem with the initialization?

Thanks a lot in advance for any feedback!!!

p.s. By the way, the function prt2file(word,wrd2) doesn't change from one situation to the other

OJAG

ted
Site Admin
Posts: 5330
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: why these initializations produce different results?

Post by ted » Wed Mar 10, 2010 8:50 pm

It's pretty subtle code. Maybe somebody else can tell you what's wrong with it. My preference would be to start with something very simple that I could get working on a toy problem, like this:
create a single compartment model cell with surface area 100 um2, with only the pas mechanism
g_pas = 0
e_pas = 0
cm = 0.001
attach an IClamp with del=0 dur=1e9 amp=1e-6

For this model, soma.v is a ramp that starts at 0 mV and rises at a rate of 1 mV/ms.

Then I'd do the following:

Code: Select all

// declare these constants
T0 = 1 // when to start recording
T1 = 3 // when to stop recording
TZ = 10 // when to stop simulation

// declare the objrefs that will (eventually) point to Vectors that will hold the recorded values
objref vvec, tvec

/*
define a custom run procedure that
sets up Vector recording and executes a simulation in three segments:
0 to T0   discard these results
T0 to T1  keep these results
T1 to TZ  ignore these results
*/
proc customrun() { localobj vtmp, ttmp
  tstop = TZ

  vtmp = new Vector() // set up recording to temporary vectors
  ttmp = new Vector()
  vtmp.record(&v(0.5))
  ttmp.record(&t)

  stdinit()
  continuerun(T0)
  frecord_init() // throw away the first part

  continuerun(T1) // record the second part
  vvec = new Vector() // copy results to "permanent" vectors
  tvec = new Vector()
  vvec = vtmp.c
  tvec = ttmp.c

  vtmp = new Vector()
  ttmp = new Vector()
  continuerun(TZ) // don't bother recording the third part
}
And I'd test it with

Code: Select all

objref g
proc showresults() {
  g = new Graph(0)
  g.size(0,10,0,10)
  g.view(0, 0, 10, 10, 362, 369, 300.48, 200.32)
  g.label(0.3, 0.8, "recorded data", 2, 1, 0, 0, 1)
  vvec.plot(g, tvec)
}

proc go() {
  customrun()
  showresults()
}

go()
And this does work.

But it would be nicer to not have to record the results from 0 to T0, especially if there's a lot of data to store. I tried changing this bit of proc customrun()

Code: Select all

  vtmp.record(&v(0.5))
  ttmp.record(&t)

  stdinit()
  continuerun(T0)
  frecord_init() // throw away the first part

  continuerun(T1) // record the second part
to

Code: Select all

  stdinit()
  continuerun(T0)
  vtmp.record(&v(0.5))
  ttmp.record(&t)
  frecord_init() // initialize Vector recording

  continuerun(T1) // record the second part
but nothing was recorded. So it looks like frecord_init() does not "connect" the recorded variable to a vector--that must be happening in the code that stdinit() calls.

But if T0 is so large that you run out of storage, maybe you can do something like this

Code: Select all

  stdinit()
  for i=1,NUM {
    continuerun(i*T0/NUM)
    frecord_init() // throw away the first part
  }
where NUM is an integer large enough that T0/NUM is not too big.

hines
Site Admin
Posts: 1517
Joined: Wed May 18, 2005 3:32 pm

Re: why these initializations produce different results?

Post by hines » Thu Mar 11, 2010 8:17 am

You are right that finitialize does the job of initializing the record vectors. I didn't try the following myself but if you don't mind being the guinea pig for it
try calling
frecord_init()
in your Start_record procedure after executing the Vector.record statements.
Just in case your tmin is 0 it is probably best to use a first FInitializeHandler arg of type 2

frecord_init was intended to initialize the recordings in case states are changed after the finitialize
call (still at time 0) and I'm not positive this is going to work but it seems to me there is a good chance
it will. I'm a little shaky about the implications of changing the record ( and play) lists in
the middle of a run. If it doesn't work I'll look into it further.

I did not consider your statement:
p.s. By the way, the function prt2file(word,wrd2) doesn't change from one situation to the other
Is that good or bad and does it need a comment?

Post Reply