Top Description Inners Fields Constructors Methods
org.apache.commons.math3.fitting.leastsquares

public Class GaussNewtonOptimizer

extends Object
implements LeastSquaresOptimizer
Class Inheritance
All Implemented Interfaces
org.apache.commons.math3.fitting.leastsquares.LeastSquaresOptimizer
Imports
org.apache.commons.math3.exception.ConvergenceException, .NullArgumentException, org.apache.commons.math3.exception.util.LocalizedFormats, org.apache.commons.math3.fitting.leastsquares.LeastSquaresProblem.Evaluation, org.apache.commons.math3.linear.ArrayRealVector, .CholeskyDecomposition, .LUDecomposition, .MatrixUtils, .NonPositiveDefiniteMatrixException, .QRDecomposition, .RealMatrix, .RealVector, .SingularMatrixException, .SingularValueDecomposition, org.apache.commons.math3.optim.ConvergenceChecker, org.apache.commons.math3.util.Incrementor, .Pair

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 and Inner Type Summary

Modifier and TypeClass and Description
public static enum
GaussNewtonOptimizer.Decomposition

The decomposition algorithm to use to solve the normal equations.

Field Summary

Modifier and TypeField and Description
private final GaussNewtonOptimizer.Decomposition
decomposition

Indicator for using LU decomposition.

private static final double
SINGULARITY_THRESHOLD

The singularity threshold for matrix decompositions.

Constructor Summary

AccessConstructor and Description
public
GaussNewtonOptimizer()

Creates a Gauss Newton optimizer.

public
GaussNewtonOptimizer(final GaussNewtonOptimizer.Decomposition
the Decomposition algorithm.
decomposition
)

Create a Gauss Newton optimizer that uses the given decomposition algorithm to solve the normal equations.

Method Summary

Modifier and TypeMethod and Description
private static Pair<RealMatrix, RealVector>

Returns:

the n by n normal matrix and the n by 1 JTr vector.
computeNormalMatrix
(final RealMatrix
the m by n jacobian matrix, J. Input.
jacobian
,
final RealVector
the m by 1 residual vector, r. Input.
residuals
)

Compute the normal matrix, JTJ.

public GaussNewtonOptimizer.Decomposition

Returns:

the matrix Decomposition algoritm.
getDecomposition
()

Get the matrix decomposition algorithm used to solve the normal equations.

public LeastSquaresOptimizer.Optimum
optimize(final LeastSquaresProblem
the problem definition, including model function and convergence criteria.
lsp
)

Implements org.apache.commons.math3.fitting.leastsquares.LeastSquaresOptimizer.optimize.

Solve the non-linear least squares problem.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

public GaussNewtonOptimizer

Returns:

a new instance.
withDecomposition
(final GaussNewtonOptimizer.Decomposition
the Decomposition algorithm to use.
newDecomposition
)

Configure the decomposition algorithm.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

decompositionback to summary
private final GaussNewtonOptimizer.Decomposition decomposition

Indicator for using LU decomposition.

SINGULARITY_THRESHOLDback to summary
private static final double SINGULARITY_THRESHOLD

The singularity threshold for matrix decompositions. Determines when a ConvergenceException is thrown. The current value was the default value for LUDecomposition.

Constructor Detail

GaussNewtonOptimizerback to summary
public GaussNewtonOptimizer()

Creates a Gauss Newton optimizer.

The default for the algorithm is to solve the normal equations using QR decomposition.

GaussNewtonOptimizerback to summary
public GaussNewtonOptimizer(final GaussNewtonOptimizer.Decomposition decomposition)

Create a Gauss Newton optimizer that uses the given decomposition algorithm to solve the normal equations.

Parameters
decomposition:GaussNewtonOptimizer.Decomposition

the Decomposition algorithm.

Method Detail

computeNormalMatrixback to summary
private static Pair<RealMatrix, RealVector> computeNormalMatrix(final RealMatrix jacobian, final RealVector residuals)

Compute the normal matrix, JTJ.

Parameters
jacobian:RealMatrix

the m by n jacobian matrix, J. Input.

residuals:RealVector

the m by 1 residual vector, r. Input.

Returns:Pair<RealMatrix, RealVector>

the n by n normal matrix and the n by 1 JTr vector.

getDecompositionback to summary
public GaussNewtonOptimizer.Decomposition getDecomposition()

Get the matrix decomposition algorithm used to solve the normal equations.

Returns:GaussNewtonOptimizer.Decomposition

the matrix Decomposition algoritm.

optimizeback to summary
public LeastSquaresOptimizer.Optimum optimize(final LeastSquaresProblem lsp)

Implements org.apache.commons.math3.fitting.leastsquares.LeastSquaresOptimizer.optimize.

Doc from org.apache.commons.math3.fitting.leastsquares.LeastSquaresOptimizer.optimize.

Solve the non-linear least squares problem.

Parameters
lsp:LeastSquaresProblem

the problem definition, including model function and convergence criteria.

Returns:LeastSquaresOptimizer.Optimum

The optimum.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
withDecompositionback to summary
public GaussNewtonOptimizer withDecomposition(final GaussNewtonOptimizer.Decomposition newDecomposition)

Configure the decomposition algorithm.

Parameters
newDecomposition:GaussNewtonOptimizer.Decomposition

the Decomposition algorithm to use.

Returns:GaussNewtonOptimizer

a new instance.

org.apache.commons.math3.fitting.leastsquares back to summary

public sealed Enum GaussNewtonOptimizer.Decomposition

extends Enum<GaussNewtonOptimizer.Decomposition>
Class Inheritance

The decomposition algorithm to use to solve the normal equations.

Field Summary

Modifier and TypeField and Description
public static final GaussNewtonOptimizer.Decomposition
CHOLESKY

Solve by forming the normal equations (JTJx=JTr) and using the CholeskyDecomposition.

public static final GaussNewtonOptimizer.Decomposition
LU

Solve by forming the normal equations (JTJx=JTr) and using the LUDecomposition.

public static final GaussNewtonOptimizer.Decomposition
QR

Solve the linear least squares problem (Jx=r) using the QRDecomposition.

public static final GaussNewtonOptimizer.Decomposition
SVD

Solve the linear least squares problem using the SingularValueDecomposition.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
protected abstract RealVector

Returns:

the solution x, to the linear least squares problem Jx=r.
solve
(RealMatrix
the Jacobian matrix, J. the number of rows >= the number or columns.
jacobian
,
RealVector
the computed residuals, r.
residuals
)

Solve the linear least squares problem Jx=r.

public static GaussNewtonOptimizer.Decomposition
public static GaussNewtonOptimizer.Decomposition[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

CHOLESKYback to summary
public static final GaussNewtonOptimizer.Decomposition CHOLESKY

Solve by forming the normal equations (JTJx=JTr) and using the CholeskyDecomposition.

Theoretically this method takes mn2/2 operations to compute the normal matrix and n3/6 operations (m > n) to solve the system using the Cholesky decomposition.

LUback to summary
public static final GaussNewtonOptimizer.Decomposition LU

Solve by forming the normal equations (JTJx=JTr) and using the LUDecomposition.

Theoretically this method takes mn2/2 operations to compute the normal matrix and n3/3 operations (m > n) to solve the system using the LU decomposition.

QRback to summary
public static final GaussNewtonOptimizer.Decomposition QR

Solve the linear least squares problem (Jx=r) using the QRDecomposition.

Theoretically this method takes mn2 - n3/3 operations (m > n) and has better numerical accuracy than any method that forms the normal equations.

SVDback to summary
public static final GaussNewtonOptimizer.Decomposition SVD

Solve the linear least squares problem using the SingularValueDecomposition.

This method is slower, but can provide a solution for rank deficient and nearly singular systems.

Constructor Detail

Decompositionback to summary
private Decomposition()

Method Detail

solveback to summary
protected abstract RealVector solve(RealMatrix jacobian, RealVector residuals)

Solve the linear least squares problem Jx=r.

Parameters
jacobian:RealMatrix

the Jacobian matrix, J. the number of rows >= the number or columns.

residuals:RealVector

the computed residuals, r.

Returns:RealVector

the solution x, to the linear least squares problem Jx=r.

Exceptions
ConvergenceException:
if the matrix properties (e.g. singular) do not permit a solution.
valueOfback to summary
public static GaussNewtonOptimizer.Decomposition valueOf(String name)
valuesback to summary
public static GaussNewtonOptimizer.Decomposition[] values()