Input a vector to neuron

The basics of how to develop, test, and use models.
Post Reply
Kim Ha
Posts: 18
Joined: Sun Jun 09, 2013 11:26 pm

Input a vector to neuron

Post by Kim Ha »

Hi Ted,
1. I am trying to input a vector which has two column, one is synaptic weight and one is delay time, to Neuron. This vector is created by Matlab and is saved as .txt file. However, I am not able to open it in Neuron. I also find that the vector with one column can be openned. What should I do with two-column vectors?
2. The second question is: when I change the synaptic weight and delay time of the model by loading the data from my above text file (assume that Neuron can read my two-column txt file), I will do the following syntax:
nclist.o(i).delay = vect.x.[1]
nclist.o(i).weight = vect.x[2]
Are these correct?
Thanks a lot!
ted
Site Admin
Posts: 6300
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Input a vector to neuron

Post by ted »

Kim Ha wrote:I am trying to input a vector which has two column, one is synaptic weight and one is delay time, to Neuron. This vector is created by Matlab and is saved as .txt file.
hoc can do the usual file text I/O. You'll want to read the Programmer's Reference documentation of ropen and fscan, or the File class's methods ropen and scanvar.
when I change the synaptic weight and delay time of the model by loading the data from my above text file (assume that Neuron can read my two-column txt file), I will do the following syntax:
nclist.o(i).delay = vect.x.[1]
nclist.o(i).weight = vect.x[2]
Are these correct?
Good question. This raises many issues.

First, hoc indices start with 0, not 1. Second, a Vector is a 1 dimensional array, so vecname.x[j] will generate an error message. It is possible to do this

Code: Select all

objref vecarray[2]
for i=0,1 vecarray[i]=new Vector()
but that gives you an "array" of object references, i.e. objrefs whose names are vecarray[0] and vecarray[1], not a multidimensional array.

Code: Select all

oc>for i=0,1 print vecarray[i]
Vector[5] 
Vector[6]
and the ith element of the jth array would be called vecarray.x[j]

Now I have a couple of questions for you.

Let's suppose that you change this
nclist.o(i).delay = vect.x[1]
nclist.o(i).weight = vect.x[2]
to this
nclist.o(i).delay = vect[0].x
nclist.o(i).weight = vect[1].x
which means that you have two vectors--vect[0] and vect[1]--where vect[0] contains the delays and vect[1] contains the corresponding weights, so setting up the weights and delays would use this loop:

Code: Select all

for i=0,nclist.count-1 {
  nclist.o(i).delay = vect[0].x[i]
  nclist.o(i).weight = vect[1].x[i]
}
Would your program be easier to understand if, instead of an array of two Vectors, each of which contains nclist.count elements, you used a List that contains nclist.count Vectors, where each Vector has two elements? If you called this list ncplist (for "NetCon parameter list"), the delay and weight for the ith NetCon would be called ncplist.o(i).x[0] and ncplist.o(i).x[1], respectively. Then to iterate over all NetCons you'd do this:

Code: Select all

for i=0,nclist.count-1 {
  nclist.o(i).delay = ncplist.o(i).x[0]
  nclist.o(i).weight = ncplist.o(i).x[1]
}
And if you wanted your programming style to be very mnemonic, you could define a couple of symbolic constants
DELAY = 0
WEIGHT = 1
so your code could look like this

Code: Select all

for i=0,nclist.count-1 {
  nclist.o(i).delay = ncplist.o(i).x[DELAY]
  nclist.o(i).weight = ncplist.o(i).x[WEIGHT]
}
Kim Ha
Posts: 18
Joined: Sun Jun 09, 2013 11:26 pm

Re: Input a vector to neuron

Post by Kim Ha »

Thank you for your instruction.
I got your idea. Actually, I was working on the same thing as yours. I save delay and weigh to two text files and then scan them to neuron files. The code looks like the following:

Code: Select all

//Note to open ha.dat file need to change the directory to the position we save the file
getcwd()
chdir("C:/nrn73/lib/hoc")
load_file("ha.dat") //not sure we need this
objref n
n = new Vector()
objref f
f = new File()
f.ropen("ha.dat") //to read the txt file to a file of Neuron
n.scanf(f) // record to vector n
print n.size() //just to check
print n.x[1] //just to check
nclist.o(1).delay = n.x[1]
The change of directory syntax also ensures my spike train file to be saved in the desired folder. Otherwise, the program will save it in C:/windows/system32. Opps! I do not know why.
I got the matlab-neuron interface work now.
Thank Ted for helping me understand many things!
ted
Site Admin
Posts: 6300
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Input a vector to neuron

Post by ted »

This
chdir("C:/nrn73/lib/hoc")
tells me you're writing into NEURON's installation tree. That's a bad idea, because
(1) if you make a mistake, you might overwrite or delete one of the files that NEURON depends on,
and
(2) if you ever install a new version of NEURON, the first thing you have to do is uninstall the previous version, and this means you will have to delete the old installation tree--and that will eliminate your own files.

It's best to put your own code in a directory that belongs to you. You might want to create such a directory in your own Documents folder, for example
C:\Users\ted\Documents\models
or perhaps in your Desktop folder
C:\Users\ted\Documents\models
Then each modeling project should have its own directory inside your models folder.
The change of directory syntax also ensures my spike train file to be saved in the desired folder. Otherwise, the program will save it in C:/windows/system32.
When I installed NEURON on my desktop pc, the installation directory turned out to be C:\, and that is also NEURON's working directory if I start NEURON by clicking on the nrngui icon in the NEURON program group. Of course, Windows prevents me from saving any ses files or writing any data files to C:\. But if I put a hoc file in a folder where I have write privileges, then double click on that file (inside Windows Explorer), NEURON starts with that folder as its working directory and I can write ses or data files there without difficulty.

Thanks for using NEURON!
Kim Ha
Posts: 18
Joined: Sun Jun 09, 2013 11:26 pm

Re: Input a vector to neuron

Post by Kim Ha »

Ted,
I have tried saving all files in a folder. In my init_fishmodel.hoc I have:

Code: Select all

load_file("nrngui.hoc")
load_file("fishmodel.hoc")
load_file("initrun_fishmodel.hoc")
load_file("wtdel.hoc")
But the program cannot find fishmodel.hoc, initrun_fishmodel.hoc and wtdel.hoc. Therefore, I have to wirte the following:

Code: Select all

load_file("nrngui.hoc")
chdir("C:/Users/Ha Ngo/My Documents/Models/twosegments")
load_file("fishmodel.hoc")
load_file("initrun_fishmodel.hoc")
load_file("wtdel.hoc")
Maybe, it is just the problem of my computer. Because at first the directory is C:/, now it is always C:/windows/system32.
ted
Site Admin
Posts: 6300
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Input a vector to neuron

Post by ted »

Please run these tests.

1. Create a text file called test.hoc that contains this statement
system("pwd")
and save it to your Desktop. Then double click on test.hoc and tell me what NEURON prints to its terminal.

2. Create a folder on your desktop called newtest.
In that folder put the following two files:
main.hoc which contains

Code: Select all

print "in main, about to load sub.hoc"
load_file("sub.hoc")
print "back in main"
and sub.hoc which contains

Code: Select all

print "in sub"
Now double click on main.hoc and tell me what NEURON prints to its terminal.
Kim Ha
Posts: 18
Joined: Sun Jun 09, 2013 11:26 pm

Re: Input a vector to neuron

Post by Kim Ha »

Ted,
For the first test, the following appears:

Code: Select all

NEURON -- Release 7.3 (849:5be3d097b917) 2013-04-11
Duke, Yale, and the BlueBrain Project -- Copyright 1984-2013
See http://www.neuron.yale.edu/neuron/credits

/cygdrive/c/Windows/system32
        0 
oc>
For the second test, the command window prints the following:

Code: Select all

NEURON -- Release 7.3 (849:5be3d097b917) 2013-04-11
Duke, Yale, and the BlueBrain Project -- Copyright 1984-2013
See http://www.neuron.yale.edu/neuron/credits

in main, about to load sub.hoc
nrniv: Couldn't find: sub.hoc
 in /cygdrive/C/Users/Ha Ngo/Desktop/newtest/main.hoc near line 2
 load_file("sub.hoc")
                     ^
        0 
back in main
oc>
ted
Site Admin
Posts: 6300
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Input a vector to neuron

Post by ted »

I think that you should move all of your own files out of NEURON's installation tree, and put them in a folder that is in some location outside of the Windows system directories. You might want to put that folder in
C:\Users\Ha Ngo\Desktop
or
C:\Users\Ha Ngo\Documents

Then do a complete uninstall of NEURON (use NEURON's own Uninstall program, which you'll find in the NEURON Program Group). After that is finished, check to make sure that there is no
C:\nrn, C:\nrn72, or C:\nrn73
and if you see one, delete it and all of its subdirectories.

Then get the most recent 32 bit (Cygwin) installer for NEURON from http://www.neuron.yale.edu/neuron/download,
install that on your PC,
and try double clicking on main.hoc
Post Reply