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 package org.apache.commons.math;
018
019
020 /**
021 * Interface for algorithms handling convergence settings.
022 * <p>
023 * This interface only deals with convergence parameters setting, not
024 * execution of the algorithms per se.
025 * </p>
026 * @see ConvergenceException
027 * @version $Revision: 811786 $ $Date: 2009-09-06 05:36:08 -0400 (Sun, 06 Sep 2009) $
028 * @since 2.0
029 */
030 public interface ConvergingAlgorithm {
031
032 /**
033 * Set the upper limit for the number of iterations.
034 * <p>
035 * Usually a high iteration count indicates convergence problems. However,
036 * the "reasonable value" varies widely for different algorithms. Users are
037 * advised to use the default value supplied by the algorithm.</p>
038 * <p>
039 * A {@link ConvergenceException} will be thrown if this number
040 * is exceeded.</p>
041 *
042 * @param count maximum number of iterations
043 */
044 void setMaximalIterationCount(int count);
045
046 /**
047 * Get the upper limit for the number of iterations.
048 *
049 * @return the actual upper limit
050 */
051 int getMaximalIterationCount();
052
053 /**
054 * Reset the upper limit for the number of iterations to the default.
055 * <p>
056 * The default value is supplied by the algorithm implementation.</p>
057 *
058 * @see #setMaximalIterationCount(int)
059 */
060 void resetMaximalIterationCount();
061
062 /**
063 * Set the absolute accuracy.
064 * <p>
065 * The default is usually chosen so that results in the interval
066 * -10..-0.1 and +0.1..+10 can be found with a reasonable accuracy. If the
067 * expected absolute value of your results is of much smaller magnitude, set
068 * this to a smaller value.</p>
069 * <p>
070 * Algorithms are advised to do a plausibility check with the relative
071 * accuracy, but clients should not rely on this.</p>
072 *
073 * @param accuracy the accuracy.
074 * @throws IllegalArgumentException if the accuracy can't be achieved by
075 * the solver or is otherwise deemed unreasonable.
076 */
077 void setAbsoluteAccuracy(double accuracy);
078
079 /**
080 * Get the actual absolute accuracy.
081 *
082 * @return the accuracy
083 */
084 double getAbsoluteAccuracy();
085
086 /**
087 * Reset the absolute accuracy to the default.
088 * <p>
089 * The default value is provided by the algorithm implementation.</p>
090 */
091 void resetAbsoluteAccuracy();
092
093 /**
094 * Set the relative accuracy.
095 * <p>
096 * This is used to stop iterations if the absolute accuracy can't be
097 * achieved due to large values or short mantissa length.</p>
098 * <p>
099 * If this should be the primary criterion for convergence rather then a
100 * safety measure, set the absolute accuracy to a ridiculously small value,
101 * like {@link org.apache.commons.math.util.MathUtils#SAFE_MIN MathUtils.SAFE_MIN}.</p>
102 *
103 * @param accuracy the relative accuracy.
104 * @throws IllegalArgumentException if the accuracy can't be achieved by
105 * the algorithm or is otherwise deemed unreasonable.
106 */
107 void setRelativeAccuracy(double accuracy);
108
109 /**
110 * Get the actual relative accuracy.
111 * @return the accuracy
112 */
113 double getRelativeAccuracy();
114
115 /**
116 * Reset the relative accuracy to the default.
117 * The default value is provided by the algorithm implementation.
118 */
119 void resetRelativeAccuracy();
120
121 /**
122 * Get the number of iterations in the last run of the algorithm.
123 * <p>
124 * This is mainly meant for testing purposes. It may occasionally
125 * help track down performance problems: if the iteration count
126 * is notoriously high, check whether the problem is evaluated
127 * properly, and whether another algorithm is more amenable to the
128 * problem.</p>
129 *
130 * @return the last iteration count.
131 * @throws IllegalStateException if there is no result available, either
132 * because no result was yet computed or the last attempt failed.
133 */
134 int getIterationCount();
135
136 }