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.math;
18  
19  
20  /**
21   * Interface for algorithms handling convergence settings.
22   * <p>
23   * This interface only deals with convergence parameters setting, not
24   * execution of the algorithms per se.
25   * </p>
26   * @see ConvergenceException
27   * @version $Revision: 785473 $ $Date: 2009-06-17 00:02:35 -0400 (Wed, 17 Jun 2009) $
28   * @since 2.0
29   */
30  public interface ConvergingAlgorithm {
31  
32      /**
33       * Set the upper limit for the number of iterations.
34       * <p>
35       * Usually a high iteration count indicates convergence problems. However,
36       * the "reasonable value" varies widely for different algorithms. Users are
37       * advised to use the default value supplied by the algorithm.</p>
38       * <p>
39       * A {@link ConvergenceException} will be thrown if this number
40       * is exceeded.</p>
41       *  
42       * @param count maximum number of iterations
43       */
44      public abstract void setMaximalIterationCount(int count);
45  
46      /**
47       * Get the upper limit for the number of iterations.
48       * 
49       * @return the actual upper limit
50       */
51      public abstract int getMaximalIterationCount();
52  
53      /**
54       * Reset the upper limit for the number of iterations to the default.
55       * <p>
56       * The default value is supplied by the algorithm implementation.</p>
57       * 
58       * @see #setMaximalIterationCount(int)
59       */
60      public abstract void resetMaximalIterationCount();
61  
62      /**
63       * Set the absolute accuracy.
64       * <p>
65       * The default is usually chosen so that results in the interval
66       * -10..-0.1 and +0.1..+10 can be found with a reasonable accuracy. If the
67       * expected absolute value of your results is of much smaller magnitude, set
68       * this to a smaller value.</p>
69       * <p>
70       * Algorithms are advised to do a plausibility check with the relative
71       * accuracy, but clients should not rely on this.</p>
72       *  
73       * @param accuracy the accuracy.
74       * @throws IllegalArgumentException if the accuracy can't be achieved by
75       * the solver or is otherwise deemed unreasonable. 
76       */
77      public abstract void setAbsoluteAccuracy(double accuracy);
78  
79      /**
80       * Get the actual absolute accuracy.
81       * 
82       * @return the accuracy
83       */
84      public abstract double getAbsoluteAccuracy();
85  
86      /**
87       * Reset the absolute accuracy to the default.
88       * <p>
89       * The default value is provided by the algorithm implementation.</p>
90       */
91      public abstract void resetAbsoluteAccuracy();
92  
93      /**
94       * Set the relative accuracy.
95       * <p>
96       * This is used to stop iterations if the absolute accuracy can't be
97       * achieved due to large values or short mantissa length.</p>
98       * <p>
99       * 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     public abstract void setRelativeAccuracy(double accuracy);
108 
109     /**
110      * Get the actual relative accuracy.
111      * @return the accuracy
112      */
113     public abstract double getRelativeAccuracy();
114 
115     /**
116      * Reset the relative accuracy to the default.
117      * The default value is provided by the algorithm implementation.
118      */
119     public abstract 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     public abstract int getIterationCount();
135 
136 }