Page 1 of 1

Executing multiple continuerun statements in run block with parameter changes

Posted: Wed Dec 13, 2017 11:43 pm
by Krishna Chaitanya

I have been trying to use multiple continuerun() statements inside run block to simulate the mossy fiber on and off conditions.

In my case, I would like to run the simulation for 5 seconds and for each second, the activated mossy fibers (spikegenerators) will be different. The end parameter of the spikegenerator was toggled on and off in each second. However, when I try to change parameters using switchon and switchoff functions, I fail to get them working unless I use stdinit() for each second.

I understood that in each second, stdinit() can't be used but the simulation wouldn't work without it.

This is the code I have been trying to use:

Code: Select all

proc run() {
for i=0, numact-1 {
	switchon()//switching on certain set of mossy fibers
	switchoff()//switching off activated mossy fibers
Kindly help me in understand how I can circumvent this problem.

Thank you.

Re: Executing multiple continuerun statements in run block with parameter changes

Posted: Thu Dec 14, 2017 12:21 pm
by ted
Are you trying to execute a single simulation that consists of a sequence of intervals
interval 0 from t = 0 to t0
interval 1 from t = t0 to t1
interval 2 from t = t1 to t2
with different "activated mossy fibers" in each interval?

Re: Executing multiple continuerun statements in run block with parameter changes

Posted: Thu Dec 14, 2017 12:46 pm
by Krishna Chaitanya
Hi Ted,

Yes. I am trying to do multiple continuerun statements for activating different mossy fibers in each run.

Kindly let me know how can I solve this?

Thank you.

Re: Executing multiple continuerun statements in run block with parameter changes

Posted: Thu Dec 14, 2017 12:53 pm
by Krishna Chaitanya
Hi Ted,

This is a single simulation with different set of mossy fibers being activated at different intervals.

Kindly let me know how can I solve this?

Thank you.

Re: Executing multiple continuerun statements in run block with parameter changes

Posted: Fri Dec 15, 2017 10:35 am
by ted
The most appropriate solution depends on details that have not been discussed.
Do the presynaptic spike events happen at random times, or at regular intervals?
Are they generated by NetStims during a run, or are the event times calculated before the simulation begins and then "played back" by VecStims?

Re: Executing multiple continuerun statements in run block with parameter changes

Posted: Fri Dec 15, 2017 12:22 pm
by Krishna Chaitanya
Hi Ted,

Sorry for not mentioning the spikegenerator properties.

Yes. The presynaptic events happen at random times. I have used a random function to generate events between t and t+DUR.

I have not used NetStim and VecStim to play the spike events.

objref rand_mos
rand_mos=new Random()
mossyfiber.spikegen.start=rand_mos.uniform(t, t+DUR)
mossyfiber.spikegen.end=1e5//to turn on the required mossy fibers.
after the run
mossyfiber.spikegen.end=0//turn off the activated mossy fibers.

Thank you.

Re: Executing multiple continuerun statements in run block with parameter changes

Posted: Sun Dec 17, 2017 11:58 pm
by ted
I have no idea what a mossyfiber.spikegen is. There are many possible traps for the unwary when it comes to simulations involving pseudorandom event sequences and sequence generators. If you're using something that I know about, such as VecStims driven by precalculated sequences, or NetStims, I can provide specific guidance, but I can't tell you much about something I've never heard of. That said, I am suspicious that the excerpt you provided

objref rand_mos
. . .
mossyfiber.spikegen.end=0//turn off the activated mossy fibers.

does not do what you want it to, and has unwanted side effects.

NetStims could be a useful way to do what you want--just take advantage of the fact that an input event with weight > 0 or < 0 can turn a NetStim on or off. Pair each NetStim with its own pseudorandom number generator and you can have as many statistically independent event streams as is practical. But those event times are governed by the negative exponential distribution, and nothing prevents a NetStim from generating one or more events that will be delivered at the "wrong time"--that is, during an interval when its particular event stream is supposed to be silent. You could prevent such events from affecting their target synapses by changing the intervening NetCons' weights to 0--although that has the side-effect of altering the statistics of the event streams.

VecStims driven by precalculated sequences seems statistically cleaner to me. For each VecStim, fill a Vector with a sequence of event times that have the desired mean ISI, then shift the event times as needed to create alternating event-free and event-rich epochs. No lost events, and within every event-rich epoch the statistics are correct. A recursive algorithm could do this nicely. The downside is the storage required for the events, and the time required to set up the Vectors. Still, it would work nicely if the Vectors aren't too big and there aren't many of them.

The proc run() etc. example you provided repeatedly calls stdinit(), which does a lot of things you don't really want to happen. Also it breaks the built-in proc run(), which interferes with debugging and further program development. Instead it is better to make a completely new proc and keep the for loop in that proc, like so:

Code: Select all

// $1 is how many epochs
// each epoch is 2*$2 long
proc epochrun() { local i
  running_ = 1
  tstop = 2*$1*$2 // in case some other code needs tstop
  for i=0,$1 {

Re: Executing multiple continuerun statements in run block with parameter changes

Posted: Thu Dec 28, 2017 8:33 am
by Krishna Chaitanya
Hi Ted,

I have tried your advice but I couldn't turn the stimulus on after I called stdinit(). Somehow, the stimulus is turning on only when it is called before stdinit(). When I try to use it after the stdinit() call, it doesn't work. Is there a reason that the <proc> functionality doesn't work when called after the stdinit()?

Kindly let me know.

Re: Executing multiple continuerun statements in run block with parameter changes

Posted: Thu Dec 28, 2017 12:48 pm
by ted
We have reached the point where it is necessary to get into the details of what switchon() and switchoff() do. Can you provide a toy example program?

Re: Executing multiple continuerun statements in run block with parameter changes

Posted: Fri Dec 29, 2017 5:29 am
by Krishna Chaitanya
Hi Ted,

I am providing the scripts of each file I used. The scripts are as follows:
1) Pregen.mod (SpikeGenerator mod file).
2) adex.hoc (template creation of spikegenerator)
3) cells_test.hoc (creating the cells)
4) modifycheckmoss.hoc (main file for changing the file parameters during run)

Code: Select all

: $Id: pregen.mod,v 1.3 2000/05/16 11:16:56 hines Exp $
: comments at end

  POINT_PROCESS SpikeGenerator
  RANGE fast_invl, slow_invl, burst_len, start, end,delay
  RANGE noise

	fast_invl	= 10 (ms)	: time between spikes in a burst (msec)
	slow_invl	= 0 (ms)	: burst period (msec)
: actually, above is interburst period in conformity with original version
: see
	burst_len	= 10		: burst length (# spikes)
	start		= 50 (ms)	: start of first interburst interval
	end		= 1e10 (ms)	: time to stop bursting
	noise		= 0		: amount of randomeaness (0.0 - 1.0)
	delay		= 4

	event (ms)
	burst_off (ms)
	burst_on (ms)
	toff (ms)

:PROCEDURE seed(x) {

	on = 1
	toff = 1e9
	y = -90
	burst = 0
	event = start - slow_invl
	while (on == 1 && event < 0) {
	if (on == 1) {
		net_send(event, 1)

FUNCTION interval(mean (ms)) (ms) {
	if (mean <= 0.) {
		mean = .01 (ms) : I would worry if it were 0.
		: since mean is a local variable, if the number it is set
		: to is dimensionless, mean will be dimensionless.
	if (noise == 0) {
		interval = mean
		interval = (1. - noise)*mean + noise*(mean*exprand(1)+delay) : (delay+noise*mean*exprand(1))

PROCEDURE event_time() {
	if (slow_invl == 0 || (burst != 0. && burst_len > 1)) {
		event = event + interval(fast_invl)
		if (event > burst_on + burst_off) {
			burst = 0.
		burst = 1.
: if slow_invl from beginning of burst to beginning of burst
:		event = event + interval(slow_invl - (burst_len-1)*fast_invl)
: use following if slow_invl is interburst interval
		event = event + interval(slow_invl)
		burst_on = event
		burst_off = interval((burst_len - 1)*fast_invl)-1e-6
	if (event > end) {
		on = 0

:printf("Pregen receive t=%g flag=%g\n", t, flag) 
	if (flag == 1 && on == 1) {
		y = 20
		net_send(event - t, 1)
		net_send(.1, 2)
	if (flag == 2) {
		y = -90

Presynaptic spike generator

This mechanism has been written to be able to use synapses in a single
neuron receiving various types of presynaptic trains.  This is a "fake"
presynaptic compartment containing a fast spike generator.  The trains
of spikes can be either periodic or noisy (Poisson-distributed), and 
either tonic or bursting.

   noise: 	between 0 (no noise-periodic) and 1 (fully noisy)
   fast_invl: 	fast interval, mean time between spikes (ms)
   slow_invl:	slow interval, mean burst silent period (ms), 0=tonic train
   burst_len: 	mean burst length (nb. spikes)

Written by Z. Mainen, modified by A. Destexhe, The Salk Institute

Modified by Michael Hines for use with CVode

Modified by Michael Hines to use logical event style with NET_RECEIVE

Code: Select all

begintemplate spikeGen
public dummyspikegen, synspikegen, nclist3, spkrecord, x, y, z, position
create dummyspikegen
public synspikegen, connect2target, sumconnect, mfgocconnect
objref synspikegen, nclist3, spkrecord

proc init() {
	create dummyspikegen
	dummyspikegen {
		spkrecord=new Vector()
		nclist3=new List()
		synspikegen=new SpikeGenerator(0.5)
		synspikegen.start=20//rand_start.uniform(20, 1000)

proc topol() {
	dummyspikegen {pt3dclear() pt3dadd(0, 0, 0, 1.2) pt3dadd(0, 0, 0, 1.2)}

proc position() {local i
	dummyspikegen for i=0, n3d()-1 {
		pt3dchange(i, $1-x+x3d(i), $2-y+y3d(i), $3-z+z3d(i), diam3d(i))
	x=$1 y=$2 z=$3

obfunc connect2target() {localobj nc
	dummyspikegen nc=new NetCon(&synspikegen.y, $o1) 
	if(numarg()==2) {$o2=nc}
	return nc

endtemplate spikeGen

Code: Select all



objref mossycells
	mossycells=new List()

func moscellAppend() {
	return mossycells.count()-1

objref mf_start_rand
mf_start_rand=new Random()

func round() {
	if ($1>0) {
		return int($1+0.5)
	}else {
		return int($1-0.5)

proc mkcells() {local k localobj cell, nc, nil
	for k=0, nmossy-1 {
		cell=new spikeGen(0.5)
		cell.synspikegen.start=round(mf_start_rand.uniform(20, 700))
		printf("The object here is so, so and so...\n")

Code: Select all


objref moss_idvec, moss_tvec
moss_tvec=new Vector()
moss_idvec=new Vector()

proc spikerecord() {localobj nil, nc_moss

	for j=0, mossycells.count-1 {
		nc_moss.record(moss_tvec, moss_idvec, j)


objref g, g1, g2, g3, g4, g5, g6, g7

printf("\n\n Simulating Cells....\n\n")
objref granulefil
granulefil=new File()
objref cvode
cvode=new CVode()

for i=0, half_mos-1 {

proc run() {//half mossy fibers with transient and rest half with sustained component - POT Simulation

	for j=half_mos, mossycells.count-1 {

	for j=half_mos, mossycells.count-1 {
I hope I made it clear. If not, kindly let me know.

Thank you.