/** * Construct a {@link LeastSquaresProblem} from the data in this builder. * * @return a new {@link LeastSquaresProblem}. */ public LeastSquaresProblem build() { return LeastSquaresFactory.create(model, target, start, weight, checker, maxEvaluations, maxIterations, lazyEvaluation, paramValidator); }
/** * Create a {@link org.apache.commons.math3.fitting.leastsquares.LeastSquaresProblem} * from the given elements. There will be no weights applied (unit weights). * * @param model the model function. Produces the computed values. * @param observed the observed (target) values * @param start the initial guess. * @param checker convergence checker * @param maxEvaluations the maximum number of times to evaluate the model * @param maxIterations the maximum number to times to iterate in the algorithm * @return the specified General Least Squares problem. */ public static LeastSquaresProblem create(final MultivariateJacobianFunction model, final RealVector observed, final RealVector start, final ConvergenceChecker<Evaluation> checker, final int maxEvaluations, final int maxIterations) { return create(model, observed, start, null, checker, maxEvaluations, maxIterations, false, null); }
/** * Create a {@link org.apache.commons.math3.fitting.leastsquares.LeastSquaresProblem} * from the given elements. * * @param model the model function. Produces the computed values. * @param observed the observed (target) values * @param start the initial guess. * @param weight the weight matrix * @param checker convergence checker * @param maxEvaluations the maximum number of times to evaluate the model * @param maxIterations the maximum number to times to iterate in the algorithm * @return the specified General Least Squares problem. */ public static LeastSquaresProblem create(final MultivariateJacobianFunction model, final RealVector observed, final RealVector start, final RealMatrix weight, final ConvergenceChecker<Evaluation> checker, final int maxEvaluations, final int maxIterations) { return weightMatrix(create(model, observed, start, checker, maxEvaluations, maxIterations), weight); }
final int maxEvaluations, final int maxIterations) { return create(model(model, jacobian), new ArrayRealVector(observed, false), new ArrayRealVector(start, false),
/** * Construct a {@link LeastSquaresProblem} from the data in this builder. * * @return a new {@link LeastSquaresProblem}. */ public LeastSquaresProblem build() { return LeastSquaresFactory.create(model, target, start, weight, checker, maxEvaluations, maxIterations, lazyEvaluation, paramValidator); }
/** * Construct a {@link LeastSquaresProblem} from the data in this builder. * * @return a new {@link LeastSquaresProblem}. */ public LeastSquaresProblem build() { return LeastSquaresFactory.create(model, target, start, weight, checker, maxEvaluations, maxIterations, lazyEvaluation, paramValidator); }
/** * Create a {@link org.apache.commons.math3.fitting.leastsquares.LeastSquaresProblem} * from the given elements. There will be no weights applied (unit weights). * * @param model the model function. Produces the computed values. * @param observed the observed (target) values * @param start the initial guess. * @param checker convergence checker * @param maxEvaluations the maximum number of times to evaluate the model * @param maxIterations the maximum number to times to iterate in the algorithm * @return the specified General Least Squares problem. */ public static LeastSquaresProblem create(final MultivariateJacobianFunction model, final RealVector observed, final RealVector start, final ConvergenceChecker<Evaluation> checker, final int maxEvaluations, final int maxIterations) { return create(model, observed, start, null, checker, maxEvaluations, maxIterations, false, null); }
/** * Create a {@link org.apache.commons.math3.fitting.leastsquares.LeastSquaresProblem} * from the given elements. There will be no weights applied (unit weights). * * @param model the model function. Produces the computed values. * @param observed the observed (target) values * @param start the initial guess. * @param checker convergence checker * @param maxEvaluations the maximum number of times to evaluate the model * @param maxIterations the maximum number to times to iterate in the algorithm * @return the specified General Least Squares problem. */ public static LeastSquaresProblem create(final MultivariateJacobianFunction model, final RealVector observed, final RealVector start, final ConvergenceChecker<Evaluation> checker, final int maxEvaluations, final int maxIterations) { return create(model, observed, start, null, checker, maxEvaluations, maxIterations, false, null); }
/** * Create a {@link org.apache.commons.math3.fitting.leastsquares.LeastSquaresProblem} * from the given elements. * * @param model the model function. Produces the computed values. * @param observed the observed (target) values * @param start the initial guess. * @param weight the weight matrix * @param checker convergence checker * @param maxEvaluations the maximum number of times to evaluate the model * @param maxIterations the maximum number to times to iterate in the algorithm * @return the specified General Least Squares problem. */ public static LeastSquaresProblem create(final MultivariateJacobianFunction model, final RealVector observed, final RealVector start, final RealMatrix weight, final ConvergenceChecker<Evaluation> checker, final int maxEvaluations, final int maxIterations) { return weightMatrix(create(model, observed, start, checker, maxEvaluations, maxIterations), weight); }
/** * Create a {@link org.apache.commons.math3.fitting.leastsquares.LeastSquaresProblem} * from the given elements. * * @param model the model function. Produces the computed values. * @param observed the observed (target) values * @param start the initial guess. * @param weight the weight matrix * @param checker convergence checker * @param maxEvaluations the maximum number of times to evaluate the model * @param maxIterations the maximum number to times to iterate in the algorithm * @return the specified General Least Squares problem. */ public static LeastSquaresProblem create(final MultivariateJacobianFunction model, final RealVector observed, final RealVector start, final RealMatrix weight, final ConvergenceChecker<Evaluation> checker, final int maxEvaluations, final int maxIterations) { return weightMatrix(create(model, observed, start, checker, maxEvaluations, maxIterations), weight); }
public Optimum solve(double[] target, double[] weights, double[] initialPoint, boolean debugInfo) { if (debugInfo) { System.out.println("Max Number of Iterations : " + MAXNUMBEROFITERATIONS); } LeastSquaresProblem leastSquaresProblem = LeastSquaresFactory.create( // function to be optimized function, // target values at optimal point in least square equation // (x0+xi)^2 + (y0+yi)^2 + ri^2 = target[i] new ArrayRealVector(target, false), new ArrayRealVector(initialPoint, false), new DiagonalMatrix(weights), null, MAXNUMBEROFITERATIONS, MAXNUMBEROFITERATIONS); return leastSquaresOptimizer.optimize(leastSquaresProblem); }
final int maxEvaluations, final int maxIterations) { return create(model(model, jacobian), new ArrayRealVector(observed, false), new ArrayRealVector(start, false),
final int maxEvaluations, final int maxIterations) { return create(model(model, jacobian), new ArrayRealVector(observed, false), new ArrayRealVector(start, false),
/** * Refine an initial guess at the homography that takes the first points in * data to the second using non-linear Levenberg Marquardt optimisation. The * initial guess would normally be computed using the direct linear * transform ({@link TransformUtilities#homographyMatrixNorm(List)}). * * @param initial * the initial estimate (probably from the DLT technique) * @param data * the pairs of data points * @return the optimised estimate */ public Matrix refine(Matrix initial, List<? extends IndependentPair<? extends Point2d, ? extends Point2d>> data) { final double[] params = new double[8]; final Parameterisation p = Parameterisation.chooseOptimalParameterisation(initial, params); final LevenbergMarquardtOptimizer lm = new LevenbergMarquardtOptimizer(); final RealVector start = new ArrayRealVector(params, false); // target values are all zero as we're computing the distances ourselves final RealVector observed = new ArrayRealVector(data.size()); final int maxEvaluations = 1000; final int maxIterations = 1000; final MultivariateJacobianFunction model = getFunctions(data, p); final Optimum result = lm.optimize(LeastSquaresFactory.create(model, observed, start, null, maxEvaluations, maxIterations)); final Matrix improved = p.paramsToMatrix(result.getPoint().toArray()); // normalise MatrixUtils.times(improved, 1.0 / improved.normInf()); return improved; }
/** * Perform Levenburg-Marquardt non-linear optimisation to get better * estimates of the parameters */ private void refine() { final LevenbergMarquardtOptimizer lm = new LevenbergMarquardtOptimizer(); final RealVector start = buildInitialVector(); final RealVector observed = buildObservedVector(); final int maxEvaluations = 1000; final int maxIterations = 1000; final MultivariateVectorFunction value = new Value(); final MultivariateMatrixFunction jacobian = new Jacobian(); final MultivariateJacobianFunction model = LeastSquaresFactory.model(value, jacobian); final Optimum result = lm.optimize(LeastSquaresFactory.create(model, observed, start, null, maxEvaluations, maxIterations)); updateEstimates(result.getPoint()); }
/** * Perform Levenburg-Marquardt non-linear optimisation to get better * estimates of the parameters */ private void refine() { final LevenbergMarquardtOptimizer lm = new LevenbergMarquardtOptimizer(); final RealVector start = buildInitialVector(); final RealVector observed = buildObservedVector(); final int maxEvaluations = 1000; final int maxIterations = 1000; final MultivariateVectorFunction value = new Value(); final MultivariateMatrixFunction jacobian = new Jacobian(); final MultivariateJacobianFunction model = LeastSquaresFactory.model(value, jacobian); final Optimum result = lm.optimize(LeastSquaresFactory.create(model, observed, start, null, maxEvaluations, maxIterations)); updateEstimates(result.getPoint()); }
@Override public Matrix refine(Matrix initial, List<? extends IndependentPair<? extends Point2d, ? extends Point2d>> data) { final LevenbergMarquardtOptimizer lm = new LevenbergMarquardtOptimizer(); final RealVector start = new ArrayRealVector(initial.getRowPackedCopy()); final RealVector observed = toRealVector(data); final int maxEvaluations = 1000; final int maxIterations = 1000; final MultivariateVectorFunction value = getValueFunction(data); final MultivariateMatrixFunction jacobian = getJacobianFunction(data); final MultivariateJacobianFunction model = LeastSquaresFactory.model(value, jacobian); final Optimum result = lm.optimize(LeastSquaresFactory.create(model, observed, start, null, maxEvaluations, maxIterations)); final Matrix improved = MatrixUtils.fromRowPacked(result.getPoint().toArray(), 3); MatrixUtils.times(improved, 1.0 / improved.get(2, 2)); return improved; } };
@Override public Matrix refine(Matrix initial, List<? extends IndependentPair<? extends Point2d, ? extends Point2d>> data) { final LevenbergMarquardtOptimizer lm = new LevenbergMarquardtOptimizer(); final RealVector start = new ArrayRealVector(initial.getRowPackedCopy()); final RealVector observed = toRealVector(data, false); final int maxEvaluations = 1000; final int maxIterations = 1000; final MultivariateVectorFunction value = getValueFunction(data); final MultivariateMatrixFunction jacobian = getJacobianFunction(data); final MultivariateJacobianFunction model = LeastSquaresFactory.model(value, jacobian); final Optimum result = lm.optimize(LeastSquaresFactory.create(model, observed, start, null, maxEvaluations, maxIterations)); final Matrix improved = MatrixUtils.fromRowPacked(result.getPoint().toArray(), 3); MatrixUtils.times(improved, 1.0 / improved.get(2, 2)); return improved; } },