Skip to content

Commit df751be

Browse files
Make NNODE tstops comparison reproducible (#1093)
Use identical initialization and random streams for the with- and without-tstops solves, restore the original sparse baseline budget, and assert that added points improve accuracy. Co-authored-by: ChrisRackauckas-Claude <accounts@chrisrackauckas.com>
1 parent d17789b commit df751be

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

test/NNODE/nnode__training_strategy_with_tstops.jl

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ using Test
2727
Dense(1 => N, σ), Dense(N => N, σ), Dense(N => N, σ), Dense(N => N, σ),
2828
Dense(N => length(u0))
2929
)
30+
init_params, _ = Lux.setup(Xoshiro(100), chain)
3031

3132
threshold = 0.2
3233

@@ -35,19 +36,25 @@ using Test
3536
WeightedIntervalTraining([0.3, 0.3, 0.4], 3),
3637
StochasticTraining(3),
3738
]
38-
alg = NNODE(chain, Adam(0.01); strategy, tstops = addedPoints)
39+
Random.seed!(100)
40+
alg = NNODE(chain, Adam(0.01), deepcopy(init_params); strategy)
41+
sol = solve(prob_oop, alg; verbose = false, maxiters = 1000, saveat)
42+
error_without_points = abs(mean(sol) - mean(true_sol))
43+
44+
Random.seed!(100)
45+
alg = NNODE(chain, Adam(0.01), deepcopy(init_params); strategy)
46+
sol = solve(
47+
prob_oop, alg; verbose = false,
48+
maxiters = 10000, saveat, tstops = addedPoints
49+
)
50+
error_with_points = abs(mean(sol) - mean(true_sol))
3951

4052
@testset "Without added points" begin
41-
sol = solve(prob_oop, alg; verbose = false, maxiters = 10000, saveat)
42-
@test abs(mean(sol) - mean(true_sol)) threshold
53+
@test error_without_points threshold
4354
end
4455

4556
@testset "With added points" begin
46-
sol = solve(
47-
prob_oop, alg; verbose = false,
48-
maxiters = 10000, saveat, tstops = addedPoints
49-
)
50-
@test abs(mean(sol) - mean(true_sol)) < threshold
57+
@test error_with_points < threshold
5158
end
5259
end
5360
end

0 commit comments

Comments
 (0)