Varying the seed

The basics of how to develop, test, and use models.
Post Reply
FariaVS
Posts: 9
Joined: Wed Feb 08, 2017 9:06 am

Varying the seed

Post by FariaVS »

I have an HH model with 1 compartment and with netstim.
I need to run 20 simulations with different synaptic inputs, vary the seed in each and save for plot analysis and further analysis.

How to use the seed and how to vary it in each simulation?
ted
Site Admin
Posts: 6287
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Varying the seed

Post by ted »

Your post was moved from its original location (the Hot tips area of the forum) because it does not fall into the category of "a of noteworthy item selected by our moderators from discussions about making and using models with NEURON".
FariaVS
Posts: 9
Joined: Wed Feb 08, 2017 9:06 am

Re: Varying the seed

Post by FariaVS »

Dear Ted,
NEURON is only for English speakers?

My post will be answered where?
Where should I post this doubt?
ted
Site Admin
Posts: 6287
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Varying the seed

Post by ted »

FariaVS wrote:NEURON is only for English speakers?
Forum users are expected to follow basic, universal rules of "forum etiquette." One of the most basic is to stay on topic. If an area in a forum is reserved for particular kinds of posts, and someone enters a post that does not fit, the forum's moderators are likely to move the post to an appropriate location. Your particular post didn't really fit into the "Hot tips" area, but it did address an issue that many users will probably be interested in, so it was moved to one of the NEURON Forum's more popular areas.
My post will be answered where?
In this very discussion thread.

So, now that we're all in the right place, I have a couple of questions for you, because the most effective answer to your question depends on exactly what you're trying to do. Does your model have just one synapse, or does it have multiple synapses? And if it has multiple synapses, do you want each synapse to have its own random activation times?
FariaVS
Posts: 9
Joined: Wed Feb 08, 2017 9:06 am

Re: Varying the seed

Post by FariaVS »

Dear Ted, thank you very much.

My model has a synapse in the synaptic mechanism (STDP) and a second synapse linked to netstim, which occurs from two other synapses.

Synapse in soma:

Code: Select all

sinapse=new ExpSynSTDP(0)
sinapse1=new ExpSyn(0.5) 
and here I created a pre-synapse:

Code: Select all

Presynapse {
 StimTrigger = new NetStim(0.8)
 StimTrigger.seed(1)
 StimTrigger.start = 200
 StimTrigger.interval = 100
 StimTrigger.number = 100
 StimTrigger.noise = 1
 
 NetInput[0]= new NetCon(StimTrigger, neuron[0].sinapse1,0.5,0,0.3)
FariaVS
Posts: 9
Joined: Wed Feb 08, 2017 9:06 am

seed

Post by FariaVS »

Dear Ted,

I'm waiting for the answer!

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

Re: Varying the seed

Post by ted »

Sorry that this reply has been so delayed.
My model has a synapse in the synaptic mechanism (STDP)
OK, that's synaptic mechanism number 1.
and a second synapse linked to netstim
and that is synaptic mechanism 2.
which occurs from two other synapses.
and those are synaptic mechanisms 3 and 4?

The example code you provide shows two synaptic mechanisms--an instance of the ExpSynSTDP class, and an instance of the ExpSyn class. And there is only one presynaptic spike source, which is an instance of the NetStim class.

Since I can't figure out quite what you want, here's an example of how to make one or more NetStims produce streams of spike events at intervals that are governed by the negative exponential distribution. This strategy pairs each NetStim with its own random number generator (RNG), and each RNG has its own "seed" (actually not really a "seed" but a unique sequence specifier--read the Programmer's Reference documentation of the Random class, especially the parts about Random123) so that each NetStim's event times are statistically independent of every other NetStim's event times.

Put the following code into a file called ran123stream.hoc

Code: Select all

// used to manage independent random streams generated by Random123
// based on RandomStream, which used MCellRan4
// syntax:  foo = new Ran123Stream(id1,id2,id3)
// where id1..3 are the stream identifiers
begintemplate Ran123Stream
public r, id1, id2, id3
public repick, start
objref r
proc init() {
  id1 = $1
  id2 = $2
  id3 = $3
  r = new Random()
  r.Random123(id1, id2, id3)
  start()
}
// to get same stream of values on each run, call rs.start() just before run()
proc start() {
  r.seq(0) // restart at position 0 in the sequence
}
func repick() {
  return r.repick()
}
endtemplate Ran123Stream
To use the Ran123Stream class, make sure that your own program loads the definition of the Ran123Stream class

Code: Select all

load_file("ran123stream.hoc")
The following code assumes that your model setup code creates a List called nslist, whose elements are the NetStims whose spike times are to be statistically independent of each other. Furthermore, it assumes that you have already specified each NetStim's interval, number, and start parameter, and set its noise parameter to 1. It is to be executed after nslist is complete.

Code: Select all

obfunc newstream() { localobj tobj
  tobj = new Ran123Stream($1, $2, $3)
  tobj.r.negexp(1) // do not change this line!
  tobj.start() // on the first run it will start at position 0 in the sequence
  $o4.noiseFromRandom(tobj.r) // associate it with a particular NetStim
  return tobj
}

rslist = new List()
ID1 = 0 // ID1 and ID2 should be whole numbers in the range 0..2^32-1
ID2 = 0
for i=0,nslist.count()-1 rslist.append(newstream(ID1, ID2, i, nslist.o(i)))
Post Reply