org.apache.commons.math3.fitting.leastsquares

## Class LevenbergMarquardtOptimizer

• All Implemented Interfaces:
WithConvergenceChecker<PointVectorValuePair,LevenbergMarquardtOptimizer>, WithMaxEvaluations<LevenbergMarquardtOptimizer>, WithMaxIterations<LevenbergMarquardtOptimizer>, WithModelAndJacobian<LevenbergMarquardtOptimizer>, WithStartPoint<LevenbergMarquardtOptimizer>, WithTarget<LevenbergMarquardtOptimizer>, WithWeight<LevenbergMarquardtOptimizer>

public class LevenbergMarquardtOptimizer
extends AbstractLeastSquaresOptimizer<LevenbergMarquardtOptimizer>
This class solves a least-squares problem using the Levenberg-Marquardt algorithm.

This implementation should work even for over-determined systems (i.e. systems having more point than equations). Over-determined systems are solved by ignoring the point which have the smallest impact according to their jacobian column norm. Only the rank of the matrix and some loop bounds are changed to implement this.

The resolution engine is a simple translation of the MINPACK lmder routine with minor changes. The changes include the over-determined resolution, the use of inherited convergence checker and the Q.R. decomposition which has been rewritten following the algorithm described in the P. Lascaux and R. Theodor book Analyse numérique matricielle appliquée à l'art de l'ingénieur, Masson 1986.

The authors of the original fortran version are:

• Argonne National Laboratory. MINPACK project. March 1980
• Burton S. Garbow
• Kenneth E. Hillstrom
• Jorge J. More
The redistribution policy for MINPACK is available here, for convenience, it is reproduced below.

 Minpack Copyright Notice (1999) University of Chicago. All rights reserved Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. The end-user documentation included with the redistribution, if any, must include the following acknowledgment: This product includes software developed by the University of Chicago, as Operator of Argonne National Laboratory. Alternately, this acknowledgment may appear in the software itself, if and wherever such third-party acknowledgments normally appear. WARRANTY DISCLAIMER. THE SOFTWARE IS SUPPLIED "AS IS" WITHOUT WARRANTY OF ANY KIND. THE COPYRIGHT HOLDER, THE UNITED STATES, THE UNITED STATES DEPARTMENT OF ENERGY, AND THEIR EMPLOYEES: (1) DISCLAIM ANY WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE OR NON-INFRINGEMENT, (2) DO NOT ASSUME ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY, COMPLETENESS, OR USEFULNESS OF THE SOFTWARE, (3) DO NOT REPRESENT THAT USE OF THE SOFTWARE WOULD NOT INFRINGE PRIVATELY OWNED RIGHTS, (4) DO NOT WARRANT THAT THE SOFTWARE WILL FUNCTION UNINTERRUPTED, THAT IT IS ERROR-FREE OR THAT ANY ERRORS WILL BE CORRECTED. LIMITATION OF LIABILITY. IN NO EVENT WILL THE COPYRIGHT HOLDER, THE UNITED STATES, THE UNITED STATES DEPARTMENT OF ENERGY, OR THEIR EMPLOYEES: BE LIABLE FOR ANY INDIRECT, INCIDENTAL, CONSEQUENTIAL, SPECIAL OR PUNITIVE DAMAGES OF ANY KIND OR NATURE, INCLUDING BUT NOT LIMITED TO LOSS OF PROFITS OR LOSS OF DATA, FOR ANY REASON WHATSOEVER, WHETHER SUCH LIABILITY IS ASSERTED ON THE BASIS OF CONTRACT, TORT (INCLUDING NEGLIGENCE OR STRICT LIABILITY), OR OTHERWISE, EVEN IF ANY OF SAID PARTIES HAS BEEN WARNED OF THE POSSIBILITY OF SUCH LOSS OR DAMAGES.
Since:
3.3
Version:
$Id: LevenbergMarquardtOptimizer.html 885258 2013-11-03 02:46:49Z tn$
• ### Constructor Summary

Constructors
Modifier Constructor and Description
protected  LevenbergMarquardtOptimizer()
Default constructor.
protected  LevenbergMarquardtOptimizer(LevenbergMarquardtOptimizer other)
Copy constructor.
• ### Method Summary

Methods
Modifier and Type Method and Description
static LevenbergMarquardtOptimizer create()
Creates a bare-bones instance.
protected PointVectorValuePair doOptimize()
Performs the bulk of the optimization algorithm.
double getCostRelativeTolerance()
Gets the value of a tuning parameter.
double getInitialStepBoundFactor()
Gets the value of a tuning parameter.
double getOrthoTolerance()
Gets the value of a tuning parameter.
double getParameterRelativeTolerance()
Gets the value of a tuning parameter.
double getRankingThreshold()
Gets the value of a tuning parameter.
LevenbergMarquardtOptimizer shallowCopy()
Creates a shallow copy of this instance.
LevenbergMarquardtOptimizer withCostRelativeTolerance(double newCostRelativeTolerance)
Modifies the given parameter.
LevenbergMarquardtOptimizer withInitialStepBoundFactor(double newInitialStepBoundFactor)
LevenbergMarquardtOptimizer withOrthoTolerance(double newOrthoTolerance)
Modifies the given parameter.
LevenbergMarquardtOptimizer withParameterRelativeTolerance(double parameterRelativeTolerance)
Modifies the given parameter.
LevenbergMarquardtOptimizer withRankingThreshold(double rankingThreshold)
Modifies the given parameter.
• ### Methods inherited from class org.apache.commons.math3.fitting.leastsquares.AbstractLeastSquaresOptimizer

computeCost, computeCovariances, computeJacobian, computeObjectiveValue, computeResiduals, computeRMS, computeSigma, computeWeightedJacobian, getJacobian, getModel, getStart, getTarget, getWeight, getWeightSquareRoot, withModelAndJacobian, withStartPoint, withTarget, withWeight
• ### Methods inherited from class org.apache.commons.math3.optim.AbstractOptimizer

getConvergenceChecker, getEvaluations, getIterations, getMaxEvaluations, getMaxIterations, incrementEvaluationCount, incrementIterationCount, optimize, self, withConvergenceChecker, withMaxEvaluations, withMaxIterations
• ### Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
• ### Constructor Detail

• #### LevenbergMarquardtOptimizer

protected LevenbergMarquardtOptimizer()
Default constructor.
• #### LevenbergMarquardtOptimizer

protected LevenbergMarquardtOptimizer(LevenbergMarquardtOptimizer other)
Copy constructor.
Parameters:
other - object to copy.
• ### Method Detail

• #### create

public static LevenbergMarquardtOptimizer create()
Creates a bare-bones instance. Several calls to withXxx methods are necessary to obtain an object with all necessary fields set to sensible values.
The default values for the algorithm settings are:
• Initial step bound factor: 100
• Cost relative tolerance: 1e-10
• Parameters relative tolerance: 1e-10
• Orthogonality tolerance: 1e-10
• QR ranking threshold: Precision.SAFE_MIN
Returns:
an instance of this class.
• #### shallowCopy

public LevenbergMarquardtOptimizer shallowCopy()
Creates a shallow copy of this instance. Further modifications of the returned object will not modify the fields in this instance.
Specified by:
shallowCopy in class AbstractOptimizer<PointVectorValuePair,LevenbergMarquardtOptimizer>
Returns:
a shallow copy.
• #### withInitialStepBoundFactor

public LevenbergMarquardtOptimizer withInitialStepBoundFactor(double newInitialStepBoundFactor)
Parameters:
newInitialStepBoundFactor - Positive input variable used in determining the initial step bound. This bound is set to the product of initialStepBoundFactor and the euclidean norm of diag * x if non-zero, or else to newInitialStepBoundFactor itself. In most cases factor should lie in the interval (0.1, 100.0). 100 is a generally recommended value. of the matrix is reduced.
Returns:
this instance.
• #### withCostRelativeTolerance

public LevenbergMarquardtOptimizer withCostRelativeTolerance(double newCostRelativeTolerance)
Modifies the given parameter.
Parameters:
newCostRelativeTolerance - Desired relative error in the sum of squares.
Returns:
this instance.
• #### withParameterRelativeTolerance

public LevenbergMarquardtOptimizer withParameterRelativeTolerance(double parameterRelativeTolerance)
Modifies the given parameter.
Parameters:
parameterRelativeTolerance - Desired relative error in the approximate solution parameters.
Returns:
this instance.
• #### withOrthoTolerance

public LevenbergMarquardtOptimizer withOrthoTolerance(double newOrthoTolerance)
Modifies the given parameter.
Parameters:
newOrthoTolerance - Desired max cosine on the orthogonality between the function vector and the columns of the Jacobian.
Returns:
this instance.
• #### withRankingThreshold

public LevenbergMarquardtOptimizer withRankingThreshold(double rankingThreshold)
Modifies the given parameter.
Parameters:
rankingThreshold - Desired threshold for QR ranking. If the squared norm of a column vector is smaller or equal to this threshold during QR decomposition, it is considered to be a zero vector and hence the rank of the matrix is reduced.
Returns:
this instance.
• #### getOrthoTolerance

public double getOrthoTolerance()
Gets the value of a tuning parameter.
Returns:
the parameter's value.
withOrthoTolerance(double)
• #### getRankingThreshold

public double getRankingThreshold()
Gets the value of a tuning parameter.
Returns:
the parameter's value.
withRankingThreshold(double)
protected PointVectorValuePair doOptimize()
doOptimize in class AbstractOptimizer<PointVectorValuePair,LevenbergMarquardtOptimizer>