Class MinUnconMultiVar
- All Implemented Interfaces:
Serializable,Cloneable
Class MinUnconMultivar uses a quasi-Newton method to find
the minimum of a function f(x) of n
variables. The problem is stated as follows:
$$\mathop {\min }\limits_{x\; \in \;R^n } f\left( x \right)$$
Given a starting point \(x_c\), the search direction is computed according to the formula
$$d = -B^{-1} g_c$$
where B is a positive definite approximation of the Hessian, and \(g_c\) is the gradient evaluated at \(x_c\). A line search is then used to find a new point
$$ x_n = \,x_c + \lambda d,\lambda > 0$$
such that
$$f\left( {x_n } \right) \le f\left( {x_c } \right) + \alpha g^T d,\,\,\,\, \alpha \in \left( {0,\,0.5} \right)$$
Finally, the optimality condition \({\rm{||g(x)|| }} \le \varepsilon\) where \(\varepsilon\) is a gradient tolerance, is sought.
When optimality is not achieved, B is updated according to the BFGS formula
$$ B \leftarrow B - \frac{{Bss^T B}}{{s^T Bs}} + \frac{{yy^T }}{{y^T s}}$$
where \(s = x_n - x_c\) and \(y = g_n - g_c\). Another search direction is then computed to begin the next iteration. For more details, see Dennis and Schnabel (1983, Appendix A).
In this implementation, the first stopping criterion for
MinUnconMultivar occurs when the norm of the gradient is less
than the given gradient tolerance gradientTolerance. The second
stopping criterion for MinUnconMultivar occurs when the scaled
distance between the last two steps is less than the step tolerance
stepTolerance.
Since by default, a finite-difference method is used to estimate the
gradient for some single precision calculations, an inaccurate estimate of
the gradient may cause the algorithm to terminate at a noncritical point.
Supply the gradient for a more accurate gradient evaluation
(setGradient).
The user may also choose to supply the Hessian. If, during intermediate calculations, the user supplied Hessian becomes non-symmetric positive definite, then the algorithm will resort to using the default approximate Hessian.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classScaled step tolerance satisfied; the current point may be an approximate local solution, or the algorithm is making very slow progress and is not near a solution, or the scaled step tolerance is too big.static classFalse convergence error; the iterates appear to be converging to a noncritical point.static interfacePublic interface for the user supplied function to theMinUnconMultiVarobject.static interfacePublic interface for the user supplied gradient to theMinUnconMultiVarobject.static interfacePublic interface for the user supplied Hessian to theMinUnconMultiVarobject.static classMaximum number of iterations exceeded.static classFive consecutive steps of the maximum allowable stepsize have been taken, either the function is unbounded below, or has a finite asymptote in some direction or the maximum allowable step size is too small. -
Constructor Summary
ConstructorsConstructorDescriptionMinUnconMultiVar(int n) Unconstrained minimum constructor for a function of n variables of typedouble. -
Method Summary
Modifier and TypeMethodDescriptiondouble[]Return the minimum point of a function of n variables of typedoubleusing a finite-difference gradient or using a user-supplied gradient.intReturns the non-fatal error status.intReturns the number of iterations used to compute a minimum.intReturns the number ofjava.lang.Threadinstances used for parallel processing.voidsetDigits(double fdigit) Set the number of good digits in the function.voidsetFscale(double fscale) Set the function scaling value for scaling the gradient.voidsetGradientTolerance(double gradientTolerance) Sets the gradient tolerance.voidsetGuess(double[] xguess) Set the initial guess of the minimum point of the input function.voidsetIhess(int ihess) Set the Hessian initialization parameter.voidsetMaximumStepsize(double maximumStepsize) Set the maximum allowable stepsize to use.voidsetMaxIterations(int maxIterations) Set the maximum number of iterations allowed.voidsetNumberOfThreads(int numberOfThreads) Sets the number ofjava.lang.Threadinstances to be used for parallel processing.voidsetStepTolerance(double stepTolerance) Set the scaled step tolerance to use when changing x.voidsetXscale(double[] xscale) Set the diagonal scaling matrix for the variables.
-
Constructor Details
-
MinUnconMultiVar
public MinUnconMultiVar(int n) Unconstrained minimum constructor for a function of n variables of typedouble.- Parameters:
n- Anintscalar value which defines the number of variables of the function whose minimum is to be found.
-
-
Method Details
-
setNumberOfThreads
public void setNumberOfThreads(int numberOfThreads) Sets the number ofjava.lang.Threadinstances to be used for parallel processing.- Parameters:
numberOfThreads- anintspecifying the number ofjava.lang.Threadinstances to be used for parallel processing. IfnumberOfThreadsis greater than 1, then interfaceFunction.fis evaluated in parallel andFunction.fmust be thread-safe. Otherwise, unexpected behavior can occur.Default:
numberOfThreads= 1.
-
getNumberOfThreads
public int getNumberOfThreads()Returns the number ofjava.lang.Threadinstances used for parallel processing.- Returns:
- an
intcontaining the number ofjava.lang.Threadinstances used for parallel processing.
-
computeMin
public double[] computeMin(MinUnconMultiVar.Function F) throws MinUnconMultiVar.FalseConvergenceException, MinUnconMultiVar.MaxIterationsException, MinUnconMultiVar.UnboundedBelowException Return the minimum point of a function of n variables of typedoubleusing a finite-difference gradient or using a user-supplied gradient.- Parameters:
F- defines the function whose minimum is to be found.Fcan be used to supply a gradient of the function. IfFimplementsGradientthen the user-supplied gradient is used. Otherwise, an attempt to find the minimum is made using a finite-difference gradient. If F implementsHessianthen the user-supplied gradient and Hessian are used. Otherwise, an approximate Hessian is used during computation.- Returns:
- a
doublearray containing the point at which the minimum of the input function occurs. - Throws:
MinUnconMultiVar.FalseConvergenceExceptionMinUnconMultiVar.MaxIterationsExceptionMinUnconMultiVar.UnboundedBelowException
-
setGuess
public void setGuess(double[] xguess) Set the initial guess of the minimum point of the input function. If this member function is not called, the elements of this array are set to 0.0..- Parameters:
xguess- adoublearray specifying the initial guess of the minimum point of the input function
-
setXscale
public void setXscale(double[] xscale) Set the diagonal scaling matrix for the variables. If this member function is not called, the elements of this array are set to 1.0..- Parameters:
xscale- adoublearray specifying the diagonal scaling matrix for the variables- Throws:
IllegalArgumentException- is thrown if any of the elements of xscale is less than or equal to 0
-
setFscale
public void setFscale(double fscale) Set the function scaling value for scaling the gradient. If this member function is not called, the value of this scalar is set to 1.0.- Parameters:
fscale- adoublescalar specifying the function scaling value for scaling the gradient- Throws:
IllegalArgumentException- is thrown iffscaleis less than or equal to 0.
-
setDigits
public void setDigits(double fdigit) Set the number of good digits in the function. If this member function is not called, fdigit is set to 15.0.- Parameters:
fdigit- adoublescalar value specifying the number of good digits in the user supplied function- Throws:
IllegalArgumentException- is thrown iffdigitis less than or equal to 0
-
setMaxIterations
public void setMaxIterations(int maxIterations) Set the maximum number of iterations allowed. If this member function is not called, the maximum number of iterations is set to 100.- Parameters:
maxIterations- anintspecifying the maximum number of iterations allowed- Throws:
IllegalArgumentException- is thrown if maxIterations is less than or equal to 0
-
setIhess
public void setIhess(int ihess) Set the Hessian initialization parameter. If this member function is not called, ihess is set to 0.0 and the Hessian is initialized to the identity matrix. If this member function is called and ihess is set to anything other than 0.0, the Hessian is initialized to the diagonal matrix containing max(abs(f(xguess)),fscale)*xscale*xscale- Parameters:
ihess- anintscalar value specifying the Hessian initialization parameter. Ifihess= 0.0 the Hessian is initialized to the identity matrix. Otherwise, the Hessian is initialized to the diagonal matrix containing max(abs(f(xguess)),fscale)*xscale*xscale where xguess is the initial guess of the computed solution and xscale is the scaling vector for the variables.
-
setStepTolerance
public void setStepTolerance(double stepTolerance) Set the scaled step tolerance to use when changing x. If this member function is not called, the scaled step tolerance is set to 3.66685e-11.The second stopping criterion for this optimizer is that the scaled distance between the last two steps be less than the step tolerance.
- Parameters:
stepTolerance- adoublescalar value specifying the scaled step tolerance. The i-th component of the scaled step between two points x and y is computed as abs(x(i)-y(i))/max(abs(x(i)),1/xscale(i)) where xscale is the scaling vector for the variables.- Throws:
IllegalArgumentException- is thrown if stepTolerance is less than or equal to 0
-
setMaximumStepsize
public void setMaximumStepsize(double maximumStepsize) Set the maximum allowable stepsize to use. If this member function is not called, maximum stepsize is set to a default value based on a scaled xguess.- Parameters:
maximumStepsize- a nonnegativedoublevalue specifying the maximum allowable stepsize- Throws:
IllegalArgumentException- is thrown if maximumStepsize is less than or equal to 0
-
setGradientTolerance
public void setGradientTolerance(double gradientTolerance) Sets the gradient tolerance. This first stopping criterion for this optimizer is that the norm of the gradient be less than the gradient tolerance. If this member function is not called, the cube root of machine precision squared is used to compute the gradient.- Parameters:
gradientTolerance- adoublespecifying the gradient tolerance used to compute the gradient- Throws:
IllegalArgumentException- is thrown if gradientTolerance is less than or equal to 0
-
getIterations
public int getIterations()Returns the number of iterations used to compute a minimum.- Returns:
- an
intspecifying the number of iterations used to compute the minimum.
-
getErrorStatus
public int getErrorStatus()Returns the non-fatal error status.- Returns:
- an
intspecifying the non-fatal error status:Status Meaning 1 The last global step failed to locate a lower point than the current x value. The current x may be an approximate local minimizer and no more accuracy is possible or the step tolerance may be too large. 2 Relative function convergence; both the actual and predicted relative reductions in the function are less than or equal to the relative function convergence tolerance. 3 Scaled step tolerance satisfied; the current point may be an approximate local solution, or the algorithm is making very slow progress and is not near a solution, or the step tolerance is too big.
-