Skip to content

Commit ec7de8d

Browse files
use current parameters in jacobian... (#191)
* use current parameters in jacobian...; * Add test for parameter usage in jacobian during continuation * Add test for parameter usage in jacobian during continuation * bump version --------- Co-authored-by: andreasmorr <[email protected]>
1 parent 1aa1f52 commit ec7de8d

File tree

3 files changed

+44
-5
lines changed

3 files changed

+44
-5
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name = "Attractors"
22
uuid = "f3fd9213-ca85-4dba-9dfd-7fc91308fec7"
33
authors = ["George Datseris <[email protected]>", "Kalel Rossi", "Alexandre Wagemakers"]
44
repo = "https://github.com/JuliaDynamics/Attractors.jl.git"
5-
version = "1.31"
5+
version = "1.31.1"
66

77
[deps]
88
BlackBoxOptim = "a134a8b2-14d6-55f6-9291-3336d3ab0209"

src/mapping/stability_measures_accumulator.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,10 +333,10 @@ function finalize_accumulator(accumulator::StabilityMeasuresAccumulator)
333333
if isinplace(ds)
334334
# For in-place systems, pre-allocate J and then compute it
335335
J = Array{Float64}(undef, length(A[1]), length(A[1]))
336-
jac(J, Array(A[1]), initial_parameters(ds), 0)
336+
jac(J, Array(A[1]), current_parameters(ds), 0)
337337
else
338338
# For out-of-place systems, compute J directly
339-
J = jac(Array(A[1]), initial_parameters(ds), 0)
339+
J = jac(Array(A[1]), current_parameters(ds), 0)
340340
end
341341

342342
λ = min(0, maximum(real.(eigvals(J))))

test/mapping/stability_measures_accumulator.jl

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,16 @@ end
131131
# Now we will test the local stability measures in `StabilityMeasuresAccumulator` in a
132132
# linear system.
133133
function linear_evolution(z, p, n)
134-
A = [-0.5 0.0; 0.0 -0.5] # Linear transformation matrix
134+
if p[1] < 0.0
135+
A = [1.0 0.0; 0.0 1.0] # Linear transformation matrix
136+
else
137+
A = [-0.5 0.0; 0.0 -0.5] # Linear transformation matrix
138+
end
135139
return SVector(A * [z[1], z[2]]...) # Convert matrix multiplication result to SVector
136140
end
137141

138142
# Create the dynamical system
139-
dynamics = CoupledODEs(linear_evolution, [1.0, 1.0], [0.0])
143+
dynamics = CoupledODEs(linear_evolution, [1.0, 1.0], [1.0])
140144

141145
# Define a grid for initial conditions
142146
grid = ([-1.0, -0.1, 0.3, 1.0], [-1.0, -0.3, 0.1, 1.0])
@@ -171,6 +175,41 @@ results_expected = Dict(
171175
end
172176
end
173177

178+
# Now we test the continuation of local stability measures using the linear map.
179+
pcurve_local = [[1 => p] for p in [-1.0, 1.0]]
180+
attractors_cont_local = [
181+
Dict(1 => StateSpaceSet([SVector(0.0, 0.0)])),
182+
Dict(1 => StateSpaceSet([SVector(0.0, 0.0)]))
183+
]
184+
185+
proximity_mapper_options_local = (
186+
Ttr=0, stop_at_Δt = false, horizon_limit = 1e2, consecutive_lost_steps = 10000
187+
)
188+
measures_cont_local = stability_measures_along_continuation(
189+
dynamics, attractors_cont_local, pcurve_local, ics_from_grid(grid), ε=0.1, finite_time=0.5,
190+
proximity_mapper_options = proximity_mapper_options_local
191+
)
192+
193+
measures_cont_local_expected = Dict(
194+
"characteristic_return_time" => [Dict(1 => Inf, -1 => NaN), Dict(1 => 2.0, -1 => NaN)],
195+
"reactivity" => [Dict(1 => 1.0, -1 => NaN), Dict(1 => -0.5, -1 => NaN)],
196+
"maximal_amplification" => [Dict(1 => Inf, -1 => NaN), Dict(1 => 1.0, -1 => NaN)],
197+
"maximal_amplification_time" => [Dict(1 => Inf, -1 => NaN), Dict(1 => 0.0, -1 => NaN)]
198+
)
199+
@testset "Local Stability Measures Continuation" begin
200+
# Validate the results
201+
for (key, value) in measures_cont_local_expected
202+
@test key in keys(measures_cont_local)
203+
for k in [1, 2]
204+
@test isapprox(
205+
sort(collect(values(value[k]))),
206+
sort(collect(values(measures_cont_local[key][k]))),
207+
atol = 1e-5,
208+
nans = true,
209+
)
210+
end
211+
end
212+
end
174213

175214
@testset "Discrete time" begin
176215
# For these parameters the map has 1 fixed point and one period 3 orbit.

0 commit comments

Comments
 (0)