# Working with Multiple Vectors of Parameters

**URL:** <https://discourse.julialang.org/t/working-with-multiple-vectors-of-parameters/98685>\
**Category:** Optimization (Mathematical)\
**Tags:** question, package\
**Created:** [May 11, 2023, 3:10pm UTC](https://discourse.julialang.org/t/working-with-multiple-vectors-of-parameters/98685 "2023-05-11T15:10:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![astrobc1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/astrobc1/32/45632_2.png) [@astrobc1](https://discourse.julialang.org/u/astrobc1)\
**Post date:** [May 11, 2023, 3:10pm UTC](https://discourse.julialang.org/t/working-with-multiple-vectors-of-parameters/98685/1 "2023-05-11T15:10:22Z")

</div>

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:

```julia
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`:

```julia
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.

```

---

<div class="post-metadata">

**Author:** ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/27854_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Post date:** [May 11, 2023, 5:40pm UTC](https://discourse.julialang.org/t/working-with-multiple-vectors-of-parameters/98685/2 "2023-05-11T17:40:05Z")

</div>

Have you tried ComponentArrays.jl?

> **[GitHub - jonniedie/ComponentArrays.jl: Arrays with arbitrarily nested named...](https://github.com/jonniedie/ComponentArrays.jl)**
>
> Arrays with arbitrarily nested named components. Contribute to jonniedie/ComponentArrays.jl development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![astrobc1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/astrobc1/32/45632_2.png) [@astrobc1](https://discourse.julialang.org/u/astrobc1)\
**Post date:** [May 11, 2023, 8:37pm UTC](https://discourse.julialang.org/t/working-with-multiple-vectors-of-parameters/98685/3 "2023-05-11T20:37:33Z")

</div>

Wow thanks! ComponentArrays.jl works perfectly!
