Closed aplavin closed 7 months 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:
Elements()
(from Accessors
itself) or its shortcut ∗
turn an optic that references a single collection to an optic referencing each element of that collection.
julia> obj = (a=(1, 2, 3),)
# without Elements():
julia> getall(obj, @o _.a)
((1, 2, 3),)
# with Elements()
julia> getall(obj, @o _.a[∗])
(1, 2, 3)
PartsOf()
does the opposite, undoing Elements()
:
julia> getall(obj, @o _.a[∗] |> PartsOf())
((1, 2, 3),)
By itself, it doesn't seem very useful.
onset(f)
replaces x
with f(x)
when set(...)
/setall(...)
is called. See the new flowchart to understand how it's relevant for AccessibleOptimization
.
julia> setall(obj, (@o _.a[∗]), (5, 10, 1))
(a = (5, 10, 1),)
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.
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"?