You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Could you correct the documentation of the TreeGP constructor? The keyword "optimizer" is not working.
Thanks in advance and keep doing the good work on the library!
The text was updated successfully, but these errors were encountered:
froucoux
changed the title
Symbolic Regression examples not working in version
Symbolic Regression examples not working in version 0.11.1
Feb 20, 2022
froucoux
changed the title
Symbolic Regression examples not working in version 0.11.1
Symbolic regression examples not working in version 0.11.1
Feb 20, 2022
I have the same problem. This is the relevant commit e05171f. There is no comment, so it is hard to guess the goal and how to specify any parameter of the GA(). Moreover, it seems that both GA and TreeGP use the same crossover and mutate functions, see gp.jl#L126C1-L135C4..
Later, there is 640c1ea modifying the doc string (it is not included in the last release yet, install with ]add Evulutionary#master). Maybe, an author of it (@agctute, @DilumAluthge, @timholy , @shindig7 , @Nagefire) could update the example so it shows the new intended way to pass the parameters to GA .
None of the examples provided in the Jupyter notebook entitled "Symbolic Regression with Genetic Programming" seem to work.
I used the last available version (0.11.1) of the package and tested it with Julia 1.7.2 and 1.6.5 LTS under Windows and Linux.
In the following example (the first one) :
`
using Evolutionary
using Random
using Plots
Plots.gr()
default(fmt = :png)
Random.seed!(42);
d, n = 1, 20
Nguyen1(x) = x * x * x + x * x + x
xs = sort!(2 * rand(n) .- 1)
syms = [:x]
funcs = Function[+, -, *, /]
fitobj(expr) = sum(abs2.(Nguyen1.(xs) - Evolutionary.Expression(expr).(xs))) / length(xs) |> sqrt
Random.seed!(987498737423);
res = Evolutionary.optimize(fitobj,
TreeGP(50, Terminal[syms...], funcs,
mindepth = 1,
maxdepth = 4,
optimizer = GA(
selection = uniformranking(5),
ɛ = 0.1,
mutationRate = 0.95,
crossoverRate = 0.05,
),
)
)
`
It returns :
ERROR: LoadError: MethodError: no method matching TreeGP(; populationSize=50, terminals=Dict(:x => 1), functions=Dict{Function, Int64}((-) => 2, (/) => 2, (*) => 2, (+) => 2), mindepth=1, maxdepth=4, optimizer=GA[P=50,x=0.05,μ=0.95,ɛ=0.1]) Closest candidates are: TreeGP(; populationSize, terminals, functions, mindepth, maxdepth, crossover, mutation, selection, crossoverRate, mutationRate, initialization, simplify, metrics) at /usr/local/julia/share/julia/base/util.jl:478 got unsupported keyword argument "optimizer" TreeGP(::Integer, ::Vector{Union{Function, Real, Symbol}}, ::Vector{Function}; kwargs...) at ~/.julia/packages/Evolutionary/65hL6/src/gp.jl:40 TreeGP(::Integer, ::Dict{Union{Function, Real, Symbol}, Int64}, ::Dict{Function, Int64}, ::Int64, ::Int64, ::Function, ::Function, ::Function, ::Real, ::Real, ::Symbol, ::Union{Nothing, Function}, ::Vector{ConvergenceMetric}) at ~/.julia/packages/Evolutionary/65hL6/src/gp.jl:26 got unsupported keyword arguments "populationSize", "terminals", "functions", "mindepth", "maxdepth", "optimizer" ... Stacktrace: [1] kwerr(kw::NamedTuple{(:populationSize, :terminals, :functions, :mindepth, :maxdepth, :optimizer), Tuple{Int64, Dict{Symbol, Int64}, Dict{Function, Int64}, Int64, Int64, GA{Evolutionary.var"#uniformrank#252"{Evolutionary.var"#uniformrank#251#253"{Int64}}, typeof(Evolutionary.genop), typeof(Evolutionary.genop)}}}, args::Type) @ Base ./error.jl:163 [2] TreeGP(pop::Int64, term::Vector{Union{Function, Real, Symbol}}, func::Vector{Function}; kwargs::Base.Pairs{Symbol, Any, Tuple{Symbol, Symbol, Symbol}, NamedTuple{(:mindepth, :maxdepth, :optimizer), Tuple{Int64, Int64, GA{Evolutionary.var"#uniformrank#252"{Evolutionary.var"#uniformrank#251#253"{Int64}}, typeof(Evolutionary.genop), typeof(Evolutionary.genop)}}}}) @ Evolutionary ~/.julia/packages/Evolutionary/65hL6/src/gp.jl:43 [3] top-level scope @ /home/julia/projects/first_project/benchmark.jl:19 in expression starting at /home/julia/projects/first_project/benchmark.jl:19
The correct code seems to be :
`
using Evolutionary
using Random
using Plots
Plots.gr()
default(fmt = :png)
Random.seed!(42);
d, n = 1, 20
Nguyen1(x) = x * x * x + x * x + x
xs = sort!(2 * rand(n) .- 1)
syms = [:x]
funcs = Function[+, -, *, /]
fitobj(expr) = sum(abs2.(Nguyen1.(xs) - Evolutionary.Expression(expr).(xs))) / length(xs) |> sqrt
Random.seed!(987498737423);
res = Evolutionary.optimize(fitobj,
TreeGP(50, Terminal[syms...], funcs,
mindepth = 1,
maxdepth = 4,
selection = uniformranking(5),
mutationRate = 0.95,
crossoverRate = 0.05
)
)
`
Questions:
Thanks in advance and keep doing the good work on the library!
The text was updated successfully, but these errors were encountered: