AbstractConvergenceChecker.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.math3.optimization;

  18. import org.apache.commons.math3.util.Precision;

  19. /**
  20.  * Base class for all convergence checker implementations.
  21.  *
  22.  * @param <PAIR> Type of (point, value) pair.
  23.  *
  24.  * @deprecated As of 3.1 (to be removed in 4.0).
  25.  * @since 3.0
  26.  */
  27. @Deprecated
  28. public abstract class AbstractConvergenceChecker<PAIR>
  29.     implements ConvergenceChecker<PAIR> {
  30.     /**
  31.      * Default relative threshold.
  32.      * @deprecated in 3.1 (to be removed in 4.0) because this value is too small
  33.      * to be useful as a default (cf. MATH-798).
  34.      */
  35.     @Deprecated
  36.     private static final double DEFAULT_RELATIVE_THRESHOLD = 100 * Precision.EPSILON;
  37.     /**
  38.      * Default absolute threshold.
  39.      * @deprecated in 3.1 (to be removed in 4.0) because this value is too small
  40.      * to be useful as a default (cf. MATH-798).
  41.      */
  42.     @Deprecated
  43.     private static final double DEFAULT_ABSOLUTE_THRESHOLD = 100 * Precision.SAFE_MIN;
  44.     /**
  45.      * Relative tolerance threshold.
  46.      */
  47.     private final double relativeThreshold;
  48.     /**
  49.      * Absolute tolerance threshold.
  50.      */
  51.     private final double absoluteThreshold;

  52.     /**
  53.      * Build an instance with default thresholds.
  54.      * @deprecated in 3.1 (to be removed in 4.0). Convergence thresholds are
  55.      * problem-dependent. As this class is intended for users who want to set
  56.      * their own convergence criterion instead of relying on an algorithm's
  57.      * default procedure, they should also set the thresholds appropriately
  58.      * (cf. MATH-798).
  59.      */
  60.     @Deprecated
  61.     public AbstractConvergenceChecker() {
  62.         this.relativeThreshold = DEFAULT_RELATIVE_THRESHOLD;
  63.         this.absoluteThreshold = DEFAULT_ABSOLUTE_THRESHOLD;
  64.     }

  65.     /**
  66.      * Build an instance with a specified thresholds.
  67.      *
  68.      * @param relativeThreshold relative tolerance threshold
  69.      * @param absoluteThreshold absolute tolerance threshold
  70.      */
  71.     public AbstractConvergenceChecker(final double relativeThreshold,
  72.                                       final double absoluteThreshold) {
  73.         this.relativeThreshold = relativeThreshold;
  74.         this.absoluteThreshold = absoluteThreshold;
  75.     }

  76.     /**
  77.      * @return the relative threshold.
  78.      */
  79.     public double getRelativeThreshold() {
  80.         return relativeThreshold;
  81.     }

  82.     /**
  83.      * @return the absolute threshold.
  84.      */
  85.     public double getAbsoluteThreshold() {
  86.         return absoluteThreshold;
  87.     }

  88.     /**
  89.      * {@inheritDoc}
  90.      */
  91.     public abstract boolean converged(int iteration,
  92.                                       PAIR previous,
  93.                                       PAIR current);
  94. }