Skip to content

Commit

Permalink
setup test structure
Browse files Browse the repository at this point in the history
  • Loading branch information
oameye committed Mar 25, 2024
1 parent f378c13 commit 787efba
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 49 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ docs/build/
/Manifest.toml
dev/levy.jl
reyk_local/
.JuliaFormatter.toml
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ julia = "1.4"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"

[targets]
test = ["Test"]
test = ["Test", "Random"]
12 changes: 12 additions & 0 deletions test/MAM.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@testset "OuMAM" begin
ou = StochSystem((u, p, t) -> -u, [], [1.0], 1.0)
x0 = -1
xT = 2.0
T = 10.0
N = 51
t = range(0, T, N)
inst_mam = min_action_method(ou, [x0], [xT], N, T, verbose = false, save_info = false)
inst_sol = ((xT - x0 * exp(-T)) * exp.(t) .+ (x0 * exp(T) - xT) * exp.(-t)) /
(exp(T) - exp(-T))
@test maximum(abs.(inst_mam' .- inst_sol)) < 0.1
end
75 changes: 38 additions & 37 deletions test/gMAM.jl
Original file line number Diff line number Diff line change
@@ -1,39 +1,40 @@
using CriticalTransitions, Test

function meier_stein(u, p, t) # out-of-place
x, y = u
dx = x - x^3 - 10 * x * y^2
dy = -(1 + x^2) * y
[dx, dy]
end
σ = 0.25
sys = StochSystem(meier_stein, [], zeros(2), σ, idfunc, nothing, I(2), "WhiteGauss")

# initial path: parabola
xx = range(-1.0, 1.0, length = 30)
yy = 0.3 .* (-xx .^ 2 .+ 1)
init = Matrix([xx yy]')

x_i = init[:,1]
x_f = init[:,end]

@testset "LBFGS" begin
gm = geometric_min_action_method(sys, x_i, x_f, maxiter = 10) # runtest
gm = geometric_min_action_method(sys, init, maxiter = 100)

path = gm[1][end]
action_val = gm[2][end]
@test all(isapprox.(path[2, :][(end - 5):end], 0, atol = 1e-3))
@test all(isapprox.(action_val, 0.3375, atol = 1e-3))
end


@testset "HeymannVandenEijnden" begin # broken
# method = "HeymannVandenEijnden"
# gm = geometric_min_action_method(sys, x_i, x_f, maxiter = 10, method=method) # runtest

# path = gm[1][end]
# action_val = gm[2][end]
# @test all(isapprox.(path[2, :][(end - 5):end], 0, atol = 1e-3))
# @test all(isapprox.(action_val, 0.3375, atol = 1e-3))
end
@testset "gMAM Meier Stein" begin
function meier_stein(u, p, t) # out-of-place
x, y = u
dx = x - x^3 - 10 * x * y^2
dy = -(1 + x^2) * y
[dx, dy]
end
σ = 0.25
sys = StochSystem(meier_stein, [], zeros(2), σ, idfunc, nothing, I(2), "WhiteGauss")

# initial path: parabola
xx = range(-1.0, 1.0, length = 30)
yy = 0.3 .* (-xx .^ 2 .+ 1)
init = Matrix([xx yy]')

x_i = init[:, 1]
x_f = init[:, end]

@testset "LBFGS" begin
gm = geometric_min_action_method(sys, x_i, x_f, maxiter = 10) # runtest
gm = geometric_min_action_method(sys, init, maxiter = 100)

path = gm[1][end]
action_val = gm[2][end]
@test all(isapprox.(path[2, :][(end - 5):end], 0, atol = 1e-3))
@test all(isapprox.(action_val, 0.3375, atol = 1e-3))
end

@testset "HeymannVandenEijnden" begin # broken
# method = "HeymannVandenEijnden"
# gm = geometric_min_action_method(sys, x_i, x_f, maxiter = 10, method=method)

# path = gm[1][end]
# action_val = gm[2][end]
# @test all(isapprox.(path[2, :][(end - 5):end], 0, atol = 1e-3))
# @test all(isapprox.(action_val, 0.3375, atol = 1e-3))
end # HeymannVandenEijnden
end # gMAM Meier Stein
25 changes: 14 additions & 11 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
using CriticalTransitions
using Test

@testset "OuMAM" begin
ou = StochSystem((u,p,t)->-u,[],1,1.0);
x0 = -1
xT = 2.
T = 10.
N = 51
t = range(0,T,N)
inst_mam = min_action_method(ou,[x0], [xT], N,T,showprogress=false);
inst_sol = ((xT - x0*exp(-T))*exp.(t) .+ (x0*exp(T) - xT)*exp.(-t))/(exp(T) - exp(-T));
@test maximum(abs.(inst_mam' .- inst_sol)) < 0.1
end
using Random
const SEED = 0xd8e5d8df
Random.seed!(SEED)

files = [
"gMAM.jl",
"stochsystem.jl",
"MAM.jl"
]

for file in files
include(file)
printstyled(file * ": OK\n"; color = :green)
end

0 comments on commit 787efba

Please sign in to comment.