Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AstitvaAggarwal committed Sep 10, 2023
1 parent a9a4c1b commit 9cfc94d
Showing 1 changed file with 17 additions and 21 deletions.
38 changes: 17 additions & 21 deletions test/BPINN_Tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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]
= collect(Float64, Array(u) + 0.2 * randn(size(u)))
time = vec(collect(Float64, ta))
Expand Down Expand Up @@ -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)
Expand All @@ -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
= u .+ (u .* 0.2) .* randn(size(u))
dataset = [x̂, time]
t = sol.t
Expand Down Expand Up @@ -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)

Expand All @@ -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)

Expand All @@ -291,8 +287,8 @@ alg = NeuralPDE.BNNODE(chainflux12,
priorsNNw = (0.0,
10.0),
param = [
Normal(-9,
8),
Normal(-7,
4),
],
n_leapfrog = 30)

Expand All @@ -306,8 +302,8 @@ alg = NeuralPDE.BNNODE(chainlux12,
priorsNNw = (0.0,
10.0),
param = [
Normal(-9,
8),
Normal(-7,
4),
],
n_leapfrog = 30)

Expand Down

0 comments on commit 9cfc94d

Please sign in to comment.