How to change parameters during a simulation

A collection of noteworthy items selected by our moderators from discussions about making and using models with NEURON.

Moderators: wwlytton, tom_morse

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

How to change parameters during a simulation

Post by ted » Sun Sep 04, 2005 1:09 pm

How to change a model's parameters in the course of a simulation is a common problem.

One way is to use the Vector class's play method. This example uses Vector play with interpolation to make celsius change "continuously" from 6.3 to 20 deg C over the course of 100 ms. Yes, that's unrealistically fast, but this is just a toy example.

Code: Select all

objref tempvec, tvec
tempvec = new Vector(3)
tvec = new Vector(3)
tempvec.x[0] = 6.3  // deg C
tvec.x[0] = 0
tempvec.x[1] = 20   // deg C
tvec.x[1] = 100
tempvec.x[2] = 20   // deg C
tvec.x[2] = 1e9

// third argument == 1 means play with interpolation
tempvec.play(&celsius, tvec, 1)
Be sure to read the Programmer's Reference documentation of Vector play.

The following example uses the event delivery system's FInitializeHandler and cvode.event to force abrupt parameter changes during a simulation: an IClamp is made to deliver a series of current pulses. In this example, the pulses repeat until the end of the simulation. It would be easy to add a counter that controls how many pulses are generated. A similar strategy can be used to drive one or more discontinuous changes in any parameter.

Code: Select all

/*
1.  During simulation initialization, the stimulus current is set to 0,
and an FInitializeHandler is used to launch an event that will arrive
at the time when we want the first jump of stim.amp to occur.
2.  Arrival of this event causes proc seti() to be called.
3.  seti() assigns a new value to stim.amp, and uses the CVode class's
event() method to launch two new events.  The first of these will come
back in the future to turn off the stimulus.  The second will come back
a bit later, to turn it back on again, and start a new cycle.
*/

objref stim
stim = new IClamp(0.5)

DUR = 0.1  // ms, duration of each pulse
AMP = 0.1  // nA
START = 5  // ms, time of first pulse
INTERVAL = 25  // ms, interval between pulse starts
// assumes DUR < INTERVAL

objref fih
fih = new FInitializeHandler("initi()")

STIMON = 0

proc initi() {
  STIMON = 0
  stim.del = 0    // we want to exert control over amp starting at 0 ms
  stim.dur = 1e9  // if we're going to change amp,
                  // dur must be long enough to span all our changes
  cvode.event(START, "seti()")
}

proc seti() {
//  print "time is ", t
  if (STIMON==0) {
    STIMON = 1
    stim.amp = AMP
    cvode.event(t + DUR, "seti()")
    cvode.event(t + INTERVAL, "seti()")
  } else {
    STIMON = 0
    stim.amp = 0
  }
  // we've changed a parameter abruptly
  // so we really should re-initialize cvode
  if (cvode.active()) {
    cvode.re_init()
  } else {
    fcurrent()
  }
}
As always, be sure to read the Programmer's Reference documentation of anything with which you are unfamiliar.

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

Re: How to change parameters during a simulation

Post by ted » Tue Mar 03, 2015 11:35 am

The above post was revised on 20150303

Post Reply