org.apache.commons.math.optimization.direct
Class BaseAbstractScalarOptimizer<FUNC extends MultivariateRealFunction>

java.lang.Object
  extended by org.apache.commons.math.optimization.direct.BaseAbstractScalarOptimizer<FUNC>
Type Parameters:
FUNC - Type of the objective function to be optimized
All Implemented Interfaces:
BaseMultivariateRealOptimizer<FUNC>, BaseOptimizer<RealPointValuePair>
Direct Known Subclasses:
AbstractScalarDifferentiableOptimizer, BOBYQAOptimizer, CMAESOptimizer, PowellOptimizer, SimplexOptimizer

public abstract class BaseAbstractScalarOptimizer<FUNC extends MultivariateRealFunction>
extends java.lang.Object
implements BaseMultivariateRealOptimizer<FUNC>

Base class for implementing optimizers for multivariate scalar functions. This base class handles the boiler-plate methods associated to thresholds settings, iterations and evaluations counting.

Since:
2.2
Version:
$Id$

Field Summary
protected  Incrementor evaluations
          Evaluations counter.
 
Constructor Summary
protected BaseAbstractScalarOptimizer()
          Simple constructor with default settings.
protected BaseAbstractScalarOptimizer(ConvergenceChecker<RealPointValuePair> checker)
           
 
Method Summary
protected  double computeObjectiveValue(double[] point)
          Compute the objective function value.
protected abstract  RealPointValuePair doOptimize()
          Perform the bulk of the optimization algorithm.
 ConvergenceChecker<RealPointValuePair> getConvergenceChecker()
          Get the convergence checker.
 int getEvaluations()
          Get the number of evaluations of the objective function.
 GoalType getGoalType()
           
 int getMaxEvaluations()
          Get the maximal number of function evaluations.
 double[] getStartPoint()
           
 RealPointValuePair optimize(int maxEval, FUNC f, GoalType goalType, double[] startPoint)
          Optimize an objective function.
 void setConvergenceChecker(ConvergenceChecker<RealPointValuePair> convergenceChecker)
          Set the convergence checker.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

evaluations

protected final Incrementor evaluations
Evaluations counter.

Constructor Detail

BaseAbstractScalarOptimizer

protected BaseAbstractScalarOptimizer()
Simple constructor with default settings. The convergence check is set to a SimpleScalarValueChecker and the allowed number of evaluations is set to Integer.MAX_VALUE.


BaseAbstractScalarOptimizer

protected BaseAbstractScalarOptimizer(ConvergenceChecker<RealPointValuePair> checker)
Parameters:
checker - Convergence checker.
Method Detail

getMaxEvaluations

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

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

setConvergenceChecker

public void setConvergenceChecker(ConvergenceChecker<RealPointValuePair> convergenceChecker)
Set the convergence checker.

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

getConvergenceChecker

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

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

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 the specified point.
Throws:
TooManyEvaluationsException - if the maximal number of evaluations is exceeded.

optimize

public RealPointValuePair optimize(int maxEval,
                                   FUNC f,
                                   GoalType goalType,
                                   double[] startPoint)
Optimize an objective function.

Specified by:
optimize in interface BaseMultivariateRealOptimizer<FUNC extends MultivariateRealFunction>
Parameters:
maxEval - Maximum number of function evaluations.
f - Objective function.
goalType - Type of optimization goal: either GoalType.MAXIMIZE or GoalType.MINIMIZE.
startPoint - Start point for optimization.
Returns:
the point/value pair giving the optimal value for objective function.

getGoalType

public GoalType getGoalType()
Returns:
the optimization type.

getStartPoint

public double[] getStartPoint()
Returns:
the initial guess.

doOptimize

protected abstract RealPointValuePair doOptimize()
Perform the bulk of the optimization algorithm.

Returns:
the point/value pair giving the optimal value for the objective function.


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