/** {@inheritDoc} */ @Override public Evaluation evaluate(final RealVector point) { // Copy so optimizer can change point without changing our instance. final RealVector p = paramValidator == null ? point.copy() : paramValidator.validate(point.copy()); if (lazyEvaluation) { return new LazyUnweightedEvaluation((ValueAndJacobianFunction) model, target, p); } else { // Evaluate value and jacobian in one function call. final Pair<RealVector, RealMatrix> value = model.value(p); return new UnweightedEvaluation(value.getFirst(), value.getSecond(), target, p); } }
/** * Create a {@link LeastSquaresProblem} from the given data. * * @param model the model function * @param target the observed data * @param start the initial guess * @param checker the convergence checker * @param maxEvaluations the allowed evaluations * @param maxIterations the allowed iterations * @param lazyEvaluation Whether the call to {@link Evaluation#evaluate(RealVector)} will defer * the evaluation until access to the value is requested. * @param paramValidator Model parameters validator. */ LocalLeastSquaresProblem( final MultivariateJacobianFunction model, final RealVector target, final RealVector start, final ConvergenceChecker<Evaluation> checker, final int maxEvaluations, final int maxIterations, final boolean lazyEvaluation, final ParameterValidator paramValidator) { super(maxEvaluations, maxIterations, checker); this.target = target; this.model = model; this.start = start; this.lazyEvaluation = lazyEvaluation; this.paramValidator = paramValidator; if (lazyEvaluation && !(model instanceof ValueAndJacobianFunction)) { // Lazy evaluation requires that value and Jacobian // can be computed separately. throw new MathIllegalStateException( LocalizedFormats.INVALID_IMPLEMENTATION, model.getClass().getName()); } }