Example usage for org.apache.commons.math3.fitting AbstractCurveFitter fit

List of usage examples for org.apache.commons.math3.fitting AbstractCurveFitter fit

Introduction

In this page you can find the example usage for org.apache.commons.math3.fitting AbstractCurveFitter fit.

Prototype

public double[] fit(Collection<WeightedObservedPoint> points) 

Source Link

Document

Fits a curve.

Usage

From source file:org.orekit.utils.SecularAndHarmonic.java

/** Fit parameters.
 * @see #getFittedParameters()/*from   w ww. ja  va2  s. c  o m*/
 */
public void fit() {

    final AbstractCurveFitter fitter = new AbstractCurveFitter() {
        /** {@inheritDoc} */
        @Override
        protected LeastSquaresProblem getProblem(final Collection<WeightedObservedPoint> observations) {
            // Prepare least-squares problem.
            final int len = observations.size();
            final double[] target = new double[len];
            final double[] weights = new double[len];

            int i = 0;
            for (final WeightedObservedPoint obs : observations) {
                target[i] = obs.getY();
                weights[i] = obs.getWeight();
                ++i;
            }

            final AbstractCurveFitter.TheoreticalValuesFunction model = new AbstractCurveFitter.TheoreticalValuesFunction(
                    new LocalParametricFunction(), observations);

            // build a new least squares problem set up to fit a secular and harmonic curve to the observed points
            return new LeastSquaresBuilder().maxEvaluations(Integer.MAX_VALUE).maxIterations(Integer.MAX_VALUE)
                    .start(fitted).target(target).weight(new DiagonalMatrix(weights))
                    .model(model.getModelFunction(), model.getModelFunctionJacobian()).build();

        }
    };

    fitted = fitter.fit(observedPoints);

}