Skip to content

Commit

Permalink
improved Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AstitvaAggarwal committed Aug 12, 2023
1 parent d467250 commit f2e502a
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions test/BPINN_Tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ luxar = [chainlux(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

@test mean(abs2.(x̂ .- meanscurve1)) < 5e-4
@test mean(abs2.(physsol1 .- meanscurve1)) < 1e-5
@test mean(abs2.(x̂ .- meanscurve2)) < 5e-4
@test mean(abs2.(physsol1 .- meanscurve2)) < 1e-5
@test mean(abs.(x̂ .- meanscurve1)) < 0.05
@test mean(abs.(physsol1 .- meanscurve1)) < 0.005
@test mean(abs.(x̂ .- meanscurve2)) < 0.05
@test mean(abs.(physsol1 .- meanscurve2)) < 0.005

println("now parameter estimation problem 1")
## PROBLEM-1 (WITH PARAMETER ESTIMATION)
Expand Down Expand Up @@ -137,14 +137,14 @@ 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

@test mean(abs2.(x̂ .- meanscurve1)) < 5e-4
@test mean(abs2.(physsol1 .- meanscurve1)) < 5e-5
@test mean(abs2.(x̂ .- meanscurve2)) < 5e-4
@test mean(abs2.(physsol1 .- meanscurve2)) < 5e-5
@test mean(abs.(x̂ .- meanscurve1)) < 5e-2
@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])) < 0.05
@test abs(p - mean([fhsamples1[i][23] for i in 2000:2500])) < 0.05
@test abs(p - mean([fhsamples2[i][23] for i in 2000:2500])) < 0.5
@test abs(p - mean([fhsamples1[i][23] for i in 2000:2500])) < 0.5

## PROBLEM-2
linear = (u, p, t) -> -u / p[1] + exp(t / p[2]) * cos(t)
Expand Down Expand Up @@ -237,42 +237,42 @@ yu = [out[i](t') for i in eachindex(out)]
fluxmean = [mean(vcat(yu...)[:, i]) for i in eachindex(t)]
meanscurve1_1 = prob.u0 .+ (t .- prob.tspan[1]) .* fluxmean

@test mean(abs2.(sol.u .- meanscurve1_1)) < 1e-4
@test mean(abs2.(physsol1 .- meanscurve1_1)) < 1e-4
@test mean(abs.(sol.u .- meanscurve1_1)) < 1e-2
@test mean(abs.(physsol1 .- meanscurve1_1)) < 1e-2

out = re1.([fhsamplesflux22[i][1:61] for i in 1000:1500])
yu = [out[i](t') for i in eachindex(out)]
fluxmean = [mean(vcat(yu...)[:, i]) for i in eachindex(t)]
meanscurve1_2 = prob.u0 .+ (t .- prob.tspan[1]) .* fluxmean

@test mean(abs2.(sol.u .- meanscurve1_2)) < 5e-3
@test mean(abs2.(physsol1 .- meanscurve1_2)) < 5e-3
@test mean(abs.(sol.u .- meanscurve1_2)) < 5e-2
@test mean(abs.(physsol1 .- meanscurve1_2)) < 5e-2

# estimated parameters(flux chain)
param1 = mean(i[62] for i in fhsamplesflux22[1000:1500])
param2 = mean(i[63] for i in fhsamplesflux22[1000:1500])
@test abs(param1 - p[1]) < abs(0.2 * p[1])
@test abs(param2 - p[2]) < abs(0.2 * p[2])
@test abs(param1 - p[1]) < abs(0.3 * p[1])
@test abs(param2 - p[2]) < abs(0.3 * p[2])

# Mean of last 500 sampled parameter's curves(lux chains)[Ensemble predictions]
θ = [vector_to_parameters(fhsampleslux12[i], θinit) for i in 1000:1500]
luxar = [chainlux12(t', θ[i], st)[1] for i in 1:500]
luxmean = [mean(vcat(luxar...)[:, i]) for i in eachindex(t)]
meanscurve2_1 = prob.u0 .+ (t .- prob.tspan[1]) .* luxmean

@test mean(abs2.(sol.u .- meanscurve2_1)) < 2e-4
@test mean(abs2.(physsol1 .- meanscurve2_1)) < 2e-4
@test mean(abs.(sol.u .- meanscurve2_1)) < 1e-2
@test mean(abs.(physsol1 .- meanscurve2_1)) < 1e-2

θ = [vector_to_parameters(fhsampleslux22[i][1:(end - 2)], θinit) for i in 1000:1500]
luxar = [chainlux12(t', θ[i], st)[1] for i in 1:500]
luxmean = [mean(vcat(luxar...)[:, i]) for i in eachindex(t)]
meanscurve2_2 = prob.u0 .+ (t .- prob.tspan[1]) .* luxmean

@test mean(abs2.(sol.u .- meanscurve2_2)) < 2e-2
@test mean(abs2.(physsol1 .- meanscurve2_2)) < 2e-2
@test mean(abs.(sol.u .- meanscurve2_2)) < 5e-2
@test mean(abs.(physsol1 .- meanscurve2_2)) < 5e-2

# estimated parameters(lux chain)
param1 = mean(i[62] for i in fhsampleslux22[1000:1500])
param2 = mean(i[63] for i in fhsampleslux22[1000:1500])
@test abs(param1 - p[1]) < abs(0.35 * p[1])
@test abs(param2 - p[2]) < abs(0.35 * p[2])
@test abs(param1 - p[1]) < abs(0.3 * p[1])
@test abs(param2 - p[2]) < abs(0.3 * p[2])

0 comments on commit f2e502a

Please sign in to comment.