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:
| 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:
|
| Modifier and Type | Class and Description |
|---|---|
| private static class | LevenbergMarquardtOptimizer.
Holds internal data. |
| Modifier and Type | Field and Description |
|---|---|
| private final double | costRelativeTolerance
Desired relative error in the sum of squares. |
| private final double | initialStepBoundFactor
Positive input variable used in determining the initial step bound. |
| private final double | orthoTolerance
Desired max cosine on the orthogonality between the function vector and the columns of the jacobian. |
| private final double | parRelativeTolerance
Desired relative error in the approximate solution parameters. |
| private final double | qrRankingThreshold
Threshold for QR ranking. |
| private static final double | TWO_EPS
Twice the "epsilon machine". |
| Access | Constructor and Description |
|---|---|
| public | |
| public | LevenbergMarquardtOptimizer(final double
initial step bound factor initialStepBoundFactor, final double cost relative tolerance costRelativeTolerance, final double parameters relative tolerance parRelativeTolerance, final double orthogonality tolerance orthoTolerance, final double threshold in the QR decomposition. Columns with a 2
norm less than this threshold are considered to be
all 0s. qrRankingThreshold)Construct an instance with all parameters specified. |
| Modifier and Type | Method and Description |
|---|---|
| private void | determineLMDirection(double[]
array containing qTy qy, double[] diagonal matrix diag, double[] diagonal elements associated with lmDir lmDiag, LevenbergMarquardtOptimizer.Data (modified in-place in this method). internalData,Number of sloved point. solvedCols, double[] work array work, double[] the "returned" LM direction is stored in this array lmDir)Solve a*x = b and d*x = 0 in the least squares sense. |
| private double | Returns: the new LM parameterArray containing qTy. qy, double Upper bound on the euclidean norm of diagR * lmDir. delta, double[] Diagonal matrix. diag, LevenbergMarquardtOptimizer.Data (modified in-place in this method). internalData,Number of solved point. solvedCols, double[] work array work1, double[] work array work2, double[] work array work3, double[] the "returned" LM direction will be stored in this array. lmDir, double the value of the LM parameter from the previous iteration. lmPar)Determines the Levenberg-Marquardt parameter. |
| public double | |
| public double | |
| public double | |
| public double | |
| public double | |
| public LeastSquaresOptimizer. | optimize(final LeastSquaresProblem
the problem definition, including model function and
convergence criteria. problem)Implements org. Solve the non-linear least squares problem. |
| private LevenbergMarquardtOptimizer. | Returns: data used in other methods of this class.Weighted Jacobian matrix at the current point. jacobian, int Number of solved point. solvedCols)Decompose a matrix A as A.P = Q.R using Householder transforms. |
| private void | qTy(double[]
vector to multiply (will be overwritten with the result) y, LevenbergMarquardtOptimizer.Data. internalDataCompute the product Qt.y for some Q.R. decomposition. |
| public LevenbergMarquardtOptimizer | Returns: a new instance.Desired relative error in the sum of squares. newCostRelativeTolerance)
|
| public LevenbergMarquardtOptimizer | Returns: a new instance.Positive input variable used in
determining the initial step bound. This bound is set to the
product of initialStepBoundFactor and the euclidean norm of
newInitialStepBoundFactor)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.
|
| public LevenbergMarquardtOptimizer | Returns: a new instance.Desired max cosine on the orthogonality between
the function vector and the columns of the Jacobian. newOrthoTolerance)Modifies the given parameter. |
| public LevenbergMarquardtOptimizer | Returns: a new instance.Desired relative error in the approximate solution
parameters. newParRelativeTolerance)
|
| public LevenbergMarquardtOptimizer | Returns: a new instance.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. newQRRankingThreshold)
|
| costRelativeTolerance | back to summary |
|---|---|
| private final double costRelativeTolerance Desired relative error in the sum of squares. | |
| initialStepBoundFactor | back to summary |
|---|---|
| private final double initialStepBoundFactor Positive input variable used in determining the initial step bound. | |
| orthoTolerance | back to summary |
|---|---|
| private final double orthoTolerance Desired max cosine on the orthogonality between the function vector and the columns of the jacobian. | |
| parRelativeTolerance | back to summary |
|---|---|
| private final double parRelativeTolerance Desired relative error in the approximate solution parameters. | |
| qrRankingThreshold | back to summary |
|---|---|
| private final double qrRankingThreshold Threshold for QR ranking. | |
| TWO_EPS | back to summary |
|---|---|
| private static final double TWO_EPS Twice the "epsilon machine". | |
| LevenbergMarquardtOptimizer | back to summary |
|---|---|
| public LevenbergMarquardtOptimizer() Default constructor. The default values for the algorithm settings are:
| |
| LevenbergMarquardtOptimizer | back to summary |
|---|---|
| public LevenbergMarquardtOptimizer(final double initialStepBoundFactor, final double costRelativeTolerance, final double parRelativeTolerance, final double orthoTolerance, final double qrRankingThreshold) Construct an instance with all parameters specified.
| |
| determineLMDirection | back to summary |
|---|---|
| private void determineLMDirection(double[] qy, double[] diag, double[] lmDiag, LevenbergMarquardtOptimizer. Solve a*x = b and d*x = 0 in the least squares sense. This implementation is a translation in Java of the MINPACK qrsolv routine. This method sets the lmDir and lmDiag attributes. The authors of the original fortran function are:
Luc Maisonobe did the Java translation.
| |
| determineLMParameter | back to summary |
|---|---|
| private double determineLMParameter(double[] qy, double delta, double[] diag, LevenbergMarquardtOptimizer. Determines the Levenberg-Marquardt parameter. This implementation is a translation in Java of the MINPACK lmpar routine. This method sets the lmPar and lmDir attributes. The authors of the original fortran function are:
Luc Maisonobe did the Java translation.
| |
| getCostRelativeTolerance | back to summary |
|---|---|
| public double getCostRelativeTolerance() Gets the value of a tuning parameter.
| |
| getInitialStepBoundFactor | back to summary |
|---|---|
| public double getInitialStepBoundFactor() Gets the value of a tuning parameter.
| |
| getOrthoTolerance | back to summary |
|---|---|
| public double getOrthoTolerance() Gets the value of a tuning parameter.
| |
| getParameterRelativeTolerance | back to summary |
|---|---|
| public double getParameterRelativeTolerance() Gets the value of a tuning parameter.
| |
| getRankingThreshold | back to summary |
|---|---|
| public double getRankingThreshold() Gets the value of a tuning parameter.
| |
| optimize | back to summary |
|---|---|
| public LeastSquaresOptimizer. Implements org. Doc from org. Solve the non-linear least squares problem.
| |
| qrDecomposition | back to summary |
|---|---|
| private LevenbergMarquardtOptimizer. Decompose a matrix A as A.P = Q.R using Householder transforms. As suggested in the P. Lascaux and R. Theodor book Analyse numérique matricielle appliquée à l'art de l'ingénieur (Masson, 1986), instead of representing the Householder transforms with uk unit vectors such that: Hk = I - 2uk.uktwe use k non-unit vectors such that: Hk = I - betakvk.vktwhere vk = ak - alphak ek. The betak coefficients are provided upon exit as recomputing them from the vk vectors would be costly. This decomposition handles rank deficient cases since the tranformations are performed in non-increasing columns norms order thanks to columns pivoting. The diagonal elements of the R matrix are therefore also in non-increasing absolute values order.
| |
| qTy | back to summary |
|---|---|
| private void qTy(double[] y, LevenbergMarquardtOptimizer. Compute the product Qt.y for some Q.R. decomposition.
| |
| withCostRelativeTolerance | back to summary |
|---|---|
public LevenbergMarquardtOptimizer withCostRelativeTolerance(double newCostRelativeTolerance)
| |
| withInitialStepBoundFactor | back to summary |
|---|---|
public LevenbergMarquardtOptimizer withInitialStepBoundFactor(double newInitialStepBoundFactor)
| |
| withOrthoTolerance | back to summary |
|---|---|
| public LevenbergMarquardtOptimizer withOrthoTolerance(double newOrthoTolerance) Modifies the given parameter.
| |
| withParameterRelativeTolerance | back to summary |
|---|---|
public LevenbergMarquardtOptimizer withParameterRelativeTolerance(double newParRelativeTolerance)
| |
| withRankingThreshold | back to summary |
|---|---|
public LevenbergMarquardtOptimizer withRankingThreshold(double newQRRankingThreshold)
| |
| Modifier and Type | Field and Description |
|---|---|
| private final double[] | beta
Coefficients of the Householder transforms vectors. |
| private final double[] | diagR
Diagonal elements of the R matrix in the QR decomposition. |
| private final double[] | jacNorm
Norms of the columns of the jacobian matrix. |
| private final int[] | permutation
Columns permutation array. |
| private final int | rank
Rank of the Jacobian matrix. |
| private final double[][] | weightedJacobian
Weighted Jacobian. |
| Access | Constructor and Description |
|---|---|
| pack-priv | InternalData(double[][]
Weighted Jacobian. weightedJacobian, int[] Columns permutation array. permutation, int Rank of the Jacobian matrix. rank, double[] Diagonal elements of the R matrix in the QR decomposition. diagR, double[] Norms of the columns of the jacobian matrix. jacNorm, double[] Coefficients of the Householder transforms vectors. beta)
|
| beta | back to summary |
|---|---|
| private final double[] beta Coefficients of the Householder transforms vectors. | |
| diagR | back to summary |
|---|---|
| private final double[] diagR Diagonal elements of the R matrix in the QR decomposition. | |
| jacNorm | back to summary |
|---|---|
| private final double[] jacNorm Norms of the columns of the jacobian matrix. | |
| permutation | back to summary |
|---|---|
| private final int[] permutation Columns permutation array. | |
| rank | back to summary |
|---|---|
| private final int rank Rank of the Jacobian matrix. | |
| weightedJacobian | back to summary |
|---|---|
| private final double[][] weightedJacobian Weighted Jacobian. | |
| InternalData | back to summary |
|---|---|
pack-priv InternalData(double[][] weightedJacobian, int[] permutation, int rank, double[] diagR, double[] jacNorm, double[] beta)
| |