use of org.apache.commons.math3.fitting.leastsquares.LeastSquaresOptimizer 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();
}
use of org.apache.commons.math3.fitting.leastsquares.LeastSquaresOptimizer in project imagingbook-common by imagingbook.
the class NonlinearLeastSquares method solveLevenvergMarquardt.
/**
* Solves the nonlinear least-squares problem defined by the arguments
* using Levenberg-Marquardt 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 solveLevenvergMarquardt(MultivariateVectorFunction V, MultivariateMatrixFunction J, RealVector z, RealVector p0) {
LeastSquaresProblem problem = makeProblem(V, J, z, p0);
LeastSquaresOptimizer optimizer = new LevenbergMarquardtOptimizer();
Optimum solution = optimizer.optimize(problem);
// System.out.println("iterations = " + solution.getIterations());
return solution.getPoint();
}
use of org.apache.commons.math3.fitting.leastsquares.LeastSquaresOptimizer in project imagingbook-common by imagingbook.
the class NonlinearLeastSquares method solveNLS2.
// --------------------------------------------------------------------
// book version
// --------------------------------------------------------------------
public static RealVector solveNLS2(MultivariateVectorFunction V, MultivariateMatrixFunction J, RealVector z, RealVector p0) {
LeastSquaresProblem problem = LeastSquaresFactory.create(model(V, J), z, p0, null, MaxEvaluations, MaxIterations);
LeastSquaresOptimizer optimizer = new LevenbergMarquardtOptimizer();
Optimum solution = optimizer.optimize(problem);
// System.out.println("iterations = " + solution.getIterations());
if (solution.getIterations() > MaxIterations)
return null;
else
return solution.getPoint();
}
Aggregations