Skip to content
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

Is there currently a feasible way to use NamedTuple or ComponentArray as x0 for Optimization.jl #736

Open
chooron opened this issue Apr 15, 2024 · 1 comment
Labels
question Further information is requested

Comments

@chooron
Copy link

chooron commented Apr 15, 2024

Question❓

The parameters given in the problem I need to optimize are of type namedtuple, for example: (model_1=(a=1.0, b=2.0), model_2=(a=2.0,b=3.0),

The parameters given in the problem I need to optimize are of type namedtuple, for example. But from the tutorial, x0, lb and ub are all Vector types. When I use namedtuple as x0, lb, ub, the code does not work:

using Optimization

rosenbrock(x, p) = (p[1] - x[:a])^2 + p[2] * (x[:b] - x[:a]^2)^2
x0 = (a=0.0, b=0.0)
p = [1.0, 100.0]

using OptimizationBBO
prob = OptimizationProblem(rosenbrock, x0, p, lb=(a=-1.0, b=-1.0), ub=(a=1.0, b=1.0))
sol = solve(prob, BBO_adaptive_de_rand_1_bin_radiuslimited())

Also I tried ComponentArray but it still doesn't seem to work:

using Optimization
using ComponentArrays

rosenbrock(x, p) = (p[1] - x[:a])^2 + p[2] * (x[:b] - x[:a]^2)^2
x0 = ComponentVector(a=0.0, b=0.0)
p = [1.0, 100.0]

using OptimizationBBO
prob = OptimizationProblem(rosenbrock, x0, p, lb=ComponentVector(a=-1.0, b=-1.0), ub=ComponentVector(a=1.0, b=1.0))
sol = solve(prob, BBO_adaptive_de_rand_1_bin_radiuslimited())
@chooron chooron added the question Further information is requested label Apr 15, 2024
@ChrisRackauckas
Copy link
Member

Yes, it works depending on the solver. The issue is that the solver you chose only allows vectors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants