OptimumImpl.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.  *      http://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. package org.apache.commons.math4.legacy.fitting.leastsquares;

  18. import org.apache.commons.math4.legacy.fitting.leastsquares.LeastSquaresOptimizer.Optimum;
  19. import org.apache.commons.math4.legacy.fitting.leastsquares.LeastSquaresProblem.Evaluation;
  20. import org.apache.commons.math4.legacy.linear.RealMatrix;
  21. import org.apache.commons.math4.legacy.linear.RealVector;

  22. /**
  23.  * A pedantic implementation of {@link Optimum}.
  24.  *
  25.  * @since 3.3
  26.  */
  27. class OptimumImpl implements Optimum {

  28.     /** abscissa and ordinate. */
  29.     private final Evaluation value;
  30.     /** number of evaluations to compute this optimum. */
  31.     private final int evaluations;
  32.     /** number of iterations to compute this optimum. */
  33.     private final int iterations;

  34.     /**
  35.      * Construct an optimum from an evaluation and the values of the counters.
  36.      *
  37.      * @param value       the function value
  38.      * @param evaluations number of times the function was evaluated
  39.      * @param iterations  number of iterations of the algorithm
  40.      */
  41.     OptimumImpl(final Evaluation value, final int evaluations, final int iterations) {
  42.         this.value = value;
  43.         this.evaluations = evaluations;
  44.         this.iterations = iterations;
  45.     }

  46.     /* auto-generated implementations */

  47.     /** {@inheritDoc} */
  48.     @Override
  49.     public int getEvaluations() {
  50.         return evaluations;
  51.     }

  52.     /** {@inheritDoc} */
  53.     @Override
  54.     public int getIterations() {
  55.         return iterations;
  56.     }

  57.     /** {@inheritDoc} */
  58.     @Override
  59.     public RealMatrix getCovariances(double threshold) {
  60.         return value.getCovariances(threshold);
  61.     }

  62.     /** {@inheritDoc} */
  63.     @Override
  64.     public RealVector getSigma(double covarianceSingularityThreshold) {
  65.         return value.getSigma(covarianceSingularityThreshold);
  66.     }

  67.     /** {@inheritDoc} */
  68.     @Override
  69.     public double getRMS() {
  70.         return value.getRMS();
  71.     }

  72.     /** {@inheritDoc} */
  73.     @Override
  74.     public RealMatrix getJacobian() {
  75.         return value.getJacobian();
  76.     }

  77.     /** {@inheritDoc} */
  78.     @Override
  79.     public double getCost() {
  80.         return value.getCost();
  81.     }

  82.     /** {@inheritDoc} */
  83.     @Override
  84.     public double getChiSquare() {
  85.         return value.getChiSquare();
  86.     }

  87.     /** {@inheritDoc} */
  88.     @Override
  89.     public double getReducedChiSquare(int n) {
  90.         return value.getReducedChiSquare(n);
  91.     }

  92.     /** {@inheritDoc} */
  93.     @Override
  94.     public RealVector getResiduals() {
  95.         return value.getResiduals();
  96.     }

  97.     /** {@inheritDoc} */
  98.     @Override
  99.     public RealVector getPoint() {
  100.         return value.getPoint();
  101.     }
  102. }