/** * Creates an optimizer set up to fit the appropriate curve. * <p> * The default implementation uses a {@link LevenbergMarquardtOptimizer * Levenberg-Marquardt} optimizer. * </p> * @return the optimizer to use for fitting the curve to the * given {@code points}. */ protected LeastSquaresOptimizer getOptimizer() { return new LevenbergMarquardtOptimizer(); }
/** * @param newCostRelativeTolerance Desired relative error in the sum of squares. * @return a new instance. */ public LevenbergMarquardtOptimizer withCostRelativeTolerance(double newCostRelativeTolerance) { return new LevenbergMarquardtOptimizer( initialStepBoundFactor, newCostRelativeTolerance, parRelativeTolerance, orthoTolerance, qrRankingThreshold); }
/** * @param newParRelativeTolerance Desired relative error in the approximate solution * parameters. * @return a new instance. */ public LevenbergMarquardtOptimizer withParameterRelativeTolerance(double newParRelativeTolerance) { return new LevenbergMarquardtOptimizer( initialStepBoundFactor, costRelativeTolerance, newParRelativeTolerance, orthoTolerance, qrRankingThreshold); }
/** * Modifies the given parameter. * * @param newOrthoTolerance Desired max cosine on the orthogonality between * the function vector and the columns of the Jacobian. * @return a new instance. */ public LevenbergMarquardtOptimizer withOrthoTolerance(double newOrthoTolerance) { return new LevenbergMarquardtOptimizer( initialStepBoundFactor, costRelativeTolerance, parRelativeTolerance, newOrthoTolerance, qrRankingThreshold); }
/** * @param newQRRankingThreshold Desired threshold for QR ranking. * If the squared norm of a column vector is smaller or equal to this * threshold during QR decomposition, it is considered to be a zero vector * and hence the rank of the matrix is reduced. * @return a new instance. */ public LevenbergMarquardtOptimizer withRankingThreshold(double newQRRankingThreshold) { return new LevenbergMarquardtOptimizer( initialStepBoundFactor, costRelativeTolerance, parRelativeTolerance, orthoTolerance, newQRRankingThreshold); }
/** * @param newInitialStepBoundFactor Positive input variable used in * determining the initial step bound. This bound is set to the * product of initialStepBoundFactor and the euclidean norm of * {@code diag * x} if non-zero, or else to {@code newInitialStepBoundFactor} * itself. In most cases factor should lie in the interval * {@code (0.1, 100.0)}. {@code 100} is a generally recommended value. * of the matrix is reduced. * @return a new instance. */ public LevenbergMarquardtOptimizer withInitialStepBoundFactor(double newInitialStepBoundFactor) { return new LevenbergMarquardtOptimizer( newInitialStepBoundFactor, costRelativeTolerance, parRelativeTolerance, orthoTolerance, qrRankingThreshold); }
/** * Creates an optimizer set up to fit the appropriate curve. * <p> * The default implementation uses a {@link LevenbergMarquardtOptimizer * Levenberg-Marquardt} optimizer. * </p> * @return the optimizer to use for fitting the curve to the * given {@code points}. */ protected LeastSquaresOptimizer getOptimizer() { return new LevenbergMarquardtOptimizer(); }
/** * @param newCostRelativeTolerance Desired relative error in the sum of squares. * @return a new instance. */ public LevenbergMarquardtOptimizer withCostRelativeTolerance(double newCostRelativeTolerance) { return new LevenbergMarquardtOptimizer( initialStepBoundFactor, newCostRelativeTolerance, parRelativeTolerance, orthoTolerance, qrRankingThreshold); }
/** * Creates an optimizer set up to fit the appropriate curve. * <p> * The default implementation uses a {@link LevenbergMarquardtOptimizer * Levenberg-Marquardt} optimizer. * </p> * @return the optimizer to use for fitting the curve to the * given {@code points}. */ protected LeastSquaresOptimizer getOptimizer() { return new LevenbergMarquardtOptimizer(); }
/** * @param newCostRelativeTolerance Desired relative error in the sum of squares. * @return a new instance. */ public LevenbergMarquardtOptimizer withCostRelativeTolerance(double newCostRelativeTolerance) { return new LevenbergMarquardtOptimizer( initialStepBoundFactor, newCostRelativeTolerance, parRelativeTolerance, orthoTolerance, qrRankingThreshold); }
/** * @param newParRelativeTolerance Desired relative error in the approximate solution * parameters. * @return a new instance. */ public LevenbergMarquardtOptimizer withParameterRelativeTolerance(double newParRelativeTolerance) { return new LevenbergMarquardtOptimizer( initialStepBoundFactor, costRelativeTolerance, newParRelativeTolerance, orthoTolerance, qrRankingThreshold); }
/** * @param newParRelativeTolerance Desired relative error in the approximate solution * parameters. * @return a new instance. */ public LevenbergMarquardtOptimizer withParameterRelativeTolerance(double newParRelativeTolerance) { return new LevenbergMarquardtOptimizer( initialStepBoundFactor, costRelativeTolerance, newParRelativeTolerance, orthoTolerance, qrRankingThreshold); }
/** * Modifies the given parameter. * * @param newOrthoTolerance Desired max cosine on the orthogonality between * the function vector and the columns of the Jacobian. * @return a new instance. */ public LevenbergMarquardtOptimizer withOrthoTolerance(double newOrthoTolerance) { return new LevenbergMarquardtOptimizer( initialStepBoundFactor, costRelativeTolerance, parRelativeTolerance, newOrthoTolerance, qrRankingThreshold); }
/** * @param newQRRankingThreshold Desired threshold for QR ranking. * If the squared norm of a column vector is smaller or equal to this * threshold during QR decomposition, it is considered to be a zero vector * and hence the rank of the matrix is reduced. * @return a new instance. */ public LevenbergMarquardtOptimizer withRankingThreshold(double newQRRankingThreshold) { return new LevenbergMarquardtOptimizer( initialStepBoundFactor, costRelativeTolerance, parRelativeTolerance, orthoTolerance, newQRRankingThreshold); }
/** * Modifies the given parameter. * * @param newOrthoTolerance Desired max cosine on the orthogonality between * the function vector and the columns of the Jacobian. * @return a new instance. */ public LevenbergMarquardtOptimizer withOrthoTolerance(double newOrthoTolerance) { return new LevenbergMarquardtOptimizer( initialStepBoundFactor, costRelativeTolerance, parRelativeTolerance, newOrthoTolerance, qrRankingThreshold); }
/** * @param newQRRankingThreshold Desired threshold for QR ranking. * If the squared norm of a column vector is smaller or equal to this * threshold during QR decomposition, it is considered to be a zero vector * and hence the rank of the matrix is reduced. * @return a new instance. */ public LevenbergMarquardtOptimizer withRankingThreshold(double newQRRankingThreshold) { return new LevenbergMarquardtOptimizer( initialStepBoundFactor, costRelativeTolerance, parRelativeTolerance, orthoTolerance, newQRRankingThreshold); }
double[][] positions = new double[][] { { 5.0, -6.0 }, { 13.0, -15.0 }, { 21.0, -3.0 }, { 12.42, -21.2 } }; double[] distances = new double[] { 8.06, 13.97, 23.32, 15.31 }; NonLinearLeastSquaresSolver solver = new NonLinearLeastSquaresSolver(new TrilaterationFunction(positions, distances), new LevenbergMarquardtOptimizer()); Optimum optimum = solver.solve(); // the answer double[] calculatedPosition = optimum.getPoint().toArray(); // error and geometry information RealVector standardDeviation = optimum.getSigma(0); RealMatrix covarianceMatrix = optimum.getCovariances(0);
// Initialize analyzers _optimizer = new LevenbergMarquardtOptimizer(); _fitter = new CurveFitter(_optimizer); // Initialize the analysis results _gaussians = new ArrayList<GaussianFunction>(); // Load the data into the gaussian fitter for (int i = 0; i != data.length; i++) _fitter.addObservedPoint(i, data[i]);
double[][] positions = new double[][] { { 1.0, 1.0 }, { 2.0, 1.0 } }; double[] distances = new double[] { 0.0, 1.0 }; TrilaterationFunction trilaterationFunction = new TrilaterationFunction(positions, distances); NonLinearLeastSquaresSolver solver = new NonLinearLeastSquaresSolver(trilaterationFunction, new LevenbergMarquardtOptimizer()); double[] expectedPosition = new double[] { 1.0, 1.0 }; Optimum optimum = solver.solve(); testResults(expectedPosition, 0.0001, optimum);
private void testCase() { TrilaterationFunction trilaterationFunction = new TrilaterationFunction(positions, distances); LinearLeastSquaresSolver lSolver = new LinearLeastSquaresSolver(trilaterationFunction); NonLinearLeastSquaresSolver nlSolver = new NonLinearLeastSquaresSolver(trilaterationFunction, new LevenbergMarquardtOptimizer()); linearCalculatedPosition = lSolver.solve(); nonLinearOptimum = nlSolver.solve(); }