From 9cfc94dae31b500da9c37d6c1ca50f5ed50064c6 Mon Sep 17 00:00:00 2001 From: Astitva Aggarwal Date: Sun, 10 Sep 2023 20:42:47 +0530 Subject: [PATCH] tests --- test/BPINN_Tests.jl | 38 +++++++++++++++++--------------------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/test/BPINN_Tests.jl b/test/BPINN_Tests.jl index 7eee5d71ba..fb01e31401 100644 --- a/test/BPINN_Tests.jl +++ b/test/BPINN_Tests.jl @@ -108,8 +108,8 @@ sol1 = solve(prob, Tsit5(); saveat = 0.01) u = sol1.u time = sol1.t -# BPINN AND TRAINING DATASET CREATION(dataset must be defined only inside provlem timespan!) -ta = range(tspan[1], tspan[2], length = 25) +# BPINN AND TRAINING DATASET CREATION(dataset must be defined only inside problem timespan!) +ta = range(tspan[1], tspan[2], length = 100) u = [linear_analytic(u0, p, ti) for ti in ta] x̂ = collect(Float64, Array(u) + 0.2 * randn(size(u))) time = vec(collect(Float64, ta)) @@ -186,25 +186,21 @@ luxar = [chainlux1(t', θ[i], st)[1] for i in 1:500] luxmean = [mean(vcat(luxar...)[:, i]) for i in eachindex(t)] meanscurve2 = prob.u0 .+ (t .- prob.tspan[1]) .* luxmean -# --------------------- ahmc_bayesian_pinn_ode() call -@test mean(abs.(x̂ .- meanscurve1)) < 5e-2 +# --------------------- ahmc_bayesian_pinn_ode() call @test mean(abs.(physsol1 .- meanscurve1)) < 5e-2 -@test mean(abs.(x̂ .- meanscurve2)) < 5e-2 @test mean(abs.(physsol1 .- meanscurve2)) < 5e-2 # ESTIMATED ODE PARAMETERS (NN1 AND NN2) @test abs(p - mean([fhsamples2[i][23] for i in 2000:2500])) < abs(0.2 * p) @test abs(p - mean([fhsamples1[i][23] for i in 2000:2500])) < abs(0.2 * p) -#---------------------- solve() call -@test mean(abs.(x̂1 .- sol2flux.ensemblesol[1])) < 8e-2 +#-------------------------- solve() call @test mean(abs.(physsol1_1 .- sol2flux.ensemblesol[1])) < 8e-2 -@test mean(abs.(x̂1 .- sol2lux.ensemblesol[1])) < 8e-2 @test mean(abs.(physsol1_1 .- sol2lux.ensemblesol[1])) < 8e-2 # ESTIMATED ODE PARAMETERS (NN1 AND NN2) -@test abs(p - sol2flux.estimated_ode_params[1]) < abs(0.1 * p) -@test abs(p - sol2lux.estimated_ode_params[1]) < abs(0.1 * p) +@test abs(p - sol2flux.estimated_ode_params[1]) < abs(0.15 * p) +@test abs(p - sol2lux.estimated_ode_params[1]) < abs(0.15 * p) ## PROBLEM-2 linear = (u, p, t) -> u / p + exp(t / p) * cos(t) @@ -215,9 +211,9 @@ prob = ODEProblem(linear, u0, tspan, p) linear_analytic = (u0, p, t) -> exp(t / p) * (u0 + sin(t)) # SOLUTION AND CREATE DATASET -sol = solve(prob, Tsit5(); saveat = 0.05) -u = sol.u[1:100] -time = sol.t[1:100] +sol = solve(prob, Tsit5(); saveat = 0.1) +u = sol.u +time = sol.t x̂ = u .+ (u .* 0.2) .* randn(size(u)) dataset = [x̂, time] t = sol.t @@ -255,8 +251,8 @@ fh_mcmc_chainflux22, fhsamplesflux22, fhstatsflux22 = ahmc_bayesian_pinn_ode(pro priorsNNw = (0.0, 10.0), param = [ - Normal(-9, - 8), + Normal(-7, + 4), ], n_leapfrog = 30) @@ -276,8 +272,8 @@ fh_mcmc_chainlux22, fhsampleslux22, fhstatslux22 = ahmc_bayesian_pinn_ode(prob, priorsNNw = (0.0, 10.0), param = [ - Normal(-9, - 8), + Normal(-7, + 4), ], n_leapfrog = 30) @@ -291,8 +287,8 @@ alg = NeuralPDE.BNNODE(chainflux12, priorsNNw = (0.0, 10.0), param = [ - Normal(-9, - 8), + Normal(-7, + 4), ], n_leapfrog = 30) @@ -306,8 +302,8 @@ alg = NeuralPDE.BNNODE(chainlux12, priorsNNw = (0.0, 10.0), param = [ - Normal(-9, - 8), + Normal(-7, + 4), ], n_leapfrog = 30)