[R-sig-dyn-mod] LSODA in R vs ode23s Matlab

Thomas Petzoldt thomas.petzoldt at tu-dresden.de
Sun Jun 11 12:10:27 CEST 2017


Dear John,

thank you for using deSolve and for your report. Robustness of a 
numerical solution depends on several things: the model specification, 
the model parameters, the solver and the solver parameters. We don't 
know which model you are using, but what I see is that you compare 
"ode23s" from Matlab with "lsoda" from R.  R has several other solvers, 
including "ode23", "ode45", "adams", "bdf", "vode", ..., and "raudau", 
and that all of them have further tuning parameters.

Please take in mind, that am error message from a solver may have good 
reasons and can be helpful to detect model-misspecification or just 
numerical instability, while another solver may just run over difficult 
ground without complaining.

The warning below means, that your simulation tried to request excessive 
numerical precision, and that the step size cannot be reduced even 
further. Is your model stiff? How did you set the atol and rtol? Have 
you already checked "bdf" or "vode"?

In conclusion, I can see no reason (yet) that supports your general 
statement about "R" vs. "Matlab", while specific examples may helpful. A 
collection of numerically challenging examples is included in the R 
package deTestSet.


On 11.06.2017 03:18, John Harrold wrote:
> Howdy Folks,
>
> So I've got a bunch of tools that I use in Matlab for solving odes,
> and I've been working on moving all this over to R. I'm generating my
> models in C both in Matlab (Simulink/S-Functions) and in R. The good
> news is that I've managed to get my stuff in R working faster than the
> code in Matlab. Now to be fair to Matlab, I'm using code I wrote years
> ago and I've put a bit of effort in to optimizing the R version.
>
> I recently ran into an issue while doing some Monte Carlo type
> simulations. About 5-20% of them were failing with integration errors
> like:
>
> DLSODA-  Warning..Internal T (=R1) and H (=R2) are
>        such that in the machine, T + H = T on the next step
>       (H = step size). Solver will continue anyway.
>
> I understand what's going on here. Since I'm automatically generating
> code, I switched over to Matlab, loaded the parameters that I was
> using in R, and ran it over there using ode23s. It was slower in
> Matlab (using compiled C in both places), but I was able to run it.
> While it appears to be slower, Matlab seems to be more robust.
>
> I'm planning on trying to generate some examples I can distribute, but
> I was wondering if anyone here had any similar examples? Is anyone
> familiar with any comparisons of the Matlab solvers as compared to R?
> Is anyone interested in doing something like this?

A collection of fair and reproducible examples is welcome.

>
> Thanks
> John

Thank you,

Thomas

-- 
Dr. Thomas Petzoldt
Technische Universitaet Dresden
Faculty of Environmental Sciences
Institute of Hydrobiology
01062 Dresden, Germany

http://tu-dresden.de/Members/thomas.petzoldt



More information about the R-sig-dynamic-models mailing list