Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AstitvaAggarwal committed Nov 3, 2024
1 parent bed9d3b commit 8ff8f10
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
17 changes: 9 additions & 8 deletions test/BPINN_PDE_tests.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@testitem "BPINN PDE I: 2D Periodic System" tags=[:pdebpinn] begin
@testitem "BPINN PDE I: 1D Periodic System" tags=[:pdebpinn] begin
using MCMCChains, Lux, ModelingToolkit, Distributions, OrdinaryDiffEq,
AdvancedHMC, Statistics, Random, Functors, NeuralPDE, MonteCarloMeasurements,
ComponentArrays
Expand All @@ -21,16 +21,16 @@
discretization = BayesianPINN([chainl], GridTraining([0.01]))

sol1 = ahmc_bayesian_pinn_pde(
pde_system, discretization; draw_samples = 1500, bcstd = [0.02],
pde_system, discretization; draw_samples = 1500, bcstd = [0.01],
phystd = [0.01], priorsNNw = (0.0, 1.0), saveats = [1 / 50.0])

analytic_sol_func(u0, t) = u0 + sinpi(2t) / (2pi)
ts = vec(sol1.timepoints[1])
u_real = [analytic_sol_func(0.0, t) for t in ts]
u_predict = pmean(sol1.ensemblesol[1])

@test u_predictu_real atol=0.5
@test mean(u_predict .- u_real) < 0.1
# absol tests
@test mean(abs, u_predict .- u_real) < 5e-2
end

@testitem "BPINN PDE II: 1D ODE" tags=[:pdebpinn] begin
Expand Down Expand Up @@ -240,7 +240,7 @@ end
bcs = [u(0) ~ 0.0]
domains = [t Interval(0.0, 2.0)]

chainl = Lux.Chain(Lux.Dense(1, 6, tanh), Lux.Dense(6, 1))
chainl = Lux.Chain(Lux.Dense(1, 6, tanh), Lux.Dense(6, 6, tanh), Lux.Dense(6, 1))
initl, st = Lux.setup(Random.default_rng(), chainl)

@named pde_system = PDESystem(eqs,
Expand Down Expand Up @@ -269,8 +269,8 @@ end
sol1 = ahmc_bayesian_pinn_pde(pde_system,
discretization;
draw_samples = 1500,
bcstd = [0.01],
phystd = [0.01], l2std = [0.02],
bcstd = [0.02],
phystd = [0.02], l2std = [0.02],
priorsNNw = (0.0, 1.0),
saveats = [1 / 50.0],
param = [LogNormal(6.0, 0.5)])
Expand Down Expand Up @@ -479,7 +479,7 @@ end
sol_new = ahmc_bayesian_pinn_pde(pde_system,
discretization;
draw_samples = 150,
bcstd = [0.1, 0.1, 0.1, 0.1, 0.1], phynewstd = [0.4],
bcstd = [0.1, 0.1, 0.1, 0.1, 0.1], phynewstd = [0.5],
phystd = [0.2], l2std = [0.5], param = [Distributions.Normal(2.0, 2)],
priorsNNw = (0.0, 1.0),
saveats = [1 / 100.0, 1 / 100.0],
Expand Down Expand Up @@ -524,5 +524,6 @@ end
param_old = sol_old.estimated_de_params[1]
α = 1
@test abs(param_new - α) < 0.2 * α
unsafe_comparisons(true)
@test abs(param_new - α) < abs(param_old - α)
end
6 changes: 3 additions & 3 deletions test/BPINN_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,10 @@ end

fh_mcmc_chainlux22, fhsampleslux22, fhstatslux22 = ahmc_bayesian_pinn_ode(
prob, chainlux12, dataset = dataset, draw_samples = 500, l2std = [0.05],
phystd = [0.01], priorsNNw = (0.0, 10.0), param = [Normal(-7, 4)])
phystd = [0.05], priorsNNw = (0.0, 10.0), param = [Normal(-7, 4)])

alg = BNNODE(chainlux12, dataset = dataset, draw_samples = 500, l2std = [0.05],
phystd = [0.01], priorsNNw = (0.0, 10.0), param = [Normal(-7, 4)])
phystd = [0.05], priorsNNw = (0.0, 10.0), param = [Normal(-7, 4)])

sol3lux_pestim = solve(prob, alg)

Expand All @@ -183,7 +183,7 @@ end
@test mean(abs, physsol1 .- meanscurve2_2) < 1e-1

# estimated parameters(lux chain)
param1 = mean(i[62] for i in fhsampleslux22[500:length(fhsampleslux22)])
param1 = mean(i[62] for i in fhsampleslux22[400:length(fhsampleslux22)])
@test abs(param1 - p) < abs(0.5 * p)
end

Expand Down

0 comments on commit 8ff8f10

Please sign in to comment.