Class GaussNewtonOptimizer
java.lang.Object
org.apache.commons.math3.fitting.leastsquares.GaussNewtonOptimizer
- All Implemented Interfaces:
LeastSquaresOptimizer
Gauss-Newton least-squares solver.
This class solve a least-square problem by solving the normal equations of the linearized problem at each iteration. Either LU decomposition or Cholesky decomposition can be used to solve the normal equations, or QR decomposition or SVD decomposition can be used to solve the linear system. LU decomposition is faster but QR decomposition is more robust for difficult problems, and SVD can compute a solution for rank-deficient problems.
- Since:
- 3.3
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
The decomposition algorithm to use to solve the normal equations.Nested classes/interfaces inherited from interface org.apache.commons.math3.fitting.leastsquares.LeastSquaresOptimizer
LeastSquaresOptimizer.Optimum
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final GaussNewtonOptimizer.Decomposition
Indicator for using LU decomposition.private static final double
The singularity threshold for matrix decompositions. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a Gauss Newton optimizer.GaussNewtonOptimizer
(GaussNewtonOptimizer.Decomposition decomposition) Create a Gauss Newton optimizer that uses the given decomposition algorithm to solve the normal equations. -
Method Summary
Modifier and TypeMethodDescriptionprivate static Pair
<RealMatrix, RealVector> computeNormalMatrix
(RealMatrix jacobian, RealVector residuals) Compute the normal matrix, JTJ.Get the matrix decomposition algorithm used to solve the normal equations.Solve the non-linear least squares problem.toString()
withDecomposition
(GaussNewtonOptimizer.Decomposition newDecomposition) Configure the decomposition algorithm.
-
Field Details
-
SINGULARITY_THRESHOLD
private static final double SINGULARITY_THRESHOLDThe singularity threshold for matrix decompositions. Determines when aConvergenceException
is thrown. The current value was the default value forLUDecomposition
.- See Also:
-
decomposition
Indicator for using LU decomposition.
-
-
Constructor Details
-
GaussNewtonOptimizer
public GaussNewtonOptimizer()Creates a Gauss Newton optimizer. The default for the algorithm is to solve the normal equations using QR decomposition. -
GaussNewtonOptimizer
Create a Gauss Newton optimizer that uses the given decomposition algorithm to solve the normal equations.- Parameters:
decomposition
- theGaussNewtonOptimizer.Decomposition
algorithm.
-
-
Method Details
-
getDecomposition
Get the matrix decomposition algorithm used to solve the normal equations.- Returns:
- the matrix
GaussNewtonOptimizer.Decomposition
algoritm.
-
withDecomposition
Configure the decomposition algorithm.- Parameters:
newDecomposition
- theGaussNewtonOptimizer.Decomposition
algorithm to use.- Returns:
- a new instance.
-
optimize
Solve the non-linear least squares problem.- Specified by:
optimize
in interfaceLeastSquaresOptimizer
- Parameters:
lsp
- the problem definition, including model function and convergence criteria.- Returns:
- The optimum.
-
toString
-
computeNormalMatrix
private static Pair<RealMatrix,RealVector> computeNormalMatrix(RealMatrix jacobian, RealVector residuals) Compute the normal matrix, JTJ.- Parameters:
jacobian
- the m by n jacobian matrix, J. Input.residuals
- the m by 1 residual vector, r. Input.- Returns:
- the n by n normal matrix and the n by 1 JTr vector.
-