NamedArrays vs NamedTuples vs Dict in objective function to optimization

I am optimizing a function that takes a vector of size ~300 as input. That objective function calls several other functions that each use a subset of the input vector. An example of that setup is below:

function mainprog(θ)
    α = θ[1:20]
    β = θ[21:35]
    ...
    fun1(α)
    fun2(β)
    ...
    return X
end

I do not want to have the α and β hardcoded like in the example above because of elegance, maintenance, and sanity reasons. I much rather prefer to have them as NamedArrays, NamedTuples, or Dict. What’s a good way of defining those subvectors α and β?

I’m worried about performance, and the only constraint that I have is that I’d like to be able to use Optim to optimize over θ without too much trouble. Does anyone have any suggestions on how to go about that?

I think there a package for exactly this.
But the name is escaping me.

Its not NamedArrays or LabelledArrays or RecursiveArrayTools (though the lasst two are closer)

Could it be AxisArrays?

no what we are talking about is having a slice of an array labelled,
not an axis (AxisArrays/NamedDims).

You might be looking for https://github.com/jonniedie/ComponentArrays.jl, announced here.

4 Likes

Yes, this might be it.

That’s the one, i was thinking of.
(I’ve not use it, but sounds like the tool for the job)

1 Like