View Javadoc
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  
19  import org.apache.commons.math4.legacy.fitting.leastsquares.LeastSquaresOptimizer.Optimum;
20  import org.apache.commons.math4.legacy.fitting.leastsquares.LeastSquaresProblem.Evaluation;
21  import org.apache.commons.math4.legacy.linear.RealMatrix;
22  import org.apache.commons.math4.legacy.linear.RealVector;
23  
24  /**
25   * A pedantic implementation of {@link Optimum}.
26   *
27   * @since 3.3
28   */
29  class OptimumImpl implements Optimum {
30  
31      /** abscissa and ordinate. */
32      private final Evaluation value;
33      /** number of evaluations to compute this optimum. */
34      private final int evaluations;
35      /** number of iterations to compute this optimum. */
36      private final int iterations;
37  
38      /**
39       * Construct an optimum from an evaluation and the values of the counters.
40       *
41       * @param value       the function value
42       * @param evaluations number of times the function was evaluated
43       * @param iterations  number of iterations of the algorithm
44       */
45      OptimumImpl(final Evaluation value, final int evaluations, final int iterations) {
46          this.value = value;
47          this.evaluations = evaluations;
48          this.iterations = iterations;
49      }
50  
51      /* auto-generated implementations */
52  
53      /** {@inheritDoc} */
54      @Override
55      public int getEvaluations() {
56          return evaluations;
57      }
58  
59      /** {@inheritDoc} */
60      @Override
61      public int getIterations() {
62          return iterations;
63      }
64  
65      /** {@inheritDoc} */
66      @Override
67      public RealMatrix getCovariances(double threshold) {
68          return value.getCovariances(threshold);
69      }
70  
71      /** {@inheritDoc} */
72      @Override
73      public RealVector getSigma(double covarianceSingularityThreshold) {
74          return value.getSigma(covarianceSingularityThreshold);
75      }
76  
77      /** {@inheritDoc} */
78      @Override
79      public double getRMS() {
80          return value.getRMS();
81      }
82  
83      /** {@inheritDoc} */
84      @Override
85      public RealMatrix getJacobian() {
86          return value.getJacobian();
87      }
88  
89      /** {@inheritDoc} */
90      @Override
91      public double getCost() {
92          return value.getCost();
93      }
94  
95      /** {@inheritDoc} */
96      @Override
97      public double getChiSquare() {
98          return value.getChiSquare();
99      }
100 
101     /** {@inheritDoc} */
102     @Override
103     public double getReducedChiSquare(int n) {
104         return value.getReducedChiSquare(n);
105     }
106 
107     /** {@inheritDoc} */
108     @Override
109     public RealVector getResiduals() {
110         return value.getResiduals();
111     }
112 
113     /** {@inheritDoc} */
114     @Override
115     public RealVector getPoint() {
116         return value.getPoint();
117     }
118 }