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

Set default options and settings for Optim.optimize() #7

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

Set default options and settings for Optim.optimize() #7

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

Comments

@Yuan-Ru-Lin
Copy link
Owner

Right now one has to type the following to perform fitting.

optimize(x -> -loglikelihood(model(x), data), x0, BFGS(), Optim.Options(extended_trace=true, callback=miunitstop))
While defining the function and giving x0 may be necessary and would be better stated explicitly, the method BFGS() and the options are not, as they should be the same unless there is a really good reason).

It is possible to wrap the call but I still want to keep it as explicit as possible. A variable for configuration would make things easier such as the PLOTS_DEFAULTS in the case of Plots.jl.

@Yuan-Ru-Lin
Copy link
Owner Author

Something like

mydefault(; additionals...)::Optim.Options = Optim.Options(extended_trace=true, callback=miunitstop; additionals...)

should work. This way, the call would become

optimize(x -> -loglikelihood(model(x), data), x0, BFGS(), mydefault())

while keeping flexibility to pass keyword arguments to control the options.

@Yuan-Ru-Lin
Copy link
Owner Author

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

This will set the default options for BFGS().

However, there is no such mechanism for Fminbox(BFGS()).

See also

https://github.com/JuliaNLSolvers/Optim.jl/blob/1f1258c8499b57c6a551ef94057604bd58f1aa31/src/multivariate/solvers/constrained/fminbox.jl#L272-L278

@Yuan-Ru-Lin
Copy link
Owner Author

I overrode optimize:

function MiunitOptions(; additionals...)::Optim.Options
    Optim.Options(extended_trace=true, callback=miunitstop; additionals...)
end

import Optim: optimize
function optimize(f,
                  l::AbstractArray,
                  u::AbstractArray,
                  initial_x::AbstractArray,
                  F::T) where {T <: Fminbox}
    optimize(f, l, u, initial_x, F, MiunitOptions())
end

I've opened an issue at Optim (JuliaNLSolvers/Optim.jl#1028). If this gets resolved, this can be replaced with something like default_options(::BFGS) = ...

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