001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 018package org.apache.commons.math3.optimization; 019 020import org.apache.commons.math3.util.Precision; 021 022/** 023 * Base class for all convergence checker implementations. 024 * 025 * @param <PAIR> Type of (point, value) pair. 026 * 027 * @deprecated As of 3.1 (to be removed in 4.0). 028 * @since 3.0 029 */ 030@Deprecated 031public abstract class AbstractConvergenceChecker<PAIR> 032 implements ConvergenceChecker<PAIR> { 033 /** 034 * Default relative threshold. 035 * @deprecated in 3.1 (to be removed in 4.0) because this value is too small 036 * to be useful as a default (cf. MATH-798). 037 */ 038 @Deprecated 039 private static final double DEFAULT_RELATIVE_THRESHOLD = 100 * Precision.EPSILON; 040 /** 041 * Default absolute threshold. 042 * @deprecated in 3.1 (to be removed in 4.0) because this value is too small 043 * to be useful as a default (cf. MATH-798). 044 */ 045 @Deprecated 046 private static final double DEFAULT_ABSOLUTE_THRESHOLD = 100 * Precision.SAFE_MIN; 047 /** 048 * Relative tolerance threshold. 049 */ 050 private final double relativeThreshold; 051 /** 052 * Absolute tolerance threshold. 053 */ 054 private final double absoluteThreshold; 055 056 /** 057 * Build an instance with default thresholds. 058 * @deprecated in 3.1 (to be removed in 4.0). Convergence thresholds are 059 * problem-dependent. As this class is intended for users who want to set 060 * their own convergence criterion instead of relying on an algorithm's 061 * default procedure, they should also set the thresholds appropriately 062 * (cf. MATH-798). 063 */ 064 @Deprecated 065 public AbstractConvergenceChecker() { 066 this.relativeThreshold = DEFAULT_RELATIVE_THRESHOLD; 067 this.absoluteThreshold = DEFAULT_ABSOLUTE_THRESHOLD; 068 } 069 070 /** 071 * Build an instance with a specified thresholds. 072 * 073 * @param relativeThreshold relative tolerance threshold 074 * @param absoluteThreshold absolute tolerance threshold 075 */ 076 public AbstractConvergenceChecker(final double relativeThreshold, 077 final double absoluteThreshold) { 078 this.relativeThreshold = relativeThreshold; 079 this.absoluteThreshold = absoluteThreshold; 080 } 081 082 /** 083 * @return the relative threshold. 084 */ 085 public double getRelativeThreshold() { 086 return relativeThreshold; 087 } 088 089 /** 090 * @return the absolute threshold. 091 */ 092 public double getAbsoluteThreshold() { 093 return absoluteThreshold; 094 } 095 096 /** 097 * {@inheritDoc} 098 */ 099 public abstract boolean converged(int iteration, 100 PAIR previous, 101 PAIR current); 102}