org.apache.commons.math3.optimization.general
Class NonLinearConjugateGradientOptimizer

java.lang.Object
  extended by org.apache.commons.math3.optimization.direct.BaseAbstractMultivariateOptimizer<DifferentiableMultivariateFunction>
      extended by org.apache.commons.math3.optimization.general.AbstractScalarDifferentiableOptimizer
          extended by org.apache.commons.math3.optimization.general.NonLinearConjugateGradientOptimizer
All Implemented Interfaces:
BaseMultivariateOptimizer<DifferentiableMultivariateFunction>, BaseOptimizer<PointValuePair>, DifferentiableMultivariateOptimizer

public class NonLinearConjugateGradientOptimizer
extends AbstractScalarDifferentiableOptimizer

Non-linear conjugate gradient optimizer.

This class supports both the Fletcher-Reeves and the Polak-Ribière update formulas for the conjugate search directions. It also supports optional preconditioning.

Since:
2.0
Version:
$Id: NonLinearConjugateGradientOptimizer.java 1244107 2012-02-14 16:17:55Z erans $

Nested Class Summary
static class NonLinearConjugateGradientOptimizer.IdentityPreconditioner
          Default identity preconditioner.
private  class NonLinearConjugateGradientOptimizer.LineSearchFunction
          Internal class for line search.
 
Field Summary
private  double initialStep
          Initial step used to bracket the optimum in line search.
private  double[] point
          Current point.
private  Preconditioner preconditioner
          Preconditioner (may be null).
private  UnivariateSolver solver
          solver to use in the line search (may be null).
private  ConjugateGradientFormula updateFormula
          Update formula for the beta parameter.
 
Fields inherited from class org.apache.commons.math3.optimization.direct.BaseAbstractMultivariateOptimizer
evaluations
 
Constructor Summary
NonLinearConjugateGradientOptimizer(ConjugateGradientFormula updateFormula)
          Constructor with default checker, line search solver and preconditioner.
NonLinearConjugateGradientOptimizer(ConjugateGradientFormula updateFormula, ConvergenceChecker<PointValuePair> checker)
          Constructor with default line search solver and preconditioner.
NonLinearConjugateGradientOptimizer(ConjugateGradientFormula updateFormula, ConvergenceChecker<PointValuePair> checker, UnivariateSolver lineSearchSolver)
          Constructor with default preconditioner.
NonLinearConjugateGradientOptimizer(ConjugateGradientFormula updateFormula, ConvergenceChecker<PointValuePair> checker, UnivariateSolver lineSearchSolver, Preconditioner preconditioner)
           
 
Method Summary
protected  PointValuePair doOptimize()
          Perform the bulk of the optimization algorithm.
private  double findUpperBound(UnivariateFunction f, double a, double h)
          Find the upper bound b ensuring bracketing of a root between a and b.
 void setInitialStep(double initialStep)
          Set the initial step used to bracket the optimum in line search.
 
Methods inherited from class org.apache.commons.math3.optimization.general.AbstractScalarDifferentiableOptimizer
computeObjectiveGradient, optimize
 
Methods inherited from class org.apache.commons.math3.optimization.direct.BaseAbstractMultivariateOptimizer
computeObjectiveValue, getConvergenceChecker, getEvaluations, getGoalType, getMaxEvaluations, getStartPoint
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.commons.math3.optimization.BaseOptimizer
getConvergenceChecker, getEvaluations, getMaxEvaluations
 

Field Detail

updateFormula

private final ConjugateGradientFormula updateFormula
Update formula for the beta parameter.


preconditioner

private final Preconditioner preconditioner
Preconditioner (may be null).


solver

private final UnivariateSolver solver
solver to use in the line search (may be null).


initialStep

private double initialStep
Initial step used to bracket the optimum in line search.


point

private double[] point
Current point.

Constructor Detail

NonLinearConjugateGradientOptimizer

public NonLinearConjugateGradientOptimizer(ConjugateGradientFormula updateFormula)
Constructor with default checker, line search solver and preconditioner.

Parameters:
updateFormula - formula to use for updating the β parameter, must be one of ConjugateGradientFormula.FLETCHER_REEVES or ConjugateGradientFormula.POLAK_RIBIERE.

NonLinearConjugateGradientOptimizer

public NonLinearConjugateGradientOptimizer(ConjugateGradientFormula updateFormula,
                                           ConvergenceChecker<PointValuePair> checker)
Constructor with default line search solver and preconditioner.

Parameters:
updateFormula - formula to use for updating the β parameter, must be one of ConjugateGradientFormula.FLETCHER_REEVES or ConjugateGradientFormula.POLAK_RIBIERE.
checker - Convergence checker.

NonLinearConjugateGradientOptimizer

public NonLinearConjugateGradientOptimizer(ConjugateGradientFormula updateFormula,
                                           ConvergenceChecker<PointValuePair> checker,
                                           UnivariateSolver lineSearchSolver)
Constructor with default preconditioner.

Parameters:
updateFormula - formula to use for updating the β parameter, must be one of ConjugateGradientFormula.FLETCHER_REEVES or ConjugateGradientFormula.POLAK_RIBIERE.
checker - Convergence checker.
lineSearchSolver - Solver to use during line search.

NonLinearConjugateGradientOptimizer

public NonLinearConjugateGradientOptimizer(ConjugateGradientFormula updateFormula,
                                           ConvergenceChecker<PointValuePair> checker,
                                           UnivariateSolver lineSearchSolver,
                                           Preconditioner preconditioner)
Parameters:
updateFormula - formula to use for updating the β parameter, must be one of ConjugateGradientFormula.FLETCHER_REEVES or ConjugateGradientFormula.POLAK_RIBIERE.
checker - Convergence checker.
lineSearchSolver - Solver to use during line search.
preconditioner - Preconditioner.
Method Detail

setInitialStep

public void setInitialStep(double initialStep)
Set the initial step used to bracket the optimum in line search.

The initial step is a factor with respect to the search direction, which itself is roughly related to the gradient of the function

Parameters:
initialStep - initial step used to bracket the optimum in line search, if a non-positive value is used, the initial step is reset to its default value of 1.0

doOptimize

protected PointValuePair doOptimize()
Perform the bulk of the optimization algorithm.

Specified by:
doOptimize in class BaseAbstractMultivariateOptimizer<DifferentiableMultivariateFunction>
Returns:
the point/value pair giving the optimal value for the objective function.

findUpperBound

private double findUpperBound(UnivariateFunction f,
                              double a,
                              double h)
Find the upper bound b ensuring bracketing of a root between a and b.

Parameters:
f - function whose root must be bracketed.
a - lower bound of the interval.
h - initial step to try.
Returns:
b such that f(a) and f(b) have opposite signs.
Throws:
MathIllegalStateException - if no bracket can be found.


Copyright (c) 2003-2013 Apache Software Foundation