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

java.lang.Object
  extended by org.apache.commons.math.optimization.univariate.AbstractUnivariateRealOptimizer
All Implemented Interfaces:
BaseOptimizer<UnivariateRealPointValuePair>, BaseUnivariateRealOptimizer<UnivariateRealFunction>, UnivariateRealOptimizer
Direct Known Subclasses:
BrentOptimizer

public abstract class AbstractUnivariateRealOptimizer
extends java.lang.Object
implements UnivariateRealOptimizer

Provide a default implementation for several functions useful to generic optimizers.

Since:
2.0
Version:
$Id: AbstractUnivariateRealOptimizer.java 1166311 2011-09-07 18:48:06Z luc $

Constructor Summary
AbstractUnivariateRealOptimizer()
           
 
Method Summary
protected  double computeObjectiveValue(double point)
          Compute the objective function value.
protected abstract  UnivariateRealPointValuePair doOptimize()
          Method for implementing actual optimization algorithms in derived classes.
 ConvergenceChecker<UnivariateRealPointValuePair> getConvergenceChecker()
          Get the convergence checker.
 int getEvaluations()
          Get the number of evaluations of the objective function.
 GoalType getGoalType()
           
 double getMax()
           
 int getMaxEvaluations()
          Get the maximal number of function evaluations.
 double getMin()
           
 double getStartValue()
           
 UnivariateRealPointValuePair optimize(int maxEval, UnivariateRealFunction f, GoalType goalType, double min, double max)
          Find an optimum in the given interval.
 UnivariateRealPointValuePair optimize(int maxEval, UnivariateRealFunction f, GoalType goalType, double min, double max, double startValue)
          Find an optimum in the given interval, start at startValue.
 void setConvergenceChecker(ConvergenceChecker<UnivariateRealPointValuePair> c)
          Set the convergence checker.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractUnivariateRealOptimizer

public AbstractUnivariateRealOptimizer()
Method Detail

getMaxEvaluations

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

Specified by:
getMaxEvaluations in interface BaseOptimizer<UnivariateRealPointValuePair>
Returns:
the maximal number of function 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 BaseOptimizer<UnivariateRealPointValuePair>
Returns:
the number of evaluations of the objective function.

getGoalType

public GoalType getGoalType()
Returns:
the optimization type.

getMin

public double getMin()
Returns:
the lower end of the search interval.

getMax

public double getMax()
Returns:
the higher end of the search interval.

getStartValue

public double getStartValue()
Returns:
the initial guess.

computeObjectiveValue

protected double computeObjectiveValue(double point)
Compute the objective function value.

Parameters:
point - Point at which the objective function must be evaluated.
Returns:
the objective function value at specified point.
Throws:
TooManyEvaluationsException - if the maximal number of evaluations is exceeded.

optimize

public UnivariateRealPointValuePair optimize(int maxEval,
                                             UnivariateRealFunction f,
                                             GoalType goalType,
                                             double min,
                                             double max,
                                             double startValue)
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 BaseUnivariateRealOptimizer<UnivariateRealFunction>
Parameters:
maxEval - Maximum number of function evaluations.
f - Function to optimize.
goalType - Type of optimization goal: either GoalType.MAXIMIZE or GoalType.MINIMIZE.
min - Lower bound for the interval.
max - Upper bound for the interval.
startValue - Start value to use.
Returns:
a (point, value) pair where the function is optimum.

optimize

public UnivariateRealPointValuePair optimize(int maxEval,
                                             UnivariateRealFunction f,
                                             GoalType goalType,
                                             double min,
                                             double max)
Find an optimum in the given interval. An optimizer may require that the interval brackets a single optimum.

Specified by:
optimize in interface BaseUnivariateRealOptimizer<UnivariateRealFunction>
Parameters:
maxEval - Maximum number of function evaluations.
f - Function to optimize.
goalType - Type of optimization goal: either GoalType.MAXIMIZE or GoalType.MINIMIZE.
min - Lower bound for the interval.
max - Upper bound for the interval.
Returns:
a (point, value) pair where the function is optimum.

setConvergenceChecker

public void setConvergenceChecker(ConvergenceChecker<UnivariateRealPointValuePair> c)
Set the convergence checker.

Specified by:
setConvergenceChecker in interface BaseOptimizer<UnivariateRealPointValuePair>
Parameters:
c - Object to use to check for convergence.

getConvergenceChecker

public ConvergenceChecker<UnivariateRealPointValuePair> getConvergenceChecker()
Get the convergence checker.

Specified by:
getConvergenceChecker in interface BaseOptimizer<UnivariateRealPointValuePair>
Returns:
the object used to check for convergence.

doOptimize

protected abstract UnivariateRealPointValuePair doOptimize()
Method for implementing actual optimization algorithms in derived classes.

Returns:
the optimum and its corresponding function value.
Throws:
TooManyEvaluationsException - if the maximal number of evaluations is exceeded.


Copyright © 2003-2011 The Apache Software Foundation. All Rights Reserved.