/** * Configure the convergence checker. * <p/> * This function is an overloaded version of {@link #checker(ConvergenceChecker)}. * * @param newChecker the convergence checker. * @return this */ public LeastSquaresBuilder checkerPair(final ConvergenceChecker<PointVectorValuePair> newChecker) { return this.checker(LeastSquaresFactory.evaluationChecker(newChecker)); }
/** * Apply a dense weight matrix to the {@link LeastSquaresProblem}. * * @param problem the unweighted problem * @param weights the matrix of weights * @return a new {@link LeastSquaresProblem} with the weights applied. The original * {@code problem} is not modified. */ public static LeastSquaresProblem weightMatrix(final LeastSquaresProblem problem, final RealMatrix weights) { final RealMatrix weightSquareRoot = squareRoot(weights); return new LeastSquaresAdapter(problem) { /** {@inheritDoc} */ @Override public Evaluation evaluate(final RealVector point) { return new DenseWeightedEvaluation(super.evaluate(point), weightSquareRoot); } }; }
/** * 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); }
/** * 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); }
/** * Configure the model function. * * @param value the model function value * @param jacobian the Jacobian of {@code value} * @return this */ public LeastSquaresBuilder model(final MultivariateVectorFunction value, final MultivariateMatrixFunction jacobian) { return model(LeastSquaresFactory.model(value, jacobian)); }
/** * Apply a diagonal weight matrix to the {@link LeastSquaresProblem}. * * @param problem the unweighted problem * @param weights the diagonal of the weight matrix * @return a new {@link LeastSquaresProblem} with the weights applied. The original * {@code problem} is not modified. */ public static LeastSquaresProblem weightDiagonal(final LeastSquaresProblem problem, final RealVector weights) { // TODO more efficient implementation return weightMatrix(problem, new DiagonalMatrix(weights.toArray())); }
/** * 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); }
/** * Configure the model function. * * @param value the model function value * @param jacobian the Jacobian of {@code value} * @return this */ public LeastSquaresBuilder model(final MultivariateVectorFunction value, final MultivariateMatrixFunction jacobian) { return model(LeastSquaresFactory.model(value, jacobian)); }
paramValidator); if (weight != null) { return weightMatrix(p, weight); } else { return p;
/** * 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. * * @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); }
/** * Configure the model function. * * @param value the model function value * @param jacobian the Jacobian of {@code value} * @return this */ public LeastSquaresBuilder model(final MultivariateVectorFunction value, final MultivariateMatrixFunction jacobian) { return model(LeastSquaresFactory.model(value, jacobian)); }
/** * Apply a diagonal weight matrix to the {@link LeastSquaresProblem}. * * @param problem the unweighted problem * @param weights the diagonal of the weight matrix * @return a new {@link LeastSquaresProblem} with the weights applied. The original * {@code problem} is not modified. */ public static LeastSquaresProblem weightDiagonal(final LeastSquaresProblem problem, final RealVector weights) { // TODO more efficient implementation return weightMatrix(problem, new DiagonalMatrix(weights.toArray())); }
/** * Configure the convergence checker. * <p/> * This function is an overloaded version of {@link #checker(ConvergenceChecker)}. * * @param newChecker the convergence checker. * @return this */ public LeastSquaresBuilder checkerPair(final ConvergenceChecker<PointVectorValuePair> newChecker) { return this.checker(LeastSquaresFactory.evaluationChecker(newChecker)); }
/** * Apply a dense weight matrix to the {@link LeastSquaresProblem}. * * @param problem the unweighted problem * @param weights the matrix of weights * @return a new {@link LeastSquaresProblem} with the weights applied. The original * {@code problem} is not modified. */ public static LeastSquaresProblem weightMatrix(final LeastSquaresProblem problem, final RealMatrix weights) { final RealMatrix weightSquareRoot = squareRoot(weights); return new LeastSquaresAdapter(problem) { /** {@inheritDoc} */ @Override public Evaluation evaluate(final RealVector point) { return new DenseWeightedEvaluation(super.evaluate(point), weightSquareRoot); } }; }
/** * 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); }