API
This section documents all functions not documented elsewhere
SemioticOpt.iteration — Functioniteration(f::Function, a::GradientDescent)One iteration of a on the function f.
This function is unexported.
iteration(f::Function, a::ProjectedGradientDescent)Apply a to f, projected based on a.t.
iteration(obj::Function, alg::PairwiseGreedyOpt)One iteration of the pairwise greedy optimization algorithm alg for objective obj.
Example
julia> using SemioticOpt
julia> using LinearAlgebra
julia> f(x, ixs, a, b) = -((a[ixs] .* x) ./ (x .+ b[ixs])) |> sum
julia> aa = Float64[1, 1, 1000, 1]
julia> bb = Float64[1, 1, 1, 1]
julia> f(x, ixs) = f(x, ixs, aa, bb)
julia> function makepgd(v)
return ProjectedGradientDescent(;
x=v,
η=1e-1,
hooks=[StopWhen((a; kws...) -> norm(SemioticOpt.x(a) - kws[:z]) < 1.0)],
t=v -> σsimplex(v, 1) # Project onto unit-simplex
)
end
julia> alg = PairwiseGreedyOpt(;
kmax=4,
x=zeros(4),
xinit=zeros(4),
f=f,
a=makepgd,
hooks=[StopWhen((a; kws...) -> kws[:f](kws[:z]) ≥ kws[:f](SemioticOpt.x(a)))]
)
julia> c = 0.1 # per non-zero cost
julia> selection = x -> f(x, 1:length(x)) + c * length(SemioticOpt.nonzeroixs(x))
julia> z = SemioticOpt.iteration(selection, alg)
4-element Vector{Float64}:
0.0
0.0
1.0
0.0SemioticOpt.f — FunctionGetter for the stop-function.
Get the function to record data
f(g::PairwiseGreedyOpt)The objective function of the inner loop.
SemioticOpt.η — Functionη(g::GradientDescent)The learning rate/step size.
SemioticOpt.hooks — Functionhooks(g::GradientDescent)The hooks used by the algorithm.
hooks(g::PairwiseGreedyOpt)The hooks used by the algorithm.
SemioticOpt.λ — FunctionGet the λ of h.
SemioticOpt.maybeminimize! — Functionmaybeminimize!(f::Function, a::OptAlgorithm, op::Function)Minimize f using a, which calls op for updating a.x.
This function may be in-place. Don't use it directly unless you know what you're doing. This function is unexported.
If you don't provide any hook with the IsStoppingCondition trait, this will loop forever.
SemioticOpt.postiteration — Functionpostiterationhook(
hs::H, a::OptAlgorithm, z::AbstractVector{T}; locals...
) where {H<:Hooks,T<:Real}Run hooks that the code should execute after SemioticOpt.iteration.
SemioticOpt.shouldstop — Functionshouldstop(hs::Hooks, a::OptAlgorithm; locals...)Map over the hooks hs to check for stopping conditions.
This performs an OR operation if there are multiple hooks that have the SemioticOpt.IsStoppingCondition trait.
SemioticOpt.x — Functionx(g::GradientDescent)
x(g::GradientDescent, v)The current best guess for the solution. If using the setter, v is the new value.
The setter is not in-place. See SemioticOpt.x!.
x(g::ProjectedGradientDescent)
x(g::ProjectedGradientDescent, v)The current best guess for the solution. If using the setter, v is the new value.
The setter is not in-place. See SemioticOpt.x!.
x(g::PairwiseGreedyOpt)
x(g::PairwiseGreedyOpt, v)The current best guess for the solution. If using the setter, v is the new value.
The setter is not in-place. See SemioticOpt.x!.
SemioticOpt.x! — FunctionSemioticOpt.x₀ — FunctionGet the anchor of h.
SemioticOpt.name — FunctionGet the name of the h.
SemioticOpt.data — FunctionGet the data of the h.