Skip to content

Commit a27b135

Browse files
committed
worked on updating tests
1 parent 3358570 commit a27b135

File tree

10 files changed

+80
-40
lines changed

10 files changed

+80
-40
lines changed

test/CoupledSDEs.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
# diagonal additive noise: σ*N(0,dt)
2222
# a vector of random numbers dW whose size matches the output of g where the noise is applied element-wise
2323
prob = SDEProblem(meier_stein, diagonal_noise(σ), zeros(2), (0.0, Inf), ())
24-
sde = CoupledSDEs(meier_stein, idfunc, zeros(2), (), σ)
24+
sde = CoupledSDEs(meier_stein, zeros(2); noise_strength=σ)
2525

2626
@test sde.integ.sol.prob.f isa SDEFunction
2727
@test sde.integ.sol.prob.f.f.f == prob.f.f
@@ -46,7 +46,7 @@
4646
σ = 0.25 # noise strength
4747
W = WienerProcess(0.0, 0.0, 0.0)
4848
prob = SDEProblem(f!, diagonal_noise!(σ), zeros(2), (0.0, Inf), (); noise=W)
49-
sde = CoupledSDEs(f!, idfunc!, zeros(2), (), σ; noise=W)
49+
sde = CoupledSDEs(f!, zeros(2); noise_process=W, noise_strength=σ)
5050

5151
@test sde.integ.sol.prob.f isa SDEFunction
5252
@test sde.integ.sol.prob.f.f.f == prob.f.f
@@ -74,7 +74,7 @@
7474
g_sde(u, p, t) = σ .* u
7575
g_Csde(u, p, t) = σ .* u
7676
prob = SDEProblem(meier_stein, g_sde, zeros(2), (0.0, Inf), ())
77-
sde = CoupledSDEs(meier_stein, g_Csde, zeros(2), (), σ)
77+
sde = CoupledSDEs(meier_stein, zeros(2); g=g_Csde)
7878

7979
@test sde.integ.sol.prob.f isa SDEFunction
8080
@test sde.integ.sol.prob.f.f.f == prob.f.f
@@ -108,7 +108,7 @@
108108
# prob = SDEProblem(f, g, ones(2), (0.0, 1.0), noise_rate_prototype = zeros(2, 4))
109109
# diffeq =(alg=SRIW1(), noise_rate_prototype = zeros(2, 4))
110110
sde = CoupledSDEs(
111-
f, g, zeros(2); noise_rate_prototype=zeros(2, 4), diffeq=(alg=RKMilCommute(),)
111+
f, zeros(2); g, noise_prototype=zeros(2, 4), diffeq=(alg=RKMilCommute(),)
112112
)
113113
prob = SDEProblem(f, g, zeros(2), (0.0, Inf); noise_rate_prototype=zeros(2, 4))
114114

@@ -133,7 +133,7 @@
133133
Z0 = zeros(2)
134134
W = CorrelatedWienerProcess(Γ, t0, W0, Z0)
135135
prob = SDEProblem(f!, diagonal_noise!(σ), zeros(2), (0.0, Inf), (); noise=W)
136-
sde = CoupledSDEs(f!, idfunc!, zeros(2), (), σ; noise=W)
136+
sde = CoupledSDEs(f!, zeros(2); noise_process=W, noise_strength=σ)
137137

138138
@test sde.integ.sol.prob.f isa SDEFunction
139139
@test sde.integ.sol.prob.f.f.f == prob.f.f
@@ -158,4 +158,4 @@
158158
@test W.covariance cov(sol; dims=2) / dt rtol = 1e-2
159159
end
160160
end
161-
end
161+
end
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
@testset "fitzhugh_nagumo" begin
2+
# Define systems
3+
g = diag_noise_funtion(0.215)
4+
system = CoupledSDEs(fitzhugh_nagumo, g, [2.0, 0.1], [0.1, 3.0, 1.0, 1.0, 1.0, 0.0])
5+
6+
# Set up domain
7+
A, B, C = [0.0, 0.0], [1.0, 0.0], [0.0, 1.0]
8+
box = intervals_to_box([-2.0, -2.0], [2.00, 2.0])
9+
step = 0.1
10+
11+
boas = basins(system, A, B, C, box; bstep = [step, step])
12+
X, Y, attractors, h = boas
13+
boundary = basinboundary(boas)
14+
@test length(attractors) == 2
15+
@test length(unique(h)) == 3
16+
@test h[end÷2+1, end÷2+1] == -1
17+
@test boundary[:,end÷2+1] == zeros(2)
18+
end

test/issue14.jl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using CriticalTransitions, StaticArrays, Test
2+
3+
function meier_stein(u, p, t) # in-place
4+
x, y = u
5+
dx = x-x^3 -10*x*y^2
6+
dy = -(1+x^2)*y
7+
SA[dx, dy]
8+
end
9+
σ = 0.25
10+
sys = StochSystem(meier_stein, [], zeros(2), σ, idfunc, nothing, I(2), "WhiteGauss")
11+
12+
# initial path: parabola
13+
xx = range(-1.0,1.0, length=30)
14+
yy = 0.3 .* (- xx .^ 2 .+ 1)
15+
init = Matrix([xx yy]')
16+
17+
gm = geometric_min_action_method(sys, init, maxiter=1000)
18+
@test all(isapprox.(path[2,:][end-5:end], 0, atol=1e-3))
19+
20+
gm[2][end]
21+
22+
isapprox(gm[2][end], 0.338, atol=1e-3)

test/largedeviations/MAM.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
@testset "MAM FitzHugh-Nagumo" begin
22
p = [0.1, 3, 1, 1, 1, 0]
33
σ = 0.1
4-
fhn = CoupledSDEs(fitzhugh_nagumo, idfunc, zeros(2), p, σ)
4+
fhn = CoupledSDEs(fitzhugh_nagumo, zeros(2), p; noise_strength=σ)
55
x_i = SA[sqrt(2 / 3), sqrt(2 / 27)]
66
x_f = SA[0.001, 0.0]
77
N, T = 200, 2.0
@@ -14,7 +14,7 @@ end
1414

1515
@testset "MAM Ornstein-Uhlenbeck" begin
1616
σ = 0.18
17-
ou = CoupledSDEs((u, p, t) -> -u, idfunc, SA[1.0], (), σ)
17+
ou = CoupledSDEs((u, p, t) -> -u, SA[1.0]; noise_strength=σ)
1818
x0 = -1
1919
xT = 2.0
2020
T = 10.0

test/largedeviations/action_fhn.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ Random.seed!(SEED)
44
# System setup - FitzHugh-Nagumo model
55
p = [1.0, 3.0, 1.0, 1.0, 1.0, 0.0] # Parameters (ϵ, β, α, γ, κ, I)
66
σ = 0.2 # noise strength
7-
sys = CoupledSDEs(fitzhugh_nagumo, idfunc, zeros(2), p, σ; seed=SEED)
7+
sys = CoupledSDEs(fitzhugh_nagumo, zeros(2), p; noise_strength=σ)#, seed=SEED)
88

9-
A = inv(CT.covariance_matrix(sys))
9+
A = inv(covariance_matrix(sys))
1010
T, N = 2.0, 100
1111

1212
x_i = SA[sqrt(2 / 3), sqrt(2 / 27)]
@@ -22,7 +22,7 @@ end
2222

2323
# Test om_action function
2424
@testset "om_action" begin
25-
S = om_action(sys, path, time)
25+
S = om_action(sys, path, time, σ)
2626
@test isapprox(S, 0.26, atol=0.01)
2727
end
2828

test/largedeviations/gMAM.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
@testset "gMAM FitzHugh-Nagumo" begin
22
p = [0.1, 3, 1, 1, 1, 0]
33
σ = 0.1
4-
fhn = CoupledSDEs(fitzhugh_nagumo, idfunc, zeros(2), p, σ)
4+
fhn = CoupledSDEs(fitzhugh_nagumo, zeros(2), p; noise_strength=σ)
55
x_i = SA[sqrt(2 / 3), sqrt(2 / 27)]
66
x_f = SA[0.001, 0.0]
77
N = 100
@@ -19,7 +19,7 @@ end
1919
end
2020
σ = 0.25
2121
# sys = CoupledSDEs(fitzhugh_nagumo, idfunc, zeros(2), p, σ)
22-
sys = CoupledSDEs(meier_stein, idfunc, zeros(2), (), σ)
22+
sys = CoupledSDEs(meier_stein, zeros(2); noise_strength=σ)
2323

2424
# initial path: parabola
2525
xx = range(-1.0, 1.0; length=30)

test/runtests.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ end
4444
JET.test_package(CriticalTransitions; target_defined_modules=true)
4545
end
4646

47-
@testset "CoupledSDEs" begin
48-
include("CoupledSDEs.jl")
49-
end
47+
#@testset "CoupledSDEs" begin
48+
# include("CoupledSDEs.jl")
49+
#end
5050

5151
@testset "ModelingToolkit" begin
5252
include("ModelingToolkit.jl")
@@ -58,9 +58,9 @@ end
5858
include("largedeviations/gMAM.jl")
5959
end
6060

61-
@testset "utilities" begin
62-
include("utils.jl")
63-
end
61+
#@testset "utilities" begin
62+
# include("utils.jl")
63+
#end
6464

6565
@testset "Trajactories" begin
6666
include("trajactories/simulate.jl")

test/trajactories/simulate.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
p = [0.1, 3.0, 1.0, 1.0, 1.0, 0.0] # Parameters (ϵ, β, α, γ, κ, I)
44
σ = 0.1
55
# Simulate
6-
sys = CoupledSDEs(fitzhugh_nagumo, idfunc, SA[1.0, 0.0], p, σ)
6+
sys = CoupledSDEs(fitzhugh_nagumo, SA[1.0, 0.0], p; noise_strength=σ)
77
traj = relax(sys, 10)
8-
sys = CoupledSDEs(fitzhugh_nagumo, idfunc, SA[1.0, 0.0], p, σ)
8+
sys = CoupledSDEs(fitzhugh_nagumo, SA[1.0, 0.0], p; noise_strength=σ)
99
sim = simulate(sys, 10)
1010
@test traj[1][1, 1] == 1.0
1111
@test sim.u[1][1] == 1.0

test/trajactories/transition.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
σ = 0.215 # noise strength
88

99
# CoupledSDEs
10-
sys = CoupledSDEs(fitzhugh_nagumo, idfunc, zeros(2), p, σ; seed=SEED)
10+
sys = CoupledSDEs(fitzhugh_nagumo, zeros(2), p; noise_strength=σ, seed=SEED)
1111

1212
fp1 = [0.816, 0.272]
1313
fp2 = [-0.816, -0.272]

test/utils.jl

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
# Test for idfunc
2-
@testset "idfunc" begin
3-
u = [1, 2, 3]
4-
p = [0.1, 0.2, 0.3]
5-
t = 0.5
6-
expected = [1, 1, 1]
7-
@test idfunc(u, p, t) == expected
8-
end
9-
10-
# Test for idfunc!
11-
@testset "idfunc!" begin
12-
du = zeros(3)
13-
u = [1, 2, 3]
14-
p = [0.1, 0.2, 0.3]
15-
t = 0.5
16-
expected = [1, 1, 1]
17-
idfunc!(du, u, p, t)
18-
@test du == expected
19-
end
2+
#@testset "idfunc" begin
3+
# u = [1, 2, 3]
4+
# p = [0.1, 0.2, 0.3]
5+
# t = 0.5
6+
# expected = [1, 1, 1]
7+
# @test idfunc(u, p, t) == expected
8+
#end
9+
#
10+
## Test for idfunc!
11+
#@testset "idfunc!" begin
12+
# du = zeros(3)
13+
# u = [1, 2, 3]
14+
# p = [0.1, 0.2, 0.3]
15+
# t = 0.5
16+
# expected = [1, 1, 1]
17+
# idfunc!(du, u, p, t)
18+
# @test du == expected
19+
#end
2020

2121
# Test for intervals_to_box
2222
@testset "intervals_to_box" begin

0 commit comments

Comments
 (0)