nonlin 1.5.2
A library that provides routines to compute the solutions to systems of nonlinear equations.
Loading...
Searching...
No Matches
nonlin_optimize::nelder_mead Type Reference

Defines a solver based upon Nelder and Mead's simplex algorithm for minimization of functions of multiple variables. More...

Inheritance diagram for nonlin_optimize::nelder_mead:
nonlin_core::equation_optimizer

Public Member Functions

procedure, public solve nm_solve
 Utilizes the Nelder-Mead simplex method for finding a minimum value of the specified function.
 
procedure, public get_simplex nm_get_simplex
 Gets an N-by-(N+1) matrix containing the current simplex.
 
procedure, public set_simplex nm_set_simplex
 Sets an N-by-(N+1) matrix as the current simplex. Notice, if this matrix is different in size from the problem dimensionallity, the Nelder-Mead routine will replace it with an appropriately sized matrix.
 
procedure, public get_initial_size nm_get_size
 Gets the size of the initial simplex that will be utilized by the Nelder-Mead algorithm in the event that the user does not supply a simplex geometry, or if the user supplies an invalid simplex geometry.
 
procedure, public set_initial_size nm_set_size
 Sets the size of the initial simplex that will be utilized by the Nelder-Mead algorithm in the event that the user does not supply a simplex geometry, or if the user supplies an invalid simplex geometry.
 
- Public Member Functions inherited from nonlin_core::equation_optimizer
procedure, public get_max_fcn_evals oe_get_max_eval
 Gets the maximum number of function evaluations allowed.
 
procedure, public set_max_fcn_evals oe_set_max_eval
 Sets the maximum number of function evaluations allowed.
 
procedure, public get_tolerance oe_get_tol
 Gets the tolerance on convergence.
 
procedure, public set_tolerance oe_set_tol
 Sets the tolerance on convergence.
 
procedure, public get_print_status oe_get_print_status
 Gets a logical value determining if iteration status should be printed.
 
procedure, public set_print_status oe_set_print_status
 Sets a logical value determining if iteration status should be printed.
 

Public Attributes

real(real64) m_initsize = 1.0d0
 A scaling parameter used to define the size of the simplex in each coordinate direction.
 
- Public Attributes inherited from nonlin_core::equation_optimizer
real(real64) m_tol = 1.0d-12
 The error tolerance used to determine convergence.
 
logical m_printstatus = .false.
 Set to true to print iteration status; else, false.
 

Private Member Functions

procedure, private extrapolate nm_extrapolate
 Extrapolates by the specified factor through the simplex across from the largest point. If the extrapolation results in a better estimate, the current high point is replaced with the new estimate.
 

Private Attributes

real(real64), dimension(:,:), allocatable m_simplex
 The simplex vertices.
 

Detailed Description

Defines a solver based upon Nelder and Mead's simplex algorithm for minimization of functions of multiple variables.

Definition at line 32 of file nonlin_optimize.f90.

Member Function/Subroutine Documentation

◆ extrapolate()

procedure, private nonlin_optimize::nelder_mead::extrapolate
private

Extrapolates by the specified factor through the simplex across from the largest point. If the extrapolation results in a better estimate, the current high point is replaced with the new estimate.

Syntax
real(real64) function extrapolate(class(nelder_mead) this, class(fcnnvar_helper) fcn, real(real64) y(:), real(real64) pcent(:), integer(int32) ihi, real(real64) fac, integer(int32) neval, real(real64) work(:))
Parameters
[in,out]thisThe nelder_mead object.
[in]fcnThe function to evaluate.
[in,out]yAn array containing the function values at each vertex.
[in,out]pcentAn array containing the centroid of vertex position information.
[in]ihiThe index of the largest magnitude vertex.
[in,out]nevalThe number of function evaluations.
[out]workAn N-element workspace array where N is the number of dimensions of the problem.
Returns
The new function estimate.

Definition at line 213 of file nonlin_optimize.f90.

◆ get_initial_size()

procedure, public nonlin_optimize::nelder_mead::get_initial_size

Gets the size of the initial simplex that will be utilized by the Nelder-Mead algorithm in the event that the user does not supply a simplex geometry, or if the user supplies an invalid simplex geometry.

Syntax
pure real(real64) get_initial_size(class(nelder_mead) this)
Parameters
[in]thisThe nelder_mead object.
Returns
The size of the simplex (length of an edge).

Definition at line 175 of file nonlin_optimize.f90.

◆ get_simplex()

procedure, public nonlin_optimize::nelder_mead::get_simplex

Gets an N-by-(N+1) matrix containing the current simplex.

Syntax
pure real(real64)(:,:) function get_simplex(class(nelder_mead) this)
Parameters
[in]thisThe nelder_mead object.
Returns
The N-by-(N+1) matrix containing the simplex. Each vertex of the simplex is stored as its own column of this matrix.

Definition at line 144 of file nonlin_optimize.f90.

◆ set_initial_size()

procedure, public nonlin_optimize::nelder_mead::set_initial_size

Sets the size of the initial simplex that will be utilized by the Nelder-Mead algorithm in the event that the user does not supply a simplex geometry, or if the user supplies an invalid simplex geometry.

Syntax
subroutine set_initial_size(class(nelder_mead) this, real(real64) x)
Parameters
[in,out]thisThe nelder_mead object.
[in]xThe size of the simplex (length of an edge).
example

Definition at line 192 of file nonlin_optimize.f90.

◆ set_simplex()

procedure, public nonlin_optimize::nelder_mead::set_simplex

Sets an N-by-(N+1) matrix as the current simplex. Notice, if this matrix is different in size from the problem dimensionallity, the Nelder-Mead routine will replace it with an appropriately sized matrix.

Syntax
subroutine set_simplex(class(nelder_mead) this, real(real64) x(:,:))
Parameters
[in,out]thisThe nelder_mead object.
[in]xThe simplex matrix. Each column of the matrix must contain the coordinates of each vertex of the simplex.
example

Definition at line 162 of file nonlin_optimize.f90.

◆ solve()

procedure, public nonlin_optimize::nelder_mead::solve
virtual

Utilizes the Nelder-Mead simplex method for finding a minimum value of the specified function.

Syntax
subroutine solve(class(nelder_mead) this, class(fcnnvar_helper) fcn, real(real64) x(:), real(real64) fout, optional type(iteration_behavior) ib, optional class(errors) err)
Parameters
[in,out]thisThe nelder_mead object.
[in]fcnThe fcnnvar_helper object containing the equation to optimize.
[in,out]xOn input, the initial guess at the optimal point. On output, the updated optimal point estimate.
[out]foutAn optional output, that if provided, returns the value of the function at x.
[out]ibAn optional output, that if provided, allows the caller to obtain iteration performance statistics.
[out]errAn optional errors-based object that if provided can be used to retrieve information relating to any errors encountered during execution. If not provided, a default implementation of the errors class is used internally to provide error handling. Possible errors and warning messages that may be encountered are as follows.
  • NL_INVALID_OPERATION_ERROR: Occurs if no equations have been defined.
  • NL_INVALID_INPUT_ERROR: Occurs if x is not appropriately sized for the problem as defined in fcn.
  • NL_OUT_OF_MEMORY_ERROR: Occurs if there is insufficient memory available.
  • NL_CONVERGENCE_ERROR: Occurs if the algorithm cannot converge within the allowed number of iterations.
Example
The following example illustrates how to find the minimum of Rosenbrock's function using this Nelder-Mead solver.
program example
implicit none
! Local Variables
type(nelder_mead) :: solver
type(fcnnvar_helper) :: obj
procedure(fcnnvar), pointer :: fcn
real(real64) :: x(2), fout
type(iteration_behavior) :: ib
! Initialization
fcn => rosenbrock
call obj%set_fcn(fcn, 2)
! Define an initial guess - the solution is (1, 1)
call random_number(x)
! Call the solver
call solver%solve(obj, x, fout, ib)
! Display the output
print '(AF8.5AF8.5A)', "Rosenbrock Minimum: (", x(1), ", ", x(2), ")"
print '(AE9.3)', "Function Value: ", fout
print '(AI0)', "Iterations: ", ib%iter_count
print '(AI0)', "Function Evaluations: ", ib%fcn_count
contains
! Rosenbrock's Function
function rosenbrock(x) result(f)
real(real64), intent(in), dimension(:) :: x
real(real64) :: f
f = 1.0d2 * (x(2) - x(1)**2)**2 + (x(1) - 1.0d0)**2
end function
end
Describes a function of N variables.
nonlin_core
nonlin_optimize
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 solver based upon Nelder and Mead's simplex algorithm for minimization of functions of mult...
The above program yields the following output.
Rosenbrock Minimum: ( 1.00000, 1.00000)
Function Value: 0.264E-12
Iterations: 59
Function Evaluations: 112
Remarks
The implementation of the Nelder-Mead algorithm presented here is a slight modification of the original work of Nelder and Mead. The Numerical Recipes implementation is also quite similar. In fact, the Numerical Recipes section relating to reflection, contraction, etc. is leveraged for this implemetation.
See Also

Implements nonlin_core::equation_optimizer.

Definition at line 133 of file nonlin_optimize.f90.

Member Data Documentation

◆ m_initsize

real(real64) nonlin_optimize::nelder_mead::m_initsize = 1.0d0

A scaling parameter used to define the size of the simplex in each coordinate direction.

Definition at line 38 of file nonlin_optimize.f90.

◆ m_simplex

real(real64), dimension(:,:), allocatable nonlin_optimize::nelder_mead::m_simplex
private

The simplex vertices.

Definition at line 35 of file nonlin_optimize.f90.


The documentation for this type was generated from the following file: