Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use of default_options in fminbox.jl? #1028

Open
Yuan-Ru-Lin opened this issue Feb 6, 2023 · 0 comments
Open

Use of default_options in fminbox.jl? #1028

Yuan-Ru-Lin opened this issue Feb 6, 2023 · 0 comments

Comments

@Yuan-Ru-Lin
Copy link

For unconstrained optimizer, there is a function default_options that can be extended to set default options of one's interests.

default_options(method::AbstractOptimizer) = NamedTuple()
function add_default_opts!(opts::Dict{Symbol, Any}, method::AbstractOptimizer)
for newopt in default_options(method)
if !haskey(opts, newopt[1])
opts[newopt[1]] = newopt[2]
end
end
end

An example is as follows.

import Optim: default_options
using Optim: BFGS
default_options(::BFGS) = (; extended_trace=true, callback=miunitstop)

The reason this is possible is because there are relevant handling in the most generic function:

function optimize(f, initial_x::AbstractArray; inplace = true, autodiff = :finite, kwargs...)
method = fallback_method(f)
checked_kwargs, method = check_kwargs(kwargs, method)
d = promote_objtype(method, initial_x, autodiff, inplace, f)
add_default_opts!(checked_kwargs, method)
options = Options(; checked_kwargs...)
optimize(d, initial_x, method, options)
end

However, this is not true in the case of optimize that takes Fminbox as an argument:

function optimize(f,
l::AbstractArray,
u::AbstractArray,
initial_x::AbstractArray,
F::Fminbox = Fminbox(),
options::Options = Options(); inplace = true, autodiff = :finite)
if f isa NonDifferentiable
f = f.f
end
od = OnceDifferentiable(f, initial_x, zero(eltype(initial_x)); autodiff = autodiff)
optimize(od, l, u, initial_x, F, options)
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant