Playing EPSPs into cell with random distribution of amp

NMODL and the Channel Builder.
Post Reply
lb5999
Posts: 56
Joined: Mon Oct 11, 2010 9:12 am

Playing EPSPs into cell with random distribution of amp

Post by lb5999 »

Hi NEURON Forum users,

I need to write a piece of code that plays into a cell a series of EPSP's that have fixed frequency and heights of random amplitude (distributed normally, say, around approximately 12mV positive to resting membrane potential). If anyone has any hints that would be great.

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

Re: Playing EPSPs into cell with random distribution of amp

Post by ted »

First, remember that normal distribution can produce nonsense values (too large in one direction and you get a monster psp, too large in the other direction and you get a psp with negative synaptic conductance).

You want simulation execution to go like this (in very crude "event-driven pseudocode"):

Code: Select all

REPEAT
  at some interval before synaptic activation, set the synaptic weight to a new value
  at the time of synaptic activation, activate the synapse
UNTIL done
Here's how.

A. Implement your model with an ExpSyn or Exp2Syn driven via a NetCon by a NetStim. The NetStim should be set up to generate events with the desired start time (call this trainstart) and ISI. Set the NetCon's delay to 0, so the synapse will be activated at
trainstart + i*ISI where i = 0, 1, 2 . . .

B. Write a proc named setweight() that does these things:
--calls a func that returns a random value
--assigns this value to the weight of the NetCon
--uses the CVode class's event() method to call setweight() at t+ISI. By which I mean the algebraic expression "t+ISI".

C. Write an FInitializeHandler that calls setweight() at trainstart-1 (i.e. 1 ms before the first event from the NetStim is delivered to the synaptic mechanism).

Then the flow of simulation execution will be as follows:

1. At the end of initialization, a cvode event will be launched that will return at trainstart-1.
2. At t == trainstart-1, this event will return, causing setweight() to be called.
setweight() will set the NetCon's weight to a new random value, and launch a new cvode event that will return at trainstart-1+ISI (i.e. 1 ms before the arrival of the 2nd event from the NetStim).
3. At t == trainstart, the event from the NetStim will be delivered to the synaptic mechanism.
4. At t == trainstart-1+ISI (1 ms before the arrival of the 2nd event from the NetStim), the second cvode event returns, causing setweight() to be called.
setweight() does _______________ (you fill in the blanks)

Documentation of the CVode and FInitializeHandler class is in the Programmer's Reference, and examples of the use of cvode.event and FInitializeHandlers are scattered throughout this Forum (which is searchable).
lb5999
Posts: 56
Joined: Mon Oct 11, 2010 9:12 am

Re: Playing EPSPs into cell with random distribution of amp

Post by lb5999 »

Hi Ted,

Thank you for your reply. I understand how you have tackled this problem, although I think I may need a few more hints.

So far I have

Code: Select all

create soma
insert hh
insert pas
objectvar ns, nc, syn
ns = new NetStim(0.5)
syn = new ExpSyn(0.5)
nc = new NetCon(ns, syn, -40, 0, 0.5)
tstop=1000
trainstart=100
ns.start=trainstart
And so now my task is B. to create a procedure that assigns a random value (between 0 and 1) to the weight of the NetCon nc, re-doing this at every interspike interval.

I am getting a bit confused with the initial stage. Firstly, I can't seem to nest a function (i.e. the function that returns a random value) inside a procedure (i.e. the setweight() procedure); as soon as I write

Code: Select all

func rand() { 


within the procedure command it returns an error.

Secondly, I am having problems cooking up a function that returns a random value. For this, so far, I have:

Code: Select all

objectvar r
func rand() {
objectvar r
r = new Random()
x = r.normal(0,1)
return x
}
This returns the same random number each time I run the function rand().. why? Also, I know this question is likely to annoy some of the more experience NEURON users (be gentle with me.. I am relatively new!), but why do I have to declare the object r outside of the func command?

Finally, once some kind NEURON user (presumable the developer, Ted) has helped me with these problems, I fear I am going to have further questions regarding the CVode part. I don't want someone to write it for me, but I do think I am going to have request a bit of a step-by-step guide with this part. Hopefully, by then I will have a firm handle on VCodes and everything else, and I can start tackling problems like this on my own; I certainly have learnt a lot already today on reading up on stuff related to my problem.

Thanks again,

lb5999
lb5999
Posts: 56
Joined: Mon Oct 11, 2010 9:12 am

Re: Playing EPSPs into cell with random distribution of amp

Post by lb5999 »

OK.. So I think I found something that paves the way to clearing up one of my problems. As is written in The NEURON Book (page 366, Chapter 13):
As mention in Chapter 12, objref arguments are passed using call by reference. This has two consequences: the called func or proc can change which object the objref argument points to, and it can also change the object itself. As a rather artificial example of the first consequence, let us define a proc that swaps the objects that two objrefs point to. [...]
I guess the problem with me wanting my random number object to change value each time I call the func rand() relates to the 'second consequence'? Still unsure how to achieve this function though.
lb5999
Posts: 56
Joined: Mon Oct 11, 2010 9:12 am

Re: Playing EPSPs into cell with random distribution of amp

Post by lb5999 »

One more thing, don't worry about addressing my question regarding object references within func and proc commands; I already knew the following (again, I quote The NEURON Book:
The objref keyword can appear within a compound statement, but the names must originally have been declared outside any func or proc before they can be redeclared (as objrefs) in a procedure
The last few words though.. "in a procedure or function "???
lb5999
Posts: 56
Joined: Mon Oct 11, 2010 9:12 am

Re: Playing EPSPs into cell with random distribution of amp

Post by lb5999 »

Also, I presume I write something like the following, to set the weight of the NetCon 'nc' to some randomly generated value (from a distibution I choose):

Code: Select all

proc setweight() {
nc.weight = rand()
}
Thanks,

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

Re: Playing EPSPs into cell with random distribution of amp

Post by ted »

lb5999 wrote:So far I have

Code: Select all

create soma
insert hh
insert pas
objectvar ns, nc, syn
ns = new NetStim(0.5)
syn = new ExpSyn(0.5)
nc = new NetCon(ns, syn, -40, 0, 0.5)
tstop=1000
trainstart=100
ns.start=trainstart
And so now my task is
to prove that it works. Before you do anything else.
lb5999
Posts: 56
Joined: Mon Oct 11, 2010 9:12 am

Re: Playing EPSPs into cell with random distribution of amp

Post by lb5999 »

I think the membrane potential responds how I would expect in both the simple soma cell, and when this code is implemented on my model.. what do you think Ted?
ted
Site Admin
Posts: 5810
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Playing EPSPs into cell with random distribution of amp

Post by ted »

Doesn't look to me like the NetStim has been told to generate any spikes.

Are you sure you want the section to have the default L and diam?
The last few words though.. "in a procedure or function "???
Could have said "in a proc or func". Despite the laconic form, you guessed the right answer.

WRT a func that returns a random value--here's a suggestion that may get you started:

Code: Select all

objref r
r = new Random()
r.normal(0, 1)

func myrand() {
  return r.repick()
}

for i=0,3 print myrand()
Left as an exercise to the reader: revise myrand() so that its return value is not too large. This involves some thought in advance:
1. deciding the criteria for what is "too large"
2. deciding how to prevent such occurrences. First, should this be done inside or outside of proc myrand()? Is it OK to simply clip the value returned by r.repick() at the max and min values? (probably not--why?) Or would it be better to repick until a value within acceptable limits is obtained?
3. finally, for the sake of reproducible results, it would be good to seed the random number generator.
lb5999
Posts: 56
Joined: Mon Oct 11, 2010 9:12 am

Re: Playing EPSPs into cell with random distribution of amp

Post by lb5999 »

Hi Ted,

Thanks for your message.

I have attempted to truncate the desired returned values, to be assigned to the weight of the NetCon, with an upper and lower bound of 1 and -1 respectively (see below). These values aren't probably what I will go for, but presumably I can easily alter them at a later date.

I figured code could go something like:
1. Let x=r.repick()
2. If (-1 <= x <= 1) then return x
3. If not, then repeat the func, i.e {return myrand()}. This will repick an x, and continue to do so until such an x satisfies 1.

Trouble is, I WAS having trouble imposing the constraint "-1 <= x <= 1" in hoc. Can you help? (Infact, am I even barking up the correct tree here?)

Thanks,

5999

Code: Select all

objref r
r = new Random()
r.normal(0,1)
func rand() {
x=r.repick()
if (-1 <= x <= 1) {return x} else {return rand()}
}
The code

Code: Select all

objref r
r = new Random()
r.normal(0,1)
func rand() {
x=r.repick()
if (x<1) if (x>-1) {return x} else {return rand()} else {return rand()}
certain works.. but I just wanted to check I am understand why, in terms of the script:

The 'statement' to the first if command expression is:

Code: Select all

 if (x>-1) {return x} 
and so if the expression x<1 is satisfied, this statement is executed. This returns 'x' whenever the picked number is between 1 and -1, as desired.

Is this the best/correct way to get this function? If so, where I am going to look up on where I should go from here, and I hope its ok to pick your brains again ted!

Thanks,

lb5999
Last edited by lb5999 on Wed Mar 30, 2011 10:13 am, edited 1 time in total.
ted
Site Admin
Posts: 5810
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Playing EPSPs into cell with random distribution of amp

Post by ted »

How to figure out stuff for yourself:
Read the Programmer's Reference documentation of "if".
Find some hoc code in NEURON's hoc library that contains examples of "if" statements.
ted
Site Admin
Posts: 5810
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Playing EPSPs into cell with random distribution of amp

Post by ted »

ted wrote:Find some hoc code in NEURON's hoc library
See the "Hot tips" area of this Forum, and while you're there you might rummage around picking up various and sundry pearls.
lb5999
Posts: 56
Joined: Mon Oct 11, 2010 9:12 am

Re: Playing EPSPs into cell with random distribution of amp

Post by lb5999 »

So I found out that with

Code: Select all

&&
I could write the following piece of syntax which did what I wanted...

Code: Select all

objectref r
r=new Random()
r.norma(0,1)
func rand() {
x=r.repick()
if (x<1.1 && x>0.9) {return x} else {return rand()}
for i=0,20 print rand()
Can you help me with the next phase please? This involves assigning this repicked value for x as the weight of the NetStim after every EPSP has been played into the cell.. I have read up about all the stuff you mentioned below, but its hard to see the role of these objects and classes in the bigger picture when you hoc knowledge is at a beginner level.

Thanks,

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

Re: Playing EPSPs into cell with random distribution of amp

Post by ted »

lb5999 wrote:So I found out that with

Code: Select all

&&
I could write the following piece of syntax which did what I wanted
Is that what you really want?

Code: Select all

r.normal(0,1)
specifies "normal distribution with mean 0 and variance 1"

Code: Select all

if (x<1.1 && x>0.9) {return x}
means you're not returning values from the vicinity of the mean--you're returning values that are well away from the mean, out on the "right hand side" of the bell where the likelihood decreases with x (you'll get more results from the interval 0.9..1 than from the interval 1..1.1) so that the mean of the values that are returned will be < 1.
Can you help me with the next phase please? This involves assigning this repicked value for x as the weight of the NetStim after every EPSP has been played into the cell.. I have read up about all the stuff you mentioned below, but its hard to see the role of these objects and classes in the bigger picture when you hoc knowledge is at a beginner level.
The answer is in items B and C in my first post in this thread. You'll find helpful examples in the Programmer's Reference and in c:\nrnxx\examples\nrniv\netcon (MSWin) or, if you're using UNIX/Linux/OS X, nrn_x.x/share/nrn/examples/nrniv/netcon
lb5999
Posts: 56
Joined: Mon Oct 11, 2010 9:12 am

Re: Playing EPSPs into cell with random distribution of amp

Post by lb5999 »

Yup you are right, the distribution I am picking from isn't ideal.. I'll change this!

Thanks for your pointers, I'll have a good think and stab at B & C and let you know how I get on,

lb5999
Post Reply