JuliaAPlavin / AccessibleOptimization.jl

MIT License
3 stars 0 forks source link

Clarification of example #2

Closed aplavin closed 7 months ago

aplavin commented 1 year ago

In GitLab by @alecloudenback on Jun 23, 2023, 24:00

Can the following example be explained a bit more? I am experimenting with an optimization problem that seems to work best when there's an inner optimization step for a subset of parameters before optimizing the remaining parameters, and was intrigued by the description. Unfortunately, I've hit a bit of a wall understanding the example and how I might adapt it to my problem. I think this is really a question about understanding the AccessorsExtras code PartsOf, onset, etc. Also, what does it mean "constrain the order"?

Constrain the order, so that the largest component (by scale) is always the last:

@p let
    OptArgs(
        @optic(_.comps[∗].scale |> PartsOf() |> onset(sort∘SVector) |> Elements()) => 0..10.,
        @optic(_.comps[∗].shift) => 0..10.,
    )
    solmod_from_vars()
    plot_datamod(data, __), __
end
aplavin commented 1 year ago

This particular example is the most involved, that's why it is put the last (: Please see the updated notebook: now it includes a flowchart, and documentation is somewhat more structured.

AccessorsExtra is indeed not well-documented for now, and these modifiers (onset, PartsOf) can be challenging to grasp without prior experience with optics elsewhere. Briefly:

julia> setall(obj, (@o _.a |> onset(Tuple∘sort∘SVector) |> Elements()), (5, 10, 1)) (a = (1, 5, 10),)


`SVector` is only needed here because tuples cannot be `sort`ed in Julia.