ChaosTools.jl
ChaosTools.jl copied to clipboard
Fix error checking in lyapunov and lyapunovspectrum
This is an attempt to fix issue 184. I've added error checking: lyapunov
and lyapunovspectrum
now return NaN values immediately in the case of instability. Note that this version only tests for the :Unstable
retcode and only if the integrator is a usual one. In case of the simple integrator types the dt<dtmin
error is raised on instability.
I also did some benchmarking on Systems.lorenz
.
With error checking:
@btime lyapunov(ds,100, Ttr = 2000 ;diffeq)
23.199 ms (666 allocations: 50.45 KiB)
0.9056821285687465
@btime lyapunovspectrum(ds,100, Ttr = 2000 ;diffeq)
27.496 ms (57 allocations: 6.91 KiB)
3-element Vector{Float64}:
0.9147419224955904
-0.005725267193229689
-14.575596505931658
Without error checking:
@btime lyapunov(ds,100, Ttr = 2000 ;diffeq)
23.201 ms (666 allocations: 50.45 KiB)
0.9056821285687465
@btime lyapunovspectrum(ds,100, Ttr = 2000 ;diffeq)
27.469 ms (57 allocations: 6.91 KiB)
3-element Vector{Float64}:
0.9147419224955904
-0.005725267193229689
-14.575596505931658
Thank you very much! This is a great step forwards!
Can you please open a PR at DynamicalSystemsBase.jl, in which you define a function
successful_step(integ) = true # this is the default definition of the function
successful_step(integ::DEIntegrator) = ... # the code you have here
which returns true
if the latest step the integrator took was successful? For integrators that don't have this return code field the function will always return true. Then you can use that function in this code here, which will lead to cleaner code as there would be no reason to initialize has_retcode
etc.
Furthermore, instead of length(get_state(ds))
use dimension(ds)
.
lastly, you need to add a test in the test suite that indeed confirms that we get NaN
s for unstble initial conditions.
Hi! I've modified this pull request. Now it's much cleaner with the suggested successful_step
functions. And also, I hope it works for all simple integrators and tests for all retcodes, not just :Unstable
. I've tested the changes locally, but I need help with this
lastly, you need to add a test in the test suite that indeed confirms that we get NaNs for unstble initial conditions.
Thanks, I'll go through the other PR now and give some help.
For the tests of the current PR, you need to add a test that computes the lyapunovspectrum for the unstable system-parameters mentioned in the issue and ensure that the return is NaN.