Skip to content

Commit b254477

Browse files
authored
add FitzHugh SDE example (#244)
* add FitzHugh SDE example * add stocahstieq to doc deps * also show attractors * Update Project.toml
1 parent c8317c0 commit b254477

File tree

3 files changed

+57
-3
lines changed

3 files changed

+57
-3
lines changed

Project.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "DynamicalSystems"
22
uuid = "61744808-ddfa-5f27-97ff-6e42cc95d634"
33
repo = "https://github.com/JuliaDynamics/DynamicalSystems.jl.git"
4-
version = "3.3.21"
4+
version = "3.3.22"
55

66
[deps]
77
Attractors = "f3fd9213-ca85-4dba-9dfd-7fc91308fec7"
@@ -30,7 +30,7 @@ ChaosTools = "3"
3030
ComplexityMeasures = "2, 3"
3131
DataStructures = "0.18"
3232
DelayEmbeddings = "2.7"
33-
DynamicalSystemsBase = "3.8.3"
33+
DynamicalSystemsBase = "3.11.0"
3434
FractalDimensions = "1"
3535
Makie = "≥ 0.19"
3636
PredefinedDynamicalSystems = "1"

docs/Project.toml

+1
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ StateSpaceSets = "40b095a5-5852-4c12-98c7-d43bf788e795"
1616
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
1717
FractalDimensions = "4665ce21-e117-4649-aed8-08bbe5ccbead"
1818
Literate = "98b081ad-f1c9-55d3-8b20-4c87d4299306"
19+
StochasticDiffEq = "789caeaf-c7a9-5a7d-9973-96adeb23e2a0"

docs/src/tutorial.jl

+54-1
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,60 @@ basins, attractors = basins_of_attraction(mapper; show_progress = false)
290290

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

293-
# One last thing to highlight in this short overview are the interactive GUI apps one
293+
# ## Stochastic systems
294+
295+
# DynamicalSystems.jl has some support for stochastic systems
296+
# in the form of Stochastic Differential Equations (SDEs).
297+
# Just like `CoupledODEs`, one can make `CoupledSDEs`!
298+
# For example here is a stochastic version of a FitzHugh-Nagumo model
299+
300+
using StochasticDiffEq # load extention for `CoupledSDEs`
301+
302+
function fitzhugh_nagumo(u, p, t)
303+
x, y = u
304+
ϵ, β, α, γ, κ, I = p
305+
dx = (-α * x^3 + γ * x - κ * y + I) / ϵ
306+
dy = -β * y + x
307+
return SVector(dx, dy)
308+
end
309+
p = [1.,3.,1.,1.,1.,0.]
310+
sde = CoupledSDEs(fitzhugh_nagumo, zeros(2), p; noise_strength = 0.05)
311+
312+
# In this particular example the SDE noise is white noise (Wiener process)
313+
# with strength (σ) of 0.05. See the documentation of `CoupledSDEs` for alternatives.
314+
315+
# In any case, in DynamicalSystems.jl all dynamical systems are part of the same
316+
# interace, stochastic or not. As long as the algorithm is not influenced by stochasticity,
317+
# we can apply it to `CoupledSDEs` just as well. For example, we can study multistability
318+
# in a stochastic system. In contrast to the previous example of the Henon map,
319+
# we have to use an alternative algorithm, because `AttractorsViaRecurrences`
320+
# only works for deterministic systems. So instead we'll use `AttractorsViaFeaturizing`:
321+
322+
featurizer(X, t) = X[end]
323+
324+
mapper = AttractorsViaFeaturizing(sde, featurizer; Ttr = 200, T = 10)
325+
326+
xg = yg = range(-1, 1; length = 101)
327+
328+
sampler, _ = statespace_sampler((xg, yg))
329+
330+
fs = basins_fractions(mapper, sampler)
331+
332+
# and we can see the stored "attractors"
333+
334+
attractors = extract_attractors(mapper)
335+
fig, ax = scatter(attractors[1])
336+
scatter!(attractors[2])
337+
fig
338+
339+
# The mathematical concept of attractors
340+
# doesn't translate trivially to stochastic systems but thankfully
341+
# this system has two fixed point attractors that are only mildly perturbed
342+
# by the noise.
343+
344+
# ## Interactive GUIs
345+
346+
# A particularly useful feature are interactive GUI apps one
294347
# can launch to examine a `DynamicalSystem`. The simplest is [`interactive_trajectory_timeseries`](@ref).
295348
# To actually make it interactive one needs to enable GLMakie.jl as a backend:
296349

0 commit comments

Comments
 (0)