Author: erans Date: Thu Jan 6 16:20:51 2011 New Revision: 1055931 URL: http://svn.apache.org/viewvc?rev=1055931&view=rev Log: MATH-458 Removed the checked "MathException" from the interpolator interfaces. Updated all affected classes. "LoessInterpolator": Replaced usage of "MathException" with specific exceptions.
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/BicubicSplineInterpolator.java commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/BivariateRealGridInterpolator.java commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/LoessInterpolator.java commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/NevilleInterpolator.java commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/SmoothingPolynomialBicubicSplineInterpolator.java commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/TricubicSplineInterpolator.java commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/TrivariateRealGridInterpolator.java commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/UnivariateRealInterpolator.java commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/polynomials/PolynomialFunctionLagrangeForm.java commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NotFiniteNumberException.java commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/util/LocalizedFormats.java commons/proper/math/trunk/src/main/resources/META-INF/localization/LocalizedFormats_fr.properties commons/proper/math/trunk/src/site/xdoc/changes.xml commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/interpolation/LoessInterpolatorTest.java Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/BicubicSplineInterpolator.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/BicubicSplineInterpolator.java?rev=1055931&r1=1055930&r2=1055931&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/BicubicSplineInterpolator.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/BicubicSplineInterpolator.java Thu Jan 6 16:20:51 2011 @@ -16,7 +16,6 @@ */ package org.apache.commons.math.analysis.interpolation; -import org.apache.commons.math.MathException; import org.apache.commons.math.analysis.UnivariateRealFunction; import org.apache.commons.math.analysis.polynomials.PolynomialSplineFunction; import org.apache.commons.math.exception.DimensionMismatchException; @@ -36,8 +35,7 @@ public class BicubicSplineInterpolator */ public BicubicSplineInterpolatingFunction interpolate(final double[] xval, final double[] yval, - final double[][] fval) - throws MathException { + final double[][] fval) { if (xval.length == 0 || yval.length == 0 || fval.length == 0) { throw new NoDataException(); } Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/BivariateRealGridInterpolator.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/BivariateRealGridInterpolator.java?rev=1055931&r1=1055930&r2=1055931&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/BivariateRealGridInterpolator.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/BivariateRealGridInterpolator.java Thu Jan 6 16:20:51 2011 @@ -16,7 +16,6 @@ */ package org.apache.commons.math.analysis.interpolation; -import org.apache.commons.math.MathException; import org.apache.commons.math.analysis.BivariateRealFunction; /** @@ -27,7 +26,7 @@ import org.apache.commons.math.analysis. */ public interface BivariateRealGridInterpolator { /** - * Computes an interpolating function for the data set. + * Compute an interpolating function for the dataset. * * @param xval All the x-coordinates of the interpolation points, sorted * in increasing order. @@ -35,10 +34,12 @@ public interface BivariateRealGridInterp * in increasing order. * @param fval The values of the interpolation points on all the grid knots: * {...@code fval[i][j] = f(xval[i], yval[j])}. - * @return a function which interpolates the data set. - * @throws MathException if arguments violate assumptions made by the - * interpolation algorithm. + * @return a function which interpolates the dataset. + * @throws org.apache.commons.math.exception.NoDataException if any of + * the arrays has zero length. + * @throws org.apache.commons.math.exception.DimensionMismatchException + * if the array lengths are inconsistent. */ - BivariateRealFunction interpolate(double[] xval, double[] yval, double[][] fval) - throws MathException; + BivariateRealFunction interpolate(double[] xval, double[] yval, + double[][] fval); } Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/LoessInterpolator.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/LoessInterpolator.java?rev=1055931&r1=1055930&r2=1055931&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/LoessInterpolator.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/LoessInterpolator.java Thu Jan 6 16:20:51 2011 @@ -19,11 +19,16 @@ package org.apache.commons.math.analysis import java.io.Serializable; import java.util.Arrays; -import org.apache.commons.math.MathException; import org.apache.commons.math.analysis.polynomials.PolynomialSplineFunction; +import org.apache.commons.math.exception.NotPositiveException; +import org.apache.commons.math.exception.OutOfRangeException; +import org.apache.commons.math.exception.DimensionMismatchException; +import org.apache.commons.math.exception.NoDataException; +import org.apache.commons.math.exception.NumberIsTooSmallException; import org.apache.commons.math.exception.util.Localizable; import org.apache.commons.math.exception.util.LocalizedFormats; import org.apache.commons.math.util.FastMath; +import org.apache.commons.math.util.MathUtils; /** * Implements the <a href="http://en.wikipedia.org/wiki/Local_regression"> @@ -43,22 +48,17 @@ import org.apache.commons.math.util.Fast */ public class LoessInterpolator implements UnivariateRealInterpolator, Serializable { - /** Default value of the bandwidth parameter. */ public static final double DEFAULT_BANDWIDTH = 0.3; - /** Default value of the number of robustness iterations. */ public static final int DEFAULT_ROBUSTNESS_ITERS = 2; - /** * Default value for accuracy. * @since 2.1 */ public static final double DEFAULT_ACCURACY = 1e-12; - /** serializable version identifier. */ private static final long serialVersionUID = 5204927143605193821L; - /** * The bandwidth parameter: when computing the loess fit at * a particular point, this fraction of source points closest @@ -68,7 +68,6 @@ public class LoessInterpolator * A sensible value is usually 0.25 to 0.5. */ private final double bandwidth; - /** * The number of robustness iterations parameter: this many * robustness iterations are done. @@ -77,7 +76,6 @@ public class LoessInterpolator * robustness iterations) to 4. */ private final int robustnessIters; - /** * If the median residual at a certain robustness iteration * is less than this amount, no more iterations are done. @@ -99,7 +97,7 @@ public class LoessInterpolator } /** - * Constructs a new {...@link LoessInterpolator} + * Construct a new {...@link LoessInterpolator} * with given bandwidth and number of robustness iterations. * <p> * Calling this constructor is equivalent to calling {link {...@link @@ -117,16 +115,15 @@ public class LoessInterpolator * A sensible value is usually 0 (just the initial fit without any * robustness iterations) to 4, the default value is * {...@link #DEFAULT_ROBUSTNESS_ITERS}. - * @throws MathException if bandwidth does not lie in the interval [0,1] - * or if robustnessIters is negative. + * @see #LoessInterpolator(double, int, double) */ - public LoessInterpolator(double bandwidth, int robustnessIters) throws MathException { + public LoessInterpolator(double bandwidth, int robustnessIters) { this(bandwidth, robustnessIters, DEFAULT_ACCURACY); } /** - * Constructs a new {...@link LoessInterpolator} + * Construct a new {...@link LoessInterpolator} * with given bandwidth, number of robustness iterations and accuracy. * * @param bandwidth when computing the loess fit at @@ -141,19 +138,19 @@ public class LoessInterpolator * {...@link #DEFAULT_ROBUSTNESS_ITERS}. * @param accuracy If the median residual at a certain robustness iteration * is less than this amount, no more iterations are done. - * @throws MathException if bandwidth does not lie in the interval [0,1] - * or if robustnessIters is negative. + * @throws OutOfRangeException if bandwidth does not lie in the interval [0,1]. + * @throws NotPositiveException if {...@code robustnessIters} is negative. * @see #LoessInterpolator(double, int) * @since 2.1 */ - public LoessInterpolator(double bandwidth, int robustnessIters, double accuracy) throws MathException { - if (bandwidth < 0 || bandwidth > 1) { - throw new MathException(LocalizedFormats.BANDWIDTH_OUT_OF_INTERVAL, - bandwidth); + public LoessInterpolator(double bandwidth, int robustnessIters, double accuracy) { + if (bandwidth < 0 || + bandwidth > 1) { + throw new OutOfRangeException(LocalizedFormats.BANDWIDTH, bandwidth, 0, 1); } this.bandwidth = bandwidth; if (robustnessIters < 0) { - throw new MathException(LocalizedFormats.NEGATIVE_ROBUSTNESS_ITERATIONS, robustnessIters); + throw new NotPositiveException(LocalizedFormats.ROBUSTNESS_ITERATIONS, robustnessIters); } this.robustnessIters = robustnessIters; this.accuracy = accuracy; @@ -169,51 +166,58 @@ public class LoessInterpolator * @param xval the arguments for the interpolation points * @param yval the values for the interpolation points * @return A cubic spline built upon a loess fit to the data at the original abscissae - * @throws MathException if some of the following conditions are false: - * <ul> - * <li> Arguments and values are of the same size that is greater than zero</li> - * <li> The arguments are in a strictly increasing order</li> - * <li> All arguments and values are finite real numbers</li> - * </ul> + * @throws org.apache.commons.math.exception.NonMonotonousSequenceException + * if {...@code xval} not sorted in strictly increasing order. + * @throws DimensionMismatchException if {...@code xval} and {...@code yval} have + * different sizes. + * @throws NoDataException if {...@code xval} or {...@code yval} has zero size. + * @throws org.apache.commons.math.exception.NotFiniteNumberException if + * any of the arguments and values are not finite real numbers. + * @throws NumberIsTooSmallException if the bandwidth is too small to + * accomodate the size of the input data (i.e. the bandwidth must be + * larger than 2/n). */ - public final PolynomialSplineFunction interpolate( - final double[] xval, final double[] yval) throws MathException { + public final PolynomialSplineFunction interpolate(final double[] xval, final double[] yval) { return new SplineInterpolator().interpolate(xval, smooth(xval, yval)); } /** * Compute a weighted loess fit on the data at the original abscissae. * - * @param xval the arguments for the interpolation points - * @param yval the values for the interpolation points - * @param weights point weights: coefficients by which the robustness weight of a point is multiplied - * @return values of the loess fit at corresponding original abscissae - * @throws MathException if some of the following conditions are false: - * <ul> - * <li> Arguments and values are of the same size that is greater than zero</li> - * <li> The arguments are in a strictly increasing order</li> - * <li> All arguments and values are finite real numbers</li> - * </ul> + * @param xval Arguments for the interpolation points. + * @param yval Values for the interpolation points. + * @param weights point weights: coefficients by which the robustness weight + * of a point is multiplied. + * @return the values of the loess fit at corresponding original abscissae. + * @throws org.apache.commons.math.exception.NonMonotonousSequenceException + * if {...@code xval} not sorted in strictly increasing order. + * @throws DimensionMismatchException if {...@code xval} and {...@code yval} have + * different sizes. + * @throws NoDataException if {...@code xval} or {...@code yval} has zero size. + * @throws org.apache.commons.math.exception.NotFiniteNumberException if + * any of the arguments and values are not finite real numbers. + * @throws NumberIsTooSmallException if the bandwidth is too small to + * accomodate the size of the input data (i.e. the bandwidth must be + * larger than 2/n). * @since 2.1 */ - public final double[] smooth(final double[] xval, final double[] yval, final double[] weights) - throws MathException { + public final double[] smooth(final double[] xval, final double[] yval, + final double[] weights) { if (xval.length != yval.length) { - throw new MathException(LocalizedFormats.MISMATCHED_LOESS_ABSCISSA_ORDINATE_ARRAYS, - xval.length, yval.length); + throw new DimensionMismatchException(xval.length, yval.length); } final int n = xval.length; if (n == 0) { - throw new MathException(LocalizedFormats.LOESS_EXPECTS_AT_LEAST_ONE_POINT); + throw new NoDataException(); } - checkAllFiniteReal(xval, LocalizedFormats.NON_REAL_FINITE_ABSCISSA); - checkAllFiniteReal(yval, LocalizedFormats.NON_REAL_FINITE_ORDINATE); - checkAllFiniteReal(weights, LocalizedFormats.NON_REAL_FINITE_WEIGHT); + checkAllFiniteReal(xval); + checkAllFiniteReal(yval); + checkAllFiniteReal(weights); - checkStrictlyIncreasing(xval); + MathUtils.checkOrder(xval); if (n == 1) { return new double[]{yval[0]}; @@ -226,8 +230,8 @@ public class LoessInterpolator int bandwidthInPoints = (int) (bandwidth * n); if (bandwidthInPoints < 2) { - throw new MathException(LocalizedFormats.TOO_SMALL_BANDWIDTH, - n, 2.0 / n, bandwidth); + throw new NumberIsTooSmallException(LocalizedFormats.BANDWIDTH, + bandwidthInPoints, 2, true); } final double[] res = new double[n]; @@ -349,18 +353,20 @@ public class LoessInterpolator * @param xval the arguments for the interpolation points * @param yval the values for the interpolation points * @return values of the loess fit at corresponding original abscissae - * @throws MathException if some of the following conditions are false: - * <ul> - * <li> Arguments and values are of the same size that is greater than zero</li> - * <li> The arguments are in a strictly increasing order</li> - * <li> All arguments and values are finite real numbers</li> - * </ul> + * @throws org.apache.commons.math.exception.NonMonotonousSequenceException + * if {...@code xval} not sorted in strictly increasing order. + * @throws DimensionMismatchException if {...@code xval} and {...@code yval} have + * different sizes. + * @throws NoDataException if {...@code xval} or {...@code yval} has zero size. + * @throws org.apache.commons.math.exception.NotFiniteNumberException if + * any of the arguments and values are not finite real numbers. + * @throws NumberIsTooSmallException if the bandwidth is too small to + * accomodate the size of the input data (i.e. the bandwidth must be + * larger than 2/n). */ - public final double[] smooth(final double[] xval, final double[] yval) - throws MathException { + public final double[] smooth(final double[] xval, final double[] yval) { if (xval.length != yval.length) { - throw new MathException(LocalizedFormats.MISMATCHED_LOESS_ABSCISSA_ORDINATE_ARRAYS, - xval.length, yval.length); + throw new DimensionMismatchException(xval.length, yval.length); } final double[] unitWeights = new double[xval.length]; @@ -371,16 +377,17 @@ public class LoessInterpolator /** * Given an index interval into xval that embraces a certain number of - * points closest to xval[i-1], update the interval so that it embraces - * the same number of points closest to xval[i], ignoring zero weights. + * points closest to {...@code xval[i-1]}, update the interval so that it + * embraces the same number of points closest to {...@code xval[i]}, + * ignoring zero weights. * - * @param xval arguments array - * @param weights weights array - * @param i the index around which the new interval should be computed - * @param bandwidthInterval a two-element array {left, right} such that: <p/> - * <tt>(left==0 or xval[i] - xval[left-1] > xval[right] - xval[i])</tt> - * <p/> and also <p/> - * <tt>(right==xval.length-1 or xval[right+1] - xval[i] > xval[i] - xval[left])</tt>. + * @param xval Arguments array. + * @param weights Weights array. + * @param i Index around which the new interval should be computed. + * @param bandwidthInterval a two-element array {left, right} such that: + * {...@code (left==0 or xval[i] - xval[left-1] > xval[right] - xval[i])} + * and + * {...@code (right==xval.length-1 or xval[right+1] - xval[i] > xval[i] - xval[left])}. * The array will be updated. */ private static void updateBandwidthInterval(final double[] xval, final double[] weights, @@ -400,15 +407,17 @@ public class LoessInterpolator } /** - * Returns the smallest index j such that j > i && (j==weights.length || weights[j] != 0) - * @param weights weights array - * @param i the index from which to start search; must be < weights.length - * @return the smallest index j such that j > i && (j==weights.length || weights[j] != 0) + * Return the smallest index {...@code j} such that + * {...@code j > i && (j == weights.length || weights[j] != 0)}. + * + * @param weights Weights array. + * @param i Index from which to start search. + * @return the smallest compliant index. */ private static int nextNonzero(final double[] weights, final int i) { int j = i + 1; while(j < weights.length && weights[j] == 0) { - j++; + ++j; } return j; } @@ -418,8 +427,8 @@ public class LoessInterpolator * <a href="http://en.wikipedia.org/wiki/Local_regression#Weight_function">tricube</a> * weight function * - * @param x the argument - * @return (1-|x|^3)^3 + * @param x Argument. + * @return <code>(1 - |x|<sup>3</sup>)<sup>3</sup></code>. */ private static double tricube(final double x) { final double tmp = 1 - x * x * x; @@ -429,35 +438,13 @@ public class LoessInterpolator /** * Check that all elements of an array are finite real numbers. * - * @param values the values array - * @param pattern pattern of the error message - * @throws MathException if one of the values is not a finite real number + * @param values Values array. + * @throws org.apache.commons.math.exception.NotFiniteNumberException + * if one of the values is not a finite real number. */ - private static void checkAllFiniteReal(final double[] values, final Localizable pattern) - throws MathException { + private static void checkAllFiniteReal(final double[] values) { for (int i = 0; i < values.length; i++) { - final double x = values[i]; - if (Double.isInfinite(x) || Double.isNaN(x)) { - throw new MathException(pattern, i, x); - } - } - } - - /** - * Check that elements of the abscissae array are in a strictly - * increasing order. - * - * @param xval the abscissae array - * @throws MathException if the abscissae array - * is not in a strictly increasing order - */ - private static void checkStrictlyIncreasing(final double[] xval) - throws MathException { - for (int i = 0; i < xval.length; ++i) { - if (i >= 1 && xval[i - 1] >= xval[i]) { - throw new MathException(LocalizedFormats.OUT_OF_ORDER_ABSCISSA_ARRAY, - i - 1, xval[i - 1], i, xval[i]); - } + MathUtils.checkFinite(values[i]); } } } Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/NevilleInterpolator.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/NevilleInterpolator.java?rev=1055931&r1=1055930&r2=1055931&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/NevilleInterpolator.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/NevilleInterpolator.java Thu Jan 6 16:20:51 2011 @@ -18,7 +18,6 @@ package org.apache.commons.math.analysis import java.io.Serializable; -import org.apache.commons.math.MathException; import org.apache.commons.math.analysis.polynomials.PolynomialFunctionLagrangeForm; /** @@ -45,10 +44,14 @@ public class NevilleInterpolator impleme * @param x the interpolating points array * @param y the interpolating values array * @return a function which interpolates the data set - * @throws MathException if arguments are invalid + * @throws org.apache.commons.math.exception.DimensionMismatchException if + * the array lengths are different. + * @throws org.apache.commons.math.exception.NumberIsTooSmallException if + * the number of points is less than 2. + * @throws org.apache.commons.math.exception.NonMonotonousSequenceException + * if two abscissae have the same value. */ - public PolynomialFunctionLagrangeForm interpolate(double x[], double y[]) - throws MathException { + public PolynomialFunctionLagrangeForm interpolate(double x[], double y[]) { return new PolynomialFunctionLagrangeForm(x, y); } } Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/SmoothingPolynomialBicubicSplineInterpolator.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/SmoothingPolynomialBicubicSplineInterpolator.java?rev=1055931&r1=1055930&r2=1055931&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/SmoothingPolynomialBicubicSplineInterpolator.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/SmoothingPolynomialBicubicSplineInterpolator.java Thu Jan 6 16:20:51 2011 @@ -18,7 +18,6 @@ package org.apache.commons.math.analysis import org.apache.commons.math.exception.DimensionMismatchException; import org.apache.commons.math.exception.NoDataException; -import org.apache.commons.math.MathException; import org.apache.commons.math.util.MathUtils; import org.apache.commons.math.optimization.general.GaussNewtonOptimizer; import org.apache.commons.math.optimization.fitting.PolynomialFitter; @@ -73,8 +72,7 @@ public class SmoothingPolynomialBicubicS @Override public BicubicSplineInterpolatingFunction interpolate(final double[] xval, final double[] yval, - final double[][] fval) - throws MathException { + final double[][] fval) { if (xval.length == 0 || yval.length == 0 || fval.length == 0) { throw new NoDataException(); } Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/TricubicSplineInterpolator.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/TricubicSplineInterpolator.java?rev=1055931&r1=1055930&r2=1055931&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/TricubicSplineInterpolator.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/TricubicSplineInterpolator.java Thu Jan 6 16:20:51 2011 @@ -18,7 +18,6 @@ package org.apache.commons.math.analysis import org.apache.commons.math.exception.DimensionMismatchException; import org.apache.commons.math.exception.NoDataException; -import org.apache.commons.math.MathException; import org.apache.commons.math.util.MathUtils; /** @@ -35,8 +34,7 @@ public class TricubicSplineInterpolator public TricubicSplineInterpolatingFunction interpolate(final double[] xval, final double[] yval, final double[] zval, - final double[][][] fval) - throws MathException { + final double[][][] fval) { if (xval.length == 0 || yval.length == 0 || zval.length == 0 || fval.length == 0) { throw new NoDataException(); } Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/TrivariateRealGridInterpolator.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/TrivariateRealGridInterpolator.java?rev=1055931&r1=1055930&r2=1055931&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/TrivariateRealGridInterpolator.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/TrivariateRealGridInterpolator.java Thu Jan 6 16:20:51 2011 @@ -16,7 +16,6 @@ */ package org.apache.commons.math.analysis.interpolation; -import org.apache.commons.math.MathException; import org.apache.commons.math.analysis.TrivariateRealFunction; /** @@ -28,7 +27,7 @@ import org.apache.commons.math.analysis. */ public interface TrivariateRealGridInterpolator { /** - * Computes an interpolating function for the data set. + * Compute an interpolating function for the dataset. * * @param xval All the x-coordinates of the interpolation points, sorted * in increasing order. @@ -39,11 +38,11 @@ public interface TrivariateRealGridInter * @param fval the values of the interpolation points on all the grid knots: * {...@code fval[i][j][k] = f(xval[i], yval[j], zval[k])}. * @return a function that interpolates the data set. - * @throws org.apache.commons.math.exception.NoDataException if any of the arrays has zero length. - * @throws org.apache.commons.math.exception.DimensionMismatchException if the array lengths are inconsistent. - * @throws MathException if arguments violate assumptions made by the - * interpolation algorithm. + * @throws org.apache.commons.math.exception.NoDataException if any of + * the arrays has zero length. + * @throws org.apache.commons.math.exception.DimensionMismatchException + * if the array lengths are inconsistent. */ - TrivariateRealFunction interpolate(double[] xval, double[] yval, double[] zval, double[][][] fval) - throws MathException; + TrivariateRealFunction interpolate(double[] xval, double[] yval, double[] zval, + double[][][] fval); } Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/UnivariateRealInterpolator.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/UnivariateRealInterpolator.java?rev=1055931&r1=1055930&r2=1055931&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/UnivariateRealInterpolator.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/interpolation/UnivariateRealInterpolator.java Thu Jan 6 16:20:51 2011 @@ -16,7 +16,6 @@ */ package org.apache.commons.math.analysis.interpolation; -import org.apache.commons.math.MathException; import org.apache.commons.math.analysis.UnivariateRealFunction; /** @@ -25,15 +24,14 @@ import org.apache.commons.math.analysis. * @version $Revision$ $Date$ */ public interface UnivariateRealInterpolator { - /** - * Computes an interpolating function for the data set. - * @param xval the arguments for the interpolation points - * @param yval the values for the interpolation points - * @return a function which interpolates the data set - * @throws MathException if arguments violate assumptions made by the - * interpolation algorithm + * Compute an interpolating function for the dataset. + * + * @param xval Arguments for the interpolation points. + * @param yval Values for the interpolation points. + * @return a function which interpolates the dataset. + * @throws org.apache.commons.math.exception.MathRuntimeException if the + * arguments violate assumptions made by the interpolation algorithm. */ - UnivariateRealFunction interpolate(double xval[], double yval[]) - throws MathException; + UnivariateRealFunction interpolate(double xval[], double yval[]); } Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/polynomials/PolynomialFunctionLagrangeForm.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/polynomials/PolynomialFunctionLagrangeForm.java?rev=1055931&r1=1055930&r2=1055931&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/polynomials/PolynomialFunctionLagrangeForm.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/polynomials/PolynomialFunctionLagrangeForm.java Thu Jan 6 16:20:51 2011 @@ -63,7 +63,10 @@ public class PolynomialFunctionLagrangeF * * @param x interpolating points * @param y function values at interpolating points - * @throws IllegalArgumentException if input arrays are not valid + * @throws DimensionMismatchException if the array lengths are different. + * @throws NumberIsTooSmallException if the number of points is less than 2. + * @throws org.apache.commons.math.exception.NonMonotonousSequenceException + * if two abscissae have the same value. */ public PolynomialFunctionLagrangeForm(double x[], double y[]) { this.x = new double[x.length]; Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NotFiniteNumberException.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NotFiniteNumberException.java?rev=1055931&r1=1055930&r2=1055931&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NotFiniteNumberException.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NotFiniteNumberException.java Thu Jan 6 16:20:51 2011 @@ -36,8 +36,8 @@ public class NotFiniteNumberException ex * @param args Optional arguments. */ public NotFiniteNumberException(Number wrong, - Object ... arguments) { - this(null, wrong, arguments); + Object ... args) { + this(null, wrong, args); } /** @@ -49,8 +49,8 @@ public class NotFiniteNumberException ex */ public NotFiniteNumberException(Localizable specific, Number wrong, - Object ... arguments) { + Object ... args) { super(specific, LocalizedFormats.NOT_FINITE_NUMBER, - wrong, arguments); + wrong, args); } } Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/util/LocalizedFormats.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/util/LocalizedFormats.java?rev=1055931&r1=1055930&r2=1055931&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/util/LocalizedFormats.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/util/LocalizedFormats.java Thu Jan 6 16:20:51 2011 @@ -47,7 +47,7 @@ public enum LocalizedFormats implements ASSYMETRIC_EIGEN_NOT_SUPPORTED("eigen decomposition of assymetric matrices not supported yet"), AT_LEAST_ONE_COLUMN("matrix must have at least one column"), AT_LEAST_ONE_ROW("matrix must have at least one row"), - BANDWIDTH_OUT_OF_INTERVAL("bandwidth must be in the interval [0,1], but got {0}"), + BANDWIDTH("bandwidth ({0})"), BINOMIAL_INVALID_PARAMETERS_ORDER("must have n >= k for binomial coefficient (n, k), got k = {0}, n = {1}"), BINOMIAL_NEGATIVE_PARAMETER("must have n >= 0 for binomial coefficient (n, k), got n = {0}"), CANNOT_CLEAR_STATISTIC_CONSTRUCTED_FROM_EXTERNAL_MOMENTS("statistics constructed from external moments cannot be cleared"), @@ -160,7 +160,7 @@ public enum LocalizedFormats implements NUMBER_OF_SUCCESSES("number of successes ({0})"), /* keep */ NEGATIVE_NUMBER_OF_TRIALS("number of trials must be non-negative ({0})"), NUMBER_OF_TRIALS("number of trials ({0})"), - NEGATIVE_ROBUSTNESS_ITERATIONS("the number of robustness iterations must be non-negative, but got {0}"), + ROBUSTNESS_ITERATIONS("number of robustness iterations ({0})"), START_POSITION("start position ({0})"), /* keep */ NON_CONVERGENT_CONTINUED_FRACTION("Continued fraction convergents failed to converge (in less than {0} iterations) for value {1}"), NON_POSITIVE_MICROSPHERE_ELEMENTS("number of microsphere elements must be positive, but got {0}"), @@ -285,7 +285,6 @@ public enum LocalizedFormats implements SUBARRAY_ENDS_AFTER_ARRAY_END("subarray ends after array end"), TOO_LARGE_CUTOFF_SINGULAR_VALUE("cutoff singular value is {0}, should be at most {1}"), TOO_MANY_ELEMENTS_TO_DISCARD_FROM_ARRAY("cannot discard {0} elements from a {1} elements array"), - TOO_SMALL_BANDWIDTH("the bandwidth must be large enough to accomodate at least 2 points. There are {0} data points, and bandwidth must be at least {1} but it is only {2}"), TOO_SMALL_COST_RELATIVE_TOLERANCE("cost relative tolerance is too small ({0}), no further reduction in the sum of squares is possible"), TOO_SMALL_INTEGRATION_INTERVAL("too small integration interval: length = {0}"), TOO_SMALL_ORTHOGONALITY_TOLERANCE("orthogonality tolerance is too small ({0}), solution is orthogonal to the jacobian"), Modified: commons/proper/math/trunk/src/main/resources/META-INF/localization/LocalizedFormats_fr.properties URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/resources/META-INF/localization/LocalizedFormats_fr.properties?rev=1055931&r1=1055930&r2=1055931&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/resources/META-INF/localization/LocalizedFormats_fr.properties (original) +++ commons/proper/math/trunk/src/main/resources/META-INF/localization/LocalizedFormats_fr.properties Thu Jan 6 16:20:51 2011 @@ -19,7 +19,7 @@ ARRAY_SUMS_TO_ZERO = somme du tableau nu ASSYMETRIC_EIGEN_NOT_SUPPORTED = la d\u00e9composition en valeurs/vecteurs propres de matrices AT_LEAST_ONE_COLUMN = une matrice doit comporter au moins une colonne AT_LEAST_ONE_ROW = une matrice doit comporter au moins une ligne -BANDWIDTH_OUT_OF_INTERVAL = la bande passante devrait \u00eatre dans l''intervalle [0,1], elle est de {0} +BANDWIDTH = bande passante ({0}) BINOMIAL_INVALID_PARAMETERS_ORDER = n doit \u00eatre sup\u00e9rieur ou \u00e9gal \u00e0 k pour le coefficient du bin\u00f4me (n, k), or k = {0}, n = {1} BINOMIAL_NEGATIVE_PARAMETER = n doit \u00eatre positif pour le coefficient du bin\u00f4me (n, k), or n = {0} CANNOT_CLEAR_STATISTIC_CONSTRUCTED_FROM_EXTERNAL_MOMENTS = les statistiques bas\u00e9es sur des moments externes ne peuvent pas \u00eatre remises \u00e0 z\u00e9ro @@ -257,7 +257,6 @@ SINGULAR_MATRIX = matrice singuli\u00e8r SUBARRAY_ENDS_AFTER_ARRAY_END = le sous-tableau se termine apr\u00e8s la fin du tableau TOO_LARGE_CUTOFF_SINGULAR_VALUE = la valeur singuli\u00e8re de coupure vaut {0}, elle ne devrait pas d\u00e9passer {1} TOO_MANY_ELEMENTS_TO_DISCARD_FROM_ARRAY = impossible d''enlever {0} \u00e9l\u00e9ments d''un tableau en contenant {1} -TOO_SMALL_BANDWIDTH = la largeur de bande doit \u00eatre assez grande pour supporter au moins 2 points. Il y a {0} donn\u00e9es et la largeur de bande doit \u00eatre au moins de {1}, or elle est seulement de {2} TOO_SMALL_COST_RELATIVE_TOLERANCE = trop petite tol\u00e9rance relative sur le co\u00fbt ({0}), aucune r\u00e9duction de la somme des carr\u00e9s n''est possible TOO_SMALL_INTEGRATION_INTERVAL = intervalle d''int\u00e9gration trop petit : {0} TOO_SMALL_ORTHOGONALITY_TOLERANCE = trop petite tol\u00e9rance sur l''orthogonalit\u00e9 ({0}), la solution est orthogonale \u00e0 la jacobienne Modified: commons/proper/math/trunk/src/site/xdoc/changes.xml URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/site/xdoc/changes.xml?rev=1055931&r1=1055930&r2=1055931&view=diff ============================================================================== --- commons/proper/math/trunk/src/site/xdoc/changes.xml (original) +++ commons/proper/math/trunk/src/site/xdoc/changes.xml Thu Jan 6 16:20:51 2011 @@ -52,6 +52,10 @@ The <action> type attribute can be add,u If the output is not quite correct, check for invisible trailing spaces! --> <release version="3.0" date="TBD" description="TBD"> + <action dev="erans" type="fix" issue="MATH-458"> + Removed "MathException" from the "throws" clause of the "interpolate" method + of the interpolators interfaces (package "analysis.interpolation"). + </action> <action dev="erans" type="fix" issue="MATH-461"> In order to comply with the new runtime exceptions policy, the classes "RealVectorFormat", "ComplexFormat", "Vector3DFormat" and "CompositeFormat" Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/interpolation/LoessInterpolatorTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/interpolation/LoessInterpolatorTest.java?rev=1055931&r1=1055930&r2=1055931&view=diff ============================================================================== --- commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/interpolation/LoessInterpolatorTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/interpolation/LoessInterpolatorTest.java Thu Jan 6 16:20:51 2011 @@ -16,8 +16,15 @@ */ package org.apache.commons.math.analysis.interpolation; -import org.apache.commons.math.MathException; import org.apache.commons.math.util.FastMath; +import org.apache.commons.math.exception.NotPositiveException; +import org.apache.commons.math.exception.OutOfRangeException; +import org.apache.commons.math.exception.DimensionMismatchException; +import org.apache.commons.math.exception.NoDataException; +import org.apache.commons.math.exception.NonMonotonousSequenceException; +import org.apache.commons.math.exception.NotFiniteNumberException; +import org.apache.commons.math.exception.NumberIsTooSmallException; + import org.junit.Assert; import org.junit.Test; @@ -27,7 +34,7 @@ import org.junit.Test; public class LoessInterpolatorTest { @Test - public void testOnOnePoint() throws MathException { + public void testOnOnePoint() { double[] xval = {0.5}; double[] yval = {0.7}; double[] res = new LoessInterpolator().smooth(xval, yval); @@ -36,7 +43,7 @@ public class LoessInterpolatorTest { } @Test - public void testOnTwoPoints() throws MathException { + public void testOnTwoPoints() { double[] xval = {0.5, 0.6}; double[] yval = {0.7, 0.8}; double[] res = new LoessInterpolator().smooth(xval, yval); @@ -46,7 +53,7 @@ public class LoessInterpolatorTest { } @Test - public void testOnStraightLine() throws MathException { + public void testOnStraightLine() { double[] xval = {1,2,3,4,5}; double[] yval = {2,4,6,8,10}; LoessInterpolator li = new LoessInterpolator(0.6, 2, 1e-12); @@ -58,7 +65,7 @@ public class LoessInterpolatorTest { } @Test - public void testOnDistortedSine() throws MathException { + public void testOnDistortedSine() { int numPoints = 100; double[] xval = new double[numPoints]; double[] yval = new double[numPoints]; @@ -90,7 +97,7 @@ public class LoessInterpolatorTest { } @Test - public void testIncreasingBandwidthIncreasesSmoothness() throws MathException { + public void testIncreasingBandwidthIncreasesSmoothness() { int numPoints = 100; double[] xval = new double[numPoints]; double[] yval = new double[numPoints]; @@ -121,7 +128,7 @@ public class LoessInterpolatorTest { } @Test - public void testIncreasingRobustnessItersIncreasesSmoothnessWithOutliers() throws MathException { + public void testIncreasingRobustnessItersIncreasesSmoothnessWithOutliers() { int numPoints = 100; double[] xval = new double[numPoints]; double[] yval = new double[numPoints]; @@ -153,74 +160,74 @@ public class LoessInterpolatorTest { } } - @Test(expected=MathException.class) - public void testUnequalSizeArguments() throws MathException { + @Test(expected=DimensionMismatchException.class) + public void testUnequalSizeArguments() { new LoessInterpolator().smooth(new double[] {1,2,3}, new double[] {1,2,3,4}); } - @Test(expected=MathException.class) - public void testEmptyData() throws MathException { + @Test(expected=NoDataException.class) + public void testEmptyData() { new LoessInterpolator().smooth(new double[] {}, new double[] {}); } - @Test(expected=MathException.class) - public void testNonStrictlyIncreasing1() throws MathException { + @Test(expected=NonMonotonousSequenceException.class) + public void testNonStrictlyIncreasing1() { new LoessInterpolator().smooth(new double[] {4,3,1,2}, new double[] {3,4,5,6}); } - @Test(expected=MathException.class) - public void testNonStrictlyIncreasing2() throws MathException { + @Test(expected=NonMonotonousSequenceException.class) + public void testNonStrictlyIncreasing2() { new LoessInterpolator().smooth(new double[] {1,2,2,3}, new double[] {3,4,5,6}); } - @Test(expected=MathException.class) - public void testNotAllFiniteReal1() throws MathException { + @Test(expected=NotFiniteNumberException.class) + public void testNotAllFiniteReal1() { new LoessInterpolator().smooth(new double[] {1,2,Double.NaN}, new double[] {3,4,5}); } - @Test(expected=MathException.class) - public void testNotAllFiniteReal2() throws MathException { + @Test(expected=NotFiniteNumberException.class) + public void testNotAllFiniteReal2() { new LoessInterpolator().smooth(new double[] {1,2,Double.POSITIVE_INFINITY}, new double[] {3,4,5}); } - @Test(expected=MathException.class) - public void testNotAllFiniteReal3() throws MathException { + @Test(expected=NotFiniteNumberException.class) + public void testNotAllFiniteReal3() { new LoessInterpolator().smooth(new double[] {1,2,Double.NEGATIVE_INFINITY}, new double[] {3,4,5}); } - @Test(expected=MathException.class) - public void testNotAllFiniteReal4() throws MathException { + @Test(expected=NotFiniteNumberException.class) + public void testNotAllFiniteReal4() { new LoessInterpolator().smooth(new double[] {3,4,5}, new double[] {1,2,Double.NaN}); } - @Test(expected=MathException.class) - public void testNotAllFiniteReal5() throws MathException { + @Test(expected=NotFiniteNumberException.class) + public void testNotAllFiniteReal5() { new LoessInterpolator().smooth(new double[] {3,4,5}, new double[] {1,2,Double.POSITIVE_INFINITY}); } - @Test(expected=MathException.class) - public void testNotAllFiniteReal6() throws MathException { + @Test(expected=NotFiniteNumberException.class) + public void testNotAllFiniteReal6() { new LoessInterpolator().smooth(new double[] {3,4,5}, new double[] {1,2,Double.NEGATIVE_INFINITY}); } - @Test(expected=MathException.class) - public void testInsufficientBandwidth() throws MathException { + @Test(expected=NumberIsTooSmallException.class) + public void testInsufficientBandwidth() { LoessInterpolator li = new LoessInterpolator(0.1, 3, 1e-12); li.smooth(new double[] {1,2,3,4,5,6,7,8,9,10,11,12}, new double[] {1,2,3,4,5,6,7,8,9,10,11,12}); } - @Test(expected=MathException.class) - public void testCompletelyIncorrectBandwidth1() throws MathException { + @Test(expected=OutOfRangeException.class) + public void testCompletelyIncorrectBandwidth1() { new LoessInterpolator(-0.2, 3, 1e-12); } - @Test(expected=MathException.class) - public void testCompletelyIncorrectBandwidth2() throws MathException { + @Test(expected=OutOfRangeException.class) + public void testCompletelyIncorrectBandwidth2() { new LoessInterpolator(1.1, 3, 1e-12); } @Test - public void testMath296withoutWeights() throws MathException { + public void testMath296withoutWeights() { double[] xval = { 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0}; @@ -251,5 +258,4 @@ public class LoessInterpolatorTest { x += dx * (1 + (2 * FastMath.random() - 1) * xnoise); } } - }