diff --git a/.gitignore b/.gitignore index f3bb14b8..00e25b40 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ docs/build/ /Manifest.toml dev/levy.jl reyk_local/ +.JuliaFormatter.toml diff --git a/Project.toml b/Project.toml index 6dd4e9e8..7f77a6a7 100644 --- a/Project.toml +++ b/Project.toml @@ -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"] diff --git a/test/MAM.jl b/test/MAM.jl new file mode 100644 index 00000000..41dabb80 --- /dev/null +++ b/test/MAM.jl @@ -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 diff --git a/test/gMAM.jl b/test/gMAM.jl index 9ae98a28..ddcdac4b 100644 --- a/test/gMAM.jl +++ b/test/gMAM.jl @@ -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 diff --git a/test/runtests.jl b/test/runtests.jl index f017560c..ba2207f0 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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 \ No newline at end of file +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