Search in sources :

Example 1 with DiagonalMatrix

use of org.hipparchus.linear.DiagonalMatrix in project Orekit by CS-SI.

the class AbstractPropagatorConverter method fit.

/**
 * Find the propagator that minimize the mean square error for a sample of {@link SpacecraftState states}.
 * @param initial initial estimation parameters (position, velocity, free parameters)
 * @return fitted parameters
 * @exception OrekitException if propagator cannot be adapted
 * @exception MathRuntimeException if maximal number of iterations is exceeded
 */
private double[] fit(final double[] initial) throws OrekitException, MathRuntimeException {
    final LeastSquaresProblem problem = new LeastSquaresBuilder().maxIterations(maxIterations).maxEvaluations(Integer.MAX_VALUE).model(getModel()).target(target).weight(new DiagonalMatrix(weight)).start(initial).checker(checker).build();
    optimum = optimizer.optimize(problem);
    return optimum.getPoint().toArray();
}
Also used : DiagonalMatrix(org.hipparchus.linear.DiagonalMatrix) LeastSquaresProblem(org.hipparchus.optim.nonlinear.vector.leastsquares.LeastSquaresProblem) LeastSquaresBuilder(org.hipparchus.optim.nonlinear.vector.leastsquares.LeastSquaresBuilder)

Example 2 with DiagonalMatrix

use of org.hipparchus.linear.DiagonalMatrix in project Orekit by CS-SI.

the class SecularAndHarmonic method fit.

/**
 * Fit parameters.
 * @see #getFittedParameters()
 */
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);
}
Also used : WeightedObservedPoint(org.hipparchus.fitting.WeightedObservedPoint) DiagonalMatrix(org.hipparchus.linear.DiagonalMatrix) Collection(java.util.Collection) WeightedObservedPoint(org.hipparchus.fitting.WeightedObservedPoint) AbstractCurveFitter(org.hipparchus.fitting.AbstractCurveFitter) LeastSquaresBuilder(org.hipparchus.optim.nonlinear.vector.leastsquares.LeastSquaresBuilder)

Aggregations

DiagonalMatrix (org.hipparchus.linear.DiagonalMatrix)2 LeastSquaresBuilder (org.hipparchus.optim.nonlinear.vector.leastsquares.LeastSquaresBuilder)2 Collection (java.util.Collection)1 AbstractCurveFitter (org.hipparchus.fitting.AbstractCurveFitter)1 WeightedObservedPoint (org.hipparchus.fitting.WeightedObservedPoint)1 LeastSquaresProblem (org.hipparchus.optim.nonlinear.vector.leastsquares.LeastSquaresProblem)1