Rasterogramm of two overlapping rings

Moderator: wwlytton

Post Reply
vladimirov
Posts: 50
Joined: Thu Jul 07, 2011 6:20 pm

Rasterogramm of two overlapping rings

Post by vladimirov »

Hi,
I am simulating two cell rings (loops) which share some cells with each other. When I use the NetCon.record(), I find that the shared cells ids are missing for the first ring.
The code is like this:

Code: Select all

proc spikerecord1() {local i  localobj nc, nil
  tvec1 = new Vector()
  idvec1 = new Vector()
  for i=0, loop1.count()-1 {
    nc = loop1.object(i).connect2target(nil)
    nc.record(tvec1, idvec1, i)
  }
}
proc spikerecord2() {local i  localobj nc, nil
  tvec2 = new Vector()
  idvec2 = new Vector()
  for i=0, loop2.count()-1 {
    nc = loop2.object(i).connect2target(nil)
    nc.record(tvec2, idvec2, i)
  }
}
spikerecord1()
spikerecord2()
So, idvect1 misses the firing cells which are shared, while idvect2 contains all firing cells correctly. Why is that and how can I fix this?
Thank you!
ted
Site Admin
Posts: 6303
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Rasterogramm of two overlapping rings

Post by ted »

To quote from the Programmer's Reference documentation of the NetCon class:
"Recording takes place on a per source, not a per netcon basis, and the source only records into one vector at a time."
Which means that spike times from any cell will be captured into the vector pair that has most recently appeared in a NetCon.record() statement.

Comments and a suggestion:

What is to be gained by having duplicate recordings from a given cell?

"Well, it's nice because after a run I can immediately say 'these spikes were generated by the cells in this loop, and those spikes were generated by the cells in that loop.'"

OK, but (1) it wastes storage, (2) the contents of the two pairs of vectors don't tell you which cells are the "shared cells" (you have to figure that out after each run), and (3) the code that sets up spike recording is complicated by having two procs that are identical in all regards except for "magic numbers" that are buried in the code (by which I mean the "1"s and "2"s that distinguish the two loops and the two pairs of vectors)--which can complicate code debugging and maintenance. Been there, done that.

It would be better to assign each cell a unique identifier at the time it is created. (I'd also put all cells in a single List and use symbolic constants declared at the top of the source code to keep track of how many cell instances there are for each cell class, how many cells are in each subnet etc., because that will make it much easier to parallelize the code later on). Then record all spike times to just one pair of vectors (makes your "model setup and instrumentation code" simpler and easier to maintain, and also saves storage by avoiding duplication of recorded data). If you like, you could use vectors of "cell id numbers" to keep track of which cells belong to which loops, or to other subnets (alternatively, you might be able to figure this out from the symbolic constants). After a run you can use the Vector class's methods--which are very fast since they're executed by compiled code--to retrieve the spike times that belong to each subnet.
vladimirov
Posts: 50
Joined: Thu Jul 07, 2011 6:20 pm

Re: Rasterogramm of two overlapping rings

Post by vladimirov »

Ted, thank you so much for detailed response and the tips.
What are symbolic constants and how can I use them in this context? Is it like "a", "b", "c"? Can you give a small example or a link where I can find it?
Thanks!
ted
Site Admin
Posts: 6303
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Rasterogramm of two overlapping rings

Post by ted »

Definition and brief example in C/C++
http://sourcemaking.com/refactoring/rep ... c-constant

Examples in hoc: imagine that the following are excerpts from a program. First, code full of "literals" (aka "magic numbers")--

Code: Select all

load_file("nrngui.hoc")
load_file("pyrclass.hoc") // defines Pyr class
 . . . more code . . .
create allcells
for i=0,23 allcells.append(new Pyr())
 . . . more code . . .
tstop = 500 // ms
// run 3 simulations, analyzing and save results from each
for i=0,2 {
  change_some_parameter()
  run()
  analyze_results(i)
  save_results(i)
}
Next, code that uses symbolic constants declared at the top of the program.

Code: Select all

NUMCELLS = 24
TSTOP = 500
NUMRUNS = 3
 . . . more symbolic constants . . .
load_file("nrngui.hoc")
load_file("pyrclass.hoc") // defines Pyr class
 . . . more code . . .
create allcells
for i=0,NUMCELLS-1 allcells.append(new Pyr())
 . . . more code . . .
tstop = TSTOP // ms
// run simulations, analyzing and save results from each
for i=0,NUMRUNS-1 {
  change_some_parameter()
  run()
  analyze_results(i)
  save_results(i)
}
Two months from now you decide to try models with a different number of cells, different simulation duration, and a different number of runs. Which code would you prefer to use?
vladimirov
Posts: 50
Joined: Thu Jul 07, 2011 6:20 pm

Re: Rasterogramm of two overlapping rings

Post by vladimirov »

Oh, that's what is symbolic constants. I always try to use this style, of course, and put all (most) controls at the top of code. I thought "symbolic constants" is something special :)
Thanks a lot, Ted!
ted
Site Admin
Posts: 6303
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Rasterogramm of two overlapping rings

Post by ted »

You and I may already know, and now someone else who reads this thread in the future will also know.
Post Reply