/** {@inheritDoc} */ public boolean converged(final int iteration, final VectorialPointValuePair previous, final VectorialPointValuePair current) { final double[] p = previous.getPointRef(); final double[] c = current.getPointRef(); for (int i = 0; i < p.length; ++i) { final double pi = p[i]; final double ci = c[i]; final double difference = Math.abs(pi - ci); final double size = Math.max(Math.abs(pi), Math.abs(ci)); if ((difference > (size * relativeThreshold)) && (difference > absoluteThreshold)) { return false; } } return true; }
/** {@inheritDoc} */ public boolean converged(final int iteration, final VectorialPointValuePair previous, final VectorialPointValuePair current) { final double[] p = previous.getPointRef(); final double[] c = current.getPointRef(); for (int i = 0; i < p.length; ++i) { final double pi = p[i]; final double ci = c[i]; final double difference = FastMath.abs(pi - ci); final double size = FastMath.max(FastMath.abs(pi), FastMath.abs(ci)); if ((difference > (size * relativeThreshold)) && (difference > absoluteThreshold)) { return false; } } return true; }
/** Fit a curve. * <p>This method compute the coefficients of the curve that best * fit the sample of observed points previously given through calls * to the {@link #addObservedPoint(WeightedObservedPoint) * addObservedPoint} method.</p> * @param f parametric function to fit * @param initialGuess first guess of the function parameters * @return fitted parameters * @exception FunctionEvaluationException if the objective function throws one during the search * @exception OptimizationException if the algorithm failed to converge * @exception IllegalArgumentException if the start point dimension is wrong */ public double[] fit(final ParametricRealFunction f, final double[] initialGuess) throws FunctionEvaluationException, OptimizationException, IllegalArgumentException { // prepare least squares problem double[] target = new double[observations.size()]; double[] weights = new double[observations.size()]; int i = 0; for (WeightedObservedPoint point : observations) { target[i] = point.getY(); weights[i] = point.getWeight(); ++i; } // perform the fit VectorialPointValuePair optimum = optimizer.optimize(new TheoreticalValuesFunction(f), target, weights, initialGuess); // extract the coefficients return optimum.getPointRef(); }
return optimum.getPointRef();