Class QuasiNewtonMultiOptimizer
java.lang.Object
com.irurueta.numerical.optimization.Optimizer
com.irurueta.numerical.optimization.MultiOptimizer
com.irurueta.numerical.optimization.QuasiNewtonMultiOptimizer
This class searches for a multi dimension function local minimum.
The local minimum is searched by starting the algorithm at a start point
The implementation of this class is based on Numerical Recipes 3rd ed.
Section 10.9 page 521.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final double
static final double
Constant defining default tolerance or accuracy to be achieved on the minimum being estimated by this class.static final double
Machine precision.(package private) double
value of the function at the minimum.(package private) GradientFunctionEvaluatorListener
Listener to obtain gradient values for the multi dimension function being evaluated.private int
Member contains number of iterations that were needed to estimate a minimum.static final int
Maximum number of iterations.static final double
Minimum allowed tolerance value.private double[]
n-dimensional start point.static final double
Scaled maximum step length allowed in line searches.private double
The fractional tolerance in the function value such that failure to decrease by more than this amount on one iteration signals done-ness.static final double
Convergence criterion on x values.static final double
Fields inherited from class com.irurueta.numerical.optimization.MultiOptimizer
fmin, listener, resultAvailable, xmin
Fields inherited from class com.irurueta.numerical.optimization.Optimizer
iterationCompletedListener, locked
-
Constructor Summary
ConstructorsConstructorDescriptionEmpty constructor.QuasiNewtonMultiOptimizer
(MultiDimensionFunctionEvaluatorListener listener, GradientFunctionEvaluatorListener gradientListener, double tolerance) Constructor.QuasiNewtonMultiOptimizer
(MultiDimensionFunctionEvaluatorListener listener, GradientFunctionEvaluatorListener gradientListener, double[] startPoint, double tolerance) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionReturns gradient listener in charge of obtaining gradient values for the function to be evaluated.int
Return number of iterations that were needed to estimate a minimum.double[]
Returns start point where algorithm will be started.double
Returns tolerance or accuracy to be expected on estimated local minimum.private void
internalSetTolerance
(double tolerance) Internal method to set tolerance or accuracy to be expected on estimated local minimum.boolean
Returns boolean indicating whether a gradient listener has already been provided and is available for retrieval.boolean
isReady()
Returns boolean indicating whether this instance is ready to start the estimation of a local minimum.boolean
Returns boolean indicating whether start point has already been provided and is ready for retrieval.private void
lnsrch
(double[] xold, double fold, double[] g, double[] p, double[] x, double[] f, double stpmax, boolean[] check) Internal method to search for a minimum along a line.void
minimize()
This function estimates a function minimum.void
setGradientListener
(GradientFunctionEvaluatorListener gradientListener) Sets gradient listener in charge of obtaining gradient values for the function to be evaluated.void
setStartPoint
(double[] startPoint) Sets start point where algorithm will be started.void
setTolerance
(double tolerance) Sets tolerance or accuracy to be expected on estimated local minimum.private double
sqr
(double x) Computes the squared value of provided double.Methods inherited from class com.irurueta.numerical.optimization.MultiOptimizer
getEvaluationAtResult, getListener, getResult, isListenerAvailable, isResultAvailable, setListener
Methods inherited from class com.irurueta.numerical.optimization.Optimizer
getOnIterationCompletedListener, isLocked, setOnIterationCompletedListener
-
Field Details
-
ITMAX
public static final int ITMAXMaximum number of iterations.- See Also:
-
EPS
public static final double EPSMachine precision.- See Also:
-
TOLX
public static final double TOLXConvergence criterion on x values.- See Also:
-
STPMX
public static final double STPMXScaled maximum step length allowed in line searches.- See Also:
-
ALF
public static final double ALF- See Also:
-
TOLX2
public static final double TOLX2- See Also:
-
DEFAULT_TOLERANCE
public static final double DEFAULT_TOLERANCEConstant defining default tolerance or accuracy to be achieved on the minimum being estimated by this class.- See Also:
-
MIN_TOLERANCE
public static final double MIN_TOLERANCEMinimum allowed tolerance value.- See Also:
-
p
private double[] pn-dimensional start point. -
tolerance
private double toleranceThe fractional tolerance in the function value such that failure to decrease by more than this amount on one iteration signals done-ness. -
iter
private int iterMember contains number of iterations that were needed to estimate a minimum. -
gradientListener
GradientFunctionEvaluatorListener gradientListenerListener to obtain gradient values for the multi dimension function being evaluated. If the gradient is unknown (e.g. doesn't have a closed expression), the provided listener could use a GradientEstimator to obtain one. -
fret
double fretvalue of the function at the minimum.
-
-
Constructor Details
-
QuasiNewtonMultiOptimizer
public QuasiNewtonMultiOptimizer()Empty constructor. -
QuasiNewtonMultiOptimizer
public QuasiNewtonMultiOptimizer(MultiDimensionFunctionEvaluatorListener listener, GradientFunctionEvaluatorListener gradientListener, double tolerance) Constructor.- Parameters:
listener
- Listener to evaluate a multidimensional function.gradientListener
- Listener to obtain gradient value for the multidimensional function being evaluated.tolerance
- Tolerance or accuracy to be expected on estimated local minimum.- Throws:
IllegalArgumentException
- Raised if tolerance is negative.
-
QuasiNewtonMultiOptimizer
public QuasiNewtonMultiOptimizer(MultiDimensionFunctionEvaluatorListener listener, GradientFunctionEvaluatorListener gradientListener, double[] startPoint, double tolerance) Constructor.- Parameters:
listener
- Listener to evaluate a multidimensional function.gradientListener
- Listener to obtain gradient value for the multidimensional function being evaluated.startPoint
- Start point where algorithm will be started. Start point should be close to the local minimum to be found. Provided array must have a length equal to the number of dimensions of the function being evaluated, otherwise and exception will be raised when searching for the minimum.tolerance
- Tolerance or accuracy to be expected on estimated local minimum.- Throws:
IllegalArgumentException
- Raised if tolerance is negative.
-
-
Method Details
-
minimize
This function estimates a function minimum. Implementations of this class will usually search a local minimum close to a start point. Given a starting point p[0..n-1], the Broyden-Fletcher-Goldfarb-Sharno variant of Davidon Fletcher-Powell minimization is performed on a function whose value and gradient are provided by respective listeners. The convergence requirement on zeroing the gradient is provided by tolerance. This method estimates the location of the minimum, sets the number of iterations that were required and the minimum value of the function at the minimum. The internal method lnsrch is called within this method to perform approximate line minimizations.- Overrides:
minimize
in classOptimizer
- Throws:
LockedException
- Raised if this instance is locked, because estimation is being computed.NotReadyException
- Raised if this instance is not ready, because a listener, a gradient listener and a start point haven't been providedOptimizationException
- Raised if the algorithm failed because of lack of convergence or because function couldn't be evaluated.
-
isReady
public boolean isReady()Returns boolean indicating whether this instance is ready to start the estimation of a local minimum. An instance is ready once a listener, a gradient listener and a start point are provided.- Overrides:
isReady
in classMultiOptimizer
- Returns:
- True if this instance is ready, false otherwise.
-
getTolerance
public double getTolerance()Returns tolerance or accuracy to be expected on estimated local minimum.- Returns:
- Tolerance or accuracy to be expected on estimated local minimum.
-
internalSetTolerance
private void internalSetTolerance(double tolerance) Internal method to set tolerance or accuracy to be expected on estimated local minimum. This method does not check whether this instance is locked.- Parameters:
tolerance
- Tolerance or accuracy to be expected on estimated local minimum.- Throws:
IllegalArgumentException
- Raised if provided tolerance is negative.
-
setTolerance
Sets tolerance or accuracy to be expected on estimated local minimum.- Parameters:
tolerance
- Tolerance or accuracy to be expected on estimated local minimum.- Throws:
LockedException
- Raised if this instance is locked.IllegalArgumentException
- Raised if provided tolerance is negative.
-
isStartPointAvailable
public boolean isStartPointAvailable()Returns boolean indicating whether start point has already been provided and is ready for retrieval.- Returns:
- True if available, false otherwise.
-
setStartPoint
Sets start point where algorithm will be started. Start point should be close to the local minimum to be found.- Parameters:
startPoint
- Start point where algorithm will be started.- Throws:
LockedException
- Raised if this instance is locked.
-
getStartPoint
Returns start point where algorithm will be started. Start point should be close to the local minimum to be found.- Returns:
- Start point where algorithm will be started.
- Throws:
NotAvailableException
- Raised if start point has not yet been provided and is not available.
-
getGradientListener
Returns gradient listener in charge of obtaining gradient values for the function to be evaluated.- Returns:
- Gradient listener.
- Throws:
NotAvailableException
- Raised if gradient listener has not yet been provided.
-
setGradientListener
public void setGradientListener(GradientFunctionEvaluatorListener gradientListener) throws LockedException Sets gradient listener in charge of obtaining gradient values for the function to be evaluated.- Parameters:
gradientListener
- Gradient listener.- Throws:
LockedException
- Raised if this instance is locked.
-
isGradientListenerAvailable
public boolean isGradientListenerAvailable()Returns boolean indicating whether a gradient listener has already been provided and is available for retrieval.- Returns:
- True if available, false otherwise.
-
getIterations
public int getIterations()Return number of iterations that were needed to estimate a minimum.- Returns:
- number of iterations that were needed.
-
sqr
private double sqr(double x) Computes the squared value of provided double.- Parameters:
x
- Value to be squared.- Returns:
- Squared value.
-
lnsrch
private void lnsrch(double[] xold, double fold, double[] g, double[] p, double[] x, double[] f, double stpmax, boolean[] check) throws OptimizationException Internal method to search for a minimum along a line. NOTE: comments of params might be incorrect.- Parameters:
xold
- previous point.fold
- previous function evaluation.g
- gradient.p
- point.x
- point.f
- function.stpmax
- stores point maximum.check
- checks line search.- Throws:
OptimizationException
- Raised if convergence was not achieved.
-