Skip to content

Commit

Permalink
doc
Browse files Browse the repository at this point in the history
  • Loading branch information
fedebenelli committed Sep 30, 2024
1 parent 15dcc7e commit 3431b65
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 8 deletions.
25 changes: 25 additions & 0 deletions src/ForTimize.f90
Original file line number Diff line number Diff line change
@@ -1,4 +1,29 @@
module ForTimize
!! # ForTimize: A Fortran optimization library
!!
!! ## Description
!! ForTimize focuses on providing a simple and easy-to-use interface for
!! optimization algorithms in Fortran. It is designed to be modular and
!! extensible, allowing users to easily add new optimization algorithms.
!!
!! ## Usage
!! To use ForTimize, simply include the `ForTimize` module in your program.
!!
!! ### Objective Function
!! The function that you want to minimize should have the following signature:
!! ```fortran
!! subroutine foo(X, F, dF, data)
!! real(pr), intent(in) :: x(:)
!! real(pr), intent(out) :: F
!! real(pr), optional, intent(out) :: dF(:)
!! class(*), optional, intent(in out) :: data
!! end subroutine foo
!! ```
!! ### Basic calling
!! ```fortran
!! use ForTimize, only: minimize
!! call minimize(foo, x, y)
!! ```
use ForTimize__constants, only: pr
use ForTimize__base
use ForTimize__minimize, only: minimize
Expand Down
15 changes: 10 additions & 5 deletions src/minimize.f90
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@ subroutine minimize(f, x, y, optim, data)
!! Minimize the objective function f.
!! If no optimizer is provided, the Nelder-Mead algorithm will be used
!! as default.
procedure(objective_function) :: f !! Objective function
real(pr), intent(in out) :: x(:) !! Vector of parameters
real(pr), intent(out) :: y !! Function value after optimization
class(Optimizer), optional :: optim !! Optimizing algorithm
class(*), optional, target, intent(in out) :: data !! Optional data to be passed to the objective function
procedure(objective_function) :: f
!! Objective function
real(pr), intent(in out) :: x(:)
!! Vector of parameters
real(pr), intent(out) :: y
!! Function value after optimization
class(Optimizer), optional :: optim
!! Optimizing algorithm
class(*), optional, target, intent(in out) :: data
!! Optional data to be passed to the objective function

type(NelderMead) :: nmopt

Expand Down
6 changes: 3 additions & 3 deletions test/check.f90
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ subroutine foo(X, F, dF, data)
end subroutine foo
end module fixture_problem

program grad_descent
program test
use ForTimize, only: GradientDescent, minimize, NelderMead
use fixture_problem, only: foo

type(GradientDescent) :: optimizer
type(NelderMead) :: nmopt
real(8) :: yold, y, x(3), x0(3)

x0 = [ 1.3, -2.5, 1.]
x0 = [1.3, -2.5, 1.]
optimizer%step = 0.001
optimizer%max_iters = 1000

Expand All @@ -61,4 +61,4 @@ program grad_descent

call minimize(foo, x0, y, nmopt)
if (yold < y) error stop 1
end program grad_descent
end program test

0 comments on commit 3431b65

Please sign in to comment.