Chapter 11 Modeling Networks 'The NEURON Book'

Moderator: wwlytton

Post Reply
R_Jarvis

Chapter 11 Modeling Networks 'The NEURON Book'

Post by R_Jarvis » Sun Nov 22, 2009 7:17 am

As the subject field suggests I am trying to work through the tutorial in Chapter 11 modeling networks in The NEURON Book.

I am using version NEURON version 7.0 on Hardy Heron Ubuntu Linux.

When I try running my init file from the interpreter I get the following errors:
oc>load_file("init.hoc")
1
1
/opt/nrn/i686/bin/nrniv: syntax error
in makenet.hoc near line 3
for i=0, ncell-1
^
xopen("makenet.hoc")
execute1("{xopen("makenet.hoc")}")
load_file("makenet.hoc")
xopen("init.hoc")
and others
0
/opt/nrn/i686/bin/nrniv: position : can't push that type onto stack
in makenet.hoc near line 6
}
^
cell_append(..., 4, 0, 0)
xopen("init.hoc")
execute1("{xopen("init.hoc")}")
load_file("init.hoc")
oc_restore_code tobj_count=1 should be 0
0
initcode failed with 1 left
/opt/nrn/i686/bin/nrniv: syntax error
in makenet.hoc near line 8
for i=0, ncell-1 for j=0, ncell-1 if (i! = j)

The file that is being called from init and causing all the problems is makenet.hoc
It looks like ncell is expected to be declared.
The code inside makenet.hoc is on page 329 of the book.

I have checked all of the code really carefully and I can't figure out the problem.

Also when I generated hoc code from the GUI I noticed some differences in code for the file prototype.hoc
On the file that I generated the first few lines were:

'// Artificial cells no longer need a default section.
//Network cell templates
//Artificial cells
// IF_IntervalFire'

I made another file which I have called netdef.hoc, that is an exact copy of the example in the book (page 325) of the .hoc code generated from the GUI.

I was wondering if any one knows what is probably wrong with my makenet.hoc file (below)? Also I was wondering if the changes I have noticed between the book and NEURON 7 are significant, or if there is anything I should be aware of?

I can see the possibility that this is a silly mistake of my own.
Sorry if this is not the best place in the forum to post this question.

Thanks.
Russell.


for i=0, ncell-1 {
cell_append(new IF_IntervalFire(), i, 0, 0)
}

for i=0, ncell-1 for j=0, ncell-1 if (i! = j) {
nc_append(i,j,-1,0,1)
}

proc createnet() {
local i, j
ncell = $1
for i=0,$1-1{
cell_append(new IF_IntervalFire(), i, 0, 0)
}
for i=0, $1-1 for j=0, $1-1 if (i !=j ){
nc_append(i,j,-1,0,1)
}
}

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

Re: Chapter 11 Modeling Networks 'The NEURON Book'

Post by ted » Sun Nov 22, 2009 8:24 pm

Thanks for using NEURON, and also for reading The NEURON Book.

I just tried the old code--which is very different from the excerpts you provide--and it still works, so there's probably something wrong with your code somewhere, but the fatal error may not be in the provided excerpts. You'll probably learn more by debugging and fixing your own code than by having me dig into it and show you what went awry, so here's a couple of questions to help you get started.

Presumably you have an init.hoc file that contains several load_file() statements. The first is probably
load_file("nrngui.hoc")
which is not where the problem lies.

It's the contents of the other files that are loaded that are in question. If you have been applying the development strategy of "iterative revision and testing" you will have tested each of them repeatedly and are quite sure that each is correct. Time to become a doubting Thomas.

Comment out all but the first nontrivial load_file statement and run
nrngui init.hoc
(or double click on init.hoc).
At the oc> prompt try
objref foo
foo = new IF_IntervalFire()
to verify that you can create a new instance of the IF_IntervalFire class.

If that works, find out if cell_append() works properly by executing the command
cell_append(new IF_IntervalFire(), 0, 0, 0)
If that doesn't work, see what you can make of the error message. Also, examine the contents of netdefs.hoc, especially func cell_append(). What objrefs does cell_append() use? Do they exist? (how can you tell if an objref exists?)

Maybe this is enough to help you home in on the problem. Let me know if you still have questions.

PS--large code excerpts look nicer in this forum if they are surrounded by appropriate markup--see Preserving code and text formatting http://www.neuron.yale.edu/phpBB/viewto ... f=20&t=493

R_Jarvis

Re: Chapter 11 Modeling Networks 'The NEURON Book'

Post by R_Jarvis » Mon Nov 23, 2009 2:37 am

Okay thank you very much for you response.

This time I have made an entirely new directory and started again from scratch. I also have copy to an electronic version of the NEURON book. I cut and paste that code from pdfs into files of the same names and added in comment symbols in front of text that was not commented in the book for makenet.hoc, and netdefs.hoc .

The code passed all of the checks you mentioned (examples below), it is only when I uncomment both non trivial files at the same time, and do the tests on page 330 that I get error messages. I think the problem is with the way 'ncell' is declared in makenet.hoc but I am still learning the syntax so I am unsure, the compiler error which makes me suspect this is at the end of this post.

In answer to your question: how can I tell if objref exists.

I think I can tell if objref exists in the command test because the number 2 is printed afterwoods corresponding to two objects made. But I am still trying to figure out how I can tell if it exists when the program is executed, rather than just from the prompt.

The first argument to cell_append()

is an objref that points to a new cell that is to be added to the list and the remaining arguments are the x,y,z coordinates that will be assigned to that cell (I think they represent physical position).

The objref (object reference) cell_append is using is 'IF_IntervalFire()'

To tell if objref exists when init executes both programs. I think I would have to check the list of numbers that appears at the oc> prompt after I have executed init.hoc. I am unsure but I think the vertical line of 0s and 1s corresponds to either object instantiations, or return statements or both.

Maybe I can also insert statements into netdefs.hoc code that check the arguments that are being put into to

func cell_append() {cells.append($o1) $o1.position($2,$3,$4)

are working when makenet.hoc tries to use that function?

Code: Select all


Here is the results from the test.

Additional mechanisms from files
 IntervalFire.mod
	0 
	1 
	0 
	1 
oc>objref foo 
oc>foo = new IF_IntervalFire()
oc>cell_append(new IF_IntervalFire(), 0, 0, 0)
	2 


Here is the contents of netdefs, cut and pasted from the book and with book comments, commented out.

Code: Select all

for i=0, ncell-1 {
	cell_append(new IF_IntervalFire(), i, 0, 0)
	}
//will make them for us, and this nested loop

for i=0, ncell-1 for j=0, ncell-1 if (i != j) {
	nc_append(i, j, -1, 0, 1)
	}

//will attach them to each other. An initial stab at embedding both of these
//in a procedure which takes a single argument that specifies the size of the
//net is

proc createnet() { local i, j
	ncell = $1
	for i=0, $1-1 {
	cell_append(new IF_IntervalFire(), i, 0, 0)
	}

for i=0, $1-1 for j=0, $1-1 if (i != j) {
	nc_append(i, j, -1, 0, 1)
	}
}

Here is what happens finally when I try to execute
oc>createnet(2)

Code: Select all

oc>ncell
/opt/nrn/i686/bin/nrniv: undefined variable ncell
 near line 14
 ncell
If I use init with netdefs.hoc makenet.hoc both uncommented at the same time I get:

Code: Select all

createnet(2)
/opt/nrn/i686/bin/nrniv: createnet undefined function
 near line 21
 createnet(2)
             ^
        createnet(2)
Thanks very much for your help again, and I appreciate any questions or advice which will help me to debug the code.

Cheers.
Russell.[

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

Re: Chapter 11 Modeling Networks 'The NEURON Book'

Post by ted » Mon Nov 23, 2009 3:03 pm

R_Jarvis wrote:I also have copy to an electronic version of the NEURON book. I cut and paste that code from pdfs into files of the same names
Michael Hines and I have not seen the digital version of the book ourselves, so I don't know whether it contains typographical errors.
In answer to your question: how can I tell if objref exists.
Here's a quick and dirty way to find out: just type the name of the suspected objref at the oc> prompt.

Code: Select all

oc>foo
/usr/local/nrn/i686/bin/nrniv: undefined variable foo
 near line 1
 foo
    ^
if the token "foo" has never been used as a scalar, or declared as a double, strdef, or objref

Code: Select all

oc>objref foo
oc>foo
        NULLobject 
because the objref does not yet point to an instance of any class

Code: Select all

oc>foo = new Graph()
oc>foo
        Graph[0] 
because foo now points to an instance of the Graph class.
I think I can tell if objref exists in the command test because the number 2 is printed afterwoods corresponding to two objects made. But I am still trying to figure out how I can tell if it exists when the program is executed, rather than just from the prompt.
Look at the code. If it succeeds, the following four predictions should be true:
1. There will be an instance of the _____ class
2. This instance will be called ______
3 and 4. It will contain _____ instances of the _____ class.

These are testable predictions. To verify them, type the name of your answer to 2 and see that it returns your answer to 1. Then use the appropriate method for class 1 to discover how many objrefs have been appended to it. Finally, write a "one liner" for loop that prints out the names of each objref that has been appended to 2.
Maybe I can also insert statements into netdefs.hoc code that check the arguments that are being put into to
func cell_append() {cells.append($o1) $o1.position($2,$3,$4)
printf statements are often useful to verify the proper sequence of program execution, and also to verify that passed arguments are correct. But the first thing to do is to decide what new things should exist after a particular chunk of code has been executed, and then verify whether or not they exist. If they do exist, you can turn your attention to the next chunk of code. If they don't, you have to dig into the current code chunk and figure out why not.

Code: Select all

oc>objref foo 
oc>foo = new IF_IntervalFire()
No error message. So the class definition is not fatally broken.

Code: Select all

oc>cell_append(new IF_IntervalFire(), 0, 0, 0)
	2 
Again no error message. So cell_append() may be working.
Here is the contents of netdefs
I don't think so. netdefs.hoc is just listing 11.2 with the last four lines commented out. It's 48 lines long, starts with

Code: Select all

// NetGUI default section. Artificial cells, if any, are located here.
  create acell_home_
  access acell_home_
and ends with

Code: Select all

//  /* IF1 */  cell_append(new IF_IntervalFire(), -67,     73, 0)
//  /* IF1 -> IF0    */  nc_append(1, 0, -1,  -0.1,1)
//  /* IF0 -> IF1    */  nc_append(0, 1, -1,  -0.1,1)

nianwosuh
Posts: 39
Joined: Tue Jul 27, 2010 11:00 pm

Re: Chapter 11 Modeling Networks 'The NEURON Book'

Post by nianwosuh » Mon Aug 16, 2010 11:17 pm

I have read the postings on the "Chapter 11 Modeling Networks in NEURON book", but the responses did not quite address my problem because there are some differences. I use the Kindle version of the NEURON book and 7.2 version of the NEURON simulation environment.

In section 11.4.1 of the NEURON Book "Defing types of artificial cells" The artificial cells in my ArtCellGui are NetStim, IntFire1, IntFire4 and IntFire4. The IntervalFire is not there. Rather than using the IntervalFire that was used in the example in the NEURON book, I worked through the example with intFire1, but when I ran the simulation, there was no spike trains in the SpikePlot, even when I played with the values of the weight.

I repeated all the steps using NetStim, but rather than using -0.1 for the weights, I used positive values. When I used negative values, only a single dot appeared on the SpikePlot, but there were two trains of spike when I used the positive values for the weight.

I continued through the example using NetStim, had no error messages until section 11.5.2 "Exploiting reuseable codes" . I created the makenet.hoc file which is

proc createnet() {local i, j
ncell = $1
for i = 0, $1 - 1 {
cell_append(new S_NetStim(), i, 0, 0)
}
for i = 0, $1 - 1 for j=0, $1 - 1 if (i !=j) {
nc_append(i, j -1, 0, 1)

}

}
I ran the initial.hoc file there was no error message generated, but when I typed "createnet(2)" at the prompt in the nrvi window, the following error message was generated

synlist not a public member of S_NetStim
nrniv: S_NetStim synlist
near line 5
createnet(2)
^
nc_append(0001 , , , )
createnet(2 )
initcode failed with 2 left.

My question then is;

How do I know the correct syntax to use in expanding net work for each artificial cell that could be used to generate spkie trains in a network

Thank you
Irene

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

Re: Chapter 11 Modeling Networks 'The NEURON Book'

Post by ted » Tue Aug 17, 2010 12:04 pm

The example in chapter 11 takes a lot of effort to struggle through--there are many conceptual issues to deal with, and many opportunities for error, especially typos.

The architecture of a network (the map of connections between the cells), the properties of the constituent cells, and the properties of the synapses that connect them, are all determinants of how that network functions. Some of your observations illustrate the importance of the properties of the cells and synapses.
Rather than using the IntervalFire that was used in the example in the NEURON book, I worked through the example with intFire1, but when I ran the simulation, there was no spike trains in the SpikePlot
and there aren't going to be any spike trains, because this network can't generate spike trains unless it is constructed from cells that fire spontaneously. An IntFire1 cell is not spontaneously active--each spike occurs in response to an excitatory input that drives its "membrane state variable" m above threshold, and once that happens, m is reset to 0 so that the cell remains silent until additional excitatory inputs are received.

If you want to replicate the example shown in the book, you'll have to use the same kind of artificial spiking cell as the book used--IntervalFire, whose NMODL source code is presented in Listing 11.1. Compile that mod file, then run NEURON starting in the same directory as where the mod file is located, and you will find that IntervalFire appears in the appropriate menus of NEURON's GUI tools. If you use the GUI to build the simple "two neuron net" out of IntervalFire cells, and then export a hoc file, you can extract the template (class definition) that you need to create a network model that uses IntervalFire cells.

One might well ask, "IntFire2 will fire spontaneously if its 'bias' ib is > 1, so wouldn't this net produce spike trains if it were constructed from IntFire2 cells?" That's an interesting hypothesis. My intuition is that IntFire2 cells can't substitute for IntervalFire cells because the dynamics of the cells and their synapses are so different. In IntervalFire cells, IPSPs are relatively brief compared to membrane time constant, but IPSPs are much longer lasting in IntFire2 cells, so I'd be surprised if such a network, built of IntFire2 cells, would be able to generate "nearly synchronized" spiking. However, the only way to be sure is plug IntFire2 cells into the network architecture and see what happens. In other words, use the GUI to build and test a two cell toy network that uses IntFire2, then export its hoc file, mine the reusable code from it, and combine it with a copy of the hoc code you have already developed to simulate the net with IntervalFire cells, so that you end up with a network of IntFire2 cells.
I continued through the example using NetStim
The network won't operate properly with NetStim either. An inhibitory input to a NetStim merely turns off its spiking until it receives an excitatory input, at which point it starts spiking.

What about the error message?

Code: Select all

proc createnet() {local i, j
    ncell = $1
    for i = 0, $1 - 1 {
     cell_append(new S_NetStim(), i, 0, 0)   
 }
for i = 0, $1 - 1 for j=0, $1 - 1 if (i !=j) {
   nc_append(i, j -1, 0, 1)
There's why you got this error msg

Code: Select all

synlist not a public member of S_NetStim
The nc_append statement is missing a comma. It should be

Code: Select all

   nc_append(i,  j,  -1, 0, 1)
Explanation:

If you look at hoc code for the template for a biophysical model cell generated by the Network Builder, you'll see that it contains a public member called synlist. The synlist is a List whose elements are objrefs that point to the various synaptic mechanisms (point processes) that are attached to the biophysical model cell. A List is used because a biophysical model cell may have many different synaptic mechanisms (point process instances) attached to it. The elements of a List are indexed by nonnegative integers--the first one is listname.object(0), the second is listname.object(1), etc.

To build a network that includes a biophysical model cell, one must be able to specify which of the cell's point processes is going to be driven by a NetCon. That's the purpose of the third argument to nc_append. Here are the first few lines of nc_append (see Listing 11.2 on page 325), with explanatory comments instead of detailed code--

Code: Select all

func nc_append() {
  if ($3>=0) {
    . . . this is a valid index into the elements of a List . . .
    . . . so attach the NetCon to synaptic mechanism number $3 on the target cell . . .
  } else {
    . . . the target cell is an artificial spiking cell--attach the NetCon directly to the target cell . . .
  }
The first two arguments of nc_append are the indices ("numeric labels") of the pre- and postsynaptic cells. If the target is a synaptic mechanism attached to a biophysical model cell, the third argument is a nonnegative integer (0, 1, . . .) that identifies which synaptic mechanism. If the target is an artificial spiking cell, the third argument to nc_append must be < 0.

nianwosuh
Posts: 39
Joined: Tue Jul 27, 2010 11:00 pm

Re: Chapter 11 Modeling Networks 'The NEURON Book'

Post by nianwosuh » Tue Aug 17, 2010 9:49 pm

Thank you very much for the detailed explainations.

Please are they references where I can read about these different artifcial neurons to help me understand when each could be used in the network models to generate spike trains?

Thank you
Irene

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

Re: Chapter 11 Modeling Networks 'The NEURON Book'

Post by ted » Wed Aug 18, 2010 10:04 am

The built-in artificial spiking cell types are IntFire1, IntFire2, and IntFire4; these are described briefly in the Programmer's Reference. IntFire1 is described in more detail in
Hines, M.L. and Carnevale, N.T.
Discrete event simulation in the NEURON environment.
Neurocomputing 58-60:1117-1122, 2004.
A preprint of the latter is available from http://www.neuron.yale.edu/neuron/nrnpubs.
However, the most thorough discussion of the three IntFire classes is presented in chapter 10 of The NEURON Book.

IntervalFire, which is not built into NEURON, is described in chapter 11 of The NEURON Book.

nianwosuh
Posts: 39
Joined: Tue Jul 27, 2010 11:00 pm

Re: Chapter 11 Modeling Networks 'The NEURON Book'

Post by nianwosuh » Wed Aug 18, 2010 3:03 pm

Thank you again.

I have tried several times to make the NMODL (listing 11.1) several times, merticously tying eacg letter as it appears in the list ing, this error message comes up always.

Under INITIAL, t0 =t,
and similarly under NET_RECEIVE.

I don't know if that is why it says to is undefined.

Thank you
Irene

gcc -DDLL_EXPORT -DPIC -I/cygdrive/C/nrn72/src/scopmath -I/cygdrive/C/nrn72/src/nrnoc -I/cygdrive/C/nrn72/src/oc -I/cygdrive/C/nrn72/lib -I/cygdrive/C/nrn72/gccinc -I/cygdrive/C/nrn72/gcc3inc -L/cygdrive/C/nrn72/gcclib -c mod_func.c
nocmodl IntervalFire
Translating IntervalFire.mod into IntervalFire.c
Warning: t0 undefined. (declared within VERBATIM?)
Thread Safe
gcc -DDLL_EXPORT -DPIC -I/cygdrive/C/nrn72/src/scopmath -I/cygdrive/C/nrn72/src/nrnoc -I/cygdrive/C/nrn72/src/oc -I/cygdrive/C/nrn72/lib -I/cygdrive/C/nrn72/gccinc -I/cygdrive/C/nrn72/gcc3inc -L/cygdrive/C/nrn72/gcclib -c IntervalFire.c
IntervalFire.c: In function ‘M_IntervalFire’:
IntervalFire.c:230: error: ‘t0’ undeclared (first use in this function)
IntervalFire.c:230: error: (Each undeclared identifier is reported only once
IntervalFire.c:230: error: for each function it appears in.)
IntervalFire.c: In function ‘initmodel’:
IntervalFire.c:251: error: ‘t0’ undeclared (first use in this function)
make: *** [IntervalFire.o] Error 1

There was an error in the process of creating nrnmech.dll
Press Return key to exit

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

source code for IntervalFire

Post by ted » Wed Aug 18, 2010 6:13 pm

nianwosuh wrote:this error message comes up always.
. . .
IntervalFire.c: In function M_IntervalFire:
IntervalFire.c:230: error: t0 undeclared (first use in this function)
Does the ASSIGNED block declare t0 (t followed by numeral zero) or does it define to (lower case t followed by lower case o)?

I see that the ASSIGNED block (of the code in The NEURON Book itself!) has a minor typographical error that doesn't seem to cause a problem: the declaration of t0 is written as

Code: Select all

  t0(ms)
rather than

Code: Select all

  t0 (ms)
I much prefer to leave a space between the 0 and the (, not least because it reminds the reader that the (ms) is a units declaration.

In any case, here is the source code for the entire mod file:

Code: Select all

: dm/dt = (minf - m)/tau
: input event adds w to m
: when m = 1, or event makes m >= 1 cell fires
: minf is calculated so that the natural interval between spikes is invl

NEURON {
	ARTIFICIAL_CELL IntervalFire
	RANGE tau, m, invl
}

PARAMETER {
	tau = 5 (ms)   <1e-9,1e9>
	invl = 10 (ms) <1e-9,1e9>
}

ASSIGNED {
	m
	minf
	t0 (ms)
}

INITIAL {
	minf = 1/(1 - exp(-invl/tau)) : so natural spike interval is invl
	m = 0
	t0 = t
	net_send(firetime(), 1)
}

FUNCTION M() {
	M = minf + (m - minf)*exp(-(t - t0)/tau)
}

NET_RECEIVE (w) {
	m = M()
	t0 = t
	if (flag == 0) {
		m = m + w
		if (m > 1) {
			m = 0
			net_event(t)
		}
		net_move(t+firetime())
	} else {
		net_event(t)
		m = 0
		net_send(firetime(), 1)
	}
}

FUNCTION firetime()(ms) { : m < 1 and minf > 1
	firetime = tau*log((minf-m)/(minf - 1))
:	printf("firetime=%g\n", firetime)
}

nianwosuh
Posts: 39
Joined: Tue Jul 27, 2010 11:00 pm

Re: Chapter 11 Modeling Networks 'The NEURON Book'

Post by nianwosuh » Thu Aug 19, 2010 3:15 pm

Thank you very much! I had a typo in my txt file "to " rather than t0.

Post Reply