LeastSquaresOptimizer.java

  1. /*
  2.  * Licensed to the Apache Software Foundation (ASF) under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * The ASF licenses this file to You under the Apache License, Version 2.0
  6.  * (the "License"); you may not use this file except in compliance with
  7.  * the License.  You may obtain a copy of the License at
  8.  *
  9.  *      https://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */

  17. /*
  18.  * This is not the original file distributed by the Apache Software Foundation
  19.  * It has been modified by the Hipparchus project
  20.  */
  21. package org.hipparchus.optim.nonlinear.vector.leastsquares;

  22. /**
  23.  * An algorithm that can be applied to a non-linear least squares problem.
  24.  */
  25. public interface LeastSquaresOptimizer {

  26.     /**
  27.      * Solve the non-linear least squares problem.
  28.      *
  29.      *
  30.      * @param leastSquaresProblem the problem definition, including model function and
  31.      *                            convergence criteria.
  32.      * @return The optimum.
  33.      */
  34.     Optimum optimize(LeastSquaresProblem leastSquaresProblem);

  35.     /**
  36.      * The optimum found by the optimizer. This object contains the point, its value, and
  37.      * some metadata.
  38.      */
  39.     interface Optimum extends LeastSquaresProblem.Evaluation {

  40.         /**
  41.          * Get the number of times the model was evaluated in order to produce this
  42.          * optimum.
  43.          *
  44.          * @return the number of model (objective) function evaluations
  45.          */
  46.         int getEvaluations();

  47.         /**
  48.          * Get the number of times the algorithm iterated in order to produce this
  49.          * optimum. In general least squares it is common to have one {@link
  50.          * #getEvaluations() evaluation} per iterations.
  51.          *
  52.          * @return the number of iterations
  53.          */
  54.         int getIterations();

  55.         /**
  56.          * Create a new optimum from an evaluation and the values of the counters.
  57.          *
  58.          * @param value       the function value
  59.          * @param evaluations number of times the function was evaluated
  60.          * @param iterations  number of iterations of the algorithm
  61.          * @return a new optimum based on the given data.
  62.          */
  63.         static Optimum of(final LeastSquaresProblem.Evaluation value,
  64.                           final int evaluations,
  65.                           final int iterations) {
  66.             return new OptimumImpl(value, evaluations, iterations);
  67.         }

  68.     }

  69. }