SimpleCurveFitter extends AbstractCurveFitter { public static SimpleCurveFitter create(ParametricUnivariateFunction f, double[] start) { return new SimpleCurveFitter(f, start, Integer.MAX_VALUE); } private  SimpleCurveFitter(ParametricUnivariateFunction function,
                              double[] initialGuess,
                              int maxIter); static SimpleCurveFitter create(ParametricUnivariateFunction f,
                                           double[] start); SimpleCurveFitter withStartPoint(double[] newStart); SimpleCurveFitter withMaxIterations(int newMaxIter);  }
@Test public void testPolynomialFit() { final Random randomizer = new Random(53882150042L); final RealDistribution rng = new UniformRealDistribution(-100, 100); rng.reseedRandomGenerator(64925784252L); final double[] coeff = { 12.9, -3.4, 2.1 }; final PolynomialFunction f = new PolynomialFunction(coeff); final WeightedObservedPoints obs = new WeightedObservedPoints(); for (int i = 0; i < 100; i++) { final double x = rng.sample(); obs.add(x, f.value(x) + 0.1 * randomizer.nextGaussian()); } final ParametricUnivariateFunction function = new PolynomialFunction.Parametric(); final SimpleCurveFitter fitter = SimpleCurveFitter.create(function, new double[] { -1e20, 3e15, -5e25 }); final double[] best = fitter.fit(obs.toList()); TestUtils.assertEquals("best != coeff", coeff, best, 2e-2); }