Class GaussNewtonOptimizer
- java.lang.Object
-
- org.apache.commons.math3.fitting.leastsquares.GaussNewtonOptimizer
-
- All Implemented Interfaces:
LeastSquaresOptimizer
public class GaussNewtonOptimizer extends java.lang.Object implements 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 Classes Modifier and Type Class Description static classGaussNewtonOptimizer.DecompositionThe 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
Fields Modifier and Type Field Description private GaussNewtonOptimizer.DecompositiondecompositionIndicator for using LU decomposition.private static doubleSINGULARITY_THRESHOLDThe singularity threshold for matrix decompositions.
-
Constructor Summary
Constructors Constructor Description GaussNewtonOptimizer()Creates 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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static Pair<RealMatrix,RealVector>computeNormalMatrix(RealMatrix jacobian, RealVector residuals)Compute the normal matrix, JTJ.GaussNewtonOptimizer.DecompositiongetDecomposition()Get the matrix decomposition algorithm used to solve the normal equations.LeastSquaresOptimizer.Optimumoptimize(LeastSquaresProblem lsp)Solve the non-linear least squares problem.java.lang.StringtoString()GaussNewtonOptimizerwithDecomposition(GaussNewtonOptimizer.Decomposition newDecomposition)Configure the decomposition algorithm.
-
-
-
Field Detail
-
SINGULARITY_THRESHOLD
private static final double SINGULARITY_THRESHOLD
The singularity threshold for matrix decompositions. Determines when aConvergenceExceptionis thrown. The current value was the default value forLUDecomposition.- See Also:
- Constant Field Values
-
decomposition
private final GaussNewtonOptimizer.Decomposition decomposition
Indicator for using LU decomposition.
-
-
Constructor Detail
-
GaussNewtonOptimizer
public GaussNewtonOptimizer()
Creates a Gauss Newton optimizer. The default for the algorithm is to solve the normal equations using QR decomposition.
-
GaussNewtonOptimizer
public GaussNewtonOptimizer(GaussNewtonOptimizer.Decomposition decomposition)
Create a Gauss Newton optimizer that uses the given decomposition algorithm to solve the normal equations.- Parameters:
decomposition- theGaussNewtonOptimizer.Decompositionalgorithm.
-
-
Method Detail
-
getDecomposition
public GaussNewtonOptimizer.Decomposition getDecomposition()
Get the matrix decomposition algorithm used to solve the normal equations.- Returns:
- the matrix
GaussNewtonOptimizer.Decompositionalgoritm.
-
withDecomposition
public GaussNewtonOptimizer withDecomposition(GaussNewtonOptimizer.Decomposition newDecomposition)
Configure the decomposition algorithm.- Parameters:
newDecomposition- theGaussNewtonOptimizer.Decompositionalgorithm to use.- Returns:
- a new instance.
-
optimize
public LeastSquaresOptimizer.Optimum optimize(LeastSquaresProblem lsp)
Solve the non-linear least squares problem.- Specified by:
optimizein interfaceLeastSquaresOptimizer- Parameters:
lsp- the problem definition, including model function and convergence criteria.- Returns:
- The optimum.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
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.
-
-