You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ps...@apache.org on 2011/02/15 02:31:14 UTC
svn commit: r1070725 [3/3] - in /commons/proper/math/branches/MATH_2_X/src:
main/java/org/apache/commons/math/
main/java/org/apache/commons/math/analysis/
main/java/org/apache/commons/math/analysis/integration/
main/java/org/apache/commons/math/analysi...
Modified: commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/SumSincFunction.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/SumSincFunction.java?rev=1070725&r1=1070724&r2=1070725&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/SumSincFunction.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/SumSincFunction.java Tue Feb 15 01:31:12 2011
@@ -16,7 +16,7 @@
*/
package org.apache.commons.math.analysis;
-import org.apache.commons.math.exception.MathUserException;
+import org.apache.commons.math.FunctionEvaluationException;
/**
* Auxiliary class for testing optimizers.
@@ -43,7 +43,7 @@ public class SumSincFunction implements
* @param point Argument.
* @return the value of this function at point {@code x}.
*/
- public double value(double[] point) throws MathUserException {
+ public double value(double[] point) throws FunctionEvaluationException {
double sum = 0;
for (int i = 0, max = point.length; i < max; i++) {
final double x = point[i];
@@ -58,7 +58,7 @@ public class SumSincFunction implements
*/
public MultivariateRealFunction partialDerivative(final int k) {
return new MultivariateRealFunction() {
- public double value(double[] point) throws MathUserException {
+ public double value(double[] point) throws FunctionEvaluationException {
return sincDeriv.value(point[k]);
}
};
@@ -70,7 +70,7 @@ public class SumSincFunction implements
public MultivariateVectorialFunction gradient() {
return new MultivariateVectorialFunction() {
public double[] value(double[] point)
- throws MathUserException {
+ throws FunctionEvaluationException {
final int n = point.length;
final double[] r = new double[n];
for (int i = 0; i < n; i++) {
Modified: commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/integration/LegendreGaussIntegratorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/integration/LegendreGaussIntegratorTest.java?rev=1070725&r1=1070724&r2=1070725&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/integration/LegendreGaussIntegratorTest.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/integration/LegendreGaussIntegratorTest.java Tue Feb 15 01:31:12 2011
@@ -18,13 +18,13 @@ package org.apache.commons.math.analysis
import java.util.Random;
+import org.apache.commons.math.FunctionEvaluationException;
import org.apache.commons.math.ConvergenceException;
import org.apache.commons.math.MathException;
import org.apache.commons.math.analysis.QuinticFunction;
import org.apache.commons.math.analysis.SinFunction;
import org.apache.commons.math.analysis.UnivariateRealFunction;
import org.apache.commons.math.analysis.polynomials.PolynomialFunction;
-import org.apache.commons.math.exception.MathUserException;
import org.apache.commons.math.util.FastMath;
import junit.framework.*;
@@ -77,7 +77,7 @@ extends TestCase {
}
public void testExactIntegration()
- throws ConvergenceException, MathUserException {
+ throws ConvergenceException, FunctionEvaluationException {
Random random = new Random(86343623467878363l);
for (int n = 2; n < 6; ++n) {
LegendreGaussIntegrator integrator =
Modified: commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/polynomials/PolynomialFunctionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/polynomials/PolynomialFunctionTest.java?rev=1070725&r1=1070724&r2=1070725&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/polynomials/PolynomialFunctionTest.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/polynomials/PolynomialFunctionTest.java Tue Feb 15 01:31:12 2011
@@ -37,7 +37,7 @@ public final class PolynomialFunctionTes
*
* <p>value of this is 2.5 everywhere.</p>
*/
- public void testConstants() {
+ public void testConstants() throws Exception {
double[] c = { 2.5 };
PolynomialFunction f = new PolynomialFunction( c );
@@ -63,7 +63,7 @@ public final class PolynomialFunctionTes
* f(0.5) = 0.0, f(1.5) = 3.0</tt> and <tt>f(3.0) = 7.5</tt>
* </p>
*/
- public void testLinear() {
+ public void testLinear() throws Exception {
double[] c = { -1.5, 3.0 };
PolynomialFunction f = new PolynomialFunction( c );
@@ -137,7 +137,7 @@ public final class PolynomialFunctionTes
* <tt>f(x) = x^3 - 2x^2 + 6x + 3, g(x) = 3x^2 - 4x + 6</tt>
* and <tt>h(x) = 6x - 4</tt>
*/
- public void testfirstDerivativeComparison() {
+ public void testfirstDerivativeComparison() throws Exception {
double[] f_coeff = { 3.0, 6.0, -2.0, 1.0 };
double[] g_coeff = { 6.0, -4.0, 3.0 };
double[] h_coeff = { -4.0, 6.0 };
@@ -237,7 +237,7 @@ public final class PolynomialFunctionTes
* <tt>f(x) = x^3 - 2x^2 + 6x + 3, g(x) = 3x^2 - 4x + 6</tt>
* and <tt>h(x) = 6x - 4</tt>
*/
- public void testMath341() {
+ public void testMath341() throws Exception {
double[] f_coeff = { 3.0, 6.0, -2.0, 1.0 };
double[] g_coeff = { 6.0, -4.0, 3.0 };
double[] h_coeff = { -4.0, 6.0 };
Modified: commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/ode/events/EventStateTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/ode/events/EventStateTest.java?rev=1070725&r1=1070724&r2=1070725&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/ode/events/EventStateTest.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/ode/events/EventStateTest.java Tue Feb 15 01:31:12 2011
@@ -19,8 +19,8 @@ package org.apache.commons.math.ode.even
import junit.framework.Assert;
+import org.apache.commons.math.FunctionEvaluationException;
import org.apache.commons.math.ConvergenceException;
-import org.apache.commons.math.exception.MathUserException;
import org.apache.commons.math.ode.sampling.AbstractStepInterpolator;
import org.apache.commons.math.ode.sampling.DummyStepInterpolator;
import org.junit.Test;
@@ -30,7 +30,7 @@ public class EventStateTest {
// JIRA: MATH-322
@Test
public void closeEvents()
- throws EventException, ConvergenceException, MathUserException {
+ throws EventException, ConvergenceException, FunctionEvaluationException {
final double r1 = 90.0;
final double r2 = 135.0;
Modified: commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/optimization/direct/MultiDirectionalTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/optimization/direct/MultiDirectionalTest.java?rev=1070725&r1=1070724&r2=1070725&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/optimization/direct/MultiDirectionalTest.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/optimization/direct/MultiDirectionalTest.java Tue Feb 15 01:31:12 2011
@@ -18,8 +18,8 @@
package org.apache.commons.math.optimization.direct;
import org.apache.commons.math.ConvergenceException;
+import org.apache.commons.math.FunctionEvaluationException;
import org.apache.commons.math.analysis.MultivariateRealFunction;
-import org.apache.commons.math.exception.MathUserException;
import org.apache.commons.math.exception.util.LocalizedFormats;
import org.apache.commons.math.optimization.GoalType;
import org.apache.commons.math.optimization.OptimizationException;
@@ -32,15 +32,15 @@ import org.junit.Test;
public class MultiDirectionalTest {
@Test
- public void testMathUserException() throws OptimizationException, MathUserException, IllegalArgumentException {
+ public void testFunctionEvaluationException() throws OptimizationException, FunctionEvaluationException, IllegalArgumentException {
MultivariateRealFunction wrong =
new MultivariateRealFunction() {
private static final long serialVersionUID = 4751314470965489371L;
- public double value(double[] x) throws MathUserException {
+ public double value(double[] x) throws FunctionEvaluationException {
if (x[0] < 0) {
- throw new MathUserException(LocalizedFormats.SIMPLE_MESSAGE, "oops");
+ throw new FunctionEvaluationException(x,LocalizedFormats.SIMPLE_MESSAGE, "oops");
} else if (x[0] > 1) {
- throw new MathUserException(new RuntimeException("oops"));
+ throw (new FunctionEvaluationException(new RuntimeException("oops"), x));
} else {
return x[0] * (1 - x[0]);
}
@@ -50,7 +50,7 @@ public class MultiDirectionalTest {
MultiDirectional optimizer = new MultiDirectional(0.9, 1.9);
optimizer.optimize(wrong, GoalType.MINIMIZE, new double[] { -1.0 });
Assert.fail("an exception should have been thrown");
- } catch (MathUserException ce) {
+ } catch (FunctionEvaluationException ce) {
// expected behavior
Assert.assertNull(ce.getCause());
}
@@ -58,7 +58,7 @@ public class MultiDirectionalTest {
MultiDirectional optimizer = new MultiDirectional(0.9, 1.9);
optimizer.optimize(wrong, GoalType.MINIMIZE, new double[] { +2.0 });
Assert.fail("an exception should have been thrown");
- } catch (MathUserException ce) {
+ } catch (FunctionEvaluationException ce) {
// expected behavior
Assert.assertNotNull(ce.getCause());
}
@@ -66,7 +66,7 @@ public class MultiDirectionalTest {
@Test
public void testMinimizeMaximize()
- throws MathUserException, ConvergenceException {
+ throws FunctionEvaluationException, ConvergenceException {
// the following function has 4 local extrema:
final double xM = -3.841947088256863675365;
@@ -79,7 +79,7 @@ public class MultiDirectionalTest {
final double valueXpYp = -valueXpYm; // global maximum
MultivariateRealFunction fourExtrema = new MultivariateRealFunction() {
private static final long serialVersionUID = -7039124064449091152L;
- public double value(double[] variables) throws MathUserException {
+ public double value(double[] variables) throws FunctionEvaluationException {
final double x = variables[0];
final double y = variables[1];
return ((x == 0) || (y == 0)) ? 0 : (FastMath.atan(x) * FastMath.atan(x + 2) * FastMath.atan(y) * FastMath.atan(y) / (x * y));
@@ -127,12 +127,12 @@ public class MultiDirectionalTest {
@Test
public void testRosenbrock()
- throws MathUserException, ConvergenceException {
+ throws FunctionEvaluationException, ConvergenceException {
MultivariateRealFunction rosenbrock =
new MultivariateRealFunction() {
private static final long serialVersionUID = -9044950469615237490L;
- public double value(double[] x) throws MathUserException {
+ public double value(double[] x) throws FunctionEvaluationException {
++count;
double a = x[1] - x[0] * x[0];
double b = 1.0 - x[0];
@@ -159,12 +159,12 @@ public class MultiDirectionalTest {
@Test
public void testPowell()
- throws MathUserException, ConvergenceException {
+ throws FunctionEvaluationException, ConvergenceException {
MultivariateRealFunction powell =
new MultivariateRealFunction() {
private static final long serialVersionUID = -832162886102041840L;
- public double value(double[] x) throws MathUserException {
+ public double value(double[] x) throws FunctionEvaluationException {
++count;
double a = x[0] + 10 * x[1];
double b = x[2] - x[3];
@@ -189,7 +189,7 @@ public class MultiDirectionalTest {
@Test
public void testMath283()
- throws MathUserException, OptimizationException {
+ throws FunctionEvaluationException, OptimizationException {
// fails because MultiDirectional.iterateSimplex is looping forever
// the while(true) should be replaced with a convergence check
MultiDirectional multiDirectional = new MultiDirectional();
Modified: commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/optimization/direct/NelderMeadTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/optimization/direct/NelderMeadTest.java?rev=1070725&r1=1070724&r2=1070725&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/optimization/direct/NelderMeadTest.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/optimization/direct/NelderMeadTest.java Tue Feb 15 01:31:12 2011
@@ -24,12 +24,12 @@ import static org.junit.Assert.assertTru
import static org.junit.Assert.fail;
import org.apache.commons.math.ConvergenceException;
+import org.apache.commons.math.FunctionEvaluationException;
import org.apache.commons.math.MathException;
import org.apache.commons.math.MaxEvaluationsExceededException;
import org.apache.commons.math.MaxIterationsExceededException;
import org.apache.commons.math.analysis.MultivariateRealFunction;
import org.apache.commons.math.analysis.MultivariateVectorialFunction;
-import org.apache.commons.math.exception.MathUserException;
import org.apache.commons.math.exception.util.LocalizedFormats;
import org.apache.commons.math.linear.Array2DRowRealMatrix;
import org.apache.commons.math.linear.RealMatrix;
@@ -45,15 +45,15 @@ import org.junit.Test;
public class NelderMeadTest {
@Test
- public void testMathUserException() throws OptimizationException, MathUserException, IllegalArgumentException {
+ public void testFunctionEvaluationException() throws OptimizationException, FunctionEvaluationException, IllegalArgumentException {
MultivariateRealFunction wrong =
new MultivariateRealFunction() {
private static final long serialVersionUID = 4751314470965489371L;
- public double value(double[] x) throws MathUserException {
+ public double value(double[] x) throws FunctionEvaluationException {
if (x[0] < 0) {
- throw new MathUserException(LocalizedFormats.SIMPLE_MESSAGE, "oops");
+ throw new FunctionEvaluationException(x, LocalizedFormats.SIMPLE_MESSAGE, "oops");
} else if (x[0] > 1) {
- throw new MathUserException(new RuntimeException("oops"));
+ throw new FunctionEvaluationException(new RuntimeException("oops"), x);
} else {
return x[0] * (1 - x[0]);
}
@@ -63,7 +63,7 @@ public class NelderMeadTest {
NelderMead optimizer = new NelderMead(0.9, 1.9, 0.4, 0.6);
optimizer.optimize(wrong, GoalType.MINIMIZE, new double[] { -1.0 });
fail("an exception should have been thrown");
- } catch (MathUserException ce) {
+ } catch (FunctionEvaluationException ce) {
// expected behavior
assertNull(ce.getCause());
}
@@ -71,7 +71,7 @@ public class NelderMeadTest {
NelderMead optimizer = new NelderMead(0.9, 1.9, 0.4, 0.6);
optimizer.optimize(wrong, GoalType.MINIMIZE, new double[] { +2.0 });
fail("an exception should have been thrown");
- } catch (MathUserException ce) {
+ } catch (FunctionEvaluationException ce) {
// expected behavior
assertNotNull(ce.getCause());
}
@@ -79,7 +79,7 @@ public class NelderMeadTest {
@Test
public void testMinimizeMaximize()
- throws MathUserException, ConvergenceException {
+ throws FunctionEvaluationException, ConvergenceException {
// the following function has 4 local extrema:
final double xM = -3.841947088256863675365;
@@ -92,7 +92,7 @@ public class NelderMeadTest {
final double valueXpYp = -valueXpYm; // global maximum
MultivariateRealFunction fourExtrema = new MultivariateRealFunction() {
private static final long serialVersionUID = -7039124064449091152L;
- public double value(double[] variables) throws MathUserException {
+ public double value(double[] variables) throws FunctionEvaluationException {
final double x = variables[0];
final double y = variables[1];
return ((x == 0) || (y == 0)) ? 0 : (FastMath.atan(x) * FastMath.atan(x + 2) * FastMath.atan(y) * FastMath.atan(y) / (x * y));
@@ -139,7 +139,7 @@ public class NelderMeadTest {
@Test
public void testRosenbrock()
- throws MathUserException, ConvergenceException {
+ throws FunctionEvaluationException, ConvergenceException {
Rosenbrock rosenbrock = new Rosenbrock();
NelderMead optimizer = new NelderMead();
@@ -160,7 +160,7 @@ public class NelderMeadTest {
@Test
public void testPowell()
- throws MathUserException, ConvergenceException {
+ throws FunctionEvaluationException, ConvergenceException {
Powell powell = new Powell();
NelderMead optimizer = new NelderMead();
@@ -177,7 +177,7 @@ public class NelderMeadTest {
@Test
public void testLeastSquares1()
- throws MathUserException, ConvergenceException {
+ throws FunctionEvaluationException, ConvergenceException {
final RealMatrix factors =
new Array2DRowRealMatrix(new double[][] {
@@ -203,7 +203,7 @@ public class NelderMeadTest {
@Test
public void testLeastSquares2()
- throws MathUserException, ConvergenceException {
+ throws FunctionEvaluationException, ConvergenceException {
final RealMatrix factors =
new Array2DRowRealMatrix(new double[][] {
@@ -229,7 +229,7 @@ public class NelderMeadTest {
@Test
public void testLeastSquares3()
- throws MathUserException, ConvergenceException {
+ throws FunctionEvaluationException, ConvergenceException {
final RealMatrix factors =
new Array2DRowRealMatrix(new double[][] {
@@ -279,7 +279,7 @@ public class NelderMeadTest {
optimizer.setConvergenceChecker(new SimpleRealPointChecker(-1.0, 1.0e-3));
optimizer.setMaxEvaluations(20);
optimizer.optimize(powell, GoalType.MINIMIZE, new double[] { 3.0, -1.0, 0.0, 1.0 });
- } catch (MathUserException fee) {
+ } catch (FunctionEvaluationException fee) {
if (fee.getCause() instanceof ConvergenceException) {
throw (ConvergenceException) fee.getCause();
}
Modified: commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/optimization/univariate/BrentOptimizerTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/optimization/univariate/BrentOptimizerTest.java?rev=1070725&r1=1070724&r2=1070725&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/optimization/univariate/BrentOptimizerTest.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/optimization/univariate/BrentOptimizerTest.java Tue Feb 15 01:31:12 2011
@@ -20,9 +20,9 @@ import static org.junit.Assert.assertEqu
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
+import org.apache.commons.math.FunctionEvaluationException;
import org.apache.commons.math.MathException;
import org.apache.commons.math.MaxIterationsExceededException;
-import org.apache.commons.math.exception.MathUserException;
import org.apache.commons.math.exception.NoDataException;
import org.apache.commons.math.analysis.QuinticFunction;
import org.apache.commons.math.analysis.SinFunction;
@@ -60,7 +60,7 @@ public final class BrentOptimizerTest {
try {
minimizer.optimize(f, GoalType.MINIMIZE, 4, 5);
fail("an exception should have been thrown");
- } catch (MathUserException mue) {
+ } catch (FunctionEvaluationException mue) {
// expected
} catch (Exception e) {
fail("wrong exception caught");
Modified: commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/transform/FastCosineTransformerTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/transform/FastCosineTransformerTest.java?rev=1070725&r1=1070724&r2=1070725&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/transform/FastCosineTransformerTest.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/transform/FastCosineTransformerTest.java Tue Feb 15 01:31:12 2011
@@ -68,7 +68,7 @@ public final class FastCosineTransformer
/**
* Test of transformer for the sine function.
*/
- public void testSinFunction() {
+ public void testSinFunction() throws Exception {
UnivariateRealFunction f = new SinFunction();
FastCosineTransformer transformer = new FastCosineTransformer();
double min, max, result[], tolerance = 1E-12; int N = 9;
Modified: commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/transform/FastFourierTransformerTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/transform/FastFourierTransformerTest.java?rev=1070725&r1=1070724&r2=1070725&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/transform/FastFourierTransformerTest.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/transform/FastFourierTransformerTest.java Tue Feb 15 01:31:12 2011
@@ -113,7 +113,7 @@ public final class FastFourierTransforme
/**
* Test of transformer for the sine function.
*/
- public void testSinFunction() {
+ public void testSinFunction() throws Exception {
UnivariateRealFunction f = new SinFunction();
FastFourierTransformer transformer = new FastFourierTransformer();
Complex result[]; int N = 1 << 8;
Modified: commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/transform/FastSineTransformerTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/transform/FastSineTransformerTest.java?rev=1070725&r1=1070724&r2=1070725&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/transform/FastSineTransformerTest.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/transform/FastSineTransformerTest.java Tue Feb 15 01:31:12 2011
@@ -68,7 +68,7 @@ public final class FastSineTransformerTe
/**
* Test of transformer for the sine function.
*/
- public void testSinFunction() {
+ public void testSinFunction() throws Exception {
UnivariateRealFunction f = new SinFunction();
FastSineTransformer transformer = new FastSineTransformer();
double min, max, result[], tolerance = 1E-12; int N = 1 << 8;