JuliaDynamics / DynamicalSystems.jl

Award winning software library for nonlinear dynamics and nonlinear timeseries analysis
https://juliadynamics.github.io/DynamicalSystemsDocs.jl/dynamicalsystems/dev/
Other
851 stars 95 forks source link

lyapunovs.jl Small bug #40

Closed finmod closed 7 years ago

finmod commented 7 years ago

Running lyapunovs.jl at:

using DynamicalSystems

lor = Systems.lorenz(ρ = 32.0) #this is not the original parameter!
issubtype(typeof(ds), ContinuousDynamicalSystem) # true

λλ = lyapunovs(lor, 10000,
dt = 0.1, diff_eq_kwargs = Dict(:abstol => 1e-9, :reltol => 1e-9))
 result:
[0.999176, 0.000774754, -14.6666]

gives the following error:

UndefVarError: ContinuousDynamicalSystem not defined

Stacktrace:
 [1] include_string(::String, ::String) at .\loading.jl:515
Datseris commented 7 years ago

@finmod thank you for posting this!

It happens because the name ContinuousDynamicalSystem is not exported from the package.

In the next release this issue will be fixed! It is already fixed at the master branch but this minor change is not enough for a new release.

finmod commented 7 years ago

Follow up question, this used to work fine:

Running:

using DynamicalSystems, OrdinaryDiffEq

ross = Systems.roessler(a = 0.1, b = 0.1, c = 14.0) #not original parameters
λ = lyapunov(ross, 10000, dt = 0.5, diff_eq_kwargs = Dict(:solver => Vern8()))
expected result: 0.06957484163052223

produces:

WARNING: Absolute tolerance (abstol) of integration is much bigger than `d0`! It is highly suggested to increase it using `diff_eq_kwargs`.
WARNING: Relative tolerance (reltol) of integration is much bigger than `d0`! It is highly suggested to increase it using `diff_eq_kwargs`.
UndefVarError: iteg1 not defined

Stacktrace:
 [1] lyapunov_final(::OrdinaryDiffEq.ODEIntegrator{OrdinaryDiffEq.Vern8,Array{Float64,1},Float64,Float64,Float64,Array{Array{Float64,1},1},DiffEqBase.ODESolution{Float64,2,Array{Array{Float64,1},1},Void,Void,Array{Float64,1},Array{Array{Array{Float64,1},1},1},DiffEqBase.ODEProblem{Array{Float64,1},Float64,true,DynamicalSystems.##61#62{DynamicalSystems.ContinuousDS{Array{Float64,1},DynamicalSystems.Systems.#eom_roessler!#5{Float64,Float64,Float64},DynamicalSystems.Systems.#jacob_roessler#6{Float64,Float64}}},Void,UniformScaling{Int64},DiffEqBase.StandardODEProblem},OrdinaryDiffEq.Vern8,OrdinaryDiffEq.InterpolationData{DynamicalSystems.##61#62{DynamicalSystems.ContinuousDS{Array{Float64,1},DynamicalSystems.Systems.#eom_roessler!#5{Float64,Float64,Float64},DynamicalSystems.Systems.#jacob_roessler#6{Float64,Float64}}},Array{Array{Float64,1},1},Array{Float64,1},Array{Array{Array{Float64,1},1},1},OrdinaryDiffEq.Vern8Cache{Array{Float64,1},Array{Float64,1},Array{Float64,1},Array{Float64,1},OrdinaryDiffEq.Vern8ConstantCache{Float64,Float64}}}},DynamicalSystems.##61#62{DynamicalSystems.ContinuousDS{Array{Float64,1},DynamicalSystems.Systems.#eom_roessler!#5{Float64,Float64,Float64},DynamicalSystems.Systems.#jacob_roessler#6{Float64,Float64}}},Void,OrdinaryDiffEq.Vern8Cache{Array{Float64,1},Array{Float64,1},Array{Float64,1},Array{Float64,1},OrdinaryDiffEq.Vern8ConstantCache{Float64,Float64}},OrdinaryDiffEq.DEOptions{Float64,Float64,Float64,Float64,DiffEqBase.#ODE_DEFAULT_NORM,DiffEqBase.CallbackSet{Tuple{},Tuple{}},DiffEqBase.#ODE_DEFAULT_ISOUTOFDOMAIN,DiffEqBase.#ODE_DEFAULT_PROG_MESSAGE,DiffEqBase.#ODE_DEFAULT_UNSTABLE_CHECK,DataStructures.BinaryHeap{Float64,DataStructures.LessThan},DataStructures.BinaryHeap{Float64,DataStructures.LessThan},Void,Void,Int64},Array{Float64,1}}, ::OrdinaryDiffEq.ODEIntegrator{OrdinaryDiffEq.Tsit5,Array{Float64,1},Float64,Float64,Float64,Array{Array{Float64,1},1},DiffEqBase.ODESolution{Float64,2,Array{Array{Float64,1},1},Void,Void,Array{Float64,1},Array{Array{Array{Float64,1},1},1},DiffEqBase.ODEProblem{Array{Float64,1},Float64,true,DynamicalSystems.##61#62{DynamicalSystems.ContinuousDS{Array{Float64,1},DynamicalSystems.Systems.#eom_roessler!#5{Float64,Float64,Float64},DynamicalSystems.Systems.#jacob_roessler#6{Float64,Float64}}},Void,UniformScaling{Int64},DiffEqBase.StandardODEProblem},OrdinaryDiffEq.Tsit5,OrdinaryDiffEq.InterpolationData{DynamicalSystems.##61#62{DynamicalSystems.ContinuousDS{Array{Float64,1},DynamicalSystems.Systems.#eom_roessler!#5{Float64,Float64,Float64},DynamicalSystems.Systems.#jacob_roessler#6{Float64,Float64}}},Array{Array{Float64,1},1},Array{Float64,1},Array{Array{Array{Float64,1},1},1},OrdinaryDiffEq.Tsit5Cache{Array{Float64,1},Array{Float64,1},Array{Float64,1},Array{Float64,1},OrdinaryDiffEq.Tsit5ConstantCache{Float64,Float64}}}},DynamicalSystems.##61#62{DynamicalSystems.ContinuousDS{Array{Float64,1},DynamicalSystems.Systems.#eom_roessler!#5{Float64,Float64,Float64},DynamicalSystems.Systems.#jacob_roessler#6{Float64,Float64}}},Void,OrdinaryDiffEq.Tsit5Cache{Array{Float64,1},Array{Float64,1},Array{Float64,1},Array{Float64,1},OrdinaryDiffEq.Tsit5ConstantCache{Float64,Float64}},OrdinaryDiffEq.DEOptions{Float64,Float64,Float64,Float64,DiffEqBase.#ODE_DEFAULT_NORM,DiffEqBase.CallbackSet{Tuple{},Tuple{}},DiffEqBase.#ODE_DEFAULT_ISOUTOFDOMAIN,DiffEqBase.#ODE_DEFAULT_PROG_MESSAGE,DiffEqBase.#ODE_DEFAULT_UNSTABLE_CHECK,DataStructures.BinaryHeap{Float64,DataStructures.LessThan},DataStructures.BinaryHeap{Float64,DataStructures.LessThan},Void,Void,Int64},Array{Float64,1}}, ::Float64, ::Float64, ::Float64, ::Float64, ::Dict{Symbol,OrdinaryDiffEq.Vern8}) at C:\Users\Denis\.julia\v0.6\DynamicalSystems\src\lyapunovs.jl:373
 [2] #lyapunov#90(::Float64, ::Float64, ::Float64, ::Float64, ::Dict{Symbol,OrdinaryDiffEq.Vern8}, ::DynamicalSystems.##83#84{Int64}, ::Function, ::DynamicalSystems.ContinuousDS{Array{Float64,1},DynamicalSystems.Systems.#eom_roessler!#5{Float64,Float64,Float64},DynamicalSystems.Systems.#jacob_roessler#6{Float64,Float64}}, ::Int64, ::Type{Val{false}}) at C:\Users\Denis\.julia\v0.6\DynamicalSystems\src\lyapunovs.jl:314
 [3] (::DynamicalSystems.#kw##lyapunov)(::Array{Any,1}, ::DynamicalSystems.#lyapunov, ::DynamicalSystems.ContinuousDS{Array{Float64,1},DynamicalSystems.Systems.#eom_roessler!#5{Float64,Float64,Float64},DynamicalSystems.Systems.#jacob_roessler#6{Float64,Float64}}, ::Int64, ::Type{Val{false}}) at .\<missing>:0 (repeats 2 times)
 [4] include_string(::String, ::String) at .\loading.jl:515
finmod commented 7 years ago

Also entropies.jl:

running:

using DynamicalSystems
y = Int.(rand(Bool, 10000)) # just some coin tosses
sh = shannon(0.01, y)       # ≡ genentropy(1, 0.01, y)
isapprox(sh, log(2),  rtol = 1e-3) # true!

gives:

MethodError: no method matching genentropy(::Int64, ::Float64, ::Array{Int64,1})
Closest candidates are:
  genentropy(::Real, ::Real, ::DynamicalSystems.Dataset) at C:\Users\Denis\.julia\v0.6\DynamicalSystems\src\dimensions/entropies.jl:88
  genentropy(::Real, ::Real, ::AbstractArray{T,2} where T) at C:\Users\Denis\.julia\v0.6\DynamicalSystems\src\dimensions/entropies.jl:92
  genentropy(::Any, ::Any, ::DynamicalSystems.Reconstruction) at C:\Users\Denis\.julia\v0.6\DynamicalSystems\src\delay_coords.jl:65
  ...

Stacktrace:
 [1] shannon(::Float64, ::Vararg{Any,N} where N) at C:\Users\Denis\.julia\v0.6\DynamicalSystems\src\dimensions\entropies.jl:112
 [2] include_string(::String, ::String) at .\loading.jl:515
Datseris commented 7 years ago

Thanks for pointing these out. The first one is solved I am getting on the second one now.

Datseris commented 7 years ago

Latest commit fixxed that. Turns out that there was no method to convert a Vector to a Dataset. There was only for Matrix.

finmod commented 7 years ago

On entropies.jl and after Pkg.Checkout(), further down:

using DynamicalSystems
hen = Systems.henon(-rand(2))
ts = timeseries(hen, 200000)
D_hen = information_dim(ts)

lor = Systems.lorenz(rand(3))
ts = timeseries(lor, 5000, dt = 0.05)
D_lor = capacity_dim(ts)

gives error:

MethodError: no method matching min_pairwise_distance(::Array{Array{Float64,1},1})
Closest candidates are:
  min_pairwise_distance(::Union{Array{Array{T<:Real,1},1}, Array{StaticArrays.SArray{Tuple{D},T<:Real,1,D},1}}) where {D, T<:Real} at C:\Users\Denis\.julia\v0.6\DynamicalSystems\src\mathfun.jl:39
  min_pairwise_distance(::AbstractArray{T,2} where T) at C:\Users\Denis\.julia\v0.6\DynamicalSystems\src\mathfun.jl:19
  min_pairwise_distance(::DynamicalSystems.Dataset) at C:\Users\Denis\.julia\v0.6\DynamicalSystems\src\mathfun.jl:36

Stacktrace:
 [1] #estimate_boxsizes#114(::Int64, ::Int64, ::Int64, ::Function, ::DynamicalSystems.Dataset{3,Float64,Array{Float64,1}}) at C:\Users\Denis\.julia\v0.6\DynamicalSystems\src\dimensions\dims.jl:155
 [2] generalized_dim(::Int64, ::DynamicalSystems.Dataset{3,Float64,Array{Float64,1}}) at C:\Users\Denis\.julia\v0.6\DynamicalSystems\src\dimensions\dims.jl:197
 [3] capacity_dim(::DynamicalSystems.Dataset{3,Float64,Array{Float64,1}}, ::Vararg{DynamicalSystems.Dataset{3,Float64,Array{Float64,1}},N} where N) at C:\Users\Denis\.julia\v0.6\DynamicalSystems\src\dimensions\dims.jl:213
 [4] include_string(::String, ::String) at .\loading.jl:515
finmod commented 7 years ago

On lyapunovs.jl after correction of:

using DynamicalSystems, OrdinaryDiffEq

ross = Systems.roessler(a = 0.1, b = 0.1, c = 14.0) #not original parameters
λ = lyapunov(ross, 10000, dt = 0.5, diff_eq_kwargs = Dict(:solver => Vern8()))
expected result: 0.06957484163052223

I get strange value of:

WARNING: Absolute tolerance (abstol) of integration is much bigger than `d0`! It is highly suggested to increase it using `diff_eq_kwargs`.
WARNING: Relative tolerance (reltol) of integration is much bigger than `d0`! It is highly suggested to increase it using `diff_eq_kwargs`.
Out[4]:
4.986138912301363

instead of expected value above

Datseris commented 7 years ago

First error you posted actually comes from NearestNeighbors package.

Now, the second one is "solved":

using DynamicalSystems, OrdinaryDiffEq

ross = Systems.roessler(a = 0.1, b = 0.1, c = 14.0) #not original parameters
λ = lyapunov(ross, 100000, dt = 10.0, diff_eq_kwargs = Dict(:solver => Vern8(), :abstol=>1e-9, :reltol=>1e-9), Ttr = 100.0)
# result:
0.0711...

The warning messages you got are there because the precision is very off otherwise.

Do you have any knowledge on the actual lyapunov value for these parameters for the roessler system? I do not I have to admit.

ChrisRackauckas commented 7 years ago

The warning messages you got are there because the precision is very off otherwise.

Well to be fair, the warning wasn't saying that the tolerances should be decreased. https://github.com/JuliaDynamics/DynamicalSystems.jl/pull/41

Datseris commented 7 years ago

So it turns out that the issue with

lor = Systems.lorenz(rand(3))
ts = timeseries(lor, 5000, dt = 0.05)
D_lor = capacity_dim(ts)

Is my fault. NearestNeighbors doesn't accept Vector{Vector}. I will fix it soon though!

Datseris commented 7 years ago

All reported problems fixed in #42 and #43