cbherbert / stochrare

This Python package aims at providing tools to study stochastic processes: integrate SDEs, solve Fokker-Planck equations, sample rare events,...
GNU General Public License v3.0
8 stars 5 forks source link

Using single precision for time #22

Open tlestang opened 4 years ago

tlestang commented 4 years ago

This is similar to #21 , although (I think) from different origin.

I've noticed that using single precision for time sometimes leads to incorrect results. For instance in DiffusionProcess1d.empirical_vector, as the total trajectory time is computed as the difference between tsample and t0:

x0 = 1.
t0 = 0. # <'float'>
dt=0.1

for tsample in [0.3, 0.5]:
    T = tsample - t0
    print("tsample = {}, T = {}".format(tsample, T))
    t, x = model.trajectory(x0, t0, T=tsample-t0, dt=dt)
    t0 = t[-1] # <'numpy.float32'>
    x0 = x[-1]

leads to

tsample = 0.3, T = 0.3 # expected
tsample = 0.5, T = 0.19999998807907104 # expected T = 0.2

This leads to an incorrect discretisation of time, as

int(T/dt)+1

will not give the expected number of time points.