JuliaDynamics / Attractors.jl

Find attractors of dynamical systems, their basins, and continue them across parameters. Study global stability (a.k.a. non-local, or resilience). Also tipping points functionality.
MIT License
27 stars 5 forks source link

Irregular grid support, issue #35 #91

Closed StefanVaylBX2023 closed 10 months ago

codecov-commenter commented 11 months ago

Codecov Report

Merging #91 (f599f75) into main (4786eb7) will increase coverage by 0.82%. The diff coverage is 94.28%.

@@            Coverage Diff             @@
##             main      #91      +/-   ##
==========================================
+ Coverage   73.43%   74.26%   +0.82%     
==========================================
  Files          21       21              
  Lines        1201     1224      +23     
==========================================
+ Hits          882      909      +27     
+ Misses        319      315       -4     
Files Changed Coverage Δ
src/mapping/attractor_mapping_recurrences.jl 91.22% <94.28%> (+0.98%) :arrow_up:

... and 1 file with indirect coverage changes

:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more

StefanVaylBX2023 commented 11 months ago

Seems good. Perhaps you can use the example of Issue #35 as an example in the documentation?

You mean docstring above the function or example for compiled documentation?

Datseris commented 11 months ago

An example in the documentation. The the docs folder in the examples markdown file. Just like you did for the minimal fatal shock.

Datseris commented 11 months ago

@StefanVaylBX2023 it is actually more useful to use this system here: https://github.com/JuliaDynamics/ChaosTools.jl/issues/258 as an example

Make the grid so that it is finer for x close to 0 and for y close to 0. It makes for the perfect example!

cc @KalelR in case you still use fast slow systems.

StefanVaylBX2023 commented 11 months ago

@StefanVaylBX2023 it is actually more useful to use this system here: JuliaDynamics/ChaosTools.jl#258 as an example

Make the grid so that it is finer for x close to 0 and for y close to 0. It makes for the perfect example!

cc @KalelR in case you still use fast slow systems.

I've been running this example for different distributions of grid (you can control it with pow , the higher pow, the more finer grid you will get closer to 0), different Dt, different u0 and different total lengths of the grid. But I cannot understand results some of the results, can you help me figure out the behavior, if it is correct or not, here is some code I've been using:

using Attractors
using DynamicalSystems

@inbounds @inline function predator_prey(u, p, t)
    α, γ, ϵ, ν, h, K, m = p
    N, P = u
    du1 = α*N*(1 - N/K) - γ*N*P / (N+h)
    du2 = ϵ * (  ν*γ*N*P/(N+h) - m*P    )
    return SVector{2}(du1, du2)
end

γ = 2.5
h = 1 
ν = 0.5 
m = 0.4
ϵ = 1.0
α = 0.8 
K = 15 

u0 = rand(2)
ds = ContinuousDynamicalSystem(predator_prey, u0, [α, γ, ϵ, ν, h, K, m])
pow = 2
xg = yg = collect(range(0, 15^(1/pow), length=1000)).^ pow
mapper = AttractorsViaRecurrences(ds, (xg, yg);  Δt=0.1, sparse = false)
basins, attractors = basins_of_attraction(mapper; show_progress = true)

attractors[1]

using CairoMakie

heatmap_basins_attractors((xg,yg),basins, attractors)

and the results I obtained plot_34

Also, using scatter doesn't help much:

mapper(u0)
u = mapper.bsn_nfo.attractors[1]
plot(u[:,1], u[:,2], seriestype = :scatter)
Datseris commented 11 months ago

what do you not understand?

StefanVaylBX2023 commented 11 months ago

what do you not understand?

I don't understand how this particular configuration is valid to be added as a final example.

Datseris commented 11 months ago

wait , i am confused. when you run this code you do not find a limit cycle as attractors?

StefanVaylBX2023 commented 11 months ago

wait , i am confused. when you run this code you do not find a limit cycle as attractors?

u0 = rand(2)
ds = ContinuousDynamicalSystem(predator_prey, u0, [α, γ, ϵ, ν, h, K, m])
pow = 4
xg = yg = collect(range(0, 15^(1/pow), length=10000)).^ pow
mapper = AttractorsViaRecurrences(ds, (xg, yg);  Δt=0.1, sparse = false)
mapper(u0)
u = mapper.bsn_nfo.attractors[1]
plot(u[:,1], u[:,2], seriestype = :scatter)

with this code i obtained a limit cycle, but it is not much different from results obtained in discussion

StefanVaylBX2023 commented 10 months ago

working on the comments rn, just one more question regarding example in the docs, what exactly do you expect to see there like plot of mapper.bsn_info.attractors or the heatmap.

Datseris commented 10 months ago

I was thinking that a good example would be using this fast slow system, and solving it once with a regular grid, and showing that it fails. Then solving it with hte irregular grid and showing that it works (i.e., finds the limit cycle).

This would need relatively coarse grid, e.g., 100 cell boxes in each dimension. but for the irregular grid the cell boxes are concentrated near the origin!

You should also turn the parameter store_once_per_cell = false.

StefanVaylBX2023 commented 10 months ago

I've addressed all of the issues you mentioned but still problem with example. With basins_of_attraction for both cases all I can get is two saddle points as attractors (I've tried tons of initial conditions and grid setups). While running mapper(u0) with u0 = rand(2) writes down cyclical attractor into bsn_nfo again in both cases, with only difference that with the same setup irregular grid gives 20-30% more points

Datseris commented 10 months ago

okay thanks, I'll have a look then!