Optimization.jl
Optimization.jl copied to clipboard
Is there currently a feasible way to use NamedTuple or ComponentArray as x0 for Optimization.jl
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())