/** Add an observed (x,y) point to the sample with unit weight. * <p>Calling this method is equivalent to call * {@code addObservedPoint(1.0, x, y)}.</p> * @param x abscissa of the point * @param y observed value of the point at x, after fitting we should * have f(x) as close as possible to this value * @see #addObservedPoint(double, double, double) * @see #addObservedPoint(WeightedObservedPoint) * @see #getObservations() */ public void addObservedPoint(double x, double y) { addObservedPoint(1.0, x, y); }
public double[] arbitFit(double[] xReal, double[] yReal, ParametricUnivariateFunction function, double[] guessValues) { int n = xReal.length; LevenbergMarquardtOptimizer optimizer = new LevenbergMarquardtOptimizer(); CurveFitter fitter = new CurveFitter(optimizer); for (int i = 0; i < n; i++) fitter.addObservedPoint(xReal[i], yReal[i]); double[] result = fitter.fit(function, guessValues); return result; }
public ArrayList<double[]> fitExponential(double time[], double voltage[]) { //length of time and voltage arrays should be in the power of 2 double size = time.length; double v80 = voltage[0] * 0.8; double rc = 0; double[] vf = new double[time.length]; for (int k = 0; k < size - 1; k++) { if (voltage[k] < v80) { rc = time[k] / .223; break; } } double[] initialGuess = new double[]{voltage[0], rc, 0}; //initialize the optimizer and curve fitter. LevenbergMarquardtOptimizer optimizer = new LevenbergMarquardtOptimizer(); CurveFitter fitter = new CurveFitter(optimizer); for (int i = 0; i < time.length; i++) fitter.addObservedPoint(time[i], voltage[i]); double[] result = fitter.fit(exponentialParametricUnivariateFunction, initialGuess); //result -> the fitted parameters. for (int i = 0; i < time.length; i++) vf[i] = result[0] * exp(-time[i] / result[1]) + result[2]; return new ArrayList<double[]>(Arrays.asList(result, vf)); }
/** Add an observed (x,y) point to the sample with unit weight. * <p>Calling this method is equivalent to call * {@code addObservedPoint(1.0, x, y)}.</p> * @param x abscissa of the point * @param y observed value of the point at x, after fitting we should * have f(x) as close as possible to this value * @see #addObservedPoint(double, double, double) * @see #addObservedPoint(WeightedObservedPoint) * @see #getObservations() */ public void addObservedPoint(double x, double y) { addObservedPoint(1.0, x, y); }
/** Add an observed (x,y) point to the sample with unit weight. * <p>Calling this method is equivalent to call * {@code addObservedPoint(1.0, x, y)}.</p> * @param x abscissa of the point * @param y observed value of the point at x, after fitting we should * have f(x) as close as possible to this value * @see #addObservedPoint(double, double, double) * @see #addObservedPoint(WeightedObservedPoint) * @see #getObservations() */ public void addObservedPoint(double x, double y) { addObservedPoint(1.0, x, y); }
CurveFitter fitter = new CurveFitter(optimizer); for (int i = 0; i < n; i++) fitter.addObservedPoint(xReal[i], yReal2[i]);
CurveFitter fitter = new CurveFitter(optimizer); for (int i = 0; i < n; i++) fitter.addObservedPoint(xReal[i], yReal2[i]);
fitter.addObservedPoint(points[i]); fitter.addObservedPoint(points[i]);
@Override public DaostormCalibration getDaoCalibration() { ParametricUnivariateFunction sqrtFn = new DefocusFunctionSqrt().getFittingFunction(); ParametricUnivariateFunction polyFn = new DefocusFunctionPoly().getFittingFunction(); CurveFitter<ParametricUnivariateFunction> fitter1 = new CurveFitter<ParametricUnivariateFunction>(new LevenbergMarquardtOptimizer(new SimplePointChecker(10e-10, 10e-10))); CurveFitter<ParametricUnivariateFunction> fitter2 = new CurveFitter<ParametricUnivariateFunction>(new LevenbergMarquardtOptimizer(new SimplePointChecker(10e-10, 10e-10))); double [] polyParams1 = new double[] {w01, c1, a1, b1, d1}; double [] polyParams2 = new double[] {w02, c2, a2, b2, d2}; double zRange = ceil(2*(abs(c1)+abs(c2))); // -zRange:+zRange for(double z = -zRange; z <= zRange; z += 5.0) { fitter1.addObservedPoint(z, polyFn.value(z, polyParams1)); fitter2.addObservedPoint(z, polyFn.value(z, polyParams2)); } double [] parSigma1 = fitter1.fit(1000, sqrtFn, new double[] {2.0, c1, 0.0, 0.0, zRange/2.0}); double [] parSigma2 = fitter2.fit(1000, sqrtFn, new double[] {2.0, c2, 0.0, 0.0, zRange/2.0}); return new DaostormCalibration(angle, homography, parSigma1[0], parSigma1[2], parSigma1[3], parSigma1[1], parSigma1[4], parSigma2[0], parSigma2[2], parSigma2[3], parSigma2[1], parSigma2[4]); } }
curvefitter.addObservedPoint(1.0, xdata[i], ydata[i]);