NAG C Library Function Document
nag_opt_simplex_easy (e04cbc)
1
Purpose
nag_opt_simplex_easy (e04cbc) minimizes a general function
of
independent variables
by the Nelder and Mead simplex method (see
Nelder and Mead (1965)). Derivatives of the function need not be supplied.
2
Specification
#include <nag.h> |
#include <nage04.h> |
void |
nag_opt_simplex_easy (Integer n,
double x[],
double *f,
double tolf,
double tolx,
void |
(*funct)(Integer n,
const double xc[],
double *fc,
Nag_Comm *comm),
|
|
Integer maxcal,
Nag_Comm *comm,
NagError *fail) |
|
3
Description
nag_opt_simplex_easy (e04cbc) finds an approximation to a minimum of a function of variables. You must supply a function to calculate the value of for any set of values of the variables.
The method is iterative. A simplex of
points is set up in the
-dimensional space of the variables (for example, in
dimensions the simplex is a triangle) under the assumption that the problem has been scaled so that the values of the independent variables at the minimum are of order unity. The starting point you have provided is the first vertex of the simplex, the remaining
vertices are generated by
nag_opt_simplex_easy (e04cbc). The vertex of the simplex with the largest function value is reflected in the centre of gravity of the remaining vertices and the function value at this new point is compared with the remaining function values. Depending on the outcome of this test the new point is accepted or rejected, a further expansion move may be made, or a contraction may be carried out. See
Nelder and Mead (1965) and
Parkinson and Hutchinson (1972) for more details. When no further progress can be made the sides of the simplex are reduced in length and the method is repeated.
The method can be slow, but computational bottlenecks have been reduced following
Singer and Singer (2004). However,
nag_opt_simplex_easy (e04cbc) is robust, and therefore very useful for functions that are subject to inaccuracies.
There are the following options for successful termination of the method: based only on the function values at the vertices of the current simplex (see
(1)); based only on a volume ratio between the current simplex and the initial one (see
(2)); or based on which one of the previous two tests passes first. The volume test may be useful if
is discontinuous, while the function-value test should be sufficient on its own if
is continuous.
4
References
Nelder J A and Mead R (1965) A simplex method for function minimization Comput. J. 7 308–313
Parkinson J M and Hutchinson D (1972) An investigation into the efficiency of variants of the simplex method Numerical Methods for Nonlinear Optimization (ed F A Lootsma) Academic Press
Singer S and Singer S (2004) Efficient implementation of the Nelder–Mead search algorithm Appl. Num. Anal. Comp. Math. 1(3) 524–534
5
Arguments
- 1:
– IntegerInput
-
On entry: , the number of variables.
Constraint:
.
- 2:
– doubleInput/Output
-
On entry: a guess at the position of the minimum. Note that the problem should be scaled so that the values of the are of order unity.
On exit: the value of
corresponding to the function value in
f.
- 3:
– double *Output
-
On exit: the lowest function value found.
- 4:
– doubleInput
-
On entry: the error tolerable in the function values, in the following sense. If
, for
, are the individual function values at the vertices of the current simplex, and if
is the mean of these values, then you can request that
nag_opt_simplex_easy (e04cbc) should terminate if
You may specify
if you wish to use only the termination criterion
(2) on the spatial values: see the description of
tolx.
Constraint:
must be greater than or equal to the
machine precision (see
Chapter x02), or if
tolf equals zero then
tolx must be greater than or equal to the
machine precision.
- 5:
– doubleInput
-
On entry: the error tolerable in the spatial values, in the following sense. If
denotes the ‘linearized’ volume of the current simplex, and if
denotes the ‘linearized’ volume of the initial simplex, then you can request that
nag_opt_simplex_easy (e04cbc) should terminate if
You may specify
if you wish to use only the termination criterion
(1) on function values: see the description of
tolf.
Constraint:
must be greater than or equal to the
machine precision (see
Chapter x02), or if
tolx equals zero then
tolf must be greater than or equal to the
machine precision.
- 6:
– function, supplied by the userExternal Function
-
funct must evaluate the function
at a specified point. It should be tested separately before being used in conjunction with
nag_opt_simplex_easy (e04cbc).
The specification of
funct is:
void |
funct (Integer n,
const double xc[],
double *fc,
Nag_Comm *comm)
|
|
- 1:
– IntegerInput
-
On entry: , the number of variables.
- 2:
– const doubleInput
-
On entry: the point at which the function value is required.
- 3:
– double *Output
-
On exit: the value of the function at the current point .
- 4:
– Nag_Comm *
Pointer to structure of type Nag_Comm; the following members are relevant to
funct.
- user – double *
- iuser – Integer *
- p – Pointer
The type Pointer will be
void *. Before calling
nag_opt_simplex_easy (e04cbc) you may allocate memory and initialize these pointers with various quantities for use by
funct when called from
nag_opt_simplex_easy (e04cbc) (see
Section 3.3.1.1 in How to Use the NAG Library and its Documentation).
Note: funct should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by
nag_opt_simplex_easy (e04cbc). If your code inadvertently
does return any NaNs or infinities,
nag_opt_simplex_easy (e04cbc) is likely to produce unexpected results.
- 7:
– function, supplied by the userExternal Function
-
monit may be used to monitor the optimization process. It is invoked once every iteration.
If no monitoring is required,
monit may be specified as NULLFN.
The specification of
monit is:
- 1:
– doubleInput
-
On entry: the smallest function value in the current simplex.
- 2:
– doubleInput
-
On entry: the largest function value in the current simplex.
- 3:
– const doubleInput
-
On entry: the position vectors of the current simplex, where is the th coordinate of the th position vector.
- 4:
– IntegerInput
-
On entry: , the number of variables.
- 5:
– IntegerInput
-
On entry: the number of times that
funct has been called so far.
- 6:
– doubleInput
-
On entry: the current value of the standard deviation in function values used in termination test
(1).
- 7:
– doubleInput
-
On entry: the current value of the linearized volume ratio used in termination test
(2).
- 8:
– Nag_Comm *
Pointer to structure of type Nag_Comm; the following members are relevant to
monit.
- user – double *
- iuser – Integer *
- p – Pointer
The type Pointer will be
void *. Before calling
nag_opt_simplex_easy (e04cbc) you may allocate memory and initialize these pointers with various quantities for use by
monit when called from
nag_opt_simplex_easy (e04cbc) (see
Section 3.3.1.1 in How to Use the NAG Library and its Documentation).
- 8:
– IntegerInput
-
On entry: the maximum number of function evaluations to be allowed.
Constraint:
.
- 9:
– Nag_Comm *
-
The NAG communication argument (see
Section 3.3.1.1 in How to Use the NAG Library and its Documentation).
- 10:
– NagError *Input/Output
-
The NAG error argument (see
Section 3.7 in How to Use the NAG Library and its Documentation).
6
Error Indicators and Warnings
- NE_ALLOC_FAIL
-
Dynamic memory allocation failed.
See
Section 2.3.1.2 in How to Use the NAG Library and its Documentation for further information.
- NE_BAD_PARAM
-
On entry, argument had an illegal value.
- NE_INT
-
On entry, .
Constraint: .
On entry, .
Constraint: .
- NE_INTERNAL_ERROR
-
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact
NAG for assistance.
See
Section 2.7.6 in How to Use the NAG Library and its Documentation for further information.
- NE_NO_LICENCE
-
Your licence key may have expired or may not have been installed correctly.
See
Section 2.7.5 in How to Use the NAG Library and its Documentation for further information.
- NE_REAL
-
On entry, and .
Constraint: if then is greater than or equal to the machine precision.
On entry, and .
Constraint: if then is greater than or equal to the machine precision.
- NE_REAL_2
-
On entry, and .
Constraint: if and then both should be greater than or equal to the machine precision.
- NW_TOO_MANY_FEVALS
-
maxcal function evaluations have been completed without any other termination test passing. Check the coding of
funct before increasing the value of
maxcal.
7
Accuracy
On a successful exit the accuracy will be as defined by
tolf or
tolx, depending on which criterion was satisfied first.
8
Parallelism and Performance
nag_opt_simplex_easy (e04cbc) makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the
x06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this function. Please also consult the
Users' Note for your implementation for any additional implementation-specific information.
Local workspace arrays of fixed lengths (depending on
n) are allocated internally by
nag_opt_simplex_easy (e04cbc). The total size of these arrays amounts to
double elements.
The time taken by nag_opt_simplex_easy (e04cbc) depends on the number of variables, the behaviour of the function and the distance of the starting point from the minimum. Each iteration consists of or function evaluations unless the size of the simplex is reduced, in which case function evaluations are required.
10
Example
This example finds a minimum of the function
This example uses the initial point
(see
Section 10.3), and we expect to reach the minimum at
.
10.1
Program Text
Program Text (e04cbce.c)
10.2
Program Data
None.
10.3
Program Results
Program Results (e04cbce.r)