Top Description Inners Fields Constructors Methods
org.apache.commons.math3.optim.nonlinear.scalar.gradient

public Class NonLinearConjugateGradientOptimizer

extends GradientMultivariateOptimizer
Class Inheritance
Imports
org.apache.commons.math3.analysis.solvers.UnivariateSolver, org.apache.commons.math3.exception.MathInternalError, .TooManyEvaluationsException, .MathUnsupportedOperationException, org.apache.commons.math3.exception.util.LocalizedFormats, org.apache.commons.math3.optim.OptimizationData, .PointValuePair, .ConvergenceChecker, org.apache.commons.math3.optim.nonlinear.scalar.GoalType, .GradientMultivariateOptimizer, .LineSearch

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.
Constraints are not supported: the call to optimize will throw MathUnsupportedOperationException if bounds are passed to it.
Since
2.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
NonLinearConjugateGradientOptimizer.BracketingStep

Deprecated As of v3.3, this class is not used anymore. This setting is replaced by the initialBracketingRange argument to the new constructors.
The initial step is a factor with respect to the search direction (which itself is roughly related to the gradient of the function).
public static enum
NonLinearConjugateGradientOptimizer.Formula

Available choices of update formulas for the updating the parameter that is used to compute the successive conjugate search directions.

public static class

Field Summary

Modifier and TypeField and Description
private final LineSearch
line

Line search algorithm.

private final Preconditioner
preconditioner

Preconditioner (may be null).

private final NonLinearConjugateGradientOptimizer.Formula
updateFormula

Update formula for the beta parameter.

Constructor Summary

AccessConstructor and Description
public
NonLinearConjugateGradientOptimizer(final NonLinearConjugateGradientOptimizer.Formula
formula to use for updating the β parameter, must be one of Formula#FLETCHER_REEVES or Formula#POLAK_RIBIERE.
updateFormula
,
ConvergenceChecker<PointValuePair>
Convergence checker.
checker
)

Constructor with default tolerances for the line search (1e-8) and preconditioner.

public
NonLinearConjugateGradientOptimizer(final NonLinearConjugateGradientOptimizer.Formula
formula to use for updating the β parameter, must be one of Formula#FLETCHER_REEVES or Formula#POLAK_RIBIERE.
updateFormula
,
ConvergenceChecker<PointValuePair>
Convergence checker.
checker
,
final UnivariateSolver
Solver to use during line search.
lineSearchSolver
)
Deprecated as of 3.3.

Constructor with default preconditioner.

public
NonLinearConjugateGradientOptimizer(final NonLinearConjugateGradientOptimizer.Formula
formula to use for updating the β parameter, must be one of Formula#FLETCHER_REEVES or Formula#POLAK_RIBIERE.
updateFormula
,
ConvergenceChecker<PointValuePair>
Convergence checker.
checker
,
double
Relative threshold for line search.
relativeTolerance
,
double
Absolute threshold for line search.
absoluteTolerance
,
double
Extent of the initial interval used to find an interval that brackets the optimum in order to perform the line search.
initialBracketingRange
)

Constructor with default preconditioner.

public
NonLinearConjugateGradientOptimizer(final NonLinearConjugateGradientOptimizer.Formula
formula to use for updating the β parameter, must be one of Formula#FLETCHER_REEVES or Formula#POLAK_RIBIERE.
updateFormula
,
ConvergenceChecker<PointValuePair>
Convergence checker.
checker
,
final UnivariateSolver
Solver to use during line search.
lineSearchSolver
,
final Preconditioner
Preconditioner.
preconditioner
)
Deprecated as of 3.3.

public
NonLinearConjugateGradientOptimizer(final NonLinearConjugateGradientOptimizer.Formula
formula to use for updating the β parameter, must be one of Formula#FLETCHER_REEVES or Formula#POLAK_RIBIERE.
updateFormula
,
ConvergenceChecker<PointValuePair>
Convergence checker.
checker
,
double
Relative threshold for line search.
relativeTolerance
,
double
Absolute threshold for line search.
absoluteTolerance
,
double
Extent of the initial interval used to find an interval that brackets the optimum in order to perform the line search.
initialBracketingRange
,
final Preconditioner
Preconditioner.
preconditioner
)

Method Summary

Modifier and TypeMethod and Description
private void
protected PointValuePair
doOptimize()

Implements abstract org.apache.commons.math3.optim.BaseOptimizer.doOptimize.

Performs the bulk of the optimization algorithm.

public PointValuePair
optimize(OptimizationData...
Optimization data. In addition to those documented in MultivariateOptimizer, this method will register the following data:
optData
)

Overrides org.apache.commons.math3.optim.nonlinear.scalar.GradientMultivariateOptimizer.optimize.

Stores data and performs the optimization.

protected void
parseOptimizationData(OptimizationData...
Optimization data. The following data will be looked for:
optData
)

Overrides org.apache.commons.math3.optim.nonlinear.scalar.GradientMultivariateOptimizer.parseOptimizationData.

Scans the list of (required and optional) optimization data that characterize the problem.

Inherited from org.apache.commons.math3.optim.nonlinear.scalar.GradientMultivariateOptimizer:
computeObjectiveGradient

Field Detail

lineback to summary
private final LineSearch line

Line search algorithm.

preconditionerback to summary
private final Preconditioner preconditioner

Preconditioner (may be null).

updateFormulaback to summary
private final NonLinearConjugateGradientOptimizer.Formula updateFormula

Update formula for the beta parameter.

Constructor Detail

NonLinearConjugateGradientOptimizerback to summary
public NonLinearConjugateGradientOptimizer(final NonLinearConjugateGradientOptimizer.Formula updateFormula, ConvergenceChecker<PointValuePair> checker)

Constructor with default tolerances for the line search (1e-8) and preconditioner.

Parameters
updateFormula:NonLinearConjugateGradientOptimizer.Formula

formula to use for updating the β parameter, must be one of Formula#FLETCHER_REEVES or Formula#POLAK_RIBIERE.

checker:ConvergenceChecker<PointValuePair>

Convergence checker.

NonLinearConjugateGradientOptimizerback to summary
public NonLinearConjugateGradientOptimizer(final NonLinearConjugateGradientOptimizer.Formula updateFormula, ConvergenceChecker<PointValuePair> checker, final UnivariateSolver lineSearchSolver)

Constructor with default preconditioner.

Parameters
updateFormula:NonLinearConjugateGradientOptimizer.Formula

formula to use for updating the β parameter, must be one of Formula#FLETCHER_REEVES or Formula#POLAK_RIBIERE.

checker:ConvergenceChecker<PointValuePair>

Convergence checker.

lineSearchSolver:UnivariateSolver

Solver to use during line search.

Annotations
@Deprecated
NonLinearConjugateGradientOptimizerback to summary
public NonLinearConjugateGradientOptimizer(final NonLinearConjugateGradientOptimizer.Formula updateFormula, ConvergenceChecker<PointValuePair> checker, double relativeTolerance, double absoluteTolerance, double initialBracketingRange)

Constructor with default preconditioner.

Parameters
updateFormula:NonLinearConjugateGradientOptimizer.Formula

formula to use for updating the β parameter, must be one of Formula#FLETCHER_REEVES or Formula#POLAK_RIBIERE.

checker:ConvergenceChecker<PointValuePair>

Convergence checker.

relativeTolerance:double

Relative threshold for line search.

absoluteTolerance:double

Absolute threshold for line search.

initialBracketingRange:double

Extent of the initial interval used to find an interval that brackets the optimum in order to perform the line search.

Since
3.3
See Also
LineSearch#LineSearch(MultivariateOptimizer, double, double, double)
NonLinearConjugateGradientOptimizerback to summary
public NonLinearConjugateGradientOptimizer(final NonLinearConjugateGradientOptimizer.Formula updateFormula, ConvergenceChecker<PointValuePair> checker, final UnivariateSolver lineSearchSolver, final Preconditioner preconditioner)
Parameters
updateFormula:NonLinearConjugateGradientOptimizer.Formula

formula to use for updating the β parameter, must be one of Formula#FLETCHER_REEVES or Formula#POLAK_RIBIERE.

checker:ConvergenceChecker<PointValuePair>

Convergence checker.

lineSearchSolver:UnivariateSolver

Solver to use during line search.

preconditioner:Preconditioner

Preconditioner.

Annotations
@Deprecated
NonLinearConjugateGradientOptimizerback to summary
public NonLinearConjugateGradientOptimizer(final NonLinearConjugateGradientOptimizer.Formula updateFormula, ConvergenceChecker<PointValuePair> checker, double relativeTolerance, double absoluteTolerance, double initialBracketingRange, final Preconditioner preconditioner)
Parameters
updateFormula:NonLinearConjugateGradientOptimizer.Formula

formula to use for updating the β parameter, must be one of Formula#FLETCHER_REEVES or Formula#POLAK_RIBIERE.

checker:ConvergenceChecker<PointValuePair>

Convergence checker.

relativeTolerance:double

Relative threshold for line search.

absoluteTolerance:double

Absolute threshold for line search.

initialBracketingRange:double

Extent of the initial interval used to find an interval that brackets the optimum in order to perform the line search.

preconditioner:Preconditioner

Preconditioner.

Since
3.3
See Also
LineSearch#LineSearch(MultivariateOptimizer, double, double, double)

Method Detail

checkParametersback to summary
private void checkParameters()

Hides org.apache.commons.math3.optim.BaseMultivariateOptimizer.checkParameters.

Doc from org.apache.commons.math3.optim.BaseMultivariateOptimizer.checkParameters.

Check parameters consistency.

Exceptions
MathUnsupportedOperationException:
if bounds were passed to the optimize method.
doOptimizeback to summary
protected PointValuePair doOptimize()

Implements abstract org.apache.commons.math3.optim.BaseOptimizer.doOptimize.

Doc from org.apache.commons.math3.optim.BaseOptimizer.doOptimize.

Performs the bulk of the optimization algorithm.

Returns:PointValuePair

the point/value pair giving the optimal value of the objective function.

Annotations
@Override
optimizeback to summary
public PointValuePair optimize(OptimizationData... optData) throws TooManyEvaluationsException

Overrides org.apache.commons.math3.optim.nonlinear.scalar.GradientMultivariateOptimizer.optimize.

Doc from org.apache.commons.math3.optim.nonlinear.scalar.GradientMultivariateOptimizer.optimize.

Stores data and performs the optimization.

The list of parameters is open-ended so that sub-classes can extend it with arguments specific to their concrete implementations.

When the method is called multiple times, instance data is overwritten only when actually present in the list of arguments: when not specified, data set in a previous call is retained (and thus is optional in subsequent calls).

Important Note

Subclasses must override parseOptimizationData(OptimizationData[]) if they need to register their own options; but then, they must also call super.parseOptimizationData(optData) within that method.

Parameters
optData:OptimizationData[]

Optimization data. In addition to those documented in MultivariateOptimizer, this method will register the following data:

Returns:PointValuePair

a point/value pair that satisfies the convergence criteria.

Annotations
@Override
Exceptions
TooManyEvaluationsException:
if the maximal number of evaluations (of the objective function) is exceeded.
parseOptimizationDataback to summary
protected void parseOptimizationData(OptimizationData... optData)

Overrides org.apache.commons.math3.optim.nonlinear.scalar.GradientMultivariateOptimizer.parseOptimizationData.

Doc from org.apache.commons.math3.optim.nonlinear.scalar.GradientMultivariateOptimizer.parseOptimizationData.

Scans the list of (required and optional) optimization data that characterize the problem.

Parameters
optData:OptimizationData[]

Optimization data. The following data will be looked for:

Annotations
@Override
org.apache.commons.math3.optim.nonlinear.scalar.gradient back to summary

public Class NonLinearConjugateGradientOptimizer.BracketingStep

extends Object
implements OptimizationData
Class Inheritance
  • java.lang.Object
  • org.apache.commons.math3.optim.nonlinear.scalar.gradient.NonLinearConjugateGradientOptimizer.BracketingStep
All Implemented Interfaces
org.apache.commons.math3.optim.OptimizationData
Annotations
@Deprecated

Deprecated

As of v3.3, this class is not used anymore. This setting is replaced by the initialBracketingRange argument to the new constructors.

The initial step is a factor with respect to the search direction (which itself is roughly related to the gradient of the function).
It is used to find an interval that brackets the optimum in line search.
Since
3.1

Field Summary

Modifier and TypeField and Description
private final double
initialStep

Initial step.

Constructor Summary

AccessConstructor and Description
public
BracketingStep(double
Initial step for the bracket search.
step
)

Method Summary

Modifier and TypeMethod and Description
public double

Returns:

the initial step.
getBracketingStep
()

Gets the initial step.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

initialStepback to summary
private final double initialStep

Initial step.

Constructor Detail

BracketingStepback to summary
public BracketingStep(double step)
Parameters
step:double

Initial step for the bracket search.

Method Detail

getBracketingStepback to summary
public double getBracketingStep()

Gets the initial step.

Returns:double

the initial step.

org.apache.commons.math3.optim.nonlinear.scalar.gradient back to summary

public final Enum NonLinearConjugateGradientOptimizer.Formula

extends Enum<NonLinearConjugateGradientOptimizer.Formula>
Class Inheritance

Available choices of update formulas for the updating the parameter that is used to compute the successive conjugate search directions. For non-linear conjugate gradients, there are two formulas: On the one hand, the Fletcher-Reeves formula is guaranteed to converge if the start point is close enough of the optimum whether the Polak-Ribière formula may not converge in rare cases. On the other hand, the Polak-Ribière formula is often faster when it does converge. Polak-Ribière is often used.
Since
2.0

Field Summary

Modifier and TypeField and Description
public static final NonLinearConjugateGradientOptimizer.Formula
FLETCHER_REEVES

Fletcher-Reeves formula.

public static final NonLinearConjugateGradientOptimizer.Formula
POLAK_RIBIERE

Polak-Ribière formula.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static NonLinearConjugateGradientOptimizer.Formula
public static NonLinearConjugateGradientOptimizer.Formula[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

FLETCHER_REEVESback to summary
public static final NonLinearConjugateGradientOptimizer.Formula FLETCHER_REEVES

Fletcher-Reeves formula.

POLAK_RIBIEREback to summary
public static final NonLinearConjugateGradientOptimizer.Formula POLAK_RIBIERE

Polak-Ribière formula.

Constructor Detail

Formulaback to summary
private Formula()

Method Detail

valueOfback to summary
public static NonLinearConjugateGradientOptimizer.Formula valueOf(String name)
valuesback to summary
public static NonLinearConjugateGradientOptimizer.Formula[] values()
org.apache.commons.math3.optim.nonlinear.scalar.gradient back to summary

public Class NonLinearConjugateGradientOptimizer.IdentityPreconditioner

extends Object
implements Preconditioner
Class Inheritance
  • java.lang.Object
  • org.apache.commons.math3.optim.nonlinear.scalar.gradient.NonLinearConjugateGradientOptimizer.IdentityPreconditioner
All Implemented Interfaces
org.apache.commons.math3.optim.nonlinear.scalar.gradient.Preconditioner

Default identity preconditioner.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public double[]
precondition(double[]
current point at which the search direction was computed
variables
,
double[]
raw search direction (i.e. opposite of the gradient)
r
)

Implements org.apache.commons.math3.optim.nonlinear.scalar.gradient.Preconditioner.precondition.

Precondition a search direction.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

IdentityPreconditionerback to summary
public IdentityPreconditioner()

Method Detail

preconditionback to summary
public double[] precondition(double[] variables, double[] r)

Implements org.apache.commons.math3.optim.nonlinear.scalar.gradient.Preconditioner.precondition.

Doc from org.apache.commons.math3.optim.nonlinear.scalar.gradient.Preconditioner.precondition.

Precondition a search direction.

The returned preconditioned search direction must be computed fast or the algorithm performances will drop drastically. A classical approach is to compute only the diagonal elements of the hessian and to divide the raw search direction by these elements if they are all positive. If at least one of them is negative, it is safer to return a clone of the raw search direction as if the hessian was the identity matrix. The rationale for this simplified choice is that a negative diagonal element means the current point is far from the optimum and preconditioning will not be efficient anyway in this case.

Parameters
variables:double[]

current point at which the search direction was computed

r:double[]

raw search direction (i.e. opposite of the gradient)

Returns:double[]

approximation of H-1r where H is the objective function hessian