|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectde.jstacs.algorithms.optimization.Optimizer
public class Optimizer
This class can be used for optimization purposes. The function will be minimized. To maximize a function use the
classes NegativeFunction and NegativeDifferentiableFunction as input. All methods for multidimensional optimization
need an implementation of DifferentiableFunction, that will be minimized. The optimizing methods try to do as less as
possible function evaluation, which is important for function that are costly to evaluate. So if you have a costly
function and you will fasten the computation, try to do as much effort as you can to make the methods
evaluateFunction
and evaluateGradientOfFunction
in your implementation as fast as
possible.
You are enabled to choose different termination modes.
OneDimensionalFunction
,
DifferentiableFunction
,
NegativeOneDimensionalFunction
,
NegativeDifferentiableFunction
,
NumericalDifferentiableFunction
Nested Class Summary | |
---|---|
static class |
Optimizer.TerminationCondition
This enum defines all kinds of termination conditions for the Optimizer . |
Field Summary | |
---|---|
static byte |
CONJUGATE_GRADIENTS_FR
This constant can be used to specify that conjugate gradients (by Fletcher and Reeves) should be used in the optimize -method. |
static byte |
CONJUGATE_GRADIENTS_PRP
This constant can be used to specify that conjugate gradients (by Polak and Ribiere should be used in the optimize -method. |
static byte |
QUASI_NEWTON_BFGS
This constant can be used to specify that the quasi Newton method of Broyden-Fletcher-Goldfarb-Shanno should be used in the optimize -method. |
static byte |
QUASI_NEWTON_DFP
This constant can be used to specify that the quasi Newton method of Davidon-Fletcher-Powell should be used in the optimize -method. |
static byte |
STEEPEST_DESCENT
This constant can be used to specify that steepest descent should be used in the optimize -method. |
Constructor Summary | |
---|---|
Optimizer()
|
Method Summary | |
---|---|
static double[] |
brentsMethod(OneDimensionalFunction f,
double a,
double x,
double b,
double tol)
Approximates a minimum (not necessary the global) in the interval [lower,upper]. |
static double[] |
brentsMethod(OneDimensionalFunction f,
double a,
double x,
double fx,
double b,
double tol)
Approximates a minimum (not necessary the global) in the interval [lower,upper]. |
static int |
conjugateGradientsFR(DifferentiableFunction f,
double[] currentValues,
Optimizer.TerminationCondition terminationMode,
double eps,
double linEps,
StartDistanceForecaster startDistance,
SafeOutputStream out,
Time t)
The conjugate gradient algorithm by Fletcher and Reeves. |
static int |
conjugateGradientsPR(DifferentiableFunction f,
double[] currentValues,
Optimizer.TerminationCondition terminationMode,
double eps,
double linEps,
StartDistanceForecaster startDistance,
SafeOutputStream out,
Time t)
The conjugate gradient algorithm by Polak and Ribiere. |
static int |
conjugateGradientsPRP(DifferentiableFunction f,
double[] currentValues,
Optimizer.TerminationCondition terminationMode,
double eps,
double linEps,
StartDistanceForecaster startDistance,
SafeOutputStream out,
Time t)
The conjugate gradient algorithm by Polak and Ribiere called Polak-Ribiere-Positive. |
static double[] |
findBracket(OneDimensionalFunction f,
double lower,
double startDistance)
This method returns a bracket containing a minimum. |
static double[] |
findBracket(OneDimensionalFunction f,
double lower,
double fLower,
double startDistance)
This method returns a bracket containing a minimum. |
static double[] |
goldenRatio(OneDimensionalFunction f,
double lower,
double upper,
double eps)
Approximates a minimum (not necessary the global) in the interval [lower,upper]. |
static double[] |
goldenRatio(OneDimensionalFunction f,
double lower,
double p1,
double fP1,
double upper,
double eps)
Approximates a minimum (not necessary the global) in the interval [lower,upper]. |
static int |
limitedMemoryBFGS(DifferentiableFunction f,
double[] currentValues,
byte m,
Optimizer.TerminationCondition terminationMode,
double eps,
double linEps,
StartDistanceForecaster startDistance,
SafeOutputStream out,
Time t)
The Broyden-Fletcher-Goldfarb-Shanno version of limited memory quasi Newton methods. |
static int |
optimize(byte algorithm,
DifferentiableFunction f,
double[] currentValues,
Optimizer.TerminationCondition terminationMode,
double eps,
double linEps,
StartDistanceForecaster startDistance,
SafeOutputStream out)
This method enables you to use all different implemented optimization algorithms by only one method. |
static int |
optimize(byte algorithm,
DifferentiableFunction f,
double[] currentValues,
Optimizer.TerminationCondition terminationMode,
double eps,
double linEps,
StartDistanceForecaster startDistance,
SafeOutputStream out,
Time t)
This method enables you to use all different implemented optimization algorithms by only one method. |
static double[] |
parabolicInterpolation(OneDimensionalFunction f,
double lower,
double p1,
double upper,
double eps)
Approximates a minimum (not necessary the global) in the intervall [lower,upper]. |
static double[] |
parabolicInterpolation(OneDimensionalFunction f,
double lower,
double fLower,
double p1,
double fP1,
double upper,
double fUpper,
double eps)
Approximates a minimum (not necessary the global) in the intervall [lower,upper]. |
static int |
quasiNewtonBFGS(DifferentiableFunction f,
double[] currentValues,
Optimizer.TerminationCondition terminationMode,
double eps,
double linEps,
StartDistanceForecaster startDistance,
SafeOutputStream out,
Time t)
The Broyden-Fletcher-Goldfarb-Shanno version of quasi Newton method. |
static int |
quasiNewtonDFP(DifferentiableFunction f,
double[] currentValues,
Optimizer.TerminationCondition terminationMode,
double eps,
double linEps,
StartDistanceForecaster startDistance,
SafeOutputStream out,
Time t)
The Davidon-Fletcher-Powell version of quasi Newton method. |
static int |
steepestDescent(DifferentiableFunction f,
double[] currentValues,
Optimizer.TerminationCondition terminationMode,
double eps,
double linEps,
StartDistanceForecaster startDistance,
SafeOutputStream out,
Time t)
The steepest descent. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final byte STEEPEST_DESCENT
optimize
-method.
public static final byte CONJUGATE_GRADIENTS_FR
optimize
-method.
public static final byte CONJUGATE_GRADIENTS_PRP
optimize
-method.
public static final byte QUASI_NEWTON_DFP
optimize
-method.
public static final byte QUASI_NEWTON_BFGS
optimize
-method.
Constructor Detail |
---|
public Optimizer()
Method Detail |
---|
public static double[] findBracket(OneDimensionalFunction f, double lower, double fLower, double startDistance) throws EvaluationException
f
- the function to be minimizedlower
- the initial value of x, lower boundfLower
- the value f(x)startDistance
- the inital distance for bracketing the minimum
EvaluationException
- if there was a mistake in evaluating the functionbrentsMethod( OneDimensionalFunction f, double a, double x, double fx, double b, double tol )
,
goldenRatio( OneDimensionalFunction f, double lower, double p1, double fP1, double upper, double
eps )
public static double[] findBracket(OneDimensionalFunction f, double lower, double startDistance) throws EvaluationException
f
- the function to be minimizedlower
- the initial value of x, lower boundstartDistance
- the inital distance for bracketing the minimum
EvaluationException
- if there was a mistake in evaluating the functionpublic static double[] brentsMethod(OneDimensionalFunction f, double a, double x, double fx, double b, double tol) throws EvaluationException
f
- the function to be minimizeda
- the initial lower boundaryx
- a abscissa inside the interval [a,b]fx
- the ordinate corresponding to xb
- the initial upper boundtol
- the termination parameter (interval size)
EvaluationException
- if there was a mistake in evaluating the functionpublic static double[] brentsMethod(OneDimensionalFunction f, double a, double x, double b, double tol) throws EvaluationException
f
- the function to be minimizeda
- the initial lower boundaryx
- a abscissa inside the interval [a,b]b
- the initial upper boundtol
- the termination parameter (interval size)
EvaluationException
- if there was a mistake in evaluating the functionpublic static double[] goldenRatio(OneDimensionalFunction f, double lower, double p1, double fP1, double upper, double eps) throws EvaluationException
f
- the function to be minimizedlower
- the lower interval boundaryp1
- a abscissa in the intervalfP1
- the ordinate corresponding to p1upper
- the upper interval boundaryeps
- the minimal interval size
EvaluationException
- if there was a mistake in evaluating the functionpublic static double[] goldenRatio(OneDimensionalFunction f, double lower, double upper, double eps) throws EvaluationException
f
- the function to be minimizedlower
- the lower interval boundaryupper
- the upper interval boundaryeps
- the minimal interval size
EvaluationException
- if there was a mistake in evaluating the functionpublic static double[] parabolicInterpolation(OneDimensionalFunction f, double lower, double fLower, double p1, double fP1, double upper, double fUpper, double eps) throws Exception
f
- the function to be minimzedlower
- the lower interval boundaryfLower
- the ordinate corresponding to lowerp1
- a abscissa in the intervalfP1
- the ordinate corresponding to p1upper
- the upper interval boundaryfUpper
- the ordinate corresponding to uppereps
- the minimal interval size
Exception
- if there was a mistake in evaluating the functionpublic static double[] parabolicInterpolation(OneDimensionalFunction f, double lower, double p1, double upper, double eps) throws Exception
f
- the function to be minimizedlower
- the lower interval boundaryp1
- a abscissa in the intervalupper
- the upper interval boundaryeps
- the minimal interval size
Exception
- if there was a mistake in evaluating the functionpublic static int steepestDescent(DifferentiableFunction f, double[] currentValues, Optimizer.TerminationCondition terminationMode, double eps, double linEps, StartDistanceForecaster startDistance, SafeOutputStream out, Time t) throws DimensionException, TerminationException, EvaluationException, IOException
f
- the function to be minimizedcurrentValues
- at the begin the start vector and at the end the minimum vectorterminationMode
- the choice how to terminate the algorithmeps
- the bound for stopping the algorithmlinEps
- the bound for stopping the linear searchstartDistance
- the initial step for the linear searchout
- the SafeOutputStream for writing the some information about the iterations, if null nothing will be
written.t
- a Time
instance used to measure the elapsed time
EvaluationException
- if there was a mistake in evaluating the function
TerminationException
- if the termination condition is unknown
DimensionException
- if the dimension of the scope of the function and the array of arguments do not match
IOException
- if some mistakes in the IO happenedpublic static int conjugateGradientsFR(DifferentiableFunction f, double[] currentValues, Optimizer.TerminationCondition terminationMode, double eps, double linEps, StartDistanceForecaster startDistance, SafeOutputStream out, Time t) throws DimensionException, TerminationException, IOException, EvaluationException
f
- the function to be minimizedcurrentValues
- at the begin the start vector and at the end the minimum vectorterminationMode
- the choice how to terminate the algorithmeps
- the bound for stopping the algorithmlinEps
- the bound for stopping the linear searchstartDistance
- the initial step for the linear searchout
- the SafeOutputStream for writing the some information about the iterations, if null nothing will be
written.t
- a Time
instance used to measure the elapsed time
EvaluationException
- if there was a mistake in evaluating the function
TerminationException
- if the termination condition is unknown
DimensionException
- if the dimension of the scope of the function and the array of arguments do not match
IOException
- if some mistakes in the IO happenedpublic static int conjugateGradientsPR(DifferentiableFunction f, double[] currentValues, Optimizer.TerminationCondition terminationMode, double eps, double linEps, StartDistanceForecaster startDistance, SafeOutputStream out, Time t) throws DimensionException, TerminationException, IOException, EvaluationException
f
- the function to be minimizedcurrentValues
- at the begin the start vector and at the end the minimum vectorterminationMode
- the choice how to terminate the algorithmeps
- the bound for stopping the algorithmlinEps
- the bound for stopping the linear searchstartDistance
- the initial step for the linear searchout
- the SafeOutputStream for writing the some information about the iterations, if null nothing will be
written.t
- a Time
instance used to measure the elapsed time
EvaluationException
- if there was a mistake in evaluating the function
TerminationException
- if the termination condition is unknown
DimensionException
- if the dimension of the scope of the function and the array of arguments do not match
IOException
- if some mistakes in the IO happenedpublic static int conjugateGradientsPRP(DifferentiableFunction f, double[] currentValues, Optimizer.TerminationCondition terminationMode, double eps, double linEps, StartDistanceForecaster startDistance, SafeOutputStream out, Time t) throws DimensionException, TerminationException, IOException, EvaluationException
f
- the function to be minimizedcurrentValues
- at the begin the start vector and at the end the minimum vectorterminationMode
- the choice how to terminate the algorithmeps
- the bound for stopping the algorithmlinEps
- the bound for stopping the linear searchstartDistance
- the initial step for the linear searchout
- the SafeOutputStream for writing the some information about the iterations, if null nothing will be
written.t
- a Time
instance used to measure the elapsed time
EvaluationException
- if there was a mistake in evaluating the function
TerminationException
- if the termination condition is unknown
DimensionException
- if the dimension of the scope of the function and the array of arguments do not match
IOException
- if some mistakes in the IO happenedpublic static int quasiNewtonDFP(DifferentiableFunction f, double[] currentValues, Optimizer.TerminationCondition terminationMode, double eps, double linEps, StartDistanceForecaster startDistance, SafeOutputStream out, Time t) throws DimensionException, TerminationException, IOException, EvaluationException
f
- the function to be minimizedcurrentValues
- at the begin the start vector and at the end the minimum vectorterminationMode
- the choice how to terminate the algorithmeps
- the bound for stopping the algorithmlinEps
- the bound for stopping the linear searchstartDistance
- the initial step for the linear searchout
- the SafeOutputStream for writing the some information about the iterations, if null nothing will be
written.t
- a Time
instance used to measure the elapsed time
EvaluationException
- if there was a mistake in evaluating the function
TerminationException
- if the termination condition is unknown
DimensionException
- if the dimension of the scope of the function and the array of arguments do not match
IOException
- if some mistakes in the IO happenedpublic static int quasiNewtonBFGS(DifferentiableFunction f, double[] currentValues, Optimizer.TerminationCondition terminationMode, double eps, double linEps, StartDistanceForecaster startDistance, SafeOutputStream out, Time t) throws DimensionException, TerminationException, IOException, EvaluationException
f
- the function to be minimizedcurrentValues
- at the begin the start vector and at the end the minimum vectorterminationMode
- the choice how to terminate the algorithmeps
- the bound for stopping the algorithmlinEps
- the bound for stopping the linear searchstartDistance
- the initial step for the linear searchout
- the SafeOutputStream for writing the some information about the iterations, if null nothing will be
written.t
- a Time
instance used to measure the elapsed time
EvaluationException
- if there was a mistake in evaluating the function
TerminationException
- if the termination condition is unknown
DimensionException
- if the dimension of the scope of the function and the array of arguments do not match
IOException
- if some mistakes in the IO happenedpublic static int limitedMemoryBFGS(DifferentiableFunction f, double[] currentValues, byte m, Optimizer.TerminationCondition terminationMode, double eps, double linEps, StartDistanceForecaster startDistance, SafeOutputStream out, Time t) throws DimensionException, TerminationException, IOException, EvaluationException
f
- the function to be minimizedcurrentValues
- at the begin the start vector and at the end the minimum vectorm
- the current number of vectors used to approximated the Hessian, typically between 3 and 10terminationMode
- the choice how to terminate the algorithmeps
- the bound for stopping the algorithmlinEps
- the bound for stopping the linear searchstartDistance
- the initial step for the linear searchout
- the SafeOutputStream for writing the some information about the iterations, if null nothing will be
written.t
- a Time
instance used to measure the elapsed time
EvaluationException
- if there was a mistake in evaluating the function
TerminationException
- if the termination condition is unknown
DimensionException
- if the dimension of the scope of the function and the array of arguments do not match
IOException
- if some mistakes in the IO happenedpublic static int optimize(byte algorithm, DifferentiableFunction f, double[] currentValues, Optimizer.TerminationCondition terminationMode, double eps, double linEps, StartDistanceForecaster startDistance, SafeOutputStream out) throws DimensionException, TerminationException, IOException, EvaluationException
algorithm
.
algorithm
- the algorithm that should be used, use 2 < x > 11 for limitedMemoryBFGS
with
m=x
or the constants of the classf
- the function to be minimizedcurrentValues
- at the begin the start vector and at the end the minimum vectorterminationMode
- the choice how to terminate the algorithmeps
- the bound for stopping the algorithmlinEps
- the bound for stopping the linear searchstartDistance
- the initial step for the linear searchout
- the SafeOutputStream for writing the some information about the iterations, if null nothing will be
written.
EvaluationException
- if there was a mistake in evaluating the function
TerminationException
- if the termination condition is unknown
DimensionException
- if the dimension of the scope of the function and the array of arguments do not match
IOException
- if some mistakes in the IO happenedSTEEPEST_DESCENT
,
CONJUGATE_GRADIENTS_FR
,
CONJUGATE_GRADIENTS_PRP
,
QUASI_NEWTON_DFP
,
QUASI_NEWTON_BFGS
public static int optimize(byte algorithm, DifferentiableFunction f, double[] currentValues, Optimizer.TerminationCondition terminationMode, double eps, double linEps, StartDistanceForecaster startDistance, SafeOutputStream out, Time t) throws DimensionException, TerminationException, IOException, EvaluationException
algorithm
.
algorithm
- the algorithm that should be used, use 2 < x > 11 for limitedMemoryBFGS
with
m=x
or the constants of the classf
- the function to be minimizedcurrentValues
- at the begin the start vector and at the end the minimum vectorterminationMode
- the choice how to terminate the algorithmeps
- the bound for stopping the algorithmlinEps
- the bound for stopping the linear searchstartDistance
- the initial step for the linear searchout
- the SafeOutputStream for writing the some information about the iterations, if null nothing will be
written.t
- a Time
instance used to measure the elapsed time
EvaluationException
- if there was a mistake in evaluating the function
TerminationException
- if the termination condition is unknown
DimensionException
- if the dimension of the scope of the function and the array of arguments do not match
IOException
- if some mistakes in the IO happenedSTEEPEST_DESCENT
,
CONJUGATE_GRADIENTS_FR
,
CONJUGATE_GRADIENTS_PRP
,
QUASI_NEWTON_DFP
,
QUASI_NEWTON_BFGS
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |