nonlin 1.5.2
A library that provides routines to compute the solutions to systems of nonlinear equations.
Loading...
Searching...
No Matches
nonlin_optimize.f90
1! nonlin_optimize.f90
2
3! REF:
4! http://ab-initio.mit.edu/wiki/index.php/NLopt_Algorithms#Nelder-Mead_Simplex
5! http://ab-initio.mit.edu/wiki/index.php/NLopt_Algorithms
6! https://scicomp.stackexchange.com/questions/14787/fortran-library-for-minimization-or-maximization-of-functions-optimization-prob
7! http://ab-initio.mit.edu/wiki/index.php/NLopt
8
14 use, intrinsic :: iso_fortran_env, only : int32, real64
15 use ferror
16 use nonlin_linesearch, only : line_search, limit_search_vector
18 use nonlin_core
19 use linalg, only : rank1_update, tri_mtx_mult, cholesky_rank1_update, &
20 cholesky_rank1_downdate, solve_cholesky, la_matrix_format_error
21 implicit none
22 private
23 public :: nelder_mead
24 public :: line_search_optimizer
25 public :: bfgs
26
27! ******************************************************************************
28! NONLIN_OPTIMIZE_NELDER_MEAD.F90
29! ------------------------------------------------------------------------------
33 private
35 real(real64), allocatable, dimension(:,:) :: m_simplex
38 real(real64) :: m_initsize = 1.0d0
39 contains
133 procedure, public :: solve => nm_solve
144 procedure, public :: get_simplex => nm_get_simplex
162 procedure, public :: set_simplex => nm_set_simplex
175 procedure, public :: get_initial_size => nm_get_size
192 procedure, public :: set_initial_size => nm_set_size
193
213 procedure, private :: extrapolate => nm_extrapolate
214 end type
215
216! ------------------------------------------------------------------------------
217 interface
218 module subroutine nm_solve(this, fcn, x, fout, ib, err)
219 class(nelder_mead), intent(inout) :: this
220 class(fcnnvar_helper), intent(in) :: fcn
221 real(real64), intent(inout), dimension(:) :: x
222 real(real64), intent(out), optional :: fout
223 type(iteration_behavior), optional :: ib
224 class(errors), intent(inout), optional, target :: err
225 end subroutine
226
227 module function nm_extrapolate(this, fcn, y, pcent, ihi, fac, neval, &
228 work) result(ytry)
229 class(nelder_mead), intent(inout) :: this
230 class(fcnnvar_helper), intent(in) :: fcn
231 real(real64), intent(inout), dimension(:) :: y, pcent
232 integer(int32), intent(in) :: ihi
233 real(real64), intent(in) :: fac
234 integer(int32), intent(inout) :: neval
235 real(real64), intent(out), dimension(:) :: work
236 real(real64) :: ytry
237 end function
238
239 pure module function nm_get_simplex(this) result(p)
240 class(nelder_mead), intent(in) :: this
241 real(real64), allocatable, dimension(:,:) :: p
242 end function
243
244 module subroutine nm_set_simplex(this, x)
245 class(nelder_mead), intent(inout) :: this
246 real(real64), dimension(:,:) :: x
247 end subroutine
248
249 pure module function nm_get_size(this) result(x)
250 class(nelder_mead), intent(in) :: this
251 real(real64) :: x
252 end function
253
254 module subroutine nm_set_size(this, x)
255 class(nelder_mead), intent(inout) :: this
256 real(real64), intent(in) :: x
257 end subroutine
258 end interface
259
260! ******************************************************************************
261! NONLIN_OPTIMIZE_LINE_SEARCH.F90
262! ------------------------------------------------------------------------------
265 type, abstract, extends(equation_optimizer) :: line_search_optimizer
266 private
268 class(line_search), allocatable :: m_linesearch
271 logical :: m_uselinesearch = .true.
273 real(real64) :: m_xtol = 1.0d-12
274 contains
284 procedure, public :: get_line_search => lso_get_line_search
294 procedure, public :: set_line_search => lso_set_line_search
304 procedure, public :: set_default_line_search => lso_set_default
314 procedure, public :: is_line_search_defined => &
315 lso_is_line_search_defined
325 procedure, public :: get_use_line_search => lso_get_use_search
335 procedure, public :: set_use_line_search => lso_set_use_search
345 procedure, public :: get_var_tolerance => lso_get_var_tol
355 procedure, public :: set_var_tolerance => lso_set_var_tol
356 end type
357
358! ------------------------------------------------------------------------------
359 interface
360 module subroutine lso_get_line_search(this, ls)
361 class(line_search_optimizer), intent(in) :: this
362 class(line_search), intent(out), allocatable :: ls
363 end subroutine
364
365 module subroutine lso_set_line_search(this, ls)
366 class(line_search_optimizer), intent(inout) :: this
367 class(line_search), intent(in) :: ls
368 end subroutine
369
370 module subroutine lso_set_default(this)
371 class(line_search_optimizer), intent(inout) :: this
372 type(line_search) :: ls
373 end subroutine
374
375 pure module function lso_is_line_search_defined(this) result(x)
376 class(line_search_optimizer), intent(in) :: this
377 logical :: x
378 end function
379
380 pure module function lso_get_use_search(this) result(x)
381 class(line_search_optimizer), intent(in) :: this
382 logical :: x
383 end function
384
385 module subroutine lso_set_use_search(this, x)
386 class(line_search_optimizer), intent(inout) :: this
387 logical, intent(in) :: x
388 end subroutine
389
390 pure module function lso_get_var_tol(this) result(x)
391 class(line_search_optimizer), intent(in) :: this
392 real(real64) :: x
393 end function
394
395 module subroutine lso_set_var_tol(this, x)
396 class(line_search_optimizer), intent(inout) :: this
397 real(real64), intent(in) :: x
398 end subroutine
399 end interface
400
401! ------------------------------------------------------------------------------
404 type, extends(line_search_optimizer) :: bfgs
405 contains
488 procedure, public :: solve => bfgs_solve
489 end type
490
491! ------------------------------------------------------------------------------
492 interface
493 module subroutine bfgs_solve(this, fcn, x, fout, ib, err)
494 class(bfgs), intent(inout) :: this
495 class(fcnnvar_helper), intent(in) :: fcn
496 real(real64), intent(inout), dimension(:) :: x
497 real(real64), intent(out), optional :: fout
498 type(iteration_behavior), optional :: ib
499 class(errors), intent(inout), optional, target :: err
500 end subroutine
501 end interface
502
503end module
nonlin_constants
nonlin_core
nonlin_linesearch
nonlin_optimize
A base class for optimization of an equation of multiple variables.
Defines a type capable of encapsulating an equation of N variables.
Defines a set of parameters that describe the behavior of the iteration process.
Defines a type capable of performing an inexact, backtracking line search to find a point as far alon...
Defines a Broyden–Fletcher–Goldfarb–Shanno (BFGS) solver for minimization of functions of multiple va...
A class describing equation optimizers that use a line search algorithm to improve convergence behavi...
Defines a solver based upon Nelder and Mead's simplex algorithm for minimization of functions of mult...