Class AbstractUnivariateRealOptimizer
- java.lang.Object
-
- org.apache.commons.math.ConvergingAlgorithmImpl
-
- org.apache.commons.math.optimization.univariate.AbstractUnivariateRealOptimizer
-
- All Implemented Interfaces:
ConvergingAlgorithm,UnivariateRealOptimizer
- Direct Known Subclasses:
BrentOptimizer
public abstract class AbstractUnivariateRealOptimizer extends ConvergingAlgorithmImpl implements UnivariateRealOptimizer
Provide a default implementation for several functions useful to generic optimizers.- Since:
- 2.0
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intgetEvaluations()Get the number of evaluations of the objective function.doublegetFunctionValue()Get the result of the last run of the optimizer.GoalTypegetGoalType()doublegetMax()intgetMaxEvaluations()Get the maximal number of functions evaluations.doublegetMin()doublegetResult()Get the result of the last run of the optimizer.doublegetStartValue()doubleoptimize(UnivariateRealFunction f, GoalType goal, double min, double max)Find an optimum in the given interval.doubleoptimize(UnivariateRealFunction f, GoalType goal, double min, double max, double startValue)Find an optimum in the given interval, start at startValue.voidsetMaxEvaluations(int maxEvaluations)Set the maximal number of functions evaluations.-
Methods inherited from class org.apache.commons.math.ConvergingAlgorithmImpl
getAbsoluteAccuracy, getIterationCount, getMaximalIterationCount, getRelativeAccuracy, resetAbsoluteAccuracy, resetMaximalIterationCount, resetRelativeAccuracy, setAbsoluteAccuracy, setMaximalIterationCount, setRelativeAccuracy
-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.commons.math.ConvergingAlgorithm
getAbsoluteAccuracy, getIterationCount, getMaximalIterationCount, getRelativeAccuracy, resetAbsoluteAccuracy, resetMaximalIterationCount, resetRelativeAccuracy, setAbsoluteAccuracy, setMaximalIterationCount, setRelativeAccuracy
-
-
-
-
Method Detail
-
getResult
public double getResult()
Get the result of the last run of the optimizer.- Specified by:
getResultin interfaceUnivariateRealOptimizer- Returns:
- the optimum.
-
getFunctionValue
public double getFunctionValue() throws FunctionEvaluationExceptionGet the result of the last run of the optimizer.- Specified by:
getFunctionValuein interfaceUnivariateRealOptimizer- Returns:
- the value of the function at the optimum.
- Throws:
FunctionEvaluationException- if an error occurs evaluating the function.
-
setMaxEvaluations
public void setMaxEvaluations(int maxEvaluations)
Set the maximal number of functions evaluations.- Specified by:
setMaxEvaluationsin interfaceUnivariateRealOptimizer- Parameters:
maxEvaluations- maximal number of function evaluations
-
getMaxEvaluations
public int getMaxEvaluations()
Get the maximal number of functions evaluations.- Specified by:
getMaxEvaluationsin interfaceUnivariateRealOptimizer- Returns:
- the maximal number of functions evaluations.
-
getEvaluations
public int getEvaluations()
Get the number of evaluations of the objective function.The number of evaluations corresponds to the last call to the
optimizemethod. It is 0 if the method has not been called yet.- Specified by:
getEvaluationsin interfaceUnivariateRealOptimizer- Returns:
- the number of evaluations of the objective function.
-
getGoalType
public GoalType getGoalType()
- Returns:
- the optimization type.
-
getMin
public double getMin()
- Returns:
- the lower of the search interval.
-
getMax
public double getMax()
- Returns:
- the higher of the search interval.
-
getStartValue
public double getStartValue()
- Returns:
- the initial guess.
-
optimize
public double optimize(UnivariateRealFunction f, GoalType goal, double min, double max, double startValue) throws MaxIterationsExceededException, FunctionEvaluationException
Find an optimum in the given interval, start at startValue.An optimizer may require that the interval brackets a single optimum.
- Specified by:
optimizein interfaceUnivariateRealOptimizer- Parameters:
f- the function to optimize.goal- type of optimization goal: eitherGoalType.MAXIMIZEorGoalType.MINIMIZE.min- the lower bound for the interval.max- the upper bound for the interval.startValue- the start value to use.- Returns:
- a value where the function is optimum.
- Throws:
FunctionEvaluationException- if an error occurs evaluating the function.MaxIterationsExceededException
-
optimize
public double optimize(UnivariateRealFunction f, GoalType goal, double min, double max) throws MaxIterationsExceededException, FunctionEvaluationException
Find an optimum in the given interval.An optimizer may require that the interval brackets a single optimum.
- Specified by:
optimizein interfaceUnivariateRealOptimizer- Parameters:
f- the function to optimize.goal- type of optimization goal: eitherGoalType.MAXIMIZEorGoalType.MINIMIZE.min- the lower bound for the interval.max- the upper bound for the interval.- Returns:
- a value where the function is optimum.
- Throws:
FunctionEvaluationException- if an error occurs evaluating the function.MaxIterationsExceededException
-
-