Class AbstractLeastSquaresOptimizer
- java.lang.Object
-
- org.apache.commons.math.optimization.general.AbstractLeastSquaresOptimizer
-
- All Implemented Interfaces:
DifferentiableMultivariateVectorialOptimizer
- Direct Known Subclasses:
GaussNewtonOptimizer
,LevenbergMarquardtOptimizer
public abstract class AbstractLeastSquaresOptimizer extends java.lang.Object implements DifferentiableMultivariateVectorialOptimizer
Base class for implementing least squares optimizers.This base class handles the boilerplate methods associated to thresholds settings, jacobian and error estimation.
- Since:
- 1.2
-
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_MAX_ITERATIONS
Default maximal number of iterations allowed.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description double
getChiSquare()
Get a Chi-Square-like value assuming the N residuals follow N distinct normal distributions centered on 0 and whose variances are the reciprocal of the weights.VectorialConvergenceChecker
getConvergenceChecker()
Get the convergence checker.double[][]
getCovariances()
Get the covariance matrix of optimized parameters.int
getEvaluations()
Get the number of evaluations of the objective function.int
getIterations()
Get the number of iterations realized by the algorithm.int
getJacobianEvaluations()
Get the number of evaluations of the objective function jacobian .int
getMaxEvaluations()
Get the maximal number of functions evaluations.int
getMaxIterations()
Get the maximal number of iterations of the algorithm.double
getRMS()
Get the Root Mean Square value.double[]
guessParametersErrors()
Guess the errors in optimized parameters.VectorialPointValuePair
optimize(DifferentiableMultivariateVectorialFunction f, double[] target, double[] weights, double[] startPoint)
Optimizes an objective function.void
setConvergenceChecker(VectorialConvergenceChecker convergenceChecker)
Set the convergence checker.void
setMaxEvaluations(int maxEvaluations)
Set the maximal number of functions evaluations.void
setMaxIterations(int maxIterations)
Set the maximal number of iterations of the algorithm.
-
-
-
Field Detail
-
DEFAULT_MAX_ITERATIONS
public static final int DEFAULT_MAX_ITERATIONS
Default maximal number of iterations allowed.- See Also:
- Constant Field Values
-
-
Method Detail
-
setMaxIterations
public void setMaxIterations(int maxIterations)
Set the maximal number of iterations of the algorithm.- Specified by:
setMaxIterations
in interfaceDifferentiableMultivariateVectorialOptimizer
- Parameters:
maxIterations
- maximal number of function calls .
-
getMaxIterations
public int getMaxIterations()
Get the maximal number of iterations of the algorithm.- Specified by:
getMaxIterations
in interfaceDifferentiableMultivariateVectorialOptimizer
- Returns:
- maximal number of iterations
-
getIterations
public int getIterations()
Get the number of iterations realized by the algorithm.- Specified by:
getIterations
in interfaceDifferentiableMultivariateVectorialOptimizer
- Returns:
- number of iterations
-
setMaxEvaluations
public void setMaxEvaluations(int maxEvaluations)
Set the maximal number of functions evaluations.- Specified by:
setMaxEvaluations
in interfaceDifferentiableMultivariateVectorialOptimizer
- Parameters:
maxEvaluations
- maximal number of function evaluations
-
getMaxEvaluations
public int getMaxEvaluations()
Get the maximal number of functions evaluations.- Specified by:
getMaxEvaluations
in interfaceDifferentiableMultivariateVectorialOptimizer
- Returns:
- maximal number of functions evaluations
-
getEvaluations
public int getEvaluations()
Get the number of evaluations of the objective function.The number of evaluation correspond to the last call to the
optimize
method. It is 0 if the method has not been called yet.- Specified by:
getEvaluations
in interfaceDifferentiableMultivariateVectorialOptimizer
- Returns:
- number of evaluations of the objective function
-
getJacobianEvaluations
public int getJacobianEvaluations()
Get the number of evaluations of the objective function jacobian .The number of evaluation correspond to the last call to the
optimize
method. It is 0 if the method has not been called yet.- Specified by:
getJacobianEvaluations
in interfaceDifferentiableMultivariateVectorialOptimizer
- Returns:
- number of evaluations of the objective function jacobian
-
setConvergenceChecker
public void setConvergenceChecker(VectorialConvergenceChecker convergenceChecker)
Set the convergence checker.- Specified by:
setConvergenceChecker
in interfaceDifferentiableMultivariateVectorialOptimizer
- Parameters:
convergenceChecker
- object to use to check for convergence
-
getConvergenceChecker
public VectorialConvergenceChecker getConvergenceChecker()
Get the convergence checker.- Specified by:
getConvergenceChecker
in interfaceDifferentiableMultivariateVectorialOptimizer
- Returns:
- object used to check for convergence
-
getRMS
public double getRMS()
Get the Root Mean Square value. Get the Root Mean Square value, i.e. the root of the arithmetic mean of the square of all weighted residuals. This is related to the criterion that is minimized by the optimizer as follows: if c if the criterion, and n is the number of measurements, then the RMS is sqrt (c/n).- Returns:
- RMS value
-
getChiSquare
public double getChiSquare()
Get a Chi-Square-like value assuming the N residuals follow N distinct normal distributions centered on 0 and whose variances are the reciprocal of the weights.- Returns:
- chi-square value
-
getCovariances
public double[][] getCovariances() throws FunctionEvaluationException, OptimizationException
Get the covariance matrix of optimized parameters.- Returns:
- covariance matrix
- Throws:
FunctionEvaluationException
- if the function jacobian cannot be evaluatedOptimizationException
- if the covariance matrix cannot be computed (singular problem)
-
guessParametersErrors
public double[] guessParametersErrors() throws FunctionEvaluationException, OptimizationException
Guess the errors in optimized parameters.Guessing is covariance-based, it only gives rough order of magnitude.
- Returns:
- errors in optimized parameters
- Throws:
FunctionEvaluationException
- if the function jacobian cannot b evaluatedOptimizationException
- if the covariances matrix cannot be computed or the number of degrees of freedom is not positive (number of measurements lesser or equal to number of parameters)
-
optimize
public VectorialPointValuePair optimize(DifferentiableMultivariateVectorialFunction f, double[] target, double[] weights, double[] startPoint) throws FunctionEvaluationException, OptimizationException, java.lang.IllegalArgumentException
Optimizes an objective function.Optimization is considered to be a weighted least-squares minimization. The cost function to be minimized is ∑weighti(objectivei-targeti)2
- Specified by:
optimize
in interfaceDifferentiableMultivariateVectorialOptimizer
- Parameters:
f
- objective functiontarget
- target value for the objective functions at optimumweights
- weight for the least squares cost computationstartPoint
- the start point for optimization- Returns:
- the point/value pair giving the optimal value for objective function
- Throws:
FunctionEvaluationException
- if the objective function throws one during the searchOptimizationException
- if the algorithm failed to convergejava.lang.IllegalArgumentException
- if the start point dimension is wrong
-
-