Recording at user-specified times

Anything that doesn't fit elsewhere.
Post Reply
henriklinden

Recording at user-specified times

Post by henriklinden »

[[ MODERATOR'S NOTE: The following was split off from the discussion thread "recording t" http://www.neuron.yale.edu/phpBB/viewto ... f=8&t=1686 because it really addresses a different question ]]

I also came across this problem regarding the "Vector.record(&var, Dt)" as I need to record data and the corresponding time vector at a lower resolution than the actual simulation is running but I'm relying on a constant temporal resolution. I tried to understand where the roundoff error comes from in order to be using "safe" values for both dt and Dt but I at the moment this is not clear to me (given the description in the Programmer's Reference).

Ted, you mentioned in the previous post that dt must have a finite representation in base 2 (meaning dt=2^x right?) but is this also true for Dt? Moreover, I noticed that even when dt and Dt are the same, for instance dt=Dt=0.1 the recorded time vector will have multiple values of some time points.. The below code reproduces the problem ( t=0.5 and 8.4 ms occur twice ):

Code: Select all

dt = 0.1
Dt = 0.1

objref vec
vec = new Vector()
vec.record(&t, Dt)

proc run_simulation() {
	tstop = $1
	finitialize()
	while (t<tstop) {
		fadvance()
	}
}

run_simulation(100)

for i=1,99 {
	print vec.x[i]
}

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

Re: recording t

Post by ted »

henriklinden wrote:Ted, you mentioned in the previous post that dt must have a finite representation in base 2 (meaning dt=2^x right?) but is this also true for Dt?
There is no restriction on the values of dt and Dt per se. You can use any values you like. But if dt < 1 and you want to reliably sample at fixed intervals Dt, dt must have a value of (1/2)^m and Dt must be n*dt where both m and n are positive integers. This is a consequence of using a floating point library in which the fractional parts of numbers are represented in base 2.

If you want to ensure evenly spaced sampling of results during a simulation, regardless of the values of dt and Dt, you can either
(1) record both t and whatever variable(s) of interest to Vectors during the simulation, then downsample afterwards using the Vector class's interpolate() method,
or
(2) first create a Vector called tvec and fill it with the desired sampling times, then use cvode.record(&rangevar, yvec, tvec, 1) to force recording at those times (be sure to read about this in the Programmer's Reference
http://www.neuron.yale.edu/neuron/stati ... tml#record
). But test to make sure that you are really getting what you expected.
henriklinden

Re: recording t

Post by henriklinden »

Ok, this was very useful. Thank you very much for the quick response!
Post Reply