Plot a graph of sum of neuron potentials in network?

Moderator: wwlytton

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

Plot a graph of sum of neuron potentials in network?

Post by vladimirov »

Hi,
I constructed a network and now try to plot its state during the simulation: e.g. how many neurons are spiking as a function of time. So, basically I have

Code: Select all

ncells=100
objectvar cell[ncells+1]
... (cell definition and connecting)
For instance, I need to plot how many somas (cell.soma.v) have voltage above -40 mV at each time point (or similar def. of spiking event)
I know it must be trivial, but I am new to hoc and not sure how to make the plot of sum of variables and update it during the simulation.

Can anybody give me an advice how to do this? Thank you!
ted
Site Admin
Posts: 6299
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Plot a graph of sum of neuron potentials in network?

Post by ted »

Assign a unique integer to each cell, then use the NetCon class's record() method to capture all spike times to one vector, and the corresponding cell IDs to another. Then you can do whatever you want (e.g. discover if a particular subset of cells is firing slow or fast or whatever). Read about the NetCon class here
http://www.neuron.yale.edu/neuron/stati ... tml#record
For working examples see
Hines, M.L. and Carnevale, N.T.
Translating network models to parallel hardware in NEURON.
J. Neurosci. Methods 169:425-455, 2008.
Preprint available from http://www.neuron.yale.edu/neuron/nrnpubs, source code available from ModelDB http://senselab.med.yale.edu/modeldb/
vladimirov
Posts: 50
Joined: Thu Jul 07, 2011 6:20 pm

Re: Plot a graph of sum of neuron potentials in network?

Post by vladimirov »

Thank you. I actually followed examples in your book and added a procedure update_plot() to the step()

Code: Select all

proc step(){local i
  if(using_cvode_){
   advance()
  } else for i=1,nstep_steprun{
   advance()
  }
  update_plot()
}

proc update_plot(){
  sum_spiking=0
  v_thresh=-40
  for i=1,ncells{
	if(cell[i].soma.v>=v_thresh){
	sum_spiking=sum_spiking+1
	} 
  }
  graph1.mark(t,sum_spiking,"O",1,2,1)
  graph1.flush()
}
Kinda poor man approach, but worked out.
Trying the NetCon methods is probably better?
ted
Site Admin
Posts: 6299
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Plot a graph of sum of neuron potentials in network?

Post by ted »

The approach I described produces very compact output (two numbers per spike) that completely describes the activity of the network. All processing of these results must be done offline (although with slight modification it could produce "live" results). It imposes a computational burden that is proportional to the number of spikes, and independent of the number of cells, integration step size, or simulation duration. Your approach generates a single number that reflects total activity in the network integrated over a rectangular window equal to spike width at the threshold level, and requies no postprocessing. It imposes a burden that is proportional to numberofcells*runtime/dt, but this isn't a big problem if the net is small. However, if spike width changes, so does the integration window; is that OK with you?
vladimirov
Posts: 50
Joined: Thu Jul 07, 2011 6:20 pm

Re: Plot a graph of sum of neuron potentials in network?

Post by vladimirov »

At present stage (testing mode) its Ok. But now I see why the NetCon mechanism is superior for large networks. Thanks a lot!
vladimirov
Posts: 50
Joined: Thu Jul 07, 2011 6:20 pm

Re: Plot a graph of sum of neuron potentials in network?

Post by vladimirov »

In you code examples, you store cells in List(). Why is it better than simply in an array like

Code: Select all

objref cells[100]
Any advantages?
ted
Site Admin
Posts: 6299
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Plot a graph of sum of neuron potentials in network?

Post by ted »

Lists are extremely convenient for managing collections of things. Lets you write code that can handle as big or as small a collection as you like. No need to bury magic numbers in your code, remember the values of those numbers, or keep track of a bunch of symbolic constants. Example: today I write

Code: Select all

objref cells[100] // uh oh, magic numbers
for i = 0,99 cells[i] = new Pyr()
 . . . many procs, funcs, and lines of code later . . .
// iterate over all cells
for i = 0,99 { // do I remember that the magic number was 100?
  statements involvling cells[i]
}
Next week I decide to use a different number of cells. Do I remember to change every instance of 99 (or 100) to the correct value?

"Why not use a symbolic constant, like this:
NUMCELLS = 100
Then you can write
objref cells[NUMCELLS]
for i = 0,NUMCELLS-1
etc."

Fine, but suppose I need to manage many different collections of objects, and each collection has a different number of items in it? Then I will have code sprinkled with many different NUMthis and NUMthat, and I have to remember which NUMthis goes with what named array of this or that. Looks ugly.

Better to do this

Code: Select all

NUMCELLS = 100
objref cells
cells = new List()
for i = 0,NUMCELLS-1 cells.append(new Pyr())
Now I can iterate over all cells simply by

Code: Select all

for i=0,cells.count()-1 {
  statements involving cells.o(i)
}
Still using symbolic constants, but only twice: once to define the constant and assign a value to it, and once to create that many instances of a particular class. After that, no need to remember magic numbers or clutter my code with silly names. If I want to change the number of items in any collection, simply change one assignment statement. But that's not all. The mere fact that the name of the list allows you to discover how many things are in it makes it possible to write generic procedures for iterating over sets--powerful abstractions that can be very helpful in program development.
vladimirov
Posts: 50
Joined: Thu Jul 07, 2011 6:20 pm

Re: Plot a graph of sum of neuron potentials in network?

Post by vladimirov »

Ok, got it. Now I will use List(), too. Thanks a lot!
Post Reply