mattja / sdeint

Numerical integration of Ito or Stratonovich SDEs
GNU General Public License v3.0
155 stars 25 forks source link

Only a question out of curiosity #19

Closed Peter230655 closed 2 years ago

Peter230655 commented 3 years ago

I am playing around with sdeint.itoint a lot - and enjoy it! It seems to me that when I integrate a given interval, say, (0, 10), the more 'steps' I give the more 'accurate' it gets - and the longer it calculates. With scipy.odeint this does not seem to be the case. Of course, only my observation, I do not really know how either program works internally.

Is my observation correct, or am I doing something wrong?

Thanks!

mattja commented 2 years ago

As you note, sdeint currently implements fixed-step algorithms. I believe scipy.odeint (like MATLAB ode45) internally uses an adaptive-step-size algorithm for ODE, then interpolate the solution onto the time grid you request.

There do exist adaptive-step-size algorithms for SODE - it is not trivial to get this right for SODE. For example in the literature see https://doi.org/10.1016/j.cam.2004.01.027 and cited papers.

With fixed step algorithms, a suitable time step to use depends on both the algorithm, and on the system you are integrating. Specifically, what are the characteristic time scales on which the system varies. (if all rates of change are bounded by a small value, you can use a larger time step). Higher-order algorithms can succeed with bigger time steps than the simplest algorithms (and remain numerically stable for a wider range of systems) but each step takes more computation time.

Peter230655 commented 2 years ago

Dear Matt, Thanks! Yes, scipy.odeint adapts the steps size: No matter, what time grid I give, if Icount the actual steps, they are always different from the grid. Take care, Peter

On Sun 13. Feb 2022 at 08:30 Matthew Aburn @.***> wrote:

As you note, sdeint currently implements fixed-step algorithms. I believe scipy.odeint (like MATLAB ode45) internally uses an adaptive-step-size algorithm for ODE, then interpolate the solution onto the time grid you request.

There do exist adaptive-step-size algorithms for SODE - it is not trivial to get this right for SODE. For example in the literature see https://doi.org/10.1016/j.cam.2004.01.027 and cited papers.

With fixed step algorithms, a suitable time step to use depends on both the algorithm, and on the system you are integrating. Specifically, what are the characteristic time scales on which the system varies. (if all rates of change are bounded by a small value, you can use a larger time step). Higher-order algorithms can succeed with bigger time steps than the simplest algorithms (and remain numerically stable for a wider range of systems) but each step takes more computation time.

— Reply to this email directly, view it on GitHub https://github.com/mattja/sdeint/issues/19#issuecomment-1037886040, or unsubscribe https://github.com/notifications/unsubscribe-auth/AT5MQUXI7LULSAKIQHJQV73U25M2DANCNFSM5D3USCLQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you authored the thread.Message ID: @.***>

-- Best regards,

Peter Stahlecker