Hello! After having to deal with different optimization methods to solve one of my problems I became really tired of:
- FInding source code /
fpm
libraries to use them - Restructuring the code to fit the specific optimization routine
- Learning the special variables that some optimizers that don’t provide sane defaults have
During all that work (my research is not based on the optimization procedures, I just use them as a tool) I couldn’t stop thinking how nice it would be to have them all packaged in the same place, with a standard API to avoid all the extra trouble. Something like what scipy.optimize.minimize
does, an easy-to-start API but with the possibility to specify details if the user knows about how the algorithms are implemented.
That’s why I’ve started drafting ForTimize
(GitHub - fedebenelli/ForTimize). ForTimize intend to ease the usage of optimizers for the end-user. Right now it has a simple functionality like
program main
use ForTimize, only: pr, minimize
use my_objective, only: foo
real(pr) :: x(3), F
! Initial guess
x = [1, 2, 5]
! Minimize uses the Nelder-Mead algorithm as a default
call minimize(foo, x, F)
! Print results
print *, x
print *, F
end program
And it is also possible to use other algorithms just by adding the optional
type(MyOptimizer) :: optim
optim%some_setting = 24
call minimize(foo, x, F, optim=optim)
All the Optimizers must inherit from an abstract
type, that ensures that the same API will be used. The base type is defined in the core.f90
file
Right now I’ve only implemented gradient descent and Nelder-Mead, as examples of two types of algorithms (with and without derivatives). Adding new Optimizers is easy, and now with fpm
it is now possible to wrap all the other implemented algorithms and using them as dependencies
Since this is far from something I really need right now, just trying to help the FOSS Fortran community, I wanted to discuss your opinions on something like this. Any kind of code reviewing, now that the codebase is minimal and easy to follow and change, is welcomed too!