Skip to content

Commit

Permalink
relax test tolerance
Browse files Browse the repository at this point in the history
  • Loading branch information
wildart committed Mar 19, 2022
1 parent 96bf096 commit cf3f2fb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
32 changes: 16 additions & 16 deletions test/gp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,23 @@
@test popexp[1] == :(x + 1)

# recursive helper functions
h = 4
gtr = TreeGP(pop, terms, funcs, maxdepth=2, initialization=:grow)
Random.seed!(rng, 1)
tmp = rand(rng, gtr, 3)
Random.seed!(rng, 1)
gt = rand(rng, gtr, 3)
Random.seed!(rng, 8237463746)
tmp = rand(rng, gtr, h)
Random.seed!(rng, 8237463746)
gt = rand(rng, gtr, h)
@test tmp == gt
@test Evolutionary.nodes(gt) < 15
@test Evolutionary.height(gt) <= 3
@test length(gt) < 15
ft = rand(rng, TreeGP(pop, terms, funcs, maxdepth=2, initialization=:full), 3)
@test Evolutionary.nodes(ft) == 15
@test Evolutionary.height(ft) == 3
@test length(ft) == 15
@test Evolutionary.depth(ft, :x) == 3
@test Evolutionary.nodes(gt) < 2^(h+1)-1
@test Evolutionary.height(gt) <= h
@test length(gt) < 2^(h+1)-1
ft = rand(rng, TreeGP(pop, terms, funcs, maxdepth=2, initialization=:full), h)
@test Evolutionary.nodes(ft) == 2^(h+1)-1
@test Evolutionary.height(ft) == h
@test length(ft) == 2^(h+1)-1
@test Evolutionary.depth(ft, :x) == 4
ft[3] = :z
@test Evolutionary.depth(ft, :z) == 3
@test Evolutionary.depth(ft, :z) == 4
@test Evolutionary.depth(ft, ft) == 0
@test Evolutionary.depth(ft, ft[3]) > 0
@test Evolutionary.depth(ft, :w) == -1
Expand Down Expand Up @@ -116,22 +117,21 @@
ys = fitfun.(rg)
function fitobj(expr)
ex = Evolutionary.Expression(expr)
#ex = Evolutionary.Expression(expr, Dict(:x=>1))
yy = ex.(rg)
sum(v->isnan(v) ? 1.0 : v, abs2.(ys .- yy) )/length(rg)
end

Random.seed!(rng, 42)
res = Evolutionary.optimize(fitobj,
TreeGP(25, Terminal[:x, randn], Function[+,-,*,Evolutionary.aq],
TreeGP(50, Terminal[:x, randn], Function[+,-,*,Evolutionary.aq],
mindepth=1,
maxdepth=3,
simplify = Evolutionary.simplify!,
selection = tournament(3),
),
Evolutionary.Options(show_trace=false, rng=rng, iterations=50)
)
@test minimum(res) < 1.1
@test minimum(res) < 1.5

end

4 changes: 2 additions & 2 deletions test/mutations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,13 @@
end

# subtree mutation does not produce offspring expression longer then the parent
mut = subtree(tr; growth=0.5)
mut = subtree(tr; growth=0.3)
Random.seed!(rng, 2)
off = [mut(copy(ex), rng=rng) for i in 1:10]
@testset "Offspring Height (Growth)" for i in 1:5
map(o->mut(o,rng=rng), off) # mutate offspring
h = map(Evolutionary.height, off)
@test all(h .<= 3+i)
@test all(h .<= 3i)
end

# hoist
Expand Down

0 comments on commit cf3f2fb

Please sign in to comment.