Search in sources :

Example 1 with GaussNewtonOptimizer

use of org.apache.commons.math3.fitting.leastsquares.GaussNewtonOptimizer in project imagingbook-common by imagingbook.

the class NonlinearLeastSquares method solveGaussNewton.

/**
 * Solves the nonlinear least-squares problem defined by the arguments
 * using Gauss-Newton optimization.
 *
 * @param V the "value" function, V(p) must return a vector for the current parameters p
 * @param J the "Jacobian" function, J(p) must return a matrix for the current parameters p
 * @param z the vector of observed ("target") values
 * @param p0 initial parameter vector
 * @return the vector of optimal parameters
 */
public static RealVector solveGaussNewton(MultivariateVectorFunction V, MultivariateMatrixFunction J, RealVector z, RealVector p0) {
    LeastSquaresProblem problem = makeProblem(V, J, z, p0);
    LeastSquaresOptimizer optimizer = new GaussNewtonOptimizer();
    Optimum solution = optimizer.optimize(problem);
    // System.out.println("iterations = " + solution.getIterations());
    return solution.getPoint();
}
Also used : Optimum(org.apache.commons.math3.fitting.leastsquares.LeastSquaresOptimizer.Optimum) GaussNewtonOptimizer(org.apache.commons.math3.fitting.leastsquares.GaussNewtonOptimizer) LeastSquaresProblem(org.apache.commons.math3.fitting.leastsquares.LeastSquaresProblem) LeastSquaresOptimizer(org.apache.commons.math3.fitting.leastsquares.LeastSquaresOptimizer)

Aggregations

GaussNewtonOptimizer (org.apache.commons.math3.fitting.leastsquares.GaussNewtonOptimizer)1 LeastSquaresOptimizer (org.apache.commons.math3.fitting.leastsquares.LeastSquaresOptimizer)1 Optimum (org.apache.commons.math3.fitting.leastsquares.LeastSquaresOptimizer.Optimum)1 LeastSquaresProblem (org.apache.commons.math3.fitting.leastsquares.LeastSquaresProblem)1