org.apache.commons.math.optimization.univariate
Class AbstractUnivariateRealOptimizer

java.lang.Object
  extended by org.apache.commons.math.ConvergingAlgorithmImpl
      extended by 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
 int getEvaluations()
          Get the number of evaluations of the objective function.
 double getFunctionValue()
          Get the result of the last run of the optimizer.
 GoalType getGoalType()
           
 double getMax()
           
 int getMaxEvaluations()
          Get the maximal number of functions evaluations.
 double getMin()
           
 double getResult()
          Get the result of the last run of the optimizer.
 double getStartValue()
           
 double optimize(UnivariateRealFunction f, GoalType goal, double min, double max)
          Find an optimum in the given interval.
 double optimize(UnivariateRealFunction f, GoalType goal, double min, double max, double startValue)
          Find an optimum in the given interval, start at startValue.
 void setMaxEvaluations(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:
getResult in interface UnivariateRealOptimizer
Returns:
the optimum.

getFunctionValue

public double getFunctionValue()
                        throws FunctionEvaluationException
Get the result of the last run of the optimizer.

Specified by:
getFunctionValue in interface UnivariateRealOptimizer
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:
setMaxEvaluations in interface UnivariateRealOptimizer
Parameters:
maxEvaluations - maximal number of function evaluations

getMaxEvaluations

public int getMaxEvaluations()
Get the maximal number of functions evaluations.

Specified by:
getMaxEvaluations in interface UnivariateRealOptimizer
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 optimize method. It is 0 if the method has not been called yet.

Specified by:
getEvaluations in interface UnivariateRealOptimizer
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:
optimize in interface UnivariateRealOptimizer
Parameters:
f - the function to optimize.
goal - type of optimization goal: either GoalType.MAXIMIZE or GoalType.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:
optimize in interface UnivariateRealOptimizer
Parameters:
f - the function to optimize.
goal - type of optimization goal: either GoalType.MAXIMIZE or GoalType.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


jHepWork 3.1 ©