JuliaDynamics / ChaosTools.jl

Tools for the exploration of chaos and nonlinear dynamics
https://juliadynamics.github.io/DynamicalSystemsDocs.jl/chaostools/stable/
MIT License
187 stars 35 forks source link

Finalize recurrences seeded continuation #274

Closed Datseris closed 1 year ago

Datseris commented 2 years ago

Will fix #273. Opening the PR already so it is easier.

Datseris commented 2 years ago

I've coded in airplanes and airports all day but the outcome was worth the pain. So now I am looking a version with lorenz84 that does something very interesting. At some point the attractors "swap" and we no longer connect the chaotic with the chaotic and the periodic with the periodic. See video:

https://user-images.githubusercontent.com/19669089/185763272-f3028b6a-3a05-4108-85b6-ed4f22b18bbb.mp4

Datseris commented 2 years ago

ah wait tis may be because of te way i make the video lol

Datseris commented 2 years ago

Yeah I was plotting wrongly. Now in the next video it seems that the merging of the chaotic attractor into the fixed point makes the resulting fixed point at the end get labelled as a new attractor. I am not sure why, nor what I should expect the correct behavior to be. I think, with the way the code is now, the color of the fixe dpoint should stay constant throughout. but I need to think about this more.

https://user-images.githubusercontent.com/19669089/185763514-90df1081-6208-4b19-919c-e106f6934cb4.mp4

Datseris commented 2 years ago

@awage the lorenz test code in this exact commit never terminates. We had problems with lorenz84 never terminating in the past. We never really figured out why this happenes, or how to solve it. But now we really need to address this problem instead of finding different metaparameters where the algorithm doesn't hault. We need to find out why it haults. And probably, we also need an internal step counter that counts steps and if they exceed some threshold we assign -1.

I am suspecting that what happens is we forever jump betweeen locating one attractor to the other one, because they are so close to each other.

Datseris commented 2 years ago

Worst part is also that you cannot interrupt the process with Ctrl+C. (This was teh case before as well, has nothing to do with the new Continuation code). I do not know why the process cannot be interrupted with Ctrl+C and we need to completely close the Julia process itself. But that's another thing to fix. I'm adding it as a todo in #274

SergeyNovak777 commented 2 years ago

Hello, I have a similar situation, but i don't usuing function for basins of atractors because system is 6D and using functions take a long time. The place of this i ploting projection phase space on 3D with two trajectory from different attractor and get this.

https://user-images.githubusercontent.com/73059239/186152692-ff4d1841-c437-42cb-a37d-f3e9bd99aff4.mov

Parameters for AttractorsViaRecurrences() use default ? In my case, I doubled the values for mx_chk_hit_bas; mx_chk_fnd_att ; mx_chk_loc_att ; mx_chk_lost This problem occurred when using sparse or without it?

Datseris commented 2 years ago

i haven't posted here in a while. I have solved the "never terminates problem". Also, with the new sparse structure, going into 1000 partitions per dimension is no problem and solves it on its own anyways.

awage commented 2 years ago

I have added the example with the Second Order Kuramoto problem. However I get an error while using AttractorsViaFeaturizing. It is related to the parameterized type T of the keyword arguments, here is the full error log:

mapper = AttractorsViaFeaturizing(psys, featurizer, clstrspcs; T = 5000., Δt = 1., diffeq)
ERROR: MethodError: no method matching AttractorsViaFeaturizing(::DynamicalSystemsBase.ProjectedIntegrator{SVector{30, Int64}, 30, typeof(_get_rand_ic), Nothing, OrdinaryDiffEq.ODEIntegrator{Tsit5{typeof(OrdinaryDiffEq.trivial_limiter!), typeof(OrdinaryDiffEq.trivial_limiter!), Static.False}, true, Vector{Float64}, Nothing, Float64, Vector{Any}, Float64, Float64, Float64, Float64, Vector{Vector{Float64}}, ODESolution{Float64, 2, Vector{Vector{Float64}}, Nothing, Nothing, Vector{Float64}, Vector{Vector{Vector{Float64}}}, ODEProblem{Vector{Float64}, Tuple{Float64, Float64}, true, Vector{Any}, ODEFunction{true, typeof(second_order_kuramoto), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing, Nothing}, Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardODEProblem}, Tsit5{typeof(OrdinaryDiffEq.trivial_limiter!), typeof(OrdinaryDiffEq.trivial_limiter!), Static.False}, OrdinaryDiffEq.InterpolationData{ODEFunction{true, typeof(second_order_kuramoto), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing, Nothing}, Vector{Vector{Float64}}, Vector{Float64}, Vector{Vector{Vector{Float64}}}, OrdinaryDiffEq.Tsit5Cache{Vector{Float64}, Vector{Float64}, Vector{Float64}, OrdinaryDiffEq.Tsit5ConstantCache{Float64, Float64}, typeof(OrdinaryDiffEq.trivial_limiter!), typeof(OrdinaryDiffEq.trivial_limiter!), Static.False}}, DiffEqBase.DEStats}, ODEFunction{true, typeof(second_order_kuramoto), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing, Nothing}, OrdinaryDiffEq.Tsit5Cache{Vector{Float64}, Vector{Float64}, Vector{Float64}, OrdinaryDiffEq.Tsit5ConstantCache{Float64, Float64}, typeof(OrdinaryDiffEq.trivial_limiter!), typeof(OrdinaryDiffEq.trivial_limiter!), Static.False}, OrdinaryDiffEq.DEOptions{Float64, Float64, Float64, Float64, PIController{Rational{Int64}}, typeof(DiffEqBase.ODE_DEFAULT_NORM), typeof(LinearAlgebra.opnorm), Nothing, CallbackSet{Tuple{}, Tuple{DiscreteCallback{typeof(condition), typeof(affect!), typeof(SciMLBase.INITIALIZE_DEFAULT), typeof(SciMLBase.FINALIZE_DEFAULT)}}}, typeof(DiffEqBase.ODE_DEFAULT_ISOUTOFDOMAIN), typeof(DiffEqBase.ODE_DEFAULT_PROG_MESSAGE), typeof(DiffEqBase.ODE_DEFAULT_UNSTABLE_CHECK), DataStructures.BinaryHeap{Float64, DataStructures.FasterForward}, DataStructures.BinaryHeap{Float64, DataStructures.FasterForward}, Nothing, Nothing, Float64, Tuple{}, Tuple{}, Tuple{}}, Vector{Float64}, Float64, Nothing, OrdinaryDiffEq.DefaultInit}}, ::typeof(featurizer), ::ClusteringConfig{Nothing, Euclidean}, ::Int64, ::Float64, ::Float64, ::NamedTuple{(:alg, :reltol, :callback, :maxiters), Tuple{Tsit5{typeof(OrdinaryDiffEq.trivial_limiter!), typeof(OrdinaryDiffEq.trivial_limiter!), Static.False}, Float64, DiscreteCallback{typeof(condition), typeof(affect!), typeof(SciMLBase.INITIALIZE_DEFAULT), typeof(SciMLBase.FINALIZE_DEFAULT)}, Float64}}, ::Nothing)
Closest candidates are:
  AttractorsViaFeaturizing(::DS, ::F, ::C, ::T, ::T, ::T, ::K, ::A) where {DS<:GeneralizedDynamicalSystem, C<:ClusteringConfig, T, K, A, F} at ~/urjc/investigacion/proyecto_basins_computing/ChaosTools.jl/src/basins/mapping/attractor_mapping_featurizing.jl:12
  AttractorsViaFeaturizing(::GeneralizedDynamicalSystem, ::Function, ::ClusteringConfig; T, Ttr, Δt, diffeq, attractors_ic) at ~/urjc/investigacion/proyecto_basins_computing/ChaosTools.jl/src/basins/mapping/attractor_mapping_featurizing.jl:65
  AttractorsViaFeaturizing(::GeneralizedDynamicalSystem, ::Function) at ~/urjc/investigacion/proyecto_basins_computing/ChaosTools.jl/src/basins/mapping/attractor_mapping_featurizing.jl:65
Stacktrace:
 [1] AttractorsViaFeaturizing(ds::DynamicalSystemsBase.ProjectedIntegrator{SVector{30, Int64}, 30, typeof(_get_rand_ic), Nothing, OrdinaryDiffEq.ODEIntegrator{Tsit5{typeof(OrdinaryDiffEq.trivial_limiter!), typeof(OrdinaryDiffEq.trivial_limiter!), Static.False}, true, Vector{Float64}, Nothing, Float64, Vector{Any}, Float64, Float64, Float64, Float64, Vector{Vector{Float64}}, ODESolution{Float64, 2, Vector{Vector{Float64}}, Nothing, Nothing, Vector{Float64}, Vector{Vector{Vector{Float64}}}, ODEProblem{Vector{Float64}, Tuple{Float64, Float64}, true, Vector{Any}, ODEFunction{true, typeof(second_order_kuramoto), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing, Nothing}, Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardODEProblem}, Tsit5{typeof(OrdinaryDiffEq.trivial_limiter!), typeof(OrdinaryDiffEq.trivial_limiter!), Static.False}, OrdinaryDiffEq.InterpolationData{ODEFunction{true, typeof(second_order_kuramoto), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing, Nothing}, Vector{Vector{Float64}}, Vector{Float64}, Vector{Vector{Vector{Float64}}}, OrdinaryDiffEq.Tsit5Cache{Vector{Float64}, Vector{Float64}, Vector{Float64}, OrdinaryDiffEq.Tsit5ConstantCache{Float64, Float64}, typeof(OrdinaryDiffEq.trivial_limiter!), typeof(OrdinaryDiffEq.trivial_limiter!), Static.False}}, DiffEqBase.DEStats}, ODEFunction{true, typeof(second_order_kuramoto), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing, Nothing}, OrdinaryDiffEq.Tsit5Cache{Vector{Float64}, Vector{Float64}, Vector{Float64}, OrdinaryDiffEq.Tsit5ConstantCache{Float64, Float64}, typeof(OrdinaryDiffEq.trivial_limiter!), typeof(OrdinaryDiffEq.trivial_limiter!), Static.False}, OrdinaryDiffEq.DEOptions{Float64, Float64, Float64, Float64, PIController{Rational{Int64}}, typeof(DiffEqBase.ODE_DEFAULT_NORM), typeof(LinearAlgebra.opnorm), Nothing, CallbackSet{Tuple{}, Tuple{DiscreteCallback{typeof(condition), typeof(affect!), typeof(SciMLBase.INITIALIZE_DEFAULT), typeof(SciMLBase.FINALIZE_DEFAULT)}}}, typeof(DiffEqBase.ODE_DEFAULT_ISOUTOFDOMAIN), typeof(DiffEqBase.ODE_DEFAULT_PROG_MESSAGE), typeof(DiffEqBase.ODE_DEFAULT_UNSTABLE_CHECK), DataStructures.BinaryHeap{Float64, DataStructures.FasterForward}, DataStructures.BinaryHeap{Float64, DataStructures.FasterForward}, Nothing, Nothing, Float64, Tuple{}, Tuple{}, Tuple{}}, Vector{Float64}, Float64, Nothing, OrdinaryDiffEq.DefaultInit}}, featurizer::Function, cluster_config::ClusteringConfig{Nothing, Euclidean}; T::Float64, Ttr::Int64, Δt::Float64, diffeq::NamedTuple{(:alg, :reltol, :callback, :maxiters), Tuple{Tsit5{typeof(OrdinaryDiffEq.trivial_limiter!), typeof(OrdinaryDiffEq.trivial_limiter!), Static.False}, Float64, DiscreteCallback{typeof(condition), typeof(affect!), typeof(SciMLBase.INITIALIZE_DEFAULT), typeof(SciMLBase.FINALIZE_DEFAULT)}, Float64}}, attractors_ic::Nothing)
   @ ChaosTools ~/urjc/investigacion/proyecto_basins_computing/ChaosTools.jl/src/basins/mapping/attractor_mapping_featurizing.jl:71
 [2] top-level scope
   @ REPL[329]:1
Datseris commented 2 years ago

@awage please open a PR to this PR as I am working on this right now and it will make problems with the source code if we both push to the same branch!

Datseris commented 2 years ago

btw i've fixed everything i wanted to do in my last commit I think haha

awage commented 2 years ago

Sorry! I will wait until you have made your changes and then open the PR. You can revert my commit if you want.

Datseris commented 2 years ago

no worries, I've remove dthe kuramoto but we put it back in with a pull request!

awage commented 2 years ago

The keyword option unsafe = true does not work, there is a problem in attractors_mapping_recurrences.jl. The following syntax work:

        !bsn_nfo.unsafe && (bsn_nfo.safety_counter += 1)
        if !bsn_nfo.unsafe && (bsn_nfo.safety_counter ≥ safety_counter_max)
Datseris commented 2 years ago

@awage I'm probably offline for two to three days, you can work on this branch if you'd like. You can also open a new branch and open a PR into this branch, perhaps this is even safer.

Datseris commented 1 year ago

I think this is done and I can merge.

Datseris commented 1 year ago

oh hell yeah baby this is merged

awage commented 1 year ago

Thumbs up!