diff --git a/Project.toml b/Project.toml index 99dc717..ee7e8a0 100644 --- a/Project.toml +++ b/Project.toml @@ -1,20 +1,23 @@ name = "AccessibleOptimization" uuid = "d88a00a0-4a21-4fe4-a515-e2123c37b885" authors = ["Alexander Plavin "] -version = "0.1.2" +version = "0.1.3" [deps] AccessorsExtra = "33016aad-b69d-45be-9359-82a41f556fd4" ConstructionBase = "187b0558-2788-49d3-abe0-74a17ed4e7c9" DataPipes = "02685ad9-2d12-40c3-9f73-c6aeda6a7ff5" +FlexiMaps = "6394faf6-06db-4fa8-b750-35ccc60383f7" Optimization = "7f7a1694-90dd-40f0-9382-eb1efda571ba" Reexport = "189a3867-3050-52da-a836-e630ba90ab69" Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" [compat] -AccessorsExtra = "0.1.43" +AccessorsExtra = "0.1.89" ConstructionBase = "1.5.1" DataPipes = "0.3.5" +FlexiMaps = "0.1.27" Optimization = "3,4" Reexport = "1.2.2" +Statistics = "1" julia = "1.6" diff --git a/src/AccessibleOptimization.jl b/src/AccessibleOptimization.jl index 3cbbd14..70a580d 100644 --- a/src/AccessibleOptimization.jl +++ b/src/AccessibleOptimization.jl @@ -4,6 +4,7 @@ using Reexport @reexport using Optimization @reexport using AccessorsExtra using DataPipes +using FlexiMaps using ConstructionBase using Statistics: mean @@ -29,31 +30,20 @@ _intbound(o) = nothing optic(v::OptArgs) = AccessorsExtra.ConcatOptics(map(_optic, v.specs)) rawu(x0, v::OptArgs) = getall(x0, optic(v)) -fromrawu(u, x0, v::OptArgs) = setall(x0, optic(v), u) +rawu(x0::Type, v::OptArgs) = @p v.specs |> map(_intbound) |> map(mean) + +fromrawu(u, x0, v::OptArgs) = AccessorsExtra.setall_or_construct(x0, optic(v), u) + rawfunc(f, x0, v::OptArgs) = (u, p) -> f(fromrawu(u, x0, v), p) -rawbounds(x0, v::OptArgs, AT=nothing) = - if @p v.specs |> any(isnothing(_intbound(_))) - @assert @p v.specs |> all(isnothing(_intbound(_))) - return () - else - @p let - v.specs - map(fill(_intbound(_), length(getall(x0, _optic(_))))) - reduce(vcat) - (lb=_convert(AT, minimum.(__)), ub=_convert(AT, maximum.(__))) - end - end -rawu(x0::Type, v::OptArgs) = @p v.specs |> map(_intbound) |> map(mean) -fromrawu(u, x0::Type, v::OptArgs) = @p map(_optic(_1) => _2, v.specs, u) |> construct(x0, __...) -rawbounds(x0::Type, v::OptArgs, AT=nothing) = +rawbounds(x0, v::OptArgs, AT=nothing) = if @p v.specs |> any(isnothing(_intbound(_))) @assert @p v.specs |> all(isnothing(_intbound(_))) return () else @p let v.specs - map(_intbound(_)) + flatmap(fill(_intbound(_), AccessorsExtra.nvals_optic(x0, _optic(_)))) (lb=_convert(AT, minimum.(__)), ub=_convert(AT, maximum.(__))) end end