<commit_before>/* Copyright 2013-2016 CS Systèmes d'Information
 * Licensed to CS Systèmes d'Information (CS) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * CS licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.orekit.rugged.adjustment;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.hipparchus.analysis.differentiation.DSFactory;
import org.hipparchus.analysis.differentiation.DerivativeStructure;
import org.hipparchus.optim.ConvergenceChecker;
import org.hipparchus.optim.nonlinear.vector.leastsquares.LeastSquaresProblem;
import org.hipparchus.optim.nonlinear.vector.leastsquares.MultivariateJacobianFunction;
import org.hipparchus.optim.nonlinear.vector.leastsquares.ParameterValidator;
import org.orekit.errors.OrekitException;
import org.orekit.errors.OrekitExceptionWrapper;
import org.orekit.rugged.errors.RuggedException;
import org.orekit.rugged.errors.RuggedExceptionWrapper;
import org.orekit.rugged.errors.RuggedMessages;
import org.orekit.rugged.linesensor.LineSensor;
import org.orekit.rugged.refining.measures.Observables;
import org.orekit.rugged.utils.DSGenerator;
import org.orekit.utils.ParameterDriver;

/**
 * Builder for optimization problem.
 * <p>
 * </p>
 *
 * @author <NAME>
 */
abstract class OptimizationProblemBuilder {

    /**
     * Margin used in parameters estimation for the inverse location lines
     * range.
     */
    protected static final int ESTIMATION_LINE_RANGE_MARGIN = 100;

    /** Derivative structure generator.*/
    protected final DSGenerator generator;

    /** parameterDriversList. */
    protected final List<ParameterDriver> drivers;

    /** number of params to refine. */
    protected final int nbParams;


    /** measures .*/
    protected Observables measures;

    protected final List<LineSensor> sensors;

    /**  OptimizationProblemBuilder constructor.
     * @param sensors
     * @param measures
     * @throws RuggedException
     */
    OptimizationProblemBuilder(final List<LineSensor> sensors,
                               final Observables measures)
                                               throws RuggedException {
        try {
            this.generator = this.createGenerator(sensors);
            this.drivers = this.generator.getSelected();
            this.nbParams = this.drivers.size();
            if (this.nbParams == 0) {
                throw new RuggedException(RuggedMessages.NO_PARAMETERS_SELECTED);
            }
        } catch (RuggedExceptionWrapper rew) {
            throw rew.getException();
        }

        this.measures = measures;
        this.sensors = sensors;
    }

    /**  nbParams getter.
     * @return returns the number of variable parameters
     */
    public final int getNbParams() {
        return this.getNbParams();
    }

    /**
     * parameters drivers list getter.
     *
     * @return selected list of parameters driver
     */
    public final List<ParameterDriver> getSelectedParametersDriver() {
        return this.drivers;
    }



    /** leastsquare problem builder.
     * @param maxEvaluations maxIterations and evaluations
     * @param convergenceThreshold parameter convergence threshold
     * @throws RuggedException if sensor is not found
     * @return the problem
     */

    public abstract LeastSquaresProblem build(int maxEvaluations, double convergenceThreshold) throws RuggedException;

    /**
     * Create the convergence check.
     * <p>
     * check Linf distance of parameters variation between previous and current
     * iteration
     * </p>
     *
     * @param parametersConvergenceThreshold convergence threshold
     * @return the checker
     */
    final ConvergenceChecker<LeastSquaresProblem.Evaluation>
    createChecker(final double parametersConvergenceThreshold) {
        final ConvergenceChecker<LeastSquaresProblem.Evaluation> checker = (iteration,
                        previous,
                        current) -> current
                        .getPoint()
                        .getLInfDistance(previous
                                         .getPoint()) <= parametersConvergenceThreshold;<commit_msg>[ENH] method getGenerator added.<commit_after>/* Copyright 2013-2016 CS Systèmes d'Information
 * Licensed to CS Systèmes d'Information (CS) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * CS licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.orekit.rugged.adjustment;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.hipparchus.analysis.differentiation.DSFactory;
import org.hipparchus.analysis.differentiation.DerivativeStructure;
import org.hipparchus.optim.ConvergenceChecker;
import org.hipparchus.optim.nonlinear.vector.leastsquares.LeastSquaresProblem;
import org.hipparchus.optim.nonlinear.vector.leastsquares.MultivariateJacobianFunction;
import org.hipparchus.optim.nonlinear.vector.leastsquares.ParameterValidator;
import org.orekit.errors.OrekitException;
import org.orekit.errors.OrekitExceptionWrapper;
import org.orekit.rugged.errors.RuggedException;
import org.orekit.rugged.errors.RuggedExceptionWrapper;
import org.orekit.rugged.errors.RuggedMessages;
import org.orekit.rugged.linesensor.LineSensor;
import org.orekit.rugged.refining.measures.Observables;
import org.orekit.rugged.utils.DSGenerator;
import org.orekit.utils.ParameterDriver;

/**
 * Builder for optimization problem.
 * <p>
 * </p>
 *
 * @author <NAME>
 */
abstract class OptimizationProblemBuilder {

    /**
     * Margin used in parameters estimation for the inverse location lines
     * range.
     */
    protected static final int ESTIMATION_LINE_RANGE_MARGIN = 100;

    /** Derivative structure generator.*/
    protected final DSGenerator generator;

    /** parameterDriversList. */
    protected final List<ParameterDriver> drivers;

    /** number of params to refine. */
    protected final int nbParams;


    /** measures .*/
    protected Observables measures;

    protected final List<LineSensor> sensors;

    /**  OptimizationProblemBuilder constructor.
     * @param sensors
     * @param measures
     * @throws RuggedException
     */
    OptimizationProblemBuilder(final List<LineSensor> sensors,
                               final Observables measures)
                                               throws RuggedException {
        try {
            this.generator = this.createGenerator(sensors);
            this.drivers = this.generator.getSelected();
            this.nbParams = this.drivers.size();
            if (this.nbParams == 0) {
                throw new RuggedException(RuggedMessages.NO_PARAMETERS_SELECTED);
            }
        } catch (RuggedExceptionWrapper rew) {
            throw rew.getException();
        }

        this.measures = measures;
        this.sensors = sensors;
    }

    /**  nbParams getter.
     * @return returns the number of variable parameters
     */
    public final int getNbParams() {
        return this.getNbParams();
    }

    /**
     * parameters drivers list getter.
     *
     * @return selected list of parameters driver
     */
    public final List<ParameterDriver> getSelectedParametersDriver() {
        return this.drivers;
    }


    /**
     * generator getter.
     *
     * @return the derivative structure generator.
     */
    public final DSGenerator getGenerator() {
        return this.generator;
    }



    /** leastsquare problem builder.
     * @param maxEvaluations maxIterations and evaluations
     * @param convergenceThreshold parameter convergence threshold
     * @throws RuggedException if sensor is not found
     * @return the problem
     */

    public abstract LeastSquaresProblem build(int maxEvaluations, double convergenceThreshold) throws RuggedException;

    /**
     * Create the convergence check.
     * <p>
     * check Linf distance of parameters variation between previous and current
     * iteration
     * </p>
     *
     * @param parametersConvergenceThreshold convergence threshold
     * @return the checker
     */
    final ConvergenceChecker<LeastSquaresProblem.Evaluation>
    createChecker(final double parametersConvergenceThreshold) {
        final ConvergenceChecker<LeastSquaresProblem.Evaluation> checker = (iteration,
                        previous,
                        current) -> current
                        .getPoint()
                        .getLInfDistance(previous
                                         .getPoint()) <= parametersConvergenceThreshold;
{'fraction_non_alphanumeric': 0.07891293407146452, 'fraction_numerical': 0.0032209360845495724, 'mean_word_length': 2.884284597341673, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7393956', 'n_tokens_mistral': 2636, 'n_tokens_neox': 2501, 'n_words': 731}