Working with Multiple Vectors of Parameters

I’m working with the SciML Optimization framework trying to optimize several Vectors of parameters with ReverseDiff.jl. I understand the Vector that’s passed to my objective function is flattened, so I’m also passing the indices of each Vector to my objective function. One additional hiccup is that the number of Vectors isn’t fixed and can vary based depending on user config, and so setting up the initial params and indices Vectors is tedious.

I looked at ParameterHandling.jl but it doesn’t work with ReverseDiff. Is there a better approach than mine?

Simple example:

initial_params = (;x=[1.0, 2.0, 3.0], y=[4.0, 4.5, 10.0], z=[1.0, 1.0, 1.0])

Convert to be compatible with the OptimizationProblem:

initial_params_vec = [1.0, 2.0, 3.0, 4.0, 4.5, 10.0, 1.0, 1.0, 1.0]
indices = (;x=1:3, y=4:6, z=7:9) # this gets passed to the objective.

Have you tried ComponentArrays.jl?

Wow thanks! ComponentArrays.jl works perfectly!

1 Like