-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Symbolic regression examples not working in version 0.11.1 #95
Comments
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 Later, there is 640c1ea modifying the doc string (it is not included in the last release yet, install with |
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: