1. Home
  2. MINIMIZE procedure

MINIMIZE procedure

Finds the minimum of a function calculated by a procedure (R.W. Payne).

Options

PRINT = string tokens What output to produce (minimum, monitoring); default mini
FUNCTIONVALUE = scalar Saves the minimum function value
DATA = any type Data to be used with procedure _MINFUNCTION
MAXCYCLE = scalar Maximum number of iterations; default 2000
NSTARTS = scalar Maximum number of restarts; default 4
STEPADJUSTMENT = scalar Adjustment to step lengths at each restart; default 0.1
EXIT = scalar Indicates whether there has been convergence (zero) or non-convergence (non-zero)
TOLERANCE = scalar Convergence criterion; default 0.0001
METHOD = string token Algorithm for fitting nonlinear model (GaussNewton, NewtonRaphson, FletcherPowell); default Newt

Parameters

PARAMETER = scalars Parameters to be estimated
LOWER = scalars Lower bound for each parameter
UPPER = scalars Upper bound for each parameter
STEPLENGTH = scalars Step length for each parameter
INITIAL = scalars Initial value for each parameter

Description

MINIMIZE searches for the minimum of a function that is calculated by a procedure _MINFUNCTION, which operates similarly to the RESAMPLE procedure that is called by procedures BOOTSTRAP and JACKKNIFE. This means that you can use any Genstat command to obtain the function value (e.g. ANOVA, FIT, SVD and so on). Any data structures that are needed by _MINFUNCTION to calculate the value of the function should be listed by the DATA option. Details are given in the Methods Section.

The parameters to be estimated in the minimization are listed by the PARAMETER parameter of MINIMIZE. Step lengths and initial values must be supplied using the STEPLENGTH and INITIAL parameters. You can also specify lower bounds with the LOWER parameter, and upper bounds with the UPPER parameter.

The PRINT option controls printed output with the settings:

    minimum to print the minimum function value and parameter values, and
    monitoring to print to monitor information showing the progress of the minimization.

By default, PRINT=minimum.

The MAXCYCLE option sets a limit on the number of function evaluations that are made by _MINFUNCTION (default 5000). The NSTARTS option controls how many times the optimization is restarted during the optimization, and the STEPADJUSTMENT option controls how the step lengths are adjusted at each restart; for more information, see Method.

If the optimization is successful, the scalars specified by the PARAMETER parameter will contain the estimated values of the parameters. The FUNCTIONVALUE option can save the minimum value.

The optimization search is performed by calling the FITNONLINEAR directive successively (see Method). You can also save a scalar, using the EXIT option, to indicate whether the minimization was successful. A zero value indicates success. Non-zero values indicate the various types of failure codes as defined by the RKEEP directive. RKEEP can be also used to save other information from the optimization.

The TOLERANCE option corresponds to the TOLERANCE option of the RCYCLE directive, specifying the tolerance for convergence (default 0.0001). Similarly, the METHOD option selects the optimization method (default NewtonRaphson).

Options: PRINT, FUNCTIONVALUE, DATA, MAXCYCLE, NSTARTS, STEPADJUSTMENT, EXIT, TOLERANCE, METHOD.

Parameters: PARAMETER, LOWER, UPPER, STEPLENGTH, INITIAL.

Method

The procedure _MINFUNCTION, that calculates the function has two options. DATA supplies a pointer containing the data structures specified by the DATA option of MINIMIZE (so, DATA[1] is the first of these structures, DATA[2] is the second, and so on). FUNCTIONVALUE is a scalar, which should be set to the function value. There is one parameter, called PARAMETER. The PROCEDURE statement that defines _MINFUNCTION should set option PARAMETER=pointer. The parameters of the function can then be referred to as PARAMETER[1], PARAMETER[2], and so on (and these will be in the same order as in the PARAMETER parameter of MINIMIZE).

MINIMIZE calls the FITNONLINEAR directive successively to perform the optimzation search. The function evaluations so far are placed into a variate y, and terminated with a missing value. The expressions Func[1...3] defined below access the values successively, placing each one in turn into the scalar Target. This is identified as the value to minimize by supplying it as the setting of the FUNCTIONVALUE option of the MODEL directive. The missing final value for Target in y causes each use of FITNONLINEAR to terminate. The next parameter values for which FITNONLINEAR wants a function value are in the scalars x[]. _MINFUNCTION is called to obtain the value, this is then placed into y, and the process continues.

EXPRESSION Func[1...3]; VALUE=!e(i=i+1),\

  !e(ELEMENTS(x[];i)=PARAMETER[]),\

  !e(Target=ELEMENTS(y;i))

The use of FITNONLINEAR slows down as the number of function evaluations increases. So MINIMIZE allows the optimization to be restarted after MAXCYCLE/NSTARTS evaluations (where MAXCYCLE and NSTARTS are two of the options of MINIMIZE). At each restart, the step lengths are adjusted by multipying by a value specified by the STEPADJUSTMENT option.

For more information about function optimization using FITNONLINEAR, see the Guide to Genstat, Part 2 Statistics, Section 3.8.4.

Action with RESTRICT

The effects of restrictions on the data variables will depend on how the calculation is defined within the _MINFUNCTION procedure.

See also

Directive: FITNONLINEAR.

Procedures: DEMC, FPARETOSET, MIN1DIMENSION, SIMPLEX.

Commands for: Regression analysis.

Example

CAPTION   'MINIMIZE examples',\
          'See Guide to Genstat Part 2 Statistics, Sections 3.8.2 & 3.8.3:',\
          '1) no linear parameters.'; STYLE=meta,2(plain)
OPEN      '%GENDIR%/Examples/GuidePart2/Reaction.dat'; CHANNEL=2
READ      [CHANNEL=2] X1,X2,X3,R
CLOSE     2
" Change units from psia to atmospheres."
CALCULATE X1,X2,X3 = X1,X2,X3 / 14.7
POINTER   [VALUES=R,X1,X2,X3] Data

PROCEDURE [PARAMETER=pointer] '_MINFUNCTION'
" calculates the function for MINIMIZE "
OPTION NAME=\
  'DATA',       "(I: pointer) data to calculate the function"\ 
  'FUNCTION';   "(O: scalar) returns the function value"\ 
  MODE=p; TYPE='pointer','scalar'

PARAMETER NAME=\
  'PARAMETER';  "(I: scalar) parameter values"\ 
  MODE=p; TYPE='scalar'; SET=yes; DECLARED=yes; PRESENT=yes
DUMMY          R,X1,X2,X3; VALUE=DATA[1...4]
DUMMY          T1,T2,T3,T4; VALUE=PARAMETER[1...4]
CALCULATE      Z = T3*(X2-X3/1.632)/(1+T2*X1+T3*X2+T4*X3)
&              F = T1*Z
&              FUNCTION = SUM((R-F)**2)
ENDPROCEDURE

MINIMIZE       [PRINT=minimum,monitor; DATA=Data; METHOD=Gauss]\
               T1,T2,T3,T4; STEPLENGTH=0.05; INITIAL=1

CAPTION   '2) linear parameter T1 fitted by linear regression.'
POINTER   [VALUES=R,X1,X2,X3,T1] Data

PROCEDURE [PARAMETER=pointer] '_MINFUNCTION'
" calculates the function for MINIMIZE "
OPTION NAME=\
  'DATA',       "(I: pointer) data to calculate the function"\ 
  'FUNCTION';   "(O: scalar) returns the function value"\ 
  MODE=p; TYPE='pointer','scalar'

PARAMETER NAME=\
  'PARAMETER';  "(I: scalar) parameter values"\ 
  MODE=p; TYPE='scalar'; SET=yes; DECLARED=yes; PRESENT=yes
DUMMY          R,X1,X2,X3,T1; VALUE=DATA[1...5]
DUMMY          T2,T3,T4; VALUE=PARAMETER[1...3]
CALCULATE      Z = T3*(X2-X3/1.632)/(1+T2*X1+T3*X2+T4*X3)
MODEL          R
FIT            [PRINT=*; CONSTANT=omit] Z
RKEEP          DEVIANCE=FUNCTION
RKESTIMATES    Z; ESTIMATE=T1
ENDPROCEDURE

MINIMIZE       [PRINT=minimum,monitor; DATA=Data]\
               T2,T3,T4; STEPLENGTH=0.05; INITIAL=1
PRINT          T1
Updated on March 7, 2019

Was this article helpful?