svn commit: r1302298 - /commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/SymmLQ.java
Author: celestin Date: Mon Mar 19 06:46:32 2012 New Revision: 1302298 URL: http://svn.apache.org/viewvc?rev=1302298&view=rev Log: In class o.a.c.math3.linear.SymmLQ - Changed parameter order for the constructor of nested class State (for consistency with the constructor of SymmLQ). - Moved some static helper methods from SymmLQ to nested class State - Changed visibility of some static fields from private to protected in order to avoid the use of synthetic getters. Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/SymmLQ.java Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/SymmLQ.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/SymmLQ.java?rev=1302298&r1=1302297&r2=1302298&view=diff == --- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/SymmLQ.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/SymmLQ.java Mon Mar 19 06:46:32 2012 @@ -347,12 +347,18 @@ public class SymmLQ * to contain a large multiple of {@code b} * @param shift the amount to be subtracted to all diagonal elements of * A + * @param delta the δ parameter for the default stopping criterion + * @param check {@code true} if self-adjointedness of both matrix and + * preconditioner should be checked */ -public State(final RealLinearOperator a, final RealLinearOperator minv, -final RealVector b, final RealVector x, final boolean goodb, +public State(final RealLinearOperator a, +final RealLinearOperator minv, +final RealVector b, +final RealVector x, +final boolean goodb, final double shift, -final boolean check, -final double delta) { +final double delta, +final boolean check) { this.a = a; this.minv = minv; this.b = b; @@ -367,6 +373,93 @@ public class SymmLQ } /** + * Performs a symmetry check on the specified linear operator, and throws an + * exception in case this check fails. Given a linear operator L, and a + * vector x, this method checks that + * x' · L · y = y' · L · x + * (within a given accuracy), where y = L · x. + * + * @param l the linear operator L + * @param x the candidate vector x + * @param y the candidate vector y = L · x + * @param z the vector z = L · y + * @throws NonSelfAdjointOperatorException when the test fails + */ +private static void checkSymmetry(final RealLinearOperator l, +final RealVector x, final RealVector y, final RealVector z) +throws NonSelfAdjointOperatorException { +final double s = y.dotProduct(y); +final double t = x.dotProduct(z); +final double epsa = (s + SymmLQ.MACH_PREC) * SymmLQ.CBRT_MACH_PREC; +if (FastMath.abs(s - t) > epsa) { +final NonSelfAdjointOperatorException e; +e = new NonSelfAdjointOperatorException(); +final ExceptionContext context = e.getContext(); +context.setValue(SymmLQ.OPERATOR, l); +context.setValue(SymmLQ.VECTOR1, x); +context.setValue(SymmLQ.VECTOR2, y); +context.setValue(SymmLQ.THRESHOLD, Double.valueOf(epsa)); +throw e; +} +} + +/** + * Throws a new {@link NonPositiveDefiniteOperatorException} with + * appropriate context. + * + * @param l the offending linear operator + * @param v the offending vector + * @throws NonPositiveDefiniteOperatorException in any circumstances + */ +private static void throwNPDLOException(final RealLinearOperator l, +final RealVector v) throws NonPositiveDefiniteOperatorException { +final NonPositiveDefiniteOperatorException e; +e = new NonPositiveDefiniteOperatorException(); +final ExceptionContext context = e.getContext(); +context.setValue(OPERATOR, l); +context.setValue(VECTOR, v); +throw e; +} + +/** + * A clone of the BLAS {@code DAXPY} function, which carries out the + * operation y ← a · x + y. This is for internal use only: no + * dimension checks are provided. + * + * @param a the scalar by which {@code x} is to be multiplied + * @param x the vector to be added to {@code y} + * @param y the vector to be incremented + */ +private static void daxpy(final double a, final RealVector x, +final RealVecto
svn propchange: r1302298 - svn:log
Author: celestin Revision: 1302298 Modified property: svn:log Modified: svn:log at Mon Mar 19 06:55:02 2012 -- --- svn:log (original) +++ svn:log Mon Mar 19 06:55:02 2012 @@ -2,3 +2,4 @@ In class o.a.c.math3.linear.SymmLQ - Changed parameter order for the constructor of nested class State (for consistency with the constructor of SymmLQ). - Moved some static helper methods from SymmLQ to nested class State - Changed visibility of some static fields from private to protected in order to avoid the use of synthetic getters. +See MATH-761.
svn propchange: r1302261 - svn:log
Author: celestin Revision: 1302261 Modified property: svn:log Modified: svn:log at Mon Mar 19 06:58:51 2012 -- --- svn:log (original) +++ svn:log Mon Mar 19 06:58:51 2012 @@ -1 +1 @@ -Make State class static +Make State class static (see MATH-761).
svn commit: r1302785 - /commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/SymmLQ.java
Author: celestin Date: Tue Mar 20 06:37:26 2012 New Revision: 1302785 URL: http://svn.apache.org/viewvc?rev=1302785&view=rev Log: In o.a.c.m3.SymmLQ: reduced visibility of some fields/methods (from protected to package protected). See MATH-761. Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/SymmLQ.java Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/SymmLQ.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/SymmLQ.java?rev=1302785&r1=1302784&r2=1302785&view=diff == --- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/SymmLQ.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/SymmLQ.java Tue Mar 20 06:37:26 2012 @@ -598,7 +598,7 @@ public class SymmLQ * value of the state variables of {@code this} object correspond to the * current iteration count {@code k}. */ -protected void update() { +void update() { final RealVector v = y.mapMultiply(1. / beta); y = a.operate(v); daxpbypz(-shift, v, -beta / oldb, r1, y); @@ -812,10 +812,10 @@ public class SymmLQ } /** The cubic root of {@link #MACH_PREC}. */ -protected static final double CBRT_MACH_PREC; +static final double CBRT_MACH_PREC; /** The machine precision. */ -protected static final double MACH_PREC; +static final double MACH_PREC; /** Key for the exception context. */ private static final String OPERATOR = "operator";
svn commit: r1302788 - /commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/SymmLQ.java
Author: celestin Date: Tue Mar 20 07:04:05 2012 New Revision: 1302788 URL: http://svn.apache.org/viewvc?rev=1302788&view=rev Log: In o.a.c.m3.linear.SymmLQ.State, implemented hasConverged() so as to avoid access to private field State.hasConverged through synthetic getters. Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/SymmLQ.java Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/SymmLQ.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/SymmLQ.java?rev=1302788&r1=1302787&r2=1302788&view=diff == --- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/SymmLQ.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/SymmLQ.java Tue Mar 20 07:04:05 2012 @@ -757,6 +757,15 @@ public class SymmLQ } hasConverged = (cgnorm <= epsx) || (cgnorm <= epsr); } + +/** + * Returns {@code true} if the default stopping criterion is fulfilled. + * + * @return {@code true} if convergence of the iterations has occured + */ +public boolean hasConverged() { +return hasConverged; +} } /** @@ -1157,7 +1166,7 @@ public class SymmLQ } /* Cause termination if beta is essentially zero. */ final boolean earlyStop; -earlyStop = (state.beta < MACH_PREC) || (state.hasConverged); +earlyStop = (state.beta < MACH_PREC) || (state.hasConverged()); manager.fireInitializationEvent(event); if (!earlyStop) { do { @@ -1165,7 +1174,7 @@ public class SymmLQ manager.fireIterationStartedEvent(event); state.update(); manager.fireIterationPerformedEvent(event); -} while (!state.hasConverged); +} while (!state.hasConverged()); } state.refine(x); /*
svn commit: r1303290 - /commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/SymmLQ.java
Author: celestin Date: Wed Mar 21 05:26:45 2012 New Revision: 1303290 URL: http://svn.apache.org/viewvc?rev=1303290&view=rev Log: In org.apache.commons.math3.linear.SymmLQ.State, created - boolean bEqualsNullVector() - boolean betaIsZero() to improve data encapsulation (see MATH-761). Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/SymmLQ.java Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/SymmLQ.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/SymmLQ.java?rev=1303290&r1=1303289&r2=1303290&view=diff == --- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/SymmLQ.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/SymmLQ.java Wed Mar 21 05:26:45 2012 @@ -226,6 +226,11 @@ public class SymmLQ * */ private static class State { +/** The cubic root of {@link #MACH_PREC}. */ +static final double CBRT_MACH_PREC; + +/** The machine precision. */ +static final double MACH_PREC; /** Reference to the linear operator. */ private final RealLinearOperator a; @@ -334,6 +339,14 @@ public class SymmLQ /** The value of zeta[1]^2 + ... + zeta[k-1]^2. */ private double ynorm2; +/** The value of {@code b == 0} (exact floating-point equality). */ +private boolean bIsNull; + +static { +MACH_PREC = Math.ulp(1.); +CBRT_MACH_PREC = Math.cbrt(MACH_PREC); +} + /** * Creates and inits to k = 1 a new instance of this class. * @@ -390,7 +403,7 @@ public class SymmLQ throws NonSelfAdjointOperatorException { final double s = y.dotProduct(y); final double t = x.dotProduct(z); -final double epsa = (s + SymmLQ.MACH_PREC) * SymmLQ.CBRT_MACH_PREC; +final double epsa = (s + MACH_PREC) * CBRT_MACH_PREC; if (FastMath.abs(s - t) > epsa) { final NonSelfAdjointOperatorException e; e = new NonSelfAdjointOperatorException(); @@ -525,8 +538,10 @@ public class SymmLQ } if (this.beta1 == 0.) { /* If b = 0 exactly, stop with x = 0. */ +this.bIsNull = true; return; } +this.bIsNull = false; this.beta1 = FastMath.sqrt(this.beta1); /* At this point * r1 = b, @@ -766,6 +781,25 @@ public class SymmLQ public boolean hasConverged() { return hasConverged; } + +/** + * Returns {@code true} if the right-hand side vector is zero exactly. + * + * @return the boolean value of {@code b == 0} + */ +public boolean bEqualsNullVector() { +return bIsNull; +} + +/** + * Returns {@code true} if {@code beta} is essentially zero. This method + * is used to check for early stop of the iterations. + * + * @return {@code true} if {@code beta < }{@link #MACH_PREC} + */ +public boolean betaEqualsZero() { +return beta < MACH_PREC; +} } /** @@ -820,12 +854,6 @@ public class SymmLQ } } -/** The cubic root of {@link #MACH_PREC}. */ -static final double CBRT_MACH_PREC; - -/** The machine precision. */ -static final double MACH_PREC; - /** Key for the exception context. */ private static final String OPERATOR = "operator"; @@ -885,11 +913,6 @@ public class SymmLQ this.check = check; } -static { -MACH_PREC = Math.ulp(1.); -CBRT_MACH_PREC = Math.cbrt(MACH_PREC); -} - /** * Returns {@code true} if symmetry of the matrix, and symmetry as well as * positive definiteness of the preconditioner should be checked. @@ -1159,14 +1182,14 @@ public class SymmLQ final State state = new State(a, minv, b, x, goodb, shift, delta, check); final IterativeLinearSolverEvent event = new SymmLQEvent(this, state); -if (state.beta1 == 0.) { +if (state.bEqualsNullVector()) { /* If b = 0 exactly, stop with x = 0. */ manager.fireTerminationEvent(event); return x; } /* Cause termination if beta is essentially zero. */ final boolean earlyStop; -earlyStop = (state.beta < MACH_PREC) || (state.hasConverged()); +earlyStop = state.betaEqualsZero() || state.hasConverged(); manager.fireInitializationEvent(event); if (!earlyStop) { do {
svn commit: r1303292 - /commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/SymmLQTest.java
Author: celestin Date: Wed Mar 21 05:49:14 2012 New Revision: 1303292 URL: http://svn.apache.org/viewvc?rev=1303292&view=rev Log: Modified unit test of o.a.c.m3.linear.SymmLQ to show that lines 1208-1209 are essential (see MATH-761). Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/SymmLQTest.java Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/SymmLQTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/SymmLQTest.java?rev=1303292&r1=1303291&r2=1303292&view=diff == --- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/SymmLQTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/SymmLQTest.java Wed Mar 21 05:49:14 2012 @@ -486,6 +486,7 @@ public class SymmLQTest { * count[3] = number of calls to terminationPerformed */ final int[] count = new int[] {0, 0, 0, 0}; +final RealVector xFromListener = new ArrayRealVector(n); final IterationListener listener = new IterationListener() { public void initializationPerformed(final IterationEvent e) { @@ -506,6 +507,8 @@ public class SymmLQTest { public void terminationPerformed(final IterationEvent e) { ++count[3]; +final IterativeLinearSolverEvent ilse = (IterativeLinearSolverEvent) e; +xFromListener.setSubVector(0, ilse.getSolution()); } }; solver = new SymmLQ(maxIterations, 1E-10, true); @@ -515,11 +518,21 @@ public class SymmLQTest { Arrays.fill(count, 0); b.set(0.); b.setEntry(j, 1.); -solver.solve(a, b); +final RealVector xFromSolver = solver.solve(a, b); String msg = String.format("column %d (initialization)", j); Assert.assertEquals(msg, 1, count[0]); msg = String.format("column %d (finalization)", j); Assert.assertEquals(msg, 1, count[3]); +/* + * Check that solution is not "over-refined". When the last iteration has + * occurred, no further refinement should be performed. + */ +for (int i = 0; i < n; i++){ +msg = String.format("row %d, column %d", i, j); +final double expected = xFromSolver.getEntry(i); +final double actual = xFromListener.getEntry(i); +Assert.assertEquals(msg, expected, actual, 0.0); +} } }
svn commit: r1303649 - /commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/SymmLQ.java
Author: celestin Date: Thu Mar 22 03:51:05 2012 New Revision: 1303649 URL: http://svn.apache.org/viewvc?rev=1303649&view=rev Log: Replaced Math with FastMath. Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/SymmLQ.java Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/SymmLQ.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/SymmLQ.java?rev=1303649&r1=1303648&r2=1303649&view=diff == --- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/SymmLQ.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/SymmLQ.java Thu Mar 22 03:51:05 2012 @@ -343,8 +343,8 @@ public class SymmLQ private boolean bIsNull; static { -MACH_PREC = Math.ulp(1.); -CBRT_MACH_PREC = Math.cbrt(MACH_PREC); +MACH_PREC = FastMath.ulp(1.); +CBRT_MACH_PREC = FastMath.cbrt(MACH_PREC); } /**
svn commit: r1303674 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math3/linear/SymmLQ.java test/java/org/apache/commons/math3/linear/SymmLQTest.java
Author: celestin Date: Thu Mar 22 07:15:24 2012 New Revision: 1303674 URL: http://svn.apache.org/viewvc?rev=1303674&view=rev Log: In o.a.c.m3.SymmLQ.State, created accessors - RealVector getRightHandSideVector(), - RealVector getSolution(), - double getNormOfResidual(), see MATH-761. Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/SymmLQ.java commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/SymmLQTest.java Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/SymmLQ.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/SymmLQ.java?rev=1303674&r1=1303673&r2=1303674&view=diff == --- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/SymmLQ.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/SymmLQ.java Thu Mar 22 07:15:24 2012 @@ -307,6 +307,12 @@ public class SymmLQ /** The value of beta[k+1] * M * P' * v[k+1]. */ private RealVector r2; +/** + * The value of the updated, preconditioned residual P * r. This value is + * given by {@code min(}{@link #cgnorm}{@code , }{@link #lqnorm}{@code )}. + */ +private double rnorm; + /** Copy of the {@code shift} parameter. */ private final double shift; @@ -331,7 +337,7 @@ public class SymmLQ * the value of xL[k-1] if {@code goodb} is {@code false}, (xL[k-1] - * bstep[k-1] * v[1]) otherwise. */ -private final RealVector x; +private final RealVector xL; /** The value of beta[k+1] * P' * v[k+1]. */ private RealVector y; @@ -375,7 +381,7 @@ public class SymmLQ this.a = a; this.minv = minv; this.b = b; -this.x = x; +this.xL = x; this.goodb = goodb; this.shift = shift; this.minvb = minv == null ? b : minv.operate(b); @@ -477,19 +483,19 @@ public class SymmLQ * the convergence tests involve only cgnorm, so we're unlikely to stop * at an LQ point, except if the iteration limit interferes. * - * @param xRefined the vector to be updated with the refined value of x + * @param xC the vector to be updated with the refined value of xL */ -public void refine(final RealVector xRefined) { -final int n = this.x.getDimension(); +void moveToCG(final RealVector xC) { +final int n = this.xL.getDimension(); if (lqnorm < cgnorm) { if (!goodb) { -xRefined.setSubVector(0, this.x); +xC.setSubVector(0, this.xL); } else { final double step = bstep / beta1; for (int i = 0; i < n; i++) { final double bi = minvb.getEntry(i); -final double xi = this.x.getEntry(i); -xRefined.setEntry(i, xi + step * bi); +final double xi = this.xL.getEntry(i); +xC.setEntry(i, xi + step * bi); } } } else { @@ -500,16 +506,16 @@ public class SymmLQ // ynorm = FastMath.sqrt(ynorm2 + zbar * zbar); if (!goodb) { for (int i = 0; i < n; i++) { -final double xi = this.x.getEntry(i); +final double xi = this.xL.getEntry(i); final double wi = wbar.getEntry(i); -xRefined.setEntry(i, xi + zbar * wi); +xC.setEntry(i, xi + zbar * wi); } } else { for (int i = 0; i < n; i++) { -final double xi = this.x.getEntry(i); +final double xi = this.xL.getEntry(i); final double wi = wbar.getEntry(i); final double bi = minvb.getEntry(i); -xRefined.setEntry(i, xi + zbar * wi + step * bi); +xC.setEntry(i, xi + zbar * wi + step * bi); } } } @@ -521,7 +527,7 @@ public class SymmLQ * 1. */ private void init() { -this.x.set(0.); +this.xL.set(0.); /* * Set up y for the first Lanczos vector. y and beta1 will be zero * if b = 0. @@ -696,12 +702,12 @@ public class SymmLQ */ final double zetaC = zeta * c; final double zetaS = zeta * s; -final int n = x.getDimension(); +final int n = xL.getDimensi
svn commit: r1304215 - /commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/SymmLQTest.java
Author: celestin Date: Fri Mar 23 07:25:44 2012 New Revision: 1304215 URL: http://svn.apache.org/viewvc?rev=1304215&view=rev Log: Corrected copy/paste typo, which caused ConjugateGradient to be tested in place of SymmLQ. Some tests now fail (see MATH-770). Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/SymmLQTest.java Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/SymmLQTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/SymmLQTest.java?rev=1304215&r1=1304214&r2=1304215&view=diff == --- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/SymmLQTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/SymmLQTest.java Fri Mar 23 07:25:44 2012 @@ -628,7 +628,7 @@ public class SymmLQTest { doTestNormOfResidual(e); } }; -solver = new ConjugateGradient(maxIterations, 1E-10, true); +solver = new SymmLQ(maxIterations, 1E-10, true); solver.getIterationManager().addIterationListener(listener); final RealVector b = new ArrayRealVector(n); for (int j = 0; j < n; j++) { @@ -675,7 +675,7 @@ public class SymmLQTest { doTestNormOfResidual(e); } }; -solver = new ConjugateGradient(maxIterations, 1E-10, true); +solver = new SymmLQ(maxIterations, 1E-10, true); solver.getIterationManager().addIterationListener(listener); final RealVector b = new ArrayRealVector(n); for (int j = 0; j < n; j++) {
svn commit: r1304216 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math3/linear/JacobiPreconditioner.java test/java/org/apache/commons/math3/linear/SymmLQTest.java
Author: celestin Date: Fri Mar 23 07:50:51 2012 New Revision: 1304216 URL: http://svn.apache.org/viewvc?rev=1304216&view=rev Log: In SymmLQTest, testPreconditionedNormOfResidual() now passes. Previous failure was due to the test itself, not to the implementation of SymmLQ. See MATH-770. Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/JacobiPreconditioner.java commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/SymmLQTest.java Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/JacobiPreconditioner.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/JacobiPreconditioner.java?rev=1304216&r1=1304215&r2=1304216&view=diff == --- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/JacobiPreconditioner.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/JacobiPreconditioner.java Fri Mar 23 07:50:51 2012 @@ -16,6 +16,8 @@ */ package org.apache.commons.math3.linear; +import org.apache.commons.math3.analysis.function.Sqrt; + /** * This class implements the standard Jacobi (diagonal) preconditioner. For a * matrix Aij, this preconditioner is @@ -98,4 +100,34 @@ public class JacobiPreconditioner extend // Dimension check is carried out by ebeMultiply return x.ebeDivide(diag); } + +/** + * Returns the square root of {@code this} diagonal operator. More + * precisely, this method returns + * P = diag(1 / √A11, 1 / √A22, …). + * + * @return the square root of {@code this} operator + */ +public RealLinearOperator sqrt(){ +final RealVector sqrtDiag = diag.map(new Sqrt()); +return new RealLinearOperator() { +/** {@inheritDoc} */ +@Override +public RealVector operate(final RealVector x) { +return x.ebeDivide(sqrtDiag); +} + +/** {@inheritDoc} */ +@Override +public int getRowDimension() { +return sqrtDiag.getDimension(); +} + +/** {@inheritDoc} */ +@Override +public int getColumnDimension() { +return sqrtDiag.getDimension(); +} +}; +} } Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/SymmLQTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/SymmLQTest.java?rev=1304216&r1=1304215&r2=1304216&view=diff == --- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/SymmLQTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/SymmLQTest.java Fri Mar 23 07:50:51 2012 @@ -19,7 +19,6 @@ package org.apache.commons.math3.linear; import java.util.Arrays; import org.apache.commons.math3.exception.DimensionMismatchException; -import org.apache.commons.math3.exception.MathUnsupportedOperationException; import org.apache.commons.math3.util.FastMath; import org.apache.commons.math3.util.IterationEvent; import org.apache.commons.math3.util.IterationListener; @@ -643,7 +642,8 @@ public class SymmLQTest { final int n = 5; final int maxIterations = 100; final RealLinearOperator a = new HilbertMatrix(n); -final RealLinearOperator m = JacobiPreconditioner.create(a); +final JacobiPreconditioner m = JacobiPreconditioner.create(a); +final RealLinearOperator p = m.sqrt(); final PreconditionedIterativeLinearSolver solver; final IterationListener listener = new IterationListener() { @@ -653,7 +653,7 @@ public class SymmLQTest { final RealVector x = evt.getSolution(); final RealVector b = evt.getRightHandSideVector(); final RealVector r = b.subtract(a.operate(x)); -final double rnorm = r.getNorm(); +final double rnorm = p.operate(r).getNorm(); Assert.assertEquals("iteration performed (residual)", rnorm, evt.getNormOfResidual(), FastMath.max(1E-5 * rnorm, 1E-10));
svn commit: r1304574 - /commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/SymmLQ.java
Author: celestin Date: Fri Mar 23 19:51:12 2012 New Revision: 1304574 URL: http://svn.apache.org/viewvc?rev=1304574&view=rev Log: In o.a.c.m3.SymmLQ.State - the current solution is now refined at each iteration, as the overhead is negligible - SymmLQ.State.xL is no longer a reference to the parameter x passed to its constructor. This way, all transparent updates of the vector x are removed. - SymmLQ.State.moveToCG(RealVector) is renamed SymmLQ.State.refineSolution(RealVector). In o.a.c.m3.SymmLQ.solveInPlace() - SymmLQ.State.init() is now called explicitly - a new DefaultIterativeLinearSolverEvent is created each time it is needed (no "clever" object reuse) - SymmLQ.State.refineSolution(RealVector) is called explicitly Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/SymmLQ.java Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/SymmLQ.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/SymmLQ.java?rev=1304574&r1=1304573&r2=1304574&view=diff == --- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/SymmLQ.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/SymmLQ.java Fri Mar 23 19:51:12 2012 @@ -360,8 +360,6 @@ public class SymmLQ * @param minv the inverse of the preconditioner, M-1 * (can be {@code null}) * @param b the right-hand side vector - * @param x the vector to be updated with the solution; {@code x} should - * not be considered as an initial guess (more) * @param goodb usually {@code false}, except if {@code x} is expected * to contain a large multiple of {@code b} * @param shift the amount to be subtracted to all diagonal elements of @@ -373,7 +371,6 @@ public class SymmLQ public State(final RealLinearOperator a, final RealLinearOperator minv, final RealVector b, -final RealVector x, final boolean goodb, final double shift, final double delta, @@ -381,14 +378,13 @@ public class SymmLQ this.a = a; this.minv = minv; this.b = b; -this.xL = x; +this.xL = new ArrayRealVector(b.getDimension()); this.goodb = goodb; this.shift = shift; this.minvb = minv == null ? b : minv.operate(b); this.hasConverged = false; this.check = check; this.delta = delta; -init(); } /** @@ -483,19 +479,19 @@ public class SymmLQ * the convergence tests involve only cgnorm, so we're unlikely to stop * at an LQ point, except if the iteration limit interferes. * - * @param xC the vector to be updated with the refined value of xL + * @param x the vector to be updated with the refined value of xL */ -void moveToCG(final RealVector xC) { + void refineSolution(final RealVector x) { final int n = this.xL.getDimension(); if (lqnorm < cgnorm) { if (!goodb) { -xC.setSubVector(0, this.xL); +x.setSubVector(0, this.xL); } else { final double step = bstep / beta1; for (int i = 0; i < n; i++) { final double bi = minvb.getEntry(i); final double xi = this.xL.getEntry(i); -xC.setEntry(i, xi + step * bi); +x.setEntry(i, xi + step * bi); } } } else { @@ -508,14 +504,14 @@ public class SymmLQ for (int i = 0; i < n; i++) { final double xi = this.xL.getEntry(i); final double wi = wbar.getEntry(i); -xC.setEntry(i, xi + zbar * wi); +x.setEntry(i, xi + zbar * wi); } } else { for (int i = 0; i < n; i++) { final double xi = this.xL.getEntry(i); final double wi = wbar.getEntry(i); final double bi = minvb.getEntry(i); -xC.setEntry(i, xi + zbar * wi + step * bi); +x.setEntry(i, xi + zbar * wi + step * bi); } } } @@ -526,7 +522,7 @@ public class SymmLQ * value of the state variables of {@code this} object correspond to k = * 1. */ -private void init() { + void init() { this.xL.set(0.); /* * Set up y for the fir
svn propchange: r1304574 - svn:log
Author: celestin Revision: 1304574 Modified property: svn:log Modified: svn:log at Fri Mar 23 19:57:22 2012 -- --- svn:log (original) +++ svn:log Fri Mar 23 19:57:22 2012 @@ -6,3 +6,4 @@ In o.a.c.m3.SymmLQ.solveInPlace() - SymmLQ.State.init() is now called explicitly - a new DefaultIterativeLinearSolverEvent is created each time it is needed (no "clever" object reuse) - SymmLQ.State.refineSolution(RealVector) is called explicitly +See MATH-761.
svn commit: r1305734 - /commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/SymmLQ.java
Author: celestin Date: Tue Mar 27 05:41:58 2012 New Revision: 1305734 URL: http://svn.apache.org/viewvc?rev=1305734&view=rev Log: Javadoc Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/SymmLQ.java Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/SymmLQ.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/SymmLQ.java?rev=1305734&r1=1305733&r2=1305734&view=diff == --- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/SymmLQ.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/SymmLQ.java Tue Mar 27 05:41:58 2012 @@ -50,17 +50,33 @@ import org.apache.commons.math3.util.Mat * * Preconditioning * - * Preconditioning may reduce the number of iterations required. The solver may be - * provided with a positive definite preconditioner M = C · CT - * that is known to approximate (A - shift · I) in some sense, where - * systems of the form M · y = x can be solved efficiently. Then SYMMLQ - * will implicitly solve the system of equations P · (A - shift · - * I) · PT · xhat = P · b, i.e. Ahat · - * xhat = bhat, where P = C-1, Ahat = P · (A - shift · - * I) · PT, bhat = P · b, and return the solution x = - * PT · xhat. The associated residual is rhat = bhat - Ahat - * · xhat = P · [b - (A - shift · I) · x] = P - * · r. + * Preconditioning may reduce the number of iterations required. The solver may + * be provided with a positive definite preconditioner + * M = C · CT + * that is known to approximate + * (A - shift · I) in some sense, where systems of the form + * M · y = x + * can be solved efficiently. Then SYMMLQ will implicitly solve the system of + * equations + * P · (A - shift · I) · PT · + * xhat = P · b, i.e. + * Ahat · xhat = bhat, + * where P = C-1, + * Ahat = P · (A - shift · I) · PT, + * bhat = P · b, + * and return the solution + * x = PT · xhat. + * The associated residual is + * rhat = bhat - Ahat · xhat + * = P · [b - (A - shift · I) · x] + * = P · r. + * + * + * In the case of preconditioning, the {@link IterativeLinearSolverEvent}s that + * this solver throws are such that + * {@link IterativeLinearSolverEvent#getNormOfResidual()} returns the norm of + * the preconditioned, updated residual, ||P · r||, not the norm + * of the true residual ||r||. * * Default stopping criterion * @@ -475,9 +491,15 @@ public class SymmLQ } /** + * * Move to the CG point if it seems better. In this version of SYMMLQ, * the convergence tests involve only cgnorm, so we're unlikely to stop * at an LQ point, except if the iteration limit interferes. + * + * + * Additional upudates are also carried out in case {@code goodb} is set + * to {@code true}. + * * * @param x the vector to be updated with the refined value of xL */
svn commit: r1305738 - /commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/PreconditionedIterativeLinearSolver.java
Author: celestin Date: Tue Mar 27 06:02:15 2012 New Revision: 1305738 URL: http://svn.apache.org/viewvc?rev=1305738&view=rev Log: Changed o.a.c.m3.linear.PreconditionedIterativeLinearSolver according to MATH-771. Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/PreconditionedIterativeLinearSolver.java Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/PreconditionedIterativeLinearSolver.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/PreconditionedIterativeLinearSolver.java?rev=1305738&r1=1305737&r2=1305738&view=diff == --- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/PreconditionedIterativeLinearSolver.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/PreconditionedIterativeLinearSolver.java Tue Mar 27 06:02:15 2012 @@ -26,15 +26,23 @@ import org.apache.commons.math3.util.Mat * * This abstract class defines preconditioned iterative solvers. When A is * ill-conditioned, instead of solving system A · x = b directly, it is - * preferable to solve M-1 · A · x = M-1 - * · b, where M approximates in some way A, while remaining comparatively - * easier to invert. M (not M-1!) is called the + * preferable to solve either + * + * (M · A) · x = M · b + * + * (left preconditioning), or + * + * (A · M) · y = b, followed by + * M · y = x + * + * (right preconditioning), where M approximates in some way A-1, + * while matrix-vector products of the type M · y remain comparatively + * easy to compute. In this library, M (not M-1!) is called the * preconditionner. * * - * Concrete implementations of this abstract class must be provided with - * M-1, the inverse of the preconditioner, as a - * {@link RealLinearOperator}. + * Concrete implementations of this abstract class must be provided with the + * preconditioner M, as a {@link RealLinearOperator}. * * * @version $Id$ @@ -68,15 +76,14 @@ public abstract class PreconditionedIter * b. * * @param a the linear operator A of the system - * @param minv the inverse of the preconditioner, M-1 - * (can be {@code null}) + * @param m the preconditioner, M (can be {@code null}) * @param b the right-hand side vector * @param x0 the initial guess of the solution * @return a new vector containing the solution * @throws NullArgumentException if one of the parameters is {@code null} - * @throws NonSquareOperatorException if {@code a} or {@code minv} is not + * @throws NonSquareOperatorException if {@code a} or {@code m} is not * square - * @throws DimensionMismatchException if {@code minv}, {@code b} or + * @throws DimensionMismatchException if {@code m}, {@code b} or * {@code x0} have dimensions inconsistent with {@code a} * @throws MaxCountExceededException at exhaustion of the iteration count, * unless a custom @@ -84,11 +91,11 @@ public abstract class PreconditionedIter * has been set at construction */ public RealVector solve(final RealLinearOperator a, -final RealLinearOperator minv, final RealVector b, final RealVector x0) +final RealLinearOperator m, final RealVector b, final RealVector x0) throws NullArgumentException, NonSquareOperatorException, DimensionMismatchException, MaxCountExceededException { MathUtils.checkNotNull(x0); -return solveInPlace(a, minv, b, x0.copy()); +return solveInPlace(a, m, b, x0.copy()); } /** {@inheritDoc} */ @@ -120,28 +127,27 @@ public abstract class PreconditionedIter * and throws an exception if one of the checks fails. * * @param a the linear operator A of the system - * @param minv the inverse of the preconditioner, M-1 - * (can be {@code null}) + * @param m the preconditioner, M (can be {@code null}) * @param b the right-hand side vector * @param x0 the initial guess of the solution * @throws NullArgumentException if one of the parameters is {@code null} - * @throws NonSquareOperatorException if {@code a} or {@code minv} is not + * @throws NonSquareOperatorException if {@code a} or {@code m} is not * square - * @throws DimensionMismatchException if {@code minv}, {@code b} or + * @throws DimensionMismatchException if {@code m}, {@code b} or * {@code x0} have dimensions inconsistent with {@code a} */ protected static void checkParameters(final RealLinearOperator a, -final RealLinearOperator minv, final RealVector b, final RealVector x0) +final RealLinearOperator m, final RealVector b, final RealVector x0) throws NullArgumentException, NonSquareOperatorException, DimensionMismatchException { checkPar
svn commit: r1306133 - /commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/ConjugateGradient.java
Author: celestin Date: Wed Mar 28 03:00:33 2012 New Revision: 1306133 URL: http://svn.apache.org/viewvc?rev=1306133&view=rev Log: Changed o.a.c.m3.linear.ConjugateGradient according to MATH-771. Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/ConjugateGradient.java Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/ConjugateGradient.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/ConjugateGradient.java?rev=1306133&r1=1306132&r2=1306133&view=diff == --- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/ConjugateGradient.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/ConjugateGradient.java Wed Mar 28 03:00:33 2012 @@ -139,10 +139,10 @@ public class ConjugateGradient /** {@inheritDoc} */ @Override public RealVector solveInPlace(final RealLinearOperator a, -final RealLinearOperator minv, final RealVector b, final RealVector x0) +final RealLinearOperator m, final RealVector b, final RealVector x0) throws NullArgumentException, NonSquareOperatorException, DimensionMismatchException, MaxCountExceededException { -checkParameters(a, minv, b, x0); +checkParameters(a, m, b, x0); final IterationManager manager = getIterationManager(); // Initialization of default stopping criterion manager.resetIterationCount(); @@ -163,7 +163,7 @@ public class ConjugateGradient final RealVector rro = RealVector.unmodifiableRealVector(r); double rnorm = r.getNorm(); RealVector z; -if (minv == null) { +if (m == null) { z = r; } else { z = null; @@ -182,15 +182,15 @@ public class ConjugateGradient evt = new DefaultIterativeLinearSolverEvent(this, manager.getIterations(), xro, bro, rro, rnorm); manager.fireIterationStartedEvent(evt); -if (minv != null) { -z = minv.operate(r); +if (m != null) { +z = m.operate(r); } final double rhoNext = r.dotProduct(z); if (check && (rhoNext <= 0.)) { final NonPositiveDefiniteOperatorException e; e = new NonPositiveDefiniteOperatorException(); final ExceptionContext context = e.getContext(); -context.setValue(OPERATOR, minv); +context.setValue(OPERATOR, m); context.setValue(VECTOR, r); throw e; }
svn commit: r1306135 - /commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/SymmLQ.java
Author: celestin Date: Wed Mar 28 03:19:33 2012 New Revision: 1306135 URL: http://svn.apache.org/viewvc?rev=1306135&view=rev Log: Changed o.a.c.m3.linear.SymmLQ according to MATH-771. Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/SymmLQ.java Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/SymmLQ.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/SymmLQ.java?rev=1306135&r1=1306134&r2=1306135&view=diff == --- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/SymmLQ.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/SymmLQ.java Wed Mar 28 03:19:33 2012 @@ -52,16 +52,15 @@ import org.apache.commons.math3.util.Mat * * Preconditioning may reduce the number of iterations required. The solver may * be provided with a positive definite preconditioner - * M = C · CT + * M = PT · P * that is known to approximate - * (A - shift · I) in some sense, where systems of the form - * M · y = x - * can be solved efficiently. Then SYMMLQ will implicitly solve the system of - * equations + * (A - shift · I)-1 in some sense, where matrix-vector + * products of the form M · y = x can be computed efficiently. Then + * SYMMLQ will implicitly solve the system of equations * P · (A - shift · I) · PT · * xhat = P · b, i.e. * Ahat · xhat = bhat, - * where P = C-1, + * where * Ahat = P · (A - shift · I) · PT, * bhat = P · b, * and return the solution @@ -73,7 +72,7 @@ import org.apache.commons.math3.util.Mat * * * In the case of preconditioning, the {@link IterativeLinearSolverEvent}s that - * this solver throws are such that + * this solver fires are such that * {@link IterativeLinearSolverEvent#getNormOfResidual()} returns the norm of * the preconditioned, updated residual, ||P · r||, not the norm * of the true residual ||r||. @@ -173,7 +172,7 @@ public class SymmLQ * = P * (A - shift * I) * P' * v[k] - alpha[k] * v[k] *- beta[k] * v[k-1] * Multiplying both sides by P', we get - * beta[k+1] * (P' * v)[k+1] = M^(-1) * (A - shift * I) * (P' * v)[k] + * beta[k+1] * (P' * v)[k+1] = M * (A - shift * I) * (P' * v)[k] * - alpha[k] * (P' * v)[k] * - beta[k] * (P' * v[k-1]), * and @@ -184,8 +183,7 @@ public class SymmLQ * In other words, the Lanczos iterations are unchanged, except for the fact * that we really compute (P' * v) instead of v. It can easily be checked * that all other formulas are unchanged. It must be noted that P is never - * explicitly used, only matrix-vector products involving M^(-1) are - * invoked. + * explicitly used, only matrix-vector products involving are invoked. * * 2. Accounting for the shift parameter *-- @@ -302,8 +300,8 @@ public class SymmLQ /** The estimate of the norm of P * rL[k-1]. */ private double lqnorm; -/** Reference to the inverse of the preconditioner, M-1. */ -private final RealLinearOperator minv; +/** Reference to the preconditioner, M. */ +private final RealLinearOperator m; /** * The value of (-eps[k+1] * zeta[k-1]). Was called {@code rhs2} in the @@ -311,16 +309,16 @@ public class SymmLQ */ private double minusEpsZeta; -/** The value of M^(-1) * b. */ -private final RealVector minvb; +/** The value of M * b. */ +private final RealVector mb; /** The value of beta[k]. */ private double oldb; -/** The value of beta[k] * M * P' * v[k]. */ +/** The value of beta[k] * M^(-1) * P' * v[k]. */ private RealVector r1; -/** The value of beta[k+1] * M * P' * v[k+1]. */ +/** The value of beta[k+1] * M^(-1) * P' * v[k+1]. */ private RealVector r2; /** @@ -373,8 +371,7 @@ public class SymmLQ * Creates and inits to k = 1 a new instance of this class. * * @param a the linear operator A of the system - * @param minv the inverse of the preconditioner, M-1 - * (can be {@code null}) + * @param m the preconditioner, M (can be {@code null}) * @param b the right-hand side vector * @param goodb usually {@code false}, except if {@code x} is expected * to contain a large multiple of {@code b} @@ -385,19 +382,19 @@ public class SymmLQ * preconditioner should be checked */ public State(final RealLinearOperator a, -final RealLinearOperator minv, +final
svn commit: r1306148 - /commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/JacobiPreconditioner.java
Author: celestin Date: Wed Mar 28 04:05:59 2012 New Revision: 1306148 URL: http://svn.apache.org/viewvc?rev=1306148&view=rev Log: Changed o.a.c.m3.linear.JacobiPreconditioner according to MATH-771. Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/JacobiPreconditioner.java Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/JacobiPreconditioner.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/JacobiPreconditioner.java?rev=1306148&r1=1306147&r2=1306148&view=diff == --- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/JacobiPreconditioner.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/JacobiPreconditioner.java Wed Mar 28 04:05:59 2012 @@ -21,10 +21,7 @@ import org.apache.commons.math3.analysis /** * This class implements the standard Jacobi (diagonal) preconditioner. For a * matrix Aij, this preconditioner is - * M = diag(A11, A22, …). - * {@link #create(RealLinearOperator)} returns the inverse of this - * preconditioner, - * M-1 = diag(1 / A11, 1 / A22, …) + * M = diag(1 / A11, 1 / A22, …). * * @version $Id$ * @since 3.0 @@ -55,8 +52,8 @@ public class JacobiPreconditioner extend * some time). With matrices, direct entry access is carried out. * * @param a the linear operator for which the preconditioner should be built - * @return the inverse of the preconditioner made of the inverse of the - * diagonal coefficients of the specified linear operator + * @return the diagonal preconditioner made of the inverse of the diagonal + * coefficients of the specified linear operator * @throws NonSquareOperatorException if {@code a} is not square */ public static JacobiPreconditioner create(final RealLinearOperator a) @@ -97,7 +94,7 @@ public class JacobiPreconditioner extend /** {@inheritDoc} */ @Override public RealVector operate(final RealVector x) { -// Dimension check is carried out by ebeMultiply +// Dimension check is carried out by ebeDivide return x.ebeDivide(diag); } @@ -106,7 +103,7 @@ public class JacobiPreconditioner extend * precisely, this method returns * P = diag(1 / √A11, 1 / √A22, …). * - * @return the square root of {@code this} operator + * @return the square root of {@code this} preconditioner */ public RealLinearOperator sqrt(){ final RealVector sqrtDiag = diag.map(new Sqrt());
svn commit: r1306150 - /commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/SymmLQ.java
Author: celestin Date: Wed Mar 28 04:18:44 2012 New Revision: 1306150 URL: http://svn.apache.org/viewvc?rev=1306150&view=rev Log: Changed o.a.c.m3.linear.SymmLQ according to MATH-771 (bis). Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/SymmLQ.java Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/SymmLQ.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/SymmLQ.java?rev=1306150&r1=1306149&r2=1306150&view=diff == --- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/SymmLQ.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/SymmLQ.java Wed Mar 28 04:18:44 2012 @@ -913,14 +913,14 @@ public class SymmLQ */ @Override public RealVector solve(final RealLinearOperator a, -final RealLinearOperator minv, final RealVector b) throws +final RealLinearOperator m, final RealVector b) throws NullArgumentException, NonSquareOperatorException, DimensionMismatchException, MaxCountExceededException, NonSelfAdjointOperatorException, NonPositiveDefiniteOperatorException, IllConditionedOperatorException { MathUtils.checkNotNull(a); final RealVector x = new ArrayRealVector(a.getColumnDimension()); -return solveInPlace(a, minv, b, x, false, 0.); +return solveInPlace(a, m, b, x, false, 0.); } /**
svn commit: r1306177 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math3/util/Decimal64.java main/java/org/apache/commons/math3/util/Decimal64Field.java test/java/org/apache/common
Author: celestin Date: Wed Mar 28 05:40:46 2012 New Revision: 1306177 URL: http://svn.apache.org/viewvc?rev=1306177&view=rev Log: Created Decimal64, a wrapper class around the primitive double type. This class implements FieldElement. See MATH-756. Added: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/Decimal64.java (with props) commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/Decimal64Field.java (with props) commons/proper/math/trunk/src/test/java/org/apache/commons/math3/util/Decimal64Test.java (with props) Added: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/Decimal64.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/Decimal64.java?rev=1306177&view=auto == --- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/Decimal64.java (added) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/Decimal64.java Wed Mar 28 05:40:46 2012 @@ -0,0 +1,304 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.math3.util; + +import org.apache.commons.math3.Field; +import org.apache.commons.math3.FieldElement; + +/** + * This class wraps a {@code double} value in an object. It is similar to the + * standard class {@link Double}, while also implementing the + * {@link FieldElement} interface. + * + * @since 3.1 + * @version $Id$ + */ +public class Decimal64 extends Number implements FieldElement, +Comparable { + +/** The constant value of {@code 0d} as a {@code Decimal64}. */ +public static final Decimal64 ZERO; + +/** The constant value of {@code 1d} as a {@code Decimal64}. */ +public static final Decimal64 ONE; + +/** + * The constant value of {@link Double#NEGATIVE_INFINITY} as a + * {@code Decimal64}. + */ +public static final Decimal64 NEGATIVE_INFINITY; + +/** + * The constant value of {@link Double#POSITIVE_INFINITY} as a + * {@code Decimal64}. + */ +public static final Decimal64 POSITIVE_INFINITY; + +/** The constant value of {@link Double#NaN} as a {@code Decimal64}. */ +public static final Decimal64 NAN; + +/** */ +private static final long serialVersionUID = 20120227L; + +static { +ZERO = new Decimal64(0d); +ONE = new Decimal64(1d); +NEGATIVE_INFINITY = new Decimal64(Double.NEGATIVE_INFINITY); +POSITIVE_INFINITY = new Decimal64(Double.POSITIVE_INFINITY); +NAN = new Decimal64(Double.NaN); +} + +/** The primitive {@code double} value of this object. */ +private final double value; + +/** + * Creates a new instance of this class. + * + * @param x the primitive {@code double} value of the object to be created + */ +public Decimal64(final double x) { +this.value = x; +} + +/* + * Methods from the FieldElement interface. + */ + +/** {@inheritDoc} */ +public Field getField() { +return Decimal64Field.getInstance(); +} + +/** + * {@inheritDoc} + * + * The current implementation strictly enforces + * {@code this.add(a).equals(new Decimal64(this.doubleValue() + * + a.doubleValue()))}. + */ +public Decimal64 add(final Decimal64 a) { +return new Decimal64(this.value + a.value); +} + +/** + * {@inheritDoc} + * + * The current implementation strictly enforces + * {@code this.subtract(a).equals(new Decimal64(this.doubleValue() + * - a.doubleValue()))}. + */ +public Decimal64 subtract(final Decimal64 a) { +return new Decimal64(this.value - a.value); +} + +/** + * {@inheritDoc} + * + * The current implementation strictly enforces + * {@code this.negate().equals(new Decimal64(-this.doubleValue()))}. + */ +public Decimal64 negate() { +return new Decimal64(-this.value); +} + +/** + * {@inheritDoc} + * + * The current implementation strictly enforces + * {@code this.multiply(a).equals(new Decimal64(this.doubleVal
svn commit: r1306759 - /commons/proper/math/trunk/src/changes/changes.xml
Author: celestin Date: Thu Mar 29 09:04:24 2012 New Revision: 1306759 URL: http://svn.apache.org/viewvc?rev=1306759&view=rev Log: Updated changes.xml following resolution of MATH-756. Modified: commons/proper/math/trunk/src/changes/changes.xml Modified: commons/proper/math/trunk/src/changes/changes.xml URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/changes/changes.xml?rev=1306759&r1=1306758&r2=1306759&view=diff == --- commons/proper/math/trunk/src/changes/changes.xml (original) +++ commons/proper/math/trunk/src/changes/changes.xml Thu Mar 29 09:04:24 2012 @@ -52,6 +52,9 @@ If the output is not quite correct, chec + +Added classes Decimal64 and Decimal64Field, which are wrapper classes around primitive doubles. These classes implement FieldElement and Field, respectively. +
svn commit: r1308098 - /commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/QRDecomposition.java
Author: celestin Date: Sun Apr 1 13:10:08 2012 New Revision: 1308098 URL: http://svn.apache.org/viewvc?rev=1308098&view=rev Log: Javadoc. Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/QRDecomposition.java Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/QRDecomposition.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/QRDecomposition.java?rev=1308098&r1=1308097&r2=1308098&view=diff == --- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/QRDecomposition.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/QRDecomposition.java Sun Apr 1 13:10:08 2012 @@ -207,7 +207,7 @@ public class QRDecomposition { /** * Returns the transpose of the matrix Q of the decomposition. * Q is an orthogonal matrix - * @return the Q matrix + * @return the transpose of the Q matrix, QT */ public RealMatrix getQT() { if (cachedQT == null) {
svn commit: r1332076 - /commons/proper/math/trunk/src/main/java/org/apache/commons/math3/optimization/general/AbstractLeastSquaresOptimizer.java
Author: celestin Date: Mon Apr 30 06:38:00 2012 New Revision: 1332076 URL: http://svn.apache.org/viewvc?rev=1332076&view=rev Log: In o.a.c.m3.optimization.general.AbstractLeastSquaresOptimizer, improved the javadoc of guessParametersErrors() (MATH-784). Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/optimization/general/AbstractLeastSquaresOptimizer.java Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/optimization/general/AbstractLeastSquaresOptimizer.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/optimization/general/AbstractLeastSquaresOptimizer.java?rev=1332076&r1=1332075&r2=1332076&view=diff == --- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/optimization/general/AbstractLeastSquaresOptimizer.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/optimization/general/AbstractLeastSquaresOptimizer.java Mon Apr 30 06:38:00 2012 @@ -224,12 +224,27 @@ public abstract class AbstractLeastSquar } /** - * Guess the errors in optimized parameters. - * Guessing is covariance-based: It only gives a rough order of magnitude. + * + * Returns an estimate of the standard deviation of each parameter. The + * returned values are the so-called (asymptotic) standard errors on the + * parameters, defined as {@code sd(a[i]) = sqrt(S / (n - m) * C[i][i])}, + * where {@code a[i]} is the optimized value of the {@code i}-th parameter, + * {@code S} is the minimized value of the sum of squares objective function + * (as returned by {@link #getChiSquare()}), {@code n} is the number of + * observations, {@code m} is the number of parameters and {@code C} is the + * covariance matrix. + * + * + * See also + * http://en.wikipedia.org/wiki/Least_squares";>Wikipedia, + * or + * http://mathworld.wolfram.com/LeastSquaresFitting.html";>MathWorld, + * equations (34) and (35) for a particular case. + * * - * @return errors in optimized parameters + * @return an estimate of the standard deviation of the optimized parameters * @throws org.apache.commons.math3.linear.SingularMatrixException - * if the covariances matrix cannot be computed. + * if the covariance matrix cannot be computed. * @throws NumberIsTooSmallException if the number of degrees of freedom is not * positive, i.e. the number of measurements is less or equal to the number of * parameters.
svn commit: r1332086 - in /commons/proper/math/trunk/src/test: java/org/apache/commons/math3/optimization/general/ resources/org/apache/commons/math3/optimization/ resources/org/apache/commons/math3/o
Author: celestin Date: Mon Apr 30 07:41:58 2012 New Revision: 1332086 URL: http://svn.apache.org/viewvc?rev=1332086&view=rev Log: Implemented convenience classes for easy access to NIST Statistical Reference Datasets (StRD). These classes are used for unit testing of AbstractLeastSquaresOptimizer. Added: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/optimization/general/AbstractLeastSquaresOptimizerTest.java commons/proper/math/trunk/src/test/java/org/apache/commons/math3/optimization/general/StatisticalReferenceDataset.java commons/proper/math/trunk/src/test/java/org/apache/commons/math3/optimization/general/StatisticalReferenceDatasetFactory.java commons/proper/math/trunk/src/test/resources/org/apache/commons/math3/optimization/ commons/proper/math/trunk/src/test/resources/org/apache/commons/math3/optimization/general/ commons/proper/math/trunk/src/test/resources/org/apache/commons/math3/optimization/general/Hahn1.dat commons/proper/math/trunk/src/test/resources/org/apache/commons/math3/optimization/general/Kirby2.dat commons/proper/math/trunk/src/test/resources/org/apache/commons/math3/optimization/general/MGH17.dat Added: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/optimization/general/AbstractLeastSquaresOptimizerTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/optimization/general/AbstractLeastSquaresOptimizerTest.java?rev=1332086&view=auto == --- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/optimization/general/AbstractLeastSquaresOptimizerTest.java (added) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/optimization/general/AbstractLeastSquaresOptimizerTest.java Mon Apr 30 07:41:58 2012 @@ -0,0 +1,96 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law + * or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ +package org.apache.commons.math3.optimization.general; + +import java.io.IOException; +import java.util.Arrays; + +import junit.framework.Assert; + +import org.apache.commons.math3.optimization.PointVectorValuePair; +import org.apache.commons.math3.util.FastMath; +import org.junit.Test; + +public class AbstractLeastSquaresOptimizerTest { + +public static AbstractLeastSquaresOptimizer createOptimizer() { +return new AbstractLeastSquaresOptimizer() { + +@Override +protected PointVectorValuePair doOptimize() { +updateResidualsAndCost(); +updateJacobian(); +return null; +} +}; +} + +@Test +public void testGetChiSquare() throws IOException { +final StatisticalReferenceDataset dataset; +dataset = StatisticalReferenceDatasetFactory.createKirby2(); +final AbstractLeastSquaresOptimizer optimizer; +optimizer = createOptimizer(); +final double[] a = dataset.getParameters(); +final double[] y = dataset.getData()[1]; +final double[] w = new double[y.length]; +Arrays.fill(w, 1.0); + +optimizer.optimize(1, dataset.getLeastSquaresProblem(), y, w, a); +final double expected = dataset.getResidualSumOfSquares(); +final double actual = optimizer.getChiSquare(); +Assert.assertEquals(dataset.getName(), expected, actual, +1E-11 * expected); +} + +@Test +public void testGetRMS() throws IOException { +final StatisticalReferenceDataset dataset; +dataset = StatisticalReferenceDatasetFactory.createKirby2(); +final AbstractLeastSquaresOptimizer optimizer; +optimizer = createOptimizer(); +final double[] a = dataset.getParameters(); +final double[] y = dataset.getData()[1]; +final double[] w = new double[y.length]; +Arrays.fill(w, 1.0); + +optimizer.optimize(1, dataset.getLeastSquaresProblem(), y, w, a); +final double expected = FastMath +.sqrt(dataset.getResidualSumOfSquares() / + dataset.getNumObservations()); +final double actual = optimizer.getRMS(); +Assert.assertEquals(dataset
svn propchange: r1332086 - svn:log
Author: celestin Revision: 1332086 Modified property: svn:log Modified: svn:log at Mon Apr 30 07:48:33 2012 -- --- svn:log (original) +++ svn:log Mon Apr 30 07:48:33 2012 @@ -1,2 +1,3 @@ Implemented convenience classes for easy access to NIST Statistical Reference Datasets (StRD). These classes are used for unit testing of AbstractLeastSquaresOptimizer. +See MATH-784.
svn commit: r1332162 - in /commons/proper/math/trunk/src/main/java/org/apache/commons/math3: optimization/direct/PowellOptimizer.java util/MathArrays.java util/Precision.java
Author: celestin Date: Mon Apr 30 11:26:10 2012 New Revision: 1332162 URL: http://svn.apache.org/viewvc?rev=1332162&view=rev Log: Checkstyle. Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/optimization/direct/PowellOptimizer.java commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/MathArrays.java commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/Precision.java Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/optimization/direct/PowellOptimizer.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/optimization/direct/PowellOptimizer.java?rev=1332162&r1=1332161&r2=1332162&view=diff == --- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/optimization/direct/PowellOptimizer.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/optimization/direct/PowellOptimizer.java Mon Apr 30 11:26:10 2012 @@ -26,7 +26,6 @@ import org.apache.commons.math3.exceptio import org.apache.commons.math3.optimization.GoalType; import org.apache.commons.math3.optimization.PointValuePair; import org.apache.commons.math3.optimization.ConvergenceChecker; -import org.apache.commons.math3.optimization.AbstractConvergenceChecker; import org.apache.commons.math3.optimization.MultivariateOptimizer; import org.apache.commons.math3.optimization.univariate.BracketFinder; import org.apache.commons.math3.optimization.univariate.BrentOptimizer; Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/MathArrays.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/MathArrays.java?rev=1332162&r1=1332161&r2=1332162&view=diff == --- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/MathArrays.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/MathArrays.java Mon Apr 30 11:26:10 2012 @@ -150,6 +150,7 @@ public class MathArrays { /** * Check that an array is monotonically increasing or decreasing. * + * @param the type of the elements in the specified array * @param val Values. * @param dir Ordering direction. * @param strict Whether the order should be strict. Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/Precision.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/Precision.java?rev=1332162&r1=1332161&r2=1332162&view=diff == --- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/Precision.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/Precision.java Mon Apr 30 11:26:10 2012 @@ -30,19 +30,13 @@ import org.apache.commons.math3.util.Fas * @version $Id$ */ public class Precision { - -/** Exponent offset in IEEE754 representation. */ -private static final long EXPONENT_OFFSET = 1023l; - /** * Smallest positive number such that {@code 1 - EPSILON} is not * numerically equal to 1. * * In IEEE 754 arithmetic, this is 2-53. */ -public static final double EPSILON = Double.longBitsToDouble((EXPONENT_OFFSET - 53l) << 52); -//This was previously expressed as = 0x1.0p-53; -// However, OpenJDK (Sparc Solaris) cannot handle such small constants: MATH-721 +public static final double EPSILON; /** * Safe minimum, such that {@code 1 / SAFE_MIN} does not overflow. @@ -50,15 +44,32 @@ public class Precision { * In IEEE 754 arithmetic, this is also the smallest normalized * number 2-1022. */ -public static final double SAFE_MIN = Double.longBitsToDouble((EXPONENT_OFFSET - 1022l) << 52); -// This was previously expressed as = 0x1.0p-1022; -// However, OpenJDK (Sparc Solaris) cannot handle such small constants: MATH-721 +public static final double SAFE_MIN; + +/** Exponent offset in IEEE754 representation. */ +private static final long EXPONENT_OFFSET = 1023l; /** Offset to order signed double numbers lexicographically. */ private static final long SGN_MASK = 0x8000L; /** Offset to order signed double numbers lexicographically. */ private static final int SGN_MASK_FLOAT = 0x8000; +static { +/* + * This was previously expressed as = 0x1.0p-53; + * However, OpenJDK (Sparc Solaris) cannot handle such small + * constants: MATH-721 + */ +EPSILON = Double.longBitsToDouble((EXPONENT_OFFSET - 53l) << 52); + +/*
svn commit: r1332163 - /commons/proper/math/trunk/src/test/java/org/apache/commons/math3/optimization/general/
Author: celestin Date: Mon Apr 30 11:30:48 2012 New Revision: 1332163 URL: http://svn.apache.org/viewvc?rev=1332163&view=rev Log: Added missing svn properties. Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/optimization/general/AbstractLeastSquaresOptimizerAbstractTest.java (contents, props changed) commons/proper/math/trunk/src/test/java/org/apache/commons/math3/optimization/general/AbstractLeastSquaresOptimizerTest.java (props changed) commons/proper/math/trunk/src/test/java/org/apache/commons/math3/optimization/general/StatisticalReferenceDataset.java (props changed) commons/proper/math/trunk/src/test/java/org/apache/commons/math3/optimization/general/StatisticalReferenceDatasetFactory.java (props changed) Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/optimization/general/AbstractLeastSquaresOptimizerAbstractTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/optimization/general/AbstractLeastSquaresOptimizerAbstractTest.java?rev=1332163&r1=1332162&r2=1332163&view=diff == --- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/optimization/general/AbstractLeastSquaresOptimizerAbstractTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/optimization/general/AbstractLeastSquaresOptimizerAbstractTest.java Mon Apr 30 11:30:48 2012 @@ -93,6 +93,7 @@ import org.junit.Test; * @author Kenneth E. Hillstrom (original fortran minpack tests) * @author Jorge J. More (original fortran minpack tests) * @author Luc Maisonobe (non-minpack tests and minpack tests Java translation) + * @version $Id$ */ public abstract class AbstractLeastSquaresOptimizerAbstractTest { Propchange: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/optimization/general/AbstractLeastSquaresOptimizerAbstractTest.java -- svn:eol-style = native Propchange: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/optimization/general/AbstractLeastSquaresOptimizerAbstractTest.java -- svn:keywords = Author Date Id Revision Propchange: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/optimization/general/AbstractLeastSquaresOptimizerTest.java -- svn:eol-style = native Propchange: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/optimization/general/AbstractLeastSquaresOptimizerTest.java -- svn:keywords = Author Date Id Revision Propchange: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/optimization/general/StatisticalReferenceDataset.java -- svn:eol-style = native Propchange: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/optimization/general/StatisticalReferenceDataset.java -- svn:keywords = Author Date Id Revision Propchange: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/optimization/general/StatisticalReferenceDatasetFactory.java -- svn:eol-style = native Propchange: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/optimization/general/StatisticalReferenceDatasetFactory.java -- svn:keywords = Author Date Id Revision
svn commit: r1332924 - in /commons/proper/math/trunk/src/test: java/org/apache/commons/math3/optimization/general/ resources/org/apache/commons/math3/optimization/general/
Author: celestin Date: Wed May 2 05:50:59 2012 New Revision: 1332924 URL: http://svn.apache.org/viewvc?rev=1332924&view=rev Log: Standard unit test of least-squares optimizers based on NIST's Statistical Reference Datasets (StRD). Added: commons/proper/math/trunk/src/test/resources/org/apache/commons/math3/optimization/general/Lanczos1.dat Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/optimization/general/AbstractLeastSquaresOptimizerAbstractTest.java commons/proper/math/trunk/src/test/java/org/apache/commons/math3/optimization/general/GaussNewtonOptimizerTest.java commons/proper/math/trunk/src/test/java/org/apache/commons/math3/optimization/general/StatisticalReferenceDatasetFactory.java Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/optimization/general/AbstractLeastSquaresOptimizerAbstractTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/optimization/general/AbstractLeastSquaresOptimizerAbstractTest.java?rev=1332924&r1=1332923&r2=1332924&view=diff == --- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/optimization/general/AbstractLeastSquaresOptimizerAbstractTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/optimization/general/AbstractLeastSquaresOptimizerAbstractTest.java Wed May 2 05:50:59 2012 @@ -17,6 +17,7 @@ package org.apache.commons.math3.optimization.general; import java.awt.geom.Point2D; +import java.io.IOException; import java.io.Serializable; import java.util.Arrays; @@ -466,6 +467,43 @@ public abstract class AbstractLeastSquar {-0.048837, -0.077056}, {-0.127729, -0.075338}, {-0.221271, -0.067526} }; +public void doTestStRD(final StatisticalReferenceDataset dataset, +final double errParams, final double errParamsSd) { +final AbstractLeastSquaresOptimizer optimizer = createOptimizer(); +final double[] w = new double[dataset.getNumObservations()]; +Arrays.fill(w, 1.0); + +final double[][] data = dataset.getData(); +final double[] initial = dataset.getStartingPoint(0); +final DifferentiableMultivariateVectorFunction problem; +problem = dataset.getLeastSquaresProblem(); +final PointVectorValuePair optimum; +optimum = optimizer.optimize(100, problem, data[1], w, initial); + +final double[] actual = optimum.getPoint(); +final double[] actualSig = optimizer.guessParametersErrors(); +for (int i = 0; i < actual.length; i++) { +double expected = dataset.getParameter(i); +double delta = FastMath.abs(errParams * expected); +Assert.assertEquals(dataset.getName() + ", param #" + i, +expected, actual[i], delta); +expected = dataset.getParameterStandardDeviation(i); +delta = FastMath.abs(errParamsSd * expected); +Assert.assertEquals(dataset.getName() + ", sd of param #" + i, +expected, actualSig[i], delta); +} +} + +@Test +public void testKirby2() throws IOException { +doTestStRD(StatisticalReferenceDatasetFactory.createKirby2(), 1E-7, 1E-7); +} + +@Test +public void testHahn1() throws IOException { +doTestStRD(StatisticalReferenceDatasetFactory.createHahn1(), 1E-7, 1E-4); +} + static class LinearProblem implements DifferentiableMultivariateVectorFunction, Serializable { private static final long serialVersionUID = 703247177355019415L; Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/optimization/general/GaussNewtonOptimizerTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/optimization/general/GaussNewtonOptimizerTest.java?rev=1332924&r1=1332923&r2=1332924&view=diff == --- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/optimization/general/GaussNewtonOptimizerTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/optimization/general/GaussNewtonOptimizerTest.java Wed May 2 05:50:59 2012 @@ -17,6 +17,8 @@ package org.apache.commons.math3.optimization.general; +import java.io.IOException; + import org.apache.commons.math3.exception.ConvergenceException; import org.apache.commons.math3.exception.TooManyEvaluationsException; import org.apache.commons.math3.optimization.SimpleVectorValueChecker; @@ -131,8 +133,19 @@ public class GaussNewtonOptimizerTest @Test(expected=ConvergenceException.class) public void testCircleFittingBadInit() { /* - * This test does not converge with this optimizer +
svn commit: r1334315 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math3/optimization/general/ main/java/org/apache/commons/math3/special/ test/java/org/apache/commons/math3/optimi
Author: celestin Date: Sat May 5 05:10:22 2012 New Revision: 1334315 URL: http://svn.apache.org/viewvc?rev=1334315&view=rev Log: In o.a.c.m3.optimization.general.AbstractLeastSquaresOptimizer - deprecated guessParametersErrors() - created getSigma() which should be used instead (but is not strictly equivalent). Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/optimization/general/AbstractLeastSquaresOptimizer.java commons/proper/math/trunk/src/main/java/org/apache/commons/math3/special/Gamma.java commons/proper/math/trunk/src/test/java/org/apache/commons/math3/optimization/general/AbstractLeastSquaresOptimizerTest.java Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/optimization/general/AbstractLeastSquaresOptimizer.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/optimization/general/AbstractLeastSquaresOptimizer.java?rev=1334315&r1=1334314&r2=1334315&view=diff == --- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/optimization/general/AbstractLeastSquaresOptimizer.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/optimization/general/AbstractLeastSquaresOptimizer.java Sat May 5 05:10:22 2012 @@ -248,6 +248,9 @@ public abstract class AbstractLeastSquar * @throws NumberIsTooSmallException if the number of degrees of freedom is not * positive, i.e. the number of measurements is less or equal to the number of * parameters. + * @deprecated as of version 3.1, {@link #getSigma()} should be used + * instead. It should be emphasized that {@link #guessParametersErrors()} and + * {@link #getSigma()} are not strictly equivalent. */ public double[] guessParametersErrors() { if (rows <= cols) { @@ -263,6 +266,28 @@ public abstract class AbstractLeastSquar return errors; } +/** + * + * Returns an estimate of the standard deviation of the parameters. The + * returned values are the square root of the diagonal coefficients of the + * covariance matrix, {@code sd(a[i]) ~= sqrt(C[i][i])}, where {@code a[i]} + * is the optimized value of the {@code i}-th parameter, and {@code C} is + * the covariance matrix. + * + * + * @return an estimate of the standard deviation of the optimized parameters + * @throws org.apache.commons.math3.linear.SingularMatrixException + * if the covariance matrix cannot be computed. + */ +public double[] getSigma() { +double[] sig = new double[cols]; +double[][] cov = getCovariances(); +for (int i = 0; i < sig.length; ++i) { +sig[i] = FastMath.sqrt(cov[i][i]); +} +return sig; +} + /** {@inheritDoc} */ @Override public PointVectorValuePair optimize(int maxEval, Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/special/Gamma.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/special/Gamma.java?rev=1334315&r1=1334314&r2=1334315&view=diff == --- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/special/Gamma.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/special/Gamma.java Sat May 5 05:10:22 2012 @@ -325,4 +325,12 @@ public class Gamma { return trigamma(x + 1) + 1 / (x * x); } + +public static double lanczos(final double x){ +double sum = 0.0; +for (int i = LANCZOS.length - 1; i > 0; --i) { +sum = sum + (LANCZOS[i] / (x + i)); +} +return sum + LANCZOS[0]; +} } Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/optimization/general/AbstractLeastSquaresOptimizerTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/optimization/general/AbstractLeastSquaresOptimizerTest.java?rev=1334315&r1=1334314&r2=1334315&view=diff == --- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/optimization/general/AbstractLeastSquaresOptimizerTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/optimization/general/AbstractLeastSquaresOptimizerTest.java Sat May 5 05:10:22 2012 @@ -75,7 +75,7 @@ public class AbstractLeastSquaresOptimiz } @Test -public void testGuessParametersErrors() throws IOException { +public void testGetSigma() throws IOException { final StatisticalReferenceDataset dataset; dataset = StatisticalReferenceDatasetFactory.createKirby2(); final AbstractLeastSquaresOpti
svn propchange: r1334315 - svn:log
Author: celestin Revision: 1334315 Modified property: svn:log Modified: svn:log at Sat May 5 05:17:58 2012 -- --- svn:log (original) +++ svn:log Sat May 5 05:17:58 2012 @@ -1,3 +1,6 @@ In o.a.c.m3.optimization.general.AbstractLeastSquaresOptimizer - deprecated guessParametersErrors() - created getSigma() which should be used instead (but is not strictly equivalent). +Updated unit tests accordingly. + +See MATH-784.
svn commit: r1336056 - /commons/proper/math/trunk/src/main/java/org/apache/commons/math3/special/Gamma.java
Author: celestin Date: Wed May 9 10:27:04 2012 New Revision: 1336056 URL: http://svn.apache.org/viewvc?rev=1336056&view=rev Log: Reverted changes accidentally committed in r1334315. Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/special/Gamma.java Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/special/Gamma.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/special/Gamma.java?rev=1336056&r1=1336055&r2=1336056&view=diff == --- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/special/Gamma.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/special/Gamma.java Wed May 9 10:27:04 2012 @@ -325,12 +325,4 @@ public class Gamma { return trigamma(x + 1) + 1 / (x * x); } - -public static double lanczos(final double x){ -double sum = 0.0; -for (int i = LANCZOS.length - 1; i > 0; --i) { -sum = sum + (LANCZOS[i] / (x + i)); -} -return sum + LANCZOS[0]; -} }
svn commit: r1336483 - /commons/proper/math/trunk/src/main/java/org/apache/commons/math3/special/Gamma.java
Author: celestin Date: Thu May 10 05:08:01 2012 New Revision: 1336483 URL: http://svn.apache.org/viewvc?rev=1336483&view=rev Log: In o.a.c.m3.special.Gamma, exposed the Lanczos approximation (MATH-753). Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/special/Gamma.java Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/special/Gamma.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/special/Gamma.java?rev=1336483&r1=1336482&r2=1336483&view=diff == --- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/special/Gamma.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/special/Gamma.java Thu May 10 05:08:01 2012 @@ -32,6 +32,13 @@ public class Gamma { * @since 2.0 */ public static final double GAMMA = 0.577215664901532860606512090082; + +/** + * The value of the {@code g} constant in the Lanczos approximation, see + * {@link #lanczos(double)}. + */ +public static final double LANCZOS_G = 607.0 / 128.0; + /** Maximum allowed numerical error. */ private static final double DEFAULT_EPSILON = 10e-15; /** Lanczos coefficients */ @@ -89,13 +96,7 @@ public class Gamma { ret = Double.NaN; } else { double g = 607.0 / 128.0; - -double sum = 0.0; -for (int i = LANCZOS.length - 1; i > 0; --i) { -sum = sum + (LANCZOS[i] / (x + i)); -} -sum = sum + LANCZOS[0]; - +double sum = lanczos(x); double tmp = x + g + .5; ret = ((x + .5) * FastMath.log(tmp)) - tmp + HALF_LOG_2_PI + FastMath.log(sum / x); @@ -325,4 +326,31 @@ public class Gamma { return trigamma(x + 1) + 1 / (x * x); } + +/** + * + * Returns the Lanczos approximation used to compute the gamma function. + * The Lanczos approximation is related to the Gamma function by the + * following equation + * + * {@code gamma(x) = sqrt(2 * pi) / x * (x + g + 0.5) ^ (x + 0.5) + * * exp(-x - g - 0.5) * lanczos(x)}, + * + * where {@code g} is a constant, returned by {@link #getLanczosG()}. + * + * + * @param x the argument + * @return the Lanczos approximation + * @see http://mathworld.wolfram.com/LanczosApproximation.html";>Lanczos Approximation, + * equations (1) through (5), and Paul Godfrey's + * http://my.fit.edu/~gabdo/gamma.txt";>Note on the computation + * of the convergent Lanczos complex Gamma approximation + */ +public static double lanczos(final double x) { +double sum = 0.0; +for (int i = LANCZOS.length - 1; i > 0; --i) { +sum = sum + (LANCZOS[i] / (x + i)); +} +return sum + LANCZOS[0]; +} }
svn commit: r1338548 - /commons/proper/math/trunk/src/main/java/org/apache/commons/math3/distribution/GammaDistribution.java
Author: celestin Date: Tue May 15 06:21:53 2012 New Revision: 1338548 URL: http://svn.apache.org/viewvc?rev=1338548&view=rev Log: New implementation of the pdf of Gamma distributions. Solves MATH-753. Additional unit tests to come. Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/distribution/GammaDistribution.java Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/distribution/GammaDistribution.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/distribution/GammaDistribution.java?rev=1338548&r1=1338547&r2=1338548&view=diff == --- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/distribution/GammaDistribution.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/distribution/GammaDistribution.java Tue May 15 06:21:53 2012 @@ -34,12 +34,59 @@ public class GammaDistribution extends A * @since 2.1 */ public static final double DEFAULT_INVERSE_ABSOLUTE_ACCURACY = 1e-9; + /** Serializable version identifier. */ private static final long serialVersionUID = -3239549463135430361L; + /** The shape parameter. */ private final double alpha; + /** The scale parameter. */ private final double beta; + +/** + * The constant value of {@code alpha + g + 0.5}, where {@code alpha} is + * the shape parameter, and {@code g} is the Lanczos constant + * {@link Gamma#LANCZOS_G}. + */ +private final double shiftedShape; + +/** + * The constant value of + * {@code alpha / beta * sqrt(e / (2 * pi * (alpha + g + 0.5))) / L(alpha)}, + * where {@code alpha} is the shape parameter, {@code beta} is the scale + * parameter, and {@code L(alpha)} is the Lanczos approximation returned by + * {@link Gamma#lanczos(double)}. This prefactor is used in + * {@link #density(double)}, when no overflow occurs with the natural + * calculation. + */ +private final double densityPrefactor1; + +/** + * The constant value of + * {@code alpha * sqrt(e / (2 * pi * (alpha + g + 0.5))) / L(alpha)}, + * where {@code alpha} is the shape parameter, and {@code L(alpha)} is the + * Lanczos approximation returned by {@link Gamma#lanczos(double)}. This + * prefactor is used in {@link #density(double)}, when overflow occurs with + * the natural calculation. + */ +private final double densityPrefactor2; + +/** + * Lower bound on {@code y = x / beta} for the selection of the computation + * method in {@link #density(double)}. For {@code y <= minY}, the natural + * calculation overflows. {@code beta} is the shape parameter. + */ +private final double minY; + +/** + * Upper bound on {@code log(y)} ({@code y = x / beta}) for the selection of + * the computation method in {@link #density(double)}. For + * {@code log(y) >= maxLogY}, the natural calculation overflows. + * {@code beta} is the shape parameter. + */ +private final double maxLogY; + /** Inverse cumulative probability accuracy. */ private final double solverAbsoluteAccuracy; @@ -77,7 +124,15 @@ public class GammaDistribution extends A this.alpha = alpha; this.beta = beta; -solverAbsoluteAccuracy = inverseCumAccuracy; +this.solverAbsoluteAccuracy = inverseCumAccuracy; +this.shiftedShape = alpha + Gamma.LANCZOS_G + 0.5; +final double aux = FastMath.E / (2.0 * FastMath.PI * shiftedShape); +this.densityPrefactor2 = alpha * FastMath.sqrt(aux) / Gamma.lanczos(alpha); +this.densityPrefactor1 = this.densityPrefactor2 / beta * +FastMath.pow(shiftedShape, -alpha) * +FastMath.exp(alpha + Gamma.LANCZOS_G); +this.minY = alpha + Gamma.LANCZOS_G - FastMath.log(Double.MAX_VALUE); +this.maxLogY = FastMath.log(Double.MAX_VALUE) / (alpha - 1.0); } /** @@ -111,11 +166,63 @@ public class GammaDistribution extends A /** {@inheritDoc} */ public double density(double x) { + /* The present method must return the value of +* +* 1 x a - x +* -- (-) exp(---) +* x Gamma(a) bb +* +* where a is the shape parameter, and b the scale parameter. +* Substituting the Lanczos approximation of Gamma(a) leads to the +* following expression of the density +* +* a e1 y a +* - sqrt(--) (---) exp(a - y + g), +* x 2 pi (a + g + 0.5) L(a) a + g + 0.5 +* +* where y = x / b. The above formula is the "natural" computation, which +* is implemented when no overflow is likely to occur. If overflow occurs +* w
svn commit: r1338986 [5/7] - /commons/proper/math/trunk/src/test/resources/org/apache/commons/math3/distribution/
Propchange: commons/proper/math/trunk/src/test/resources/org/apache/commons/math3/distribution/gamma-distribution-shape-1000.csv -- svn:eol-style = native Propchange: commons/proper/math/trunk/src/test/resources/org/apache/commons/math3/distribution/gamma-distribution-shape-1000.csv -- svn:keywords = Author Date Id Revision
svn commit: r1338986 [1/7] - /commons/proper/math/trunk/src/test/resources/org/apache/commons/math3/distribution/
Author: celestin Date: Wed May 16 03:31:10 2012 New Revision: 1338986 URL: http://svn.apache.org/viewvc?rev=1338986&view=rev Log: Gamma distribution: reference data for unit tests (see MATH-753). Added: commons/proper/math/trunk/src/test/resources/org/apache/commons/math3/distribution/ commons/proper/math/trunk/src/test/resources/org/apache/commons/math3/distribution/gamma-distribution-shape-1.csv (with props) commons/proper/math/trunk/src/test/resources/org/apache/commons/math3/distribution/gamma-distribution-shape-10.csv (with props) commons/proper/math/trunk/src/test/resources/org/apache/commons/math3/distribution/gamma-distribution-shape-100.csv (with props) commons/proper/math/trunk/src/test/resources/org/apache/commons/math3/distribution/gamma-distribution-shape-1000.csv (with props) commons/proper/math/trunk/src/test/resources/org/apache/commons/math3/distribution/gamma-distribution-shape-142.csv (with props) commons/proper/math/trunk/src/test/resources/org/apache/commons/math3/distribution/gamma-distribution.mac (with props)
svn commit: r1338986 [7/7] - /commons/proper/math/trunk/src/test/resources/org/apache/commons/math3/distribution/
Propchange: commons/proper/math/trunk/src/test/resources/org/apache/commons/math3/distribution/gamma-distribution-shape-142.csv -- svn:eol-style = native Propchange: commons/proper/math/trunk/src/test/resources/org/apache/commons/math3/distribution/gamma-distribution-shape-142.csv -- svn:keywords = Author Date Id Revision Added: commons/proper/math/trunk/src/test/resources/org/apache/commons/math3/distribution/gamma-distribution.mac URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/resources/org/apache/commons/math3/distribution/gamma-distribution.mac?rev=1338986&view=auto == --- commons/proper/math/trunk/src/test/resources/org/apache/commons/math3/distribution/gamma-distribution.mac (added) +++ commons/proper/math/trunk/src/test/resources/org/apache/commons/math3/distribution/gamma-distribution.mac Wed May 16 03:31:10 2012 @@ -0,0 +1,67 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * This Maxima script allows the creation of reference data for the Gamma + * distribution. + */ + +/* + * Set floating-point accuracy to four times the double precision. + */ +fpprec : 64; + +/* + * Probability density function for Gamma distribution with shape parameter a + * and scale parameter b. + */ +p(x, a, b) := (x / b)**a * exp(-x / b) / x / gamma(a); + +/* + * Make sure x is a list of exactly representable doubles: use only power-of-two + * fractions of unity. + */ +out : openw("gamma-distribution-shape-1.csv"); +x : float(makelist(i / 32, i, 1, 3200)); +y : p(bfloat(x), 1, 1); +printf(out, "~{~h, ~h~%~}", join(x, y)); +close(out); + +out : openw("gamma-distribution-shape-10.csv"); +x : float(makelist(i / 4, i, 1, 400)); +y : p(bfloat(x), 10, 1); +printf(out, "~{~h, ~h~%~}", join(x, y)); +close(out); + +out : openw("gamma-distribution-shape-100.csv"); +x : float(append(makelist(i / 32, i, 1, 32 * 3), makelist(i + 3, i, 1, 297))); +y : p(bfloat(x), 100, 1); +printf(out, "~{~h, ~h~%~}", join(x, y)); +close(out); + +out : openw("gamma-distribution-shape-142.csv"); +x : float(append(makelist(i / 32, i, 1, 32 * 10), makelist(i + 10, i, 1, 440))); +y : p(bfloat(x), 142, 1); +printf(out, "~{~h, ~h~%~}", join(x, y)); +close(out); + +out : openw("gamma-distribution-shape-1000.csv"); +x : float(append(makelist(i / 32, i, 1, 32 * 10), makelist(i + 10, i, 1, 2990))); +y : p(bfloat(x), 1000, 1); +printf(out, "~{~h, ~h~%~}", join(x, y)); +close(out); + Propchange: commons/proper/math/trunk/src/test/resources/org/apache/commons/math3/distribution/gamma-distribution.mac -- svn:eol-style = native Propchange: commons/proper/math/trunk/src/test/resources/org/apache/commons/math3/distribution/gamma-distribution.mac -- svn:keywords = Author Date Id Revision
svn commit: r1338989 - /commons/proper/math/trunk/src/test/java/org/apache/commons/math3/optimization/general/StraightLineProblem.java
Author: celestin Date: Wed May 16 03:34:32 2012 New Revision: 1338989 URL: http://svn.apache.org/viewvc?rev=1338989&view=rev Log: Removed illegal @Override. Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/optimization/general/StraightLineProblem.java Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/optimization/general/StraightLineProblem.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/optimization/general/StraightLineProblem.java?rev=1338989&r1=1338988&r2=1338989&view=diff == --- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/optimization/general/StraightLineProblem.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/optimization/general/StraightLineProblem.java Wed May 16 03:34:32 2012 @@ -135,7 +135,7 @@ class StraightLineProblem implements Dif for (int i = 0; i < points.size(); i++) { final double[] p = points.get(i); -// Partial derivative wrt "a". +// Partial derivative wrt "a". jacobian[i][0] = p[0]; // Partial derivative wrt "b". jacobian[i][1] = 1; @@ -157,7 +157,6 @@ class StraightLineProblem implements Dif this.b = b; } -@Override public double value(double x) { return a * x + b; }
svn commit: r1339014 - /commons/proper/math/trunk/src/test/java/org/apache/commons/math3/distribution/GammaDistributionTest.java
Author: celestin Date: Wed May 16 05:36:40 2012 New Revision: 1339014 URL: http://svn.apache.org/viewvc?rev=1339014&view=rev Log: Unit tests for GammaDistribution, based on reference data generated with Maxima. Solves MATH-753. Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/distribution/GammaDistributionTest.java Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/distribution/GammaDistributionTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/distribution/GammaDistributionTest.java?rev=1339014&r1=1339013&r2=1339014&view=diff == --- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/distribution/GammaDistributionTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/distribution/GammaDistributionTest.java Wed May 16 05:36:40 2012 @@ -17,7 +17,15 @@ package org.apache.commons.math3.distribution; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; + import org.apache.commons.math3.exception.NotStrictlyPositiveException; +import org.apache.commons.math3.special.Gamma; +import org.apache.commons.math3.stat.descriptive.SummaryStatistics; +import org.apache.commons.math3.util.FastMath; import org.junit.Assert; import org.junit.Test; @@ -167,4 +175,155 @@ public class GammaDistributionTest exten Assert.assertEquals(dist.getNumericalMean(), 1.1d * 4.2d, tol); Assert.assertEquals(dist.getNumericalVariance(), 1.1d * 4.2d * 4.2d, tol); } + +public static double density(final double x, final double shape, + final double scale) { +/* + * This is a copy of + * double GammaDistribution.density(double) + * prior to r1338548. + */ +if (x < 0) { +return 0; +} +return FastMath.pow(x / scale, shape - 1) / scale * + FastMath.exp(-x / scale) / FastMath.exp(Gamma.logGamma(shape)); +} + +/* + * MATH-753: large values of x or shape parameter cause density(double) to + * overflow. Reference data is generated with the Maxima script + * gamma-distribution.mac, which can be found in + * src/test/resources/org/apache/commons/math3/distribution. + */ + +private void doTestMath753(final double shape, +final double meanNoOF, final double sdNoOF, +final double meanOF, final double sdOF, +final String resourceName) throws IOException { +final GammaDistribution distribution = new GammaDistribution(shape, 1.0); +final SummaryStatistics statOld = new SummaryStatistics(); +final SummaryStatistics statNewNoOF = new SummaryStatistics(); +final SummaryStatistics statNewOF = new SummaryStatistics(); + +final InputStream resourceAsStream; +resourceAsStream = this.getClass().getResourceAsStream(resourceName); +Assert.assertNotNull("Could not find resource " + resourceName, + resourceAsStream); +final BufferedReader in; +in = new BufferedReader(new InputStreamReader(resourceAsStream)); + +try { +for (String line = in.readLine(); line != null; line = in +.readLine()) { +final String[] tokens = line.split(", "); +Assert.assertTrue("expected two floating-point values", + tokens.length == 2); +final double x = Double.parseDouble(tokens[0]); +final String msg = "x = " + x + ", shape = " + shape + + ", scale = 1.0"; +final double expected = Double.parseDouble(tokens[1]); +final double ulp = FastMath.ulp(expected); +final double actualOld = density(x, shape, 1.0); +final double actualNew = distribution.density(x); +final double errOld, errNew; +errOld = FastMath.abs((actualOld - expected) / ulp); +errNew = FastMath.abs((actualNew - expected) / ulp); + +if (Double.isNaN(actualOld) || Double.isInfinite(actualOld)) { +Assert.assertFalse(msg, Double.isNaN(actualNew)); +Assert.assertFalse(msg, Double.isInfinite(actualNew)); +statNewOF.addValue(errNew); +} else { +statOld.addValue(errOld); +statNewNoOF.addValue(errNew); +} +} +if (statOld.getN() != 0) { +/* + * If no overflow occurs, check that new implementation is + * better than old one. +
svn commit: r1341318 - /commons/proper/math/trunk/src/main/java/org/apache/commons/math3/distribution/GammaDistribution.java
Author: celestin Date: Tue May 22 06:34:37 2012 New Revision: 1341318 URL: http://svn.apache.org/viewvc?rev=1341318&view=rev Log: In o.a.c.m3.distribution.GammaDistribution, - renamed class variable alpha to shape, - renamed class variable beta to scale. Updated javadoc accordingly. See MATH-791. Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/distribution/GammaDistribution.java Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/distribution/GammaDistribution.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/distribution/GammaDistribution.java?rev=1341318&r1=1341317&r2=1341318&view=diff == --- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/distribution/GammaDistribution.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/distribution/GammaDistribution.java Tue May 22 06:34:37 2012 @@ -36,26 +36,24 @@ public class GammaDistribution extends A public static final double DEFAULT_INVERSE_ABSOLUTE_ACCURACY = 1e-9; /** Serializable version identifier. */ -private static final long serialVersionUID = -3239549463135430361L; +private static final long serialVersionUID = 20120522L; /** The shape parameter. */ -private final double alpha; +private final double shape; /** The scale parameter. */ -private final double beta; +private final double scale; /** - * The constant value of {@code alpha + g + 0.5}, where {@code alpha} is - * the shape parameter, and {@code g} is the Lanczos constant - * {@link Gamma#LANCZOS_G}. + * The constant value of {@code shape + g + 0.5}, where {@code g} is the + * Lanczos constant {@link Gamma#LANCZOS_G}. */ private final double shiftedShape; /** * The constant value of - * {@code alpha / beta * sqrt(e / (2 * pi * (alpha + g + 0.5))) / L(alpha)}, - * where {@code alpha} is the shape parameter, {@code beta} is the scale - * parameter, and {@code L(alpha)} is the Lanczos approximation returned by + * {@code shape / scale * sqrt(e / (2 * pi * (shape + g + 0.5))) / L(shape)}, + * where {@code L(shape)} is the Lanczos approximation returned by * {@link Gamma#lanczos(double)}. This prefactor is used in * {@link #density(double)}, when no overflow occurs with the natural * calculation. @@ -64,26 +62,25 @@ public class GammaDistribution extends A /** * The constant value of - * {@code alpha * sqrt(e / (2 * pi * (alpha + g + 0.5))) / L(alpha)}, - * where {@code alpha} is the shape parameter, and {@code L(alpha)} is the - * Lanczos approximation returned by {@link Gamma#lanczos(double)}. This - * prefactor is used in {@link #density(double)}, when overflow occurs with - * the natural calculation. + * {@code shape * sqrt(e / (2 * pi * (shape + g + 0.5))) / L(shape)}, + * where {@code L(shape)} is the Lanczos approximation returned by + * {@link Gamma#lanczos(double)}. This prefactor is used in + * {@link #density(double)}, when overflow occurs with the natural + * calculation. */ private final double densityPrefactor2; /** - * Lower bound on {@code y = x / beta} for the selection of the computation + * Lower bound on {@code y = x / scale} for the selection of the computation * method in {@link #density(double)}. For {@code y <= minY}, the natural - * calculation overflows. {@code beta} is the shape parameter. + * calculation overflows. */ private final double minY; /** - * Upper bound on {@code log(y)} ({@code y = x / beta}) for the selection of - * the computation method in {@link #density(double)}. For + * Upper bound on {@code log(y)} ({@code y = x / scale}) for the selection + * of the computation method in {@link #density(double)}. For * {@code log(y) >= maxLogY}, the natural calculation overflows. - * {@code beta} is the shape parameter. */ private final double maxLogY; @@ -91,66 +88,67 @@ public class GammaDistribution extends A private final double solverAbsoluteAccuracy; /** - * Create a new gamma distribution with the given {@code alpha} and - * {@code beta} values. - * @param alpha the shape parameter. - * @param beta the scale parameter. + * Creates a new gamma distribution with specified values of the shape and + * scale parameters. + * + * @param shape the shape parameter + * @param scale the scale parameter */ -public GammaDistribution(double alpha, double beta) { -this(alpha, beta, DEFAULT_INVERSE_ABSOLUTE_ACCURACY); +public GammaDistribution(double shape, double scale) { +this(shape, scale, DEFAULT_INVERSE_ABSOLUTE_ACCURACY); } /** -
svn commit: r1342404 - /commons/proper/math/trunk/src/main/java/org/apache/commons/math3/distribution/GammaDistribution.java
Author: celestin Date: Thu May 24 19:23:37 2012 New Revision: 1342404 URL: http://svn.apache.org/viewvc?rev=1342404&view=rev Log: In o.a.c.m3.distribution.GammaDistribution - deprecated getAlpha() and created getShape() - deprecated getBeta() and created getScale(). See MATH-791. Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/distribution/GammaDistribution.java Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/distribution/GammaDistribution.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/distribution/GammaDistribution.java?rev=1342404&r1=1342403&r2=1342404&view=diff == --- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/distribution/GammaDistribution.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/distribution/GammaDistribution.java Thu May 24 19:23:37 2012 @@ -36,7 +36,7 @@ public class GammaDistribution extends A public static final double DEFAULT_INVERSE_ABSOLUTE_ACCURACY = 1e-9; /** Serializable version identifier. */ -private static final long serialVersionUID = 20120522L; +private static final long serialVersionUID = 20120524L; /** The shape parameter. */ private final double shape; @@ -104,7 +104,7 @@ public class GammaDistribution extends A * * @param shape the shape parameter * @param scale the scale parameter - * @param inverseCumAccuracy the aximum absolute error in inverse + * @param inverseCumAccuracy the maximum absolute error in inverse * cumulative probability estimates (defaults to * {@link #DEFAULT_INVERSE_ABSOLUTE_ACCURACY}). * @throws NotStrictlyPositiveException if {@code shape <= 0} or @@ -114,10 +114,10 @@ public class GammaDistribution extends A public GammaDistribution(double shape, double scale, double inverseCumAccuracy) throws NotStrictlyPositiveException { if (shape <= 0) { -throw new NotStrictlyPositiveException(LocalizedFormats.ALPHA, shape); +throw new NotStrictlyPositiveException(LocalizedFormats.SHAPE, shape); } if (scale <= 0) { -throw new NotStrictlyPositiveException(LocalizedFormats.BETA, scale); +throw new NotStrictlyPositiveException(LocalizedFormats.SCALE, scale); } this.shape = shape; @@ -137,21 +137,43 @@ public class GammaDistribution extends A * Returns the shape parameter of {@code this} distribution. * * @return the shape parameter + * @deprecated as of version 3.1, {@link #getShape()} should be preferred. + * This method will be removed in version 4.0. */ public double getAlpha() { return shape; } /** + * Returns the shape parameter of {@code this} distribution. + * + * @return the shape parameter + */ +public double getShape() { +return shape; +} + +/** * Returns the scale parameter of {@code this} distribution. * * @return the scale parameter + * @deprecated as of version 3.1, {@link #getScale()} should be preferred. + * This method will be removed in version 4.0. */ public double getBeta() { return scale; } /** + * Returns the scale parameter of {@code this} distribution. + * + * @return the scale parameter + */ +public double getScale() { +return scale; +} + +/** * {@inheritDoc} * * For this distribution {@code P(X = x)} always evaluates to 0. @@ -262,7 +284,7 @@ public class GammaDistribution extends A * mean is {@code alpha * beta}. */ public double getNumericalMean() { -return getAlpha() * getBeta(); +return shape * scale; } /** @@ -274,8 +296,7 @@ public class GammaDistribution extends A * @return {@inheritDoc} */ public double getNumericalVariance() { -final double b = getBeta(); -return getAlpha() * b * b; +return shape * scale * scale; } /**
svn commit: r1343157 - /commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/RealVectorPreservingVisitor.java
Author: celestin Date: Mon May 28 07:54:16 2012 New Revision: 1343157 URL: http://svn.apache.org/viewvc?rev=1343157&view=rev Log: MATH-792: created a visitor for vectors. Entries of the vector being visited are not modified. Added: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/RealVectorPreservingVisitor.java (with props) Added: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/RealVectorPreservingVisitor.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/RealVectorPreservingVisitor.java?rev=1343157&view=auto == --- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/RealVectorPreservingVisitor.java (added) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/RealVectorPreservingVisitor.java Mon May 28 07:54:16 2012 @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.math3.linear; + +/** + * This interface defines a visitor for the entries of a vector. Visitors + * implementing this interface do not alter the entries of the vector being + * visited. + * + * @version $Id$ + * @since 3.1 + */ +public interface RealVectorPreservingVisitor { +/** + * Start visiting a vector. This method is called once, before any entry + * of the vector is visited. + * + * @param dimension the size of the vector + * @param start the index of the first entry to be visited + * @param end the index of the last entry to be visited (inclusive) + */ +void start(int dimension, int start, int end); + +/** + * Visit one entry of the vector. + * + * @param index the index of the entry being visited + * @param value the value of the entry being visited + */ +void visit(int index, double value); + +/** + * End visiting a vector. This method is called once, after all entries of + * the vector have been visited. + * + * @return the value that the {@code walkInXxxOrder} must return + */ +// TODO Check above javadoc comment (add proper link to methods in +// RealVector class) +double end(); +} Propchange: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/RealVectorPreservingVisitor.java -- svn:eol-style = native Propchange: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/RealVectorPreservingVisitor.java -- svn:keywords = Author Date Id Revision
svn commit: r1343163 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math3/linear/ test/java/org/apache/commons/math3/linear/
Author: celestin Date: Mon May 28 08:31:13 2012 New Revision: 1343163 URL: http://svn.apache.org/viewvc?rev=1343163&view=rev Log: MATH-792: - various methods to visit the entries of a RealVector (entries are unmodified), - default implementation in RealVector abstract class, - unit tests in abstract RealVectorAbstractClass, - all XxxRealVectorTest classes now extend RealVectorAbstractClass. Added: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java (with props) Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/RealVector.java commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/RealVectorPreservingVisitor.java commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/ArrayRealVectorTest.java commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorTest.java commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/SparseRealVectorTest.java Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/RealVector.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/RealVector.java?rev=1343163&r1=1343162&r2=1343163&view=diff == --- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/RealVector.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/RealVector.java Mon May 28 08:31:13 2012 @@ -22,6 +22,7 @@ import java.util.NoSuchElementException; import org.apache.commons.math3.exception.MathUnsupportedOperationException; import org.apache.commons.math3.exception.DimensionMismatchException; +import org.apache.commons.math3.exception.NumberIsTooSmallException; import org.apache.commons.math3.exception.OutOfRangeException; import org.apache.commons.math3.exception.MathArithmeticException; import org.apache.commons.math3.analysis.FunctionUtils; @@ -191,6 +192,37 @@ public abstract class RealVector { } /** + * Checks that the indices of a subvector are valid. + * + * @param start the index of the first entry of the subvector + * @param end the index of the last entry of the subvector (inclusive) + * @throws OutOfRangeException if {@code start} of {@code end} are not valid + * @throws NumberIsTooSmallException if {@code end < start} + */ +protected void checkIndices(final int start, final int end) { +final int dim = getDimension(); +if ((start < 0) || (start >= dim)) { +throw new OutOfRangeException(LocalizedFormats.INDEX, + Integer.valueOf(start), + Integer.valueOf(0), + Integer.valueOf(dim - 1)); +} +if ((end < 0) || (end >= dim)) { +throw new OutOfRangeException(LocalizedFormats.INDEX, + Integer.valueOf(end), + Integer.valueOf(0), + Integer.valueOf(dim - 1)); +} +if (end < start){ +// TODO Use more specific error message +throw new NumberIsTooSmallException(LocalizedFormats.INITIAL_ROW_AFTER_FINAL_ROW, +Integer.valueOf(end), +Integer.valueOf(start), +false); +} +} + +/** * Compute the sum of this vector and {@code v}. * Returns a new vector. Does not change instance data. * @@ -807,9 +839,82 @@ public abstract class RealVector { return this; } + /** - * An entry in the vector. + * Visits (but does not change) all entries of this vector in default order + * (increasing index). + * + * @param visitor the visitor to be used to process the entries of this + * vector + * @return the value returned by {@link RealVectorPreservingVisitor#end()} + * at the end of the walk */ +public double walkInDefaultOrder(final RealVectorPreservingVisitor visitor) { +final int dim = getDimension(); +visitor.start(dim, 0, dim - 1); +for (int i = 0; i < dim; i++) { +visitor.visit(i, getEntry(i)); +} +return visitor.end(); +} + +/** + * Visits (and possibly change) some entries of this vector in default order + * (increasing index). + * + * @param visitor visitor to be used to process the entries of this vector + * @param start the index of the first entry to be visited + * @param end the index of the last entry to be visited (inclusive) + * @return the value returned by {
svn commit: r1343217 - /commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/UnmodifiableRealVectorAbstractTest.java
Author: celestin Date: Mon May 28 12:09:41 2012 New Revision: 1343217 URL: http://svn.apache.org/viewvc?rev=1343217&view=rev Log: MATH-792: walkInXyzOrder methods are excluded from automatic testing (based on reflexion). Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/UnmodifiableRealVectorAbstractTest.java Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/UnmodifiableRealVectorAbstractTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/UnmodifiableRealVectorAbstractTest.java?rev=1343217&r1=1343216&r2=1343217&view=diff == --- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/UnmodifiableRealVectorAbstractTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/UnmodifiableRealVectorAbstractTest.java Mon May 28 12:09:41 2012 @@ -62,6 +62,8 @@ public abstract class UnmodifiableRealVe EXCLUDE.add("setSubVector"); EXCLUDE.add("iterator"); EXCLUDE.add("sparseIterator"); +EXCLUDE.add("walkInDefaultOrder"); +EXCLUDE.add("walkInOptimizedOrder"); // Excluded because they are inherited from "Object". for (Method m : Object.class.getMethods()) {
svn commit: r1343219 - /commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java
Author: celestin Date: Mon May 28 12:17:38 2012 New Revision: 1343219 URL: http://svn.apache.org/viewvc?rev=1343219&view=rev Log: Copy/paste typo (MATH-792). Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java?rev=1343219&r1=1343218&r2=1343219&view=diff == --- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java Mon May 28 12:17:38 2012 @@ -226,6 +226,6 @@ public abstract class RealVectorAbstract return 0; } }; -v.walkInDefaultOrder(visitor, expectedStart, expectedEnd); +v.walkInOptimizedOrder(visitor, expectedStart, expectedEnd); } }
svn commit: r1343293 - /commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/RealVector.java
Author: celestin Date: Mon May 28 15:39:57 2012 New Revision: 1343293 URL: http://svn.apache.org/viewvc?rev=1343293&view=rev Log: Removed explicit conversion from int to Integer. Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/RealVector.java Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/RealVector.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/RealVector.java?rev=1343293&r1=1343292&r2=1343293&view=diff == --- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/RealVector.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/RealVector.java Mon May 28 15:39:57 2012 @@ -202,23 +202,17 @@ public abstract class RealVector { protected void checkIndices(final int start, final int end) { final int dim = getDimension(); if ((start < 0) || (start >= dim)) { -throw new OutOfRangeException(LocalizedFormats.INDEX, - Integer.valueOf(start), - Integer.valueOf(0), - Integer.valueOf(dim - 1)); +throw new OutOfRangeException(LocalizedFormats.INDEX, start, 0, + dim - 1); } if ((end < 0) || (end >= dim)) { -throw new OutOfRangeException(LocalizedFormats.INDEX, - Integer.valueOf(end), - Integer.valueOf(0), - Integer.valueOf(dim - 1)); +throw new OutOfRangeException(LocalizedFormats.INDEX, end, 0, + dim - 1); } -if (end < start){ +if (end < start) { // TODO Use more specific error message throw new NumberIsTooSmallException(LocalizedFormats.INITIAL_ROW_AFTER_FINAL_ROW, -Integer.valueOf(end), -Integer.valueOf(start), -false); +end, start, false); } }
svn commit: r1343339 - /commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/RealVectorPreservingVisitor.java
Author: celestin Date: Mon May 28 17:53:37 2012 New Revision: 1343339 URL: http://svn.apache.org/viewvc?rev=1343339&view=rev Log: Javadoc typo. Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/RealVectorPreservingVisitor.java Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/RealVectorPreservingVisitor.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/RealVectorPreservingVisitor.java?rev=1343339&r1=1343338&r2=1343339&view=diff == --- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/RealVectorPreservingVisitor.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/RealVectorPreservingVisitor.java Mon May 28 17:53:37 2012 @@ -52,7 +52,7 @@ public interface RealVectorPreservingVis * {@link RealVector#walkInDefaultOrder(RealVectorPreservingVisitor, int, int)}, * {@link RealVector#walkInOptimizedOrder(RealVectorPreservingVisitor)} * or - * {@link RealVector#walkInOptimizedOrder(RealVectorPreservingVisitor, int, int) + * {@link RealVector#walkInOptimizedOrder(RealVectorPreservingVisitor, int, int)} */ double end(); }
svn commit: r1343342 - in /commons/proper/math/trunk: ./ src/main/java/org/apache/commons/math3/linear/ src/test/java/org/apache/commons/math3/linear/
Author: celestin Date: Mon May 28 18:03:44 2012 New Revision: 1343342 URL: http://svn.apache.org/viewvc?rev=1343342&view=rev Log: MATH-792: - definition of RealVectorChangingVisitor, - various methods to visit the entries of a RealVector (entries are possibly modified), - default implementation in RealVector abstract class, - unit tests in abstract RealVectorAbstractClass. Added: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/RealVectorChangingVisitor.java (with props) Modified: commons/proper/math/trunk/checkstyle.xml commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/ArrayRealVector.java commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/RealVector.java commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java Modified: commons/proper/math/trunk/checkstyle.xml URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/checkstyle.xml?rev=1343342&r1=1343341&r2=1343342&view=diff == --- commons/proper/math/trunk/checkstyle.xml (original) +++ commons/proper/math/trunk/checkstyle.xml Mon May 28 18:03:44 2012 @@ -1,196 +1,118 @@ - + +http://www.puppycrawl.com/dtds/configuration_1_3.dtd";> - -http://www.puppycrawl.com/dtds/configuration_1_1.dtd";> - - +This configuration file was written by the eclipse-cs plugin configuration editor +--> + + - - - - + - - - - - - - + - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + - - + + - - - + - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + - - - + - - - - - - - - - - - - + + - - + + - - + + - - + + - - + + - - + + - - + + - Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/ArrayRealVector.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/ArrayRealVector.java?rev=1343342&r1=1343341&r2=1343342&view=diff == --- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/ArrayRealVector.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/ArrayRealVector.java Mon May 28 18:03:44 2012 @@ -881,4 +881,26 @@ public class ArrayRealVector extends Rea } return this; } + +/** {@inheritDoc} */ +@Override +public double walkInDefaultOrder(final RealVectorPreservingVisitor visitor) { +visitor.start(data.length, 0, data.length - 1); +for (int i = 0; i < data.length; i++) { +visitor.visit(i, data[i]); +} +return visitor.end(); +} + +/** {@inheritDoc} */ +@Override +public double walkInDefaultOrder(final RealVectorPreservingVisitor visitor, + final int start, final int end) { +checkIndices(start, end); +visitor.start(data.length, start, end); +for (int i = start; i <= end; i++) { +visitor.visit(i, data[i]); +} +return visitor.end(); +} } Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/RealVector.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/RealVector.java?rev=1343342&r1=1343341&r2=1343342&view=diff == --- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/RealVector.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/RealVector.java Mon May 28 18:03:44 2012 @@ -835,7 +835,7 @@ public abstract class RealVector { /** - * Visits (but does not change) all entries of this vector in default order + * Visits (but does not alter) all entries of this vector in default order * (increasing index). * * @pa
svn commit: r1343345 - /commons/proper/math/trunk/checkstyle.xml
Author: celestin Date: Mon May 28 18:17:44 2012 New Revision: 1343345 URL: http://svn.apache.org/viewvc?rev=1343345&view=rev Log: Reverted changes mistakenly committed in r1343342. Modified: commons/proper/math/trunk/checkstyle.xml Modified: commons/proper/math/trunk/checkstyle.xml URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/checkstyle.xml?rev=1343345&r1=1343344&r2=1343345&view=diff == --- commons/proper/math/trunk/checkstyle.xml (original) +++ commons/proper/math/trunk/checkstyle.xml Mon May 28 18:17:44 2012 @@ -1,118 +1,196 @@ - -http://www.puppycrawl.com/dtds/configuration_1_3.dtd";> + - + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + --> + +http://www.puppycrawl.com/dtds/configuration_1_1.dtd";> + + - + + - + + + + + + + + - + + + + + + + - + + + + + - - - - - - - + + + + + + + + + + + + + + + + + + + + - - + + + + - + + + + + + - + - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + +
svn commit: r1343346 - /commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/ArrayRealVector.java
Author: celestin Date: Mon May 28 18:21:39 2012 New Revision: 1343346 URL: http://svn.apache.org/viewvc?rev=1343346&view=rev Log: Reverted changes mistakenly committed in r1343342. Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/ArrayRealVector.java Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/ArrayRealVector.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/ArrayRealVector.java?rev=1343346&r1=1343345&r2=1343346&view=diff == --- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/ArrayRealVector.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/ArrayRealVector.java Mon May 28 18:21:39 2012 @@ -881,26 +881,4 @@ public class ArrayRealVector extends Rea } return this; } - -/** {@inheritDoc} */ -@Override -public double walkInDefaultOrder(final RealVectorPreservingVisitor visitor) { -visitor.start(data.length, 0, data.length - 1); -for (int i = 0; i < data.length; i++) { -visitor.visit(i, data[i]); -} -return visitor.end(); -} - -/** {@inheritDoc} */ -@Override -public double walkInDefaultOrder(final RealVectorPreservingVisitor visitor, - final int start, final int end) { -checkIndices(start, end); -visitor.start(data.length, start, end); -for (int i = start; i <= end; i++) { -visitor.visit(i, data[i]); -} -return visitor.end(); -} }
svn commit: r1343546 - /commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/RealVector.java
Author: celestin Date: Tue May 29 05:34:41 2012 New Revision: 1343546 URL: http://svn.apache.org/viewvc?rev=1343546&view=rev Log: Added 'final' keyword. Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/RealVector.java Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/RealVector.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/RealVector.java?rev=1343546&r1=1343545&r2=1343546&view=diff == --- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/RealVector.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/RealVector.java Tue May 29 05:34:41 2012 @@ -865,7 +865,7 @@ public abstract class RealVector { * the indices are not valid. */ public double walkInDefaultOrder(final RealVectorPreservingVisitor visitor, - int start, int end) { + final int start, final int end) { checkIndices(start, end); visitor.start(getDimension(), start, end); for (int i = start; i <= end; i++) { @@ -904,7 +904,7 @@ public abstract class RealVector { * the indices are not valid. */ public double walkInOptimizedOrder(final RealVectorPreservingVisitor visitor, - int start, int end) { + final int start, final int end) { return walkInDefaultOrder(visitor, start, end); } @@ -939,7 +939,7 @@ public abstract class RealVector { * the indices are not valid. */ public double walkInDefaultOrder(final RealVectorChangingVisitor visitor, - int start, int end) { + final int start, final int end) { checkIndices(start, end); visitor.start(getDimension(), start, end); for (int i = start; i <= end; i++) { @@ -978,7 +978,7 @@ public abstract class RealVector { * the indices are not valid. */ public double walkInOptimizedOrder(final RealVectorChangingVisitor visitor, - int start, int end) { + final int start, final int end) { return walkInDefaultOrder(visitor, start, end); }
svn commit: r1343547 - /commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/ArrayRealVector.java
Author: celestin Date: Tue May 29 05:36:19 2012 New Revision: 1343547 URL: http://svn.apache.org/viewvc?rev=1343547&view=rev Log: MATH-792: implementation of the visitor pattern for ArrayRealVector (overrides default implementation in RealVector). Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/ArrayRealVector.java Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/ArrayRealVector.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/ArrayRealVector.java?rev=1343547&r1=1343546&r2=1343547&view=diff == --- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/ArrayRealVector.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/ArrayRealVector.java Tue May 29 05:36:19 2012 @@ -881,4 +881,90 @@ public class ArrayRealVector extends Rea } return this; } + +/** {@inheritDoc} */ +@Override +public double walkInDefaultOrder(final RealVectorPreservingVisitor visitor) { +visitor.start(data.length, 0, data.length - 1); +for (int i = 0; i < data.length; i++) { +visitor.visit(i, data[i]); +} +return visitor.end(); +} + +/** {@inheritDoc} */ +@Override +public double walkInDefaultOrder(final RealVectorPreservingVisitor visitor, +final int start, final int end) { +checkIndices(start, end); +visitor.start(data.length, start, end); +for (int i = start; i <= end; i++) { +visitor.visit(i, data[i]); +} +return visitor.end(); +} + +/** + * {@inheritDoc} + * + * In this implementation, the optimized order is the default order. + */ +@Override +public double walkInOptimizedOrder(final RealVectorPreservingVisitor visitor) { +return walkInDefaultOrder(visitor); +} + +/** + * {@inheritDoc} + * + * In this implementation, the optimized order is the default order. + */ +@Override +public double walkInOptimizedOrder(final RealVectorPreservingVisitor visitor, +final int start, final int end) { +return walkInDefaultOrder(visitor, start, end); +} + +/** {@inheritDoc} */ +@Override +public double walkInDefaultOrder(final RealVectorChangingVisitor visitor) { +visitor.start(data.length, 0, data.length - 1); +for (int i = 0; i < data.length; i++) { +data[i] = visitor.visit(i, data[i]); +} +return visitor.end(); +} + +/** {@inheritDoc} */ +@Override +public double walkInDefaultOrder(final RealVectorChangingVisitor visitor, +final int start, final int end) { +checkIndices(start, end); +visitor.start(data.length, start, end); +for (int i = start; i <= end; i++) { +data[i] = visitor.visit(i, data[i]); +} +return visitor.end(); +} + +/** + * {@inheritDoc} + * + * In this implementation, the optimized order is the default order. + */ +@Override +public double walkInOptimizedOrder(final RealVectorChangingVisitor visitor) { +return walkInDefaultOrder(visitor); +} + +/** + * {@inheritDoc} + * + * In this implementation, the optimized order is the default order. + */ +@Override +public double walkInOptimizedOrder(final RealVectorChangingVisitor visitor, +final int start, final int end) { +return walkInDefaultOrder(visitor, start, end); +} }
svn commit: r1344102 - /commons/proper/math/trunk/src/test/java/org/apache/commons/math3/TestUtils.java
Author: celestin Date: Wed May 30 05:13:28 2012 New Revision: 1344102 URL: http://svn.apache.org/viewvc?rev=1344102&view=rev Log: Created utility method to assert equality of two instances of RealVector. Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/TestUtils.java Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/TestUtils.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/TestUtils.java?rev=1344102&r1=1344101&r2=1344102&view=diff == --- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/TestUtils.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/TestUtils.java Wed May 30 05:13:28 2012 @@ -30,6 +30,7 @@ import org.apache.commons.math3.complex. import org.apache.commons.math3.distribution.RealDistribution; import org.apache.commons.math3.linear.FieldMatrix; import org.apache.commons.math3.linear.RealMatrix; +import org.apache.commons.math3.linear.RealVector; import org.apache.commons.math3.stat.inference.ChiSquareTest; import org.apache.commons.math3.util.FastMath; import org.apache.commons.math3.util.Precision; @@ -239,6 +240,28 @@ public class TestUtils { assertContains(null, values, x, epsilon); } +/** + * Asserts that all entries of the specified vectors are equal to within a + * positive {@code delta}. + * + * @param message the identifying message for the assertion error (can be + * {@code null}) + * @param expected expected value + * @param actual actual value + * @param delta the maximum difference between the entries of the expected + * and actual vectors for which both entries are still considered equal + */ +public static void assertEquals(final String message, +final RealVector expected, final RealVector actual, final double delta) { +Assert.assertEquals(message + ", dimension", expected.getDimension(), +actual.getDimension()); +final int dim = expected.getDimension(); +for (int i = 0; i < dim; i++) { +Assert.assertEquals(message + ", entry #" + i, +expected.getEntry(i), actual.getEntry(i), delta); +} +} + /** verifies that two matrices are close (1-norm) */ public static void assertEquals(String msg, RealMatrix expected, RealMatrix observed, double tolerance) { @@ -345,11 +368,11 @@ public class TestUtils { } return sumsq; } - + /** * Asserts the null hypothesis for a ChiSquare test. Fails and dumps arguments and test * statistics if the null hypothesis can be rejected with confidence 100 * (1 - alpha)% - * + * * @param valueLabels labels for the values of the discrete distribution under test * @param expected expected counts * @param observed observed counts @@ -381,13 +404,13 @@ public class TestUtils { msgBuffer.append(alpha); msgBuffer.append("."); Assert.fail(msgBuffer.toString()); -} +} } - + /** * Asserts the null hypothesis for a ChiSquare test. Fails and dumps arguments and test * statistics if the null hypothesis can be rejected with confidence 100 * (1 - alpha)% - * + * * @param values integer values whose observed and expected counts are being compared * @param expected expected counts * @param observed observed counts @@ -400,11 +423,11 @@ public class TestUtils { } assertChiSquareAccept(labels, expected, observed, alpha); } - + /** * Asserts the null hypothesis for a ChiSquare test. Fails and dumps arguments and test * statistics if the null hypothesis can be rejected with confidence 100 * (1 - alpha)% - * + * * @param expected expected counts * @param observed observed counts * @param alpha significance level of the test @@ -416,7 +439,7 @@ public class TestUtils { } assertChiSquareAccept(labels, expected, observed, alpha); } - + /** * Computes the 25th, 50th and 75th percentiles of the given distribution and returns * these values in an array. @@ -428,7 +451,7 @@ public class TestUtils { quantiles[2] = distribution.inverseCumulativeProbability(0.75d); return quantiles; } - + /** * Updates observed counts of values in quartiles. * counts[0] <-> 1st quartile ... counts[3] <-> top quartile @@ -442,9 +465,9 @@ public class TestUtils { counts[2]++; } else { counts[1]++; -} +} } - + /** * Eliminates points with zero mass from densityPoints and densityValues parallel * arrays. Returns th
svn commit: r1344104 - /commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java
Author: celestin Date: Wed May 30 05:25:46 2012 New Revision: 1344104 URL: http://svn.apache.org/viewvc?rev=1344104&view=rev Log: Added missing license. Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java?rev=1344104&r1=1344103&r2=1344104&view=diff == --- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java Wed May 30 05:25:46 2012 @@ -1,3 +1,19 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.apache.commons.math3.linear; import java.util.Arrays;
svn commit: r1344570 - /commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/ArrayRealVector.java
Author: celestin Date: Thu May 31 05:49:03 2012 New Revision: 1344570 URL: http://svn.apache.org/viewvc?rev=1344570&view=rev Log: ArrayRealVector.getEntry(int) did not throw the expected when called with an invalid index. Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/ArrayRealVector.java Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/ArrayRealVector.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/ArrayRealVector.java?rev=1344570&r1=1344569&r2=1344570&view=diff == --- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/ArrayRealVector.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/ArrayRealVector.java Thu May 31 05:49:03 2012 @@ -25,6 +25,7 @@ import org.apache.commons.math3.exceptio import org.apache.commons.math3.exception.DimensionMismatchException; import org.apache.commons.math3.exception.NumberIsTooLargeException; import org.apache.commons.math3.exception.MathArithmeticException; +import org.apache.commons.math3.exception.OutOfRangeException; import org.apache.commons.math3.exception.util.LocalizedFormats; import org.apache.commons.math3.util.MathUtils; import org.apache.commons.math3.util.FastMath; @@ -620,7 +621,12 @@ public class ArrayRealVector extends Rea /** {@inheritDoc} */ @Override public double getEntry(int index) { -return data[index]; +try { +return data[index]; +} catch (IndexOutOfBoundsException e) { +throw new OutOfRangeException(LocalizedFormats.INDEX, index, 0, +getDimension() - 1); +} } /** {@inheritDoc} */
svn commit: r1344571 - in /commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear: ArrayRealVectorTest.java RealVectorAbstractTest.java RealVectorTest.java SparseRealVectorTest.java
Author: celestin Date: Thu May 31 05:51:16 2012 New Revision: 1344571 URL: http://svn.apache.org/viewvc?rev=1344571&view=rev Log: MATH-795: factored out testDataInOut(). Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/ArrayRealVectorTest.java commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorTest.java commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/SparseRealVectorTest.java Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/ArrayRealVectorTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/ArrayRealVectorTest.java?rev=1344571&r1=1344570&r2=1344571&view=diff == --- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/ArrayRealVectorTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/ArrayRealVectorTest.java Thu May 31 05:51:16 2012 @@ -49,7 +49,6 @@ import org.apache.commons.math3.analysis import org.apache.commons.math3.exception.DimensionMismatchException; import org.apache.commons.math3.exception.MathArithmeticException; import org.apache.commons.math3.exception.MathIllegalArgumentException; -import org.apache.commons.math3.exception.OutOfRangeException; import org.apache.commons.math3.util.FastMath; import org.junit.Assert; import org.junit.Test; @@ -60,18 +59,6 @@ import org.junit.Test; * @version $Id$ */ public class ArrayRealVectorTest extends RealVectorAbstractTest { - -// -protected double[][] ma1 = {{1d, 2d, 3d}, {4d, 5d, 6d}, {7d, 8d, 9d}}; -protected double[] vec1 = {1d, 2d, 3d}; -protected double[] vec2 = {4d, 5d, 6d}; -protected double[] vec3 = {7d, 8d, 9d}; -protected double[] vec4 = {1d, 2d, 3d, 4d, 5d, 6d, 7d, 8d, 9d}; -protected double[] vec5 = { -4d, 0d, 3d, 1d, -6d, 3d}; -protected double[] vec_null = {0d, 0d, 0d}; -protected Double[] dvec1 = {1d, 2d, 3d, 4d, 5d, 6d, 7d, 8d, 9d}; -protected double[][] mat1 = {{1d, 2d, 3d}, {4d, 5d, 6d},{ 7d, 8d, 9d}}; - // tolerances protected double entryTolerance = 10E-16; protected double normTolerance = 10E-14; @@ -508,29 +495,12 @@ public class ArrayRealVectorTest extends } +@Override @Test public void testDataInOut() { +super.testDataInOut(); ArrayRealVector v1 = new ArrayRealVector(vec1); -ArrayRealVector v2 = new ArrayRealVector(vec2); -ArrayRealVector v4 = new ArrayRealVector(vec4); -RealVectorTestImpl v2_t = new RealVectorTestImpl(vec2); - -RealVector v_append_1 = v1.append(v2); -Assert.assertEquals("testData len", 6, v_append_1.getDimension()); -Assert.assertEquals("testData is 4.0 ", 4.0, v_append_1.getEntry(3), 0); - -RealVector v_append_2 = v1.append(2.0); -Assert.assertEquals("testData len", 4, v_append_2.getDimension()); -Assert.assertEquals("testData is 2.0 ", 2.0, v_append_2.getEntry(3), 0); - -RealVector v_append_4 = v1.append(v2_t); -Assert.assertEquals("testData len", 6, v_append_4.getDimension()); -Assert.assertEquals("testData is 4.0 ", 4.0, v_append_4.getEntry(3), 0); - -RealVector v_append_5 = v1.append((RealVector) v2); -Assert.assertEquals("testData len", 6, v_append_5.getDimension()); -Assert.assertEquals("testData is 4.0 ", 4.0, v_append_5.getEntry(3), 0); RealVector v_copy = v1.copy(); Assert.assertEquals("testData len", 3, v_copy.getDimension()); @@ -539,62 +509,6 @@ public class ArrayRealVectorTest extends double[] a_double = v1.toArray(); Assert.assertEquals("testData len", 3, a_double.length); Assert.assertNotSame("testData not same object ", v1.getDataRef(), a_double); - - -// ArrayRealVector vout4 = (ArrayRealVector) v1.clone(); -// Assert.assertEquals("testData len", 3, vout4.getDimension()); -// Assert.assertEquals("testData not same object ", v1.getDataRef(), vout4.getDataRef()); - - -RealVector vout5 = v4.getSubVector(3, 3); -Assert.assertEquals("testData len", 3, vout5.getDimension()); -Assert.assertEquals("testData is 4.0 ", 5.0, vout5.getEntry(1), 0); -try { -v4.getSubVector(3, 7); -Assert.fail("OutOfRangeException expected"); -} catch (OutOfRangeException ex) { -// expected behavior -} - -ArrayRealVector v_set1 = v1.copy(); -v_set1.setEntry(1, 11.0); -Assert.assertEquals("testData is 11.0 &
svn commit: r1344574 - /commons/proper/math/trunk/src/changes/changes.xml
Author: celestin Date: Thu May 31 06:13:33 2012 New Revision: 1344574 URL: http://svn.apache.org/viewvc?rev=1344574&view=rev Log: Added MATH-791 to the list of changes. Modified: commons/proper/math/trunk/src/changes/changes.xml Modified: commons/proper/math/trunk/src/changes/changes.xml URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/changes/changes.xml?rev=1344574&r1=1344573&r2=1344574&view=diff == --- commons/proper/math/trunk/src/changes/changes.xml (original) +++ commons/proper/math/trunk/src/changes/changes.xml Thu May 31 06:13:33 2012 @@ -52,6 +52,10 @@ If the output is not quite correct, chec + +In GammaDistribution, deprecated getAlpha() and getBeta(). Replaced with +getShape() and getScale(), respectively. + Use inline computation for OrderedTuple hash code.
svn commit: r1344989 - in /commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear: ArrayRealVectorTest.java RealVectorAbstractTest.java SparseRealVectorTest.java
Author: celestin Date: Fri Jun 1 05:31:47 2012 New Revision: 1344989 URL: http://svn.apache.org/viewvc?rev=1344989&view=rev Log: MATH-795: factored out testMapFunctions. Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/ArrayRealVectorTest.java commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/SparseRealVectorTest.java Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/ArrayRealVectorTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/ArrayRealVectorTest.java?rev=1344989&r1=1344988&r2=1344989&view=diff == --- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/ArrayRealVectorTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/ArrayRealVectorTest.java Fri Jun 1 05:31:47 2012 @@ -59,9 +59,6 @@ import org.junit.Test; * @version $Id$ */ public class ArrayRealVectorTest extends RealVectorAbstractTest { -// tolerances -protected double entryTolerance = 10E-16; -protected double normTolerance = 10E-14; // Testclass to test the RealVector interface // only with enough content to support the test @@ -512,334 +509,6 @@ public class ArrayRealVectorTest extends } @Test -public void testMapFunctions() { -ArrayRealVector v1 = new ArrayRealVector(vec1); - -//octave = v1 .+ 2.0 -RealVector v_mapAdd = v1.mapAdd(2.0d); -double[] result_mapAdd = {3d, 4d, 5d}; -assertClose("compare vectors" ,result_mapAdd,v_mapAdd.toArray(),normTolerance); - -//octave = v1 .+ 2.0 -RealVector v_mapAddToSelf = v1.copy(); -v_mapAddToSelf.mapAddToSelf(2.0d); -double[] result_mapAddToSelf = {3d, 4d, 5d}; -assertClose("compare vectors" ,result_mapAddToSelf,v_mapAddToSelf.toArray(),normTolerance); - -//octave = v1 .- 2.0 -RealVector v_mapSubtract = v1.mapSubtract(2.0d); -double[] result_mapSubtract = {-1d, 0d, 1d}; -assertClose("compare vectors" ,result_mapSubtract,v_mapSubtract.toArray(),normTolerance); - -//octave = v1 .- 2.0 -RealVector v_mapSubtractToSelf = v1.copy(); -v_mapSubtractToSelf.mapSubtractToSelf(2.0d); -double[] result_mapSubtractToSelf = {-1d, 0d, 1d}; -assertClose("compare vectors" ,result_mapSubtractToSelf,v_mapSubtractToSelf.toArray(),normTolerance); - -//octave = v1 .* 2.0 -RealVector v_mapMultiply = v1.mapMultiply(2.0d); -double[] result_mapMultiply = {2d, 4d, 6d}; -assertClose("compare vectors" ,result_mapMultiply,v_mapMultiply.toArray(),normTolerance); - -//octave = v1 .* 2.0 -RealVector v_mapMultiplyToSelf = v1.copy(); -v_mapMultiplyToSelf.mapMultiplyToSelf(2.0d); -double[] result_mapMultiplyToSelf = {2d, 4d, 6d}; -assertClose("compare vectors" ,result_mapMultiplyToSelf,v_mapMultiplyToSelf.toArray(),normTolerance); - -//octave = v1 ./ 2.0 -RealVector v_mapDivide = v1.mapDivide(2.0d); -double[] result_mapDivide = {.5d, 1d, 1.5d}; -assertClose("compare vectors" ,result_mapDivide,v_mapDivide.toArray(),normTolerance); - -//octave = v1 ./ 2.0 -RealVector v_mapDivideToSelf = v1.copy(); -v_mapDivideToSelf.mapDivideToSelf(2.0d); -double[] result_mapDivideToSelf = {.5d, 1d, 1.5d}; -assertClose("compare vectors" ,result_mapDivideToSelf,v_mapDivideToSelf.toArray(),normTolerance); - -//octave = v1 .^ 2.0 -RealVector v_mapPow = v1.map(new Power(2)); -double[] result_mapPow = {1d, 4d, 9d}; -assertClose("compare vectors" ,result_mapPow,v_mapPow.toArray(),normTolerance); - -//octave = v1 .^ 2.0 -RealVector v_mapPowToSelf = v1.copy(); -v_mapPowToSelf.mapToSelf(new Power(2)); -double[] result_mapPowToSelf = {1d, 4d, 9d}; -assertClose("compare vectors" ,result_mapPowToSelf,v_mapPowToSelf.toArray(),normTolerance); - -//octave = exp(v1) -RealVector v_mapExp = v1.map(new Exp()); -double[] result_mapExp = {2.718281828459045e+00d,7.389056098930650e+00d, 2.008553692318767e+01d}; -assertClose("compare vectors" ,result_mapExp,v_mapExp.toArray(),normTolerance); - -//octave = exp(v1) -RealVector v_mapExpToSelf = v1.copy(); -v_mapExpToSelf.mapToSelf(new Exp()); -double[] result_mapExpToSelf = {2.718281828459045e+00d,7.389056098930650e+00d, 2.008553692318767e+01d}; -assertClose("compare vectors" ,res
svn commit: r1345443 - in /commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear: ArrayRealVectorTest.java RealVectorAbstractTest.java RealVectorTest.java SparseRealVectorTest.java
Author: celestin Date: Sat Jun 2 05:34:40 2012 New Revision: 1345443 URL: http://svn.apache.org/viewvc?rev=1345443&view=rev Log: MATH-795: factored out testBasicFunctions(). Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/ArrayRealVectorTest.java commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorTest.java commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/SparseRealVectorTest.java Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/ArrayRealVectorTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/ArrayRealVectorTest.java?rev=1345443&r1=1345442&r2=1345443&view=diff == --- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/ArrayRealVectorTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/ArrayRealVectorTest.java Sat Jun 2 05:34:40 2012 @@ -510,6 +510,7 @@ public class ArrayRealVectorTest extends @Test public void testBasicFunctions() { +super.testBasicFunctions(); ArrayRealVector v1 = new ArrayRealVector(vec1); ArrayRealVector v2 = new ArrayRealVector(vec2); ArrayRealVector v5 = new ArrayRealVector(vec5); @@ -517,141 +518,6 @@ public class ArrayRealVectorTest extends RealVectorTestImpl v2_t = new RealVectorTestImpl(vec2); -// emacs calc: [-4, 0, 3, 1, -6, 3] A --> 8.4261497731763586307 -double d_getNorm = v5.getNorm(); -Assert.assertEquals("compare values ", 8.4261497731763586307, d_getNorm, normTolerance); - -// emacs calc: [-4, 0, 3, 1, -6, 3] vN --> 17 -double d_getL1Norm = v5.getL1Norm(); -Assert.assertEquals("compare values ", 17.0, d_getL1Norm, normTolerance); - -// emacs calc: [-4, 0, 3, 1, -6, 3] vn --> 6 -double d_getLInfNorm = v5.getLInfNorm(); -Assert.assertEquals("compare values ", 6.0, d_getLInfNorm, normTolerance); - - -//octave = sqrt(sumsq(v1-v2)) -double dist = v1.getDistance(v2); -Assert.assertEquals("compare values ",v1.subtract(v2).getNorm(), dist, normTolerance); - -//octave = sqrt(sumsq(v1-v2)) -double dist_2 = v1.getDistance(v2_t); -Assert.assertEquals("compare values ", v1.subtract(v2).getNorm(),dist_2, normTolerance); - -//octave = sqrt(sumsq(v1-v2)) -double dist_3 = v1.getDistance(v2); -Assert.assertEquals("compare values ", v1.subtract(v2).getNorm(),dist_3, normTolerance); - -//octave = ??? -double d_getL1Distance = v1. getL1Distance(v2); -Assert.assertEquals("compare values ", 9d, d_getL1Distance, normTolerance); - -double d_getL1Distance_2 = v1.getL1Distance(v2_t); -Assert.assertEquals("compare values ", 9d, d_getL1Distance_2, normTolerance); - -double d_getL1Distance_3 = v1.getL1Distance(v2); -Assert.assertEquals("compare values ", 9d, d_getL1Distance_3, normTolerance); - -//octave = ??? -double d_getLInfDistance = v1.getLInfDistance(v2); -Assert.assertEquals("compare values ", 3d, d_getLInfDistance, normTolerance); - -double d_getLInfDistance_2 = v1. getLInfDistance(v2_t); -Assert.assertEquals("compare values ", 3d, d_getLInfDistance_2, normTolerance); - -double d_getLInfDistance_3 = v1. getLInfDistance(v2); -Assert.assertEquals("compare values ", 3d, d_getLInfDistance_3, normTolerance); - -//octave = v1 + v2 -ArrayRealVector v_add = v1.add(v2); -double[] result_add = {5d, 7d, 9d}; -assertClose("compare vect" ,v_add.toArray(), result_add, normTolerance); - -RealVectorTestImpl vt2 = new RealVectorTestImpl(vec2); -RealVector v_add_i = v1.add(vt2); -double[] result_add_i = {5d, 7d, 9d}; -assertClose("compare vect" ,v_add_i.toArray(),result_add_i,normTolerance); - -//octave = v1 - v2 -ArrayRealVector v_subtract = v1.subtract(v2); -double[] result_subtract = {-3d, -3d, -3d}; -assertClose("compare vect" ,v_subtract.toArray(),result_subtract,normTolerance); - -RealVector v_subtract_i = v1.subtract(vt2); -double[] result_subtract_i = {-3d, -3d, -3d}; -assertClose("compare vect" ,v_subtract_i.toArray(),result_subtract_i,normTolerance); - -// octave v1 .* v2 -ArrayRealVector v_ebeMultiply = v1.ebeMultiply(v2); -double[] result_ebeMultiply = {4d, 10d, 18d}; -asse
svn commit: r1345472 - in /commons/proper/math/trunk/src: changes/ main/java/org/apache/commons/math3/exception/util/ main/resources/assets/org/apache/commons/math3/exception/util/ test/java/org/apach
Author: celestin Date: Sat Jun 2 09:46:23 2012 New Revision: 1345472 URL: http://svn.apache.org/viewvc?rev=1345472&view=rev Log: In LocalizedFormats, removed ALPHA and BETA which are no longer used (MATH-796). Modified: commons/proper/math/trunk/src/changes/changes.xml commons/proper/math/trunk/src/main/java/org/apache/commons/math3/exception/util/LocalizedFormats.java commons/proper/math/trunk/src/main/resources/assets/org/apache/commons/math3/exception/util/LocalizedFormats_fr.properties commons/proper/math/trunk/src/test/java/org/apache/commons/math3/exception/util/LocalizedFormatsTest.java Modified: commons/proper/math/trunk/src/changes/changes.xml URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/changes/changes.xml?rev=1345472&r1=1345471&r2=1345472&view=diff == --- commons/proper/math/trunk/src/changes/changes.xml (original) +++ commons/proper/math/trunk/src/changes/changes.xml Sat Jun 2 09:46:23 2012 @@ -52,6 +52,11 @@ If the output is not quite correct, chec + +Removed unused fields LocalizedFormats.ALPHA and LocalizedFormats.BETA. This is +an acceptable compatibility break, as these fields are only meant for internal +use. + Fix computation of upperCumulativeProbability in HypergeometricDistribution and cleanup of duplicate probability mass function. Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/exception/util/LocalizedFormats.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/exception/util/LocalizedFormats.java?rev=1345472&r1=1345471&r2=1345472&view=diff == --- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/exception/util/LocalizedFormats.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/exception/util/LocalizedFormats.java Sat Jun 2 09:46:23 2012 @@ -191,8 +191,6 @@ public enum LocalizedFormats implements NOT_INCREASING_NUMBER_OF_POINTS("points {0} and {1} are not increasing ({2} > {3})"), NOT_INCREASING_SEQUENCE("points {3} and {2} are not increasing ({1} > {0})"), /* keep */ NOT_MULTIPLICATION_COMPATIBLE_MATRICES("{0}x{1} and {2}x{3} matrices are not multiplication compatible"), -ALPHA("alpha"), /* keep */ -BETA("beta"), /* keep */ NOT_POSITIVE_DEFINITE_MATRIX("not positive definite matrix"), /* keep */ NON_POSITIVE_DEFINITE_MATRIX("not positive definite matrix: diagonal element at ({1},{1}) is smaller than {2} ({0})"), NON_POSITIVE_DEFINITE_OPERATOR("non positive definite linear operator"), /* keep */ Modified: commons/proper/math/trunk/src/main/resources/assets/org/apache/commons/math3/exception/util/LocalizedFormats_fr.properties URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/resources/assets/org/apache/commons/math3/exception/util/LocalizedFormats_fr.properties?rev=1345472&r1=1345471&r2=1345472&view=diff == --- commons/proper/math/trunk/src/main/resources/assets/org/apache/commons/math3/exception/util/LocalizedFormats_fr.properties (original) +++ commons/proper/math/trunk/src/main/resources/assets/org/apache/commons/math3/exception/util/LocalizedFormats_fr.properties Sat Jun 2 09:46:23 2012 @@ -163,8 +163,6 @@ NOT_ENOUGH_POINTS_IN_SPLINE_PARTITION = NOT_INCREASING_NUMBER_OF_POINTS = les points {0} et {1} ne sont pas croissants ({2} > {3}) NOT_INCREASING_SEQUENCE = les points {3} et {2} ne sont pas croissants ({1} > {0}) NOT_MULTIPLICATION_COMPATIBLE_MATRICES = les dimensions {0}x{1} et {2}x{3} sont incompatibles pour la multiplication matricielle -ALPHA = alpha -BETA = beta NOT_POSITIVE_DEFINITE_MATRIX = matrice non d\u00e9finie positive NON_POSITIVE_DEFINITE_MATRIX = matrice non d\u00e9finie positive: l''\u00e9l\u00e9ment diagonal ({1},{1}) est inf\u00e9rieur \u00e0 {2} ({0}) NON_POSITIVE_DEFINITE_OPERATOR = op\u00e9rateur lin\u00e9aire non d\u00e9fini positif Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/exception/util/LocalizedFormatsTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/exception/util/LocalizedFormatsTest.java?rev=1345472&r1=1345471&r2=1345472&view=diff == --- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/exception/util/LocalizedFormatsTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/exception/util/LocalizedFormatsTest.java Sat Jun
svn commit: r1345837 - in /commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear: ArrayRealVectorTest.java RealVectorAbstractTest.java SparseRealVectorTest.java
Author: celestin Date: Mon Jun 4 05:40:33 2012 New Revision: 1345837 URL: http://svn.apache.org/viewvc?rev=1345837&view=rev Log: MATH-795: factored out testOuterProduct() and testMisc(). Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/ArrayRealVectorTest.java commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/SparseRealVectorTest.java Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/ArrayRealVectorTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/ArrayRealVectorTest.java?rev=1345837&r1=1345836&r2=1345837&view=diff == --- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/ArrayRealVectorTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/ArrayRealVectorTest.java Mon Jun 4 05:40:33 2012 @@ -22,30 +22,6 @@ import java.util.Random; import org.apache.commons.math3.TestUtils; import org.apache.commons.math3.analysis.UnivariateFunction; -import org.apache.commons.math3.analysis.function.Abs; -import org.apache.commons.math3.analysis.function.Acos; -import org.apache.commons.math3.analysis.function.Asin; -import org.apache.commons.math3.analysis.function.Atan; -import org.apache.commons.math3.analysis.function.Cbrt; -import org.apache.commons.math3.analysis.function.Ceil; -import org.apache.commons.math3.analysis.function.Cos; -import org.apache.commons.math3.analysis.function.Cosh; -import org.apache.commons.math3.analysis.function.Exp; -import org.apache.commons.math3.analysis.function.Expm1; -import org.apache.commons.math3.analysis.function.Floor; -import org.apache.commons.math3.analysis.function.Inverse; -import org.apache.commons.math3.analysis.function.Log; -import org.apache.commons.math3.analysis.function.Log10; -import org.apache.commons.math3.analysis.function.Log1p; -import org.apache.commons.math3.analysis.function.Power; -import org.apache.commons.math3.analysis.function.Rint; -import org.apache.commons.math3.analysis.function.Signum; -import org.apache.commons.math3.analysis.function.Sin; -import org.apache.commons.math3.analysis.function.Sinh; -import org.apache.commons.math3.analysis.function.Sqrt; -import org.apache.commons.math3.analysis.function.Tan; -import org.apache.commons.math3.analysis.function.Tanh; -import org.apache.commons.math3.analysis.function.Ulp; import org.apache.commons.math3.exception.DimensionMismatchException; import org.apache.commons.math3.exception.MathArithmeticException; import org.apache.commons.math3.exception.MathIllegalArgumentException; @@ -509,54 +485,6 @@ public class ArrayRealVectorTest extends } @Test -public void testBasicFunctions() { -super.testBasicFunctions(); -ArrayRealVector v1 = new ArrayRealVector(vec1); -ArrayRealVector v2 = new ArrayRealVector(vec2); -ArrayRealVector v5 = new ArrayRealVector(vec5); -ArrayRealVector v_null = new ArrayRealVector(vec_null); - -RealVectorTestImpl v2_t = new RealVectorTestImpl(vec2); - -} - -@Test -public void testMisc() { -ArrayRealVector v1 = new ArrayRealVector(vec1); -ArrayRealVector v4 = new ArrayRealVector(vec4); -RealVector v4_2 = new ArrayRealVector(vec4); - -String out1 = v1.toString(); -Assert.assertTrue("some output ", out1.length()!=0); -/* - double[] dout1 = v1.copyOut(); -Assert.assertEquals("testData len", 3, dout1.length); -Assert.assertNotSame("testData not same object ", v1.getDataRef(), dout1); - */ -try { -v1.checkVectorDimensions(2); -Assert.fail("MathIllegalArgumentException expected"); -} catch (MathIllegalArgumentException ex) { -// expected behavior -} - - try { -v1.checkVectorDimensions(v4); -Assert.fail("MathIllegalArgumentException expected"); -} catch (MathIllegalArgumentException ex) { -// expected behavior -} - -try { -v1.checkVectorDimensions(v4_2); -Assert.fail("MathIllegalArgumentException expected"); -} catch (MathIllegalArgumentException ex) { -// expected behavior -} - -} - -@Test public void testPredicates() { ArrayRealVector v = new ArrayRealVector(new double[] { 0, 1, 2 }); @@ -670,22 +598,6 @@ public class ArrayRealVectorTest extends v.cosine(w); } -@Test -public void testOuterProduct() { -final ArrayRealVector u = new ArrayRealVector(new double[] {1, 2, -3}); -final ArrayRealVector v
svn commit: r1346240 - in /commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear: ArrayRealVectorTest.java RealVectorAbstractTest.java SparseRealVectorTest.java
Author: celestin Date: Tue Jun 5 05:10:55 2012 New Revision: 1346240 URL: http://svn.apache.org/viewvc?rev=1346240&view=rev Log: MATH-795: factoring out testPredicates(). Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/ArrayRealVectorTest.java commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/SparseRealVectorTest.java Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/ArrayRealVectorTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/ArrayRealVectorTest.java?rev=1346240&r1=1346239&r2=1346240&view=diff == --- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/ArrayRealVectorTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/ArrayRealVectorTest.java Tue Jun 5 05:10:55 2012 @@ -485,40 +485,18 @@ public class ArrayRealVectorTest extends } @Test +@Override public void testPredicates() { +super.testPredicates(); -ArrayRealVector v = new ArrayRealVector(new double[] { 0, 1, 2 }); - -Assert.assertFalse(v.isNaN()); -v.setEntry(1, Double.NaN); -Assert.assertTrue(v.isNaN()); - -Assert.assertFalse(v.isInfinite()); -v.setEntry(0, Double.POSITIVE_INFINITY); -Assert.assertFalse(v.isInfinite()); -v.setEntry(1, 1); -Assert.assertTrue(v.isInfinite()); -v.setEntry(0, 1); -Assert.assertFalse(v.isInfinite()); - -v.setEntry(0, 0); -Assert.assertEquals(v, new ArrayRealVector(new double[] { 0, 1, 2 })); -Assert.assertNotSame(v, new ArrayRealVector(new double[] { 0, 1, 2 + FastMath.ulp(2)})); -Assert.assertNotSame(v, new ArrayRealVector(new double[] { 0, 1, 2, 3 })); - -Assert.assertEquals(new ArrayRealVector(new double[] { Double.NaN, 1, 2 }).hashCode(), - new ArrayRealVector(new double[] { 0, Double.NaN, 2 }).hashCode()); - -Assert.assertTrue(new ArrayRealVector(new double[] { Double.NaN, 1, 2 }).hashCode() != - new ArrayRealVector(new double[] { 0, 1, 2 }).hashCode()); - -Assert.assertTrue(v.equals(v)); -Assert.assertTrue(v.equals(v.copy())); -Assert.assertFalse(v.equals(null)); +final ArrayRealVector v = (ArrayRealVector) create(new double[] { 0, 1, 2 }); Assert.assertFalse(v.equals(v.getDataRef())); -Assert.assertFalse(v.equals(v.getSubVector(0, v.getDimension() - 1))); -Assert.assertTrue(v.equals(v.getSubVector(0, v.getDimension(; +Assert.assertEquals(create(new double[] { Double.NaN, 1, 2 }).hashCode(), + create(new double[] { 0, Double.NaN, 2 }).hashCode()); + +Assert.assertTrue(create(new double[] { Double.NaN, 1, 2 }).hashCode() != + create(new double[] { 0, 1, 2 }).hashCode()); } @Test Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java?rev=1346240&r1=1346239&r2=1346240&view=diff == --- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java Tue Jun 5 05:10:55 2012 @@ -48,6 +48,7 @@ import org.apache.commons.math3.exceptio import org.apache.commons.math3.exception.MathIllegalArgumentException; import org.apache.commons.math3.exception.NumberIsTooSmallException; import org.apache.commons.math3.exception.OutOfRangeException; +import org.apache.commons.math3.util.FastMath; import org.junit.Test; @@ -713,6 +714,32 @@ public abstract class RealVectorAbstract } } +@Test +public void testPredicates() { +final RealVector v = create(new double[] { 0, 1, 2 }); + +Assert.assertFalse(v.isNaN()); +v.setEntry(1, Double.NaN); +Assert.assertTrue(v.isNaN()); + +Assert.assertFalse(v.isInfinite()); +v.setEntry(0, Double.POSITIVE_INFINITY); +Assert.assertFalse(v.isInfinite()); +v.setEntry(1, 1); +Assert.assertTrue(v.isInfinite()); + +v.setEntry(0, 0); +Assert.assertEquals(v, create(new double[] { 0, 1, 2 })); +Assert.assertNotSame(v, create(new double[] { 0, 1, 2 + FastMath.ulp(2)})); +Assert.assertNotSame(v, create(new double[] { 0, 1, 2, 3 })); + +Assert.assertTrue(v.equals(v)); +Asser
svn commit: r1346243 - in /commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear: ArrayRealVectorTest.java RealVectorAbstractTest.java RealVectorTest.java SparseRealVectorTest.java
Author: celestin Date: Tue Jun 5 05:37:37 2012 New Revision: 1346243 URL: http://svn.apache.org/viewvc?rev=1346243&view=rev Log: MATH-795 - Factored out testSerial(). - In RealVectorTest, the vector returned by create(double[]) should really be of type RealVectorTest.TestVectorImpl, as the minimal implementation is to be tested. This causes some tests not to pass, they are skipped for the time being (overriden from RealVectorAbstractTest, without @Test annotation). When the tests in RealVectorAbstractTest are split, only the smaller tests which do not make sense in the present context will be skipped. - In RealVectorTest, the constructor of RealVectorTest.TestVectorImpl now makes a defensive copy of the specified double[] array (see Javadoc of + RealVectorAbstractTest.create(double[]), + RealVectorAbstractTest.createAlien(double[]). Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/ArrayRealVectorTest.java commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorTest.java commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/SparseRealVectorTest.java Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/ArrayRealVectorTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/ArrayRealVectorTest.java?rev=1346243&r1=1346242&r2=1346243&view=diff == --- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/ArrayRealVectorTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/ArrayRealVectorTest.java Tue Jun 5 05:37:37 2012 @@ -500,12 +500,6 @@ public class ArrayRealVectorTest extends } @Test -public void testSerial() { -ArrayRealVector v = new ArrayRealVector(new double[] { 0, 1, 2 }); -Assert.assertEquals(v,TestUtils.serializeAndRecover(v)); -} - -@Test public void testZeroVectors() { Assert.assertEquals(0, new ArrayRealVector(new double[0]).getDimension()); Assert.assertEquals(0, new ArrayRealVector(new double[0], true).getDimension()); Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java?rev=1346243&r1=1346242&r2=1346243&view=diff == --- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java Tue Jun 5 05:37:37 2012 @@ -20,6 +20,7 @@ import java.util.Arrays; import junit.framework.Assert; +import org.apache.commons.math3.TestUtils; import org.apache.commons.math3.analysis.function.Abs; import org.apache.commons.math3.analysis.function.Acos; import org.apache.commons.math3.analysis.function.Asin; @@ -55,7 +56,10 @@ import org.junit.Test; public abstract class RealVectorAbstractTest { /** * Creates a new instance of {@link RealVector}, with specified entries. - * The returned vector must be of the type currently tested. + * The returned vector must be of the type currently tested. It should be + * noted that some tests assume that no references to the specified + * {@code double[]} are kept in the returned object: if necessary, defensive + * copy of this array should be made. * * @param data the entries of the vector to be created * @return a new {@link RealVector} of the type to be tested @@ -65,7 +69,9 @@ public abstract class RealVectorAbstract /** * Creates a new instance of {@link RealVector}, with specified entries. * The type of the returned vector must be different from the type currently - * tested. + * tested. It should be noted that some tests assume that no references to + * the specified {@code double[]} are kept in the returned object: if + * necessary, defensive copy of this array should be made. * * @param data the entries of the vector to be created * @return a new {@link RealVector} of an alien type @@ -740,6 +746,12 @@ public abstract class RealVectorAbstract Assert.assertTrue(v.equals(v.getSubVector(0, v.getDimension(; } +@Test +public void testSerial() { +RealVector v = create(new double[] { 0, 1, 2 }); +Assert.assertEquals(v,TestUtils.serializeAndRecover(v)); +} + /* * TESTS OF THE VISITOR PATTERN */ Modified: commons/proper/math/trunk/src/test/java/org
svn commit: r1346245 - in /commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear: ArrayRealVectorTest.java RealVectorAbstractTest.java
Author: celestin Date: Tue Jun 5 05:45:41 2012 New Revision: 1346245 URL: http://svn.apache.org/viewvc?rev=1346245&view=rev Log: MATH-795: factored out testAddToEntry(). Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/ArrayRealVectorTest.java commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/ArrayRealVectorTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/ArrayRealVectorTest.java?rev=1346245&r1=1346244&r2=1346245&view=diff == --- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/ArrayRealVectorTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/ArrayRealVectorTest.java Tue Jun 5 05:45:41 2012 @@ -740,19 +740,6 @@ public class ArrayRealVectorTest extends } } -@Test -public void testAddToEntry() { -final double[] v = new double[] { 1, 2, 3 }; -final ArrayRealVector x = new ArrayRealVector(v); -final double inc = 7; -for (int i = 0; i < x.getDimension(); i++) { -x.addToEntry(i, inc); -} -for (int i = 0; i < x.getDimension(); i++) { -Assert.assertEquals(v[i] + inc, x.getEntry(i), 0); -} -} - @Override public RealVector create(final double[] data) { return new ArrayRealVector(data, true); Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java?rev=1346245&r1=1346244&r2=1346245&view=diff == --- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java Tue Jun 5 05:45:41 2012 @@ -752,6 +752,20 @@ public abstract class RealVectorAbstract Assert.assertEquals(v,TestUtils.serializeAndRecover(v)); } + +@Test +public void testAddToEntry() { +final double[] v = new double[] { 1, 2, 3 }; +final RealVector x = create(v); +final double inc = 7; +for (int i = 0; i < x.getDimension(); i++) { +x.addToEntry(i, inc); +} +for (int i = 0; i < x.getDimension(); i++) { +Assert.assertEquals(v[i] + inc, x.getEntry(i), 0); +} +} + /* * TESTS OF THE VISITOR PATTERN */
svn commit: r1346467 - in /commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear: ArrayRealVectorTest.java RealVectorAbstractTest.java
Author: celestin Date: Tue Jun 5 17:01:57 2012 New Revision: 1346467 URL: http://svn.apache.org/viewvc?rev=1346467&view=rev Log: MATH-795: factored out testMinMax(). Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/ArrayRealVectorTest.java commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/ArrayRealVectorTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/ArrayRealVectorTest.java?rev=1346467&r1=1346466&r2=1346467&view=diff == --- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/ArrayRealVectorTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/ArrayRealVectorTest.java Tue Jun 5 17:01:57 2012 @@ -507,30 +507,6 @@ public class ArrayRealVectorTest extends } @Test -public void testMinMax() { -ArrayRealVector v1 = new ArrayRealVector(new double[] { 0, -6, 4, 12, 7 }); -Assert.assertEquals(1, v1.getMinIndex()); -Assert.assertEquals(-6, v1.getMinValue(), 1.0e-12); -Assert.assertEquals(3, v1.getMaxIndex()); -Assert.assertEquals(12, v1.getMaxValue(), 1.0e-12); -ArrayRealVector v2 = new ArrayRealVector(new double[] { Double.NaN, 3, Double.NaN, -2 }); -Assert.assertEquals(3, v2.getMinIndex()); -Assert.assertEquals(-2, v2.getMinValue(), 1.0e-12); -Assert.assertEquals(1, v2.getMaxIndex()); -Assert.assertEquals(3, v2.getMaxValue(), 1.0e-12); -ArrayRealVector v3 = new ArrayRealVector(new double[] { Double.NaN, Double.NaN }); -Assert.assertEquals(-1, v3.getMinIndex()); -Assert.assertTrue(Double.isNaN(v3.getMinValue())); -Assert.assertEquals(-1, v3.getMaxIndex()); -Assert.assertTrue(Double.isNaN(v3.getMaxValue())); -ArrayRealVector v4 = new ArrayRealVector(new double[0]); -Assert.assertEquals(-1, v4.getMinIndex()); -Assert.assertTrue(Double.isNaN(v4.getMinValue())); -Assert.assertEquals(-1, v4.getMaxIndex()); -Assert.assertTrue(Double.isNaN(v4.getMaxValue())); -} - -@Test public void testCosine() { final ArrayRealVector v = new ArrayRealVector(new double[] {1, 0, 0}); Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java?rev=1346467&r1=1346466&r2=1346467&view=diff == --- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java Tue Jun 5 17:01:57 2012 @@ -752,7 +752,6 @@ public abstract class RealVectorAbstract Assert.assertEquals(v,TestUtils.serializeAndRecover(v)); } - @Test public void testAddToEntry() { final double[] v = new double[] { 1, 2, 3 }; @@ -766,6 +765,30 @@ public abstract class RealVectorAbstract } } +@Test +public void testMinMax() { +final RealVector v1 = create(new double[] {0, -6, 4, 12, 7}); +Assert.assertEquals(1, v1.getMinIndex()); +Assert.assertEquals(-6, v1.getMinValue(), 1.0e-12); +Assert.assertEquals(3, v1.getMaxIndex()); +Assert.assertEquals(12, v1.getMaxValue(), 1.0e-12); +final RealVector v2 = create(new double[] {Double.NaN, 3, Double.NaN, -2}); +Assert.assertEquals(3, v2.getMinIndex()); +Assert.assertEquals(-2, v2.getMinValue(), 1.0e-12); +Assert.assertEquals(1, v2.getMaxIndex()); +Assert.assertEquals(3, v2.getMaxValue(), 1.0e-12); +final RealVector v3 = create(new double[] {Double.NaN, Double.NaN}); +Assert.assertEquals(-1, v3.getMinIndex()); +Assert.assertTrue(Double.isNaN(v3.getMinValue())); +Assert.assertEquals(-1, v3.getMaxIndex()); +Assert.assertTrue(Double.isNaN(v3.getMaxValue())); +final RealVector v4 = create(new double[0]); +Assert.assertEquals(-1, v4.getMinIndex()); +Assert.assertTrue(Double.isNaN(v4.getMinValue())); +Assert.assertEquals(-1, v4.getMaxIndex()); +Assert.assertTrue(Double.isNaN(v4.getMaxValue())); +} + /* * TESTS OF THE VISITOR PATTERN */
svn commit: r1346471 - in /commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear: ArrayRealVectorTest.java RealVectorAbstractTest.java RealVectorTest.java
Author: celestin Date: Tue Jun 5 17:08:20 2012 New Revision: 1346471 URL: http://svn.apache.org/viewvc?rev=1346471&view=rev Log: MATH-795: factored out testCosine(). Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/ArrayRealVectorTest.java commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorTest.java Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/ArrayRealVectorTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/ArrayRealVectorTest.java?rev=1346471&r1=1346470&r2=1346471&view=diff == --- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/ArrayRealVectorTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/ArrayRealVectorTest.java Tue Jun 5 17:08:20 2012 @@ -506,27 +506,6 @@ public class ArrayRealVectorTest extends Assert.assertEquals(0, new ArrayRealVector(new double[0], false).getDimension()); } -@Test -public void testCosine() { -final ArrayRealVector v = new ArrayRealVector(new double[] {1, 0, 0}); - -double[] wData = new double[] {1, 1, 0}; -RealVector w = new ArrayRealVector(wData); -Assert.assertEquals(FastMath.sqrt(2) / 2, v.cosine(w), normTolerance); - -wData = new double[] {1, 0, 0}; -w = new ArrayRealVector(wData); -Assert.assertEquals(1, v.cosine(w), normTolerance); - -wData = new double[] {0, 1, 0}; -w = new ArrayRealVector(wData); -Assert.assertEquals(0, v.cosine(w), 0); - -wData = new double[] {-1, 0, 0}; -w = new ArrayRealVector(wData); -Assert.assertEquals(-1, v.cosine(w), normTolerance); -} - @Test(expected=MathArithmeticException.class) public void testCosinePrecondition1() { final ArrayRealVector v = new ArrayRealVector(new double[] {0, 0, 0}); Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java?rev=1346471&r1=1346470&r2=1346471&view=diff == --- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java Tue Jun 5 17:08:20 2012 @@ -789,6 +789,27 @@ public abstract class RealVectorAbstract Assert.assertTrue(Double.isNaN(v4.getMaxValue())); } +@Test +public void testCosine() { +final RealVector v = create(new double[] {1, 0, 0}); + +double[] wData = new double[] {1, 1, 0}; +RealVector w = create(wData); +Assert.assertEquals(FastMath.sqrt(2) / 2, v.cosine(w), normTolerance); + +wData = new double[] {1, 0, 0}; +w = create(wData); +Assert.assertEquals(1, v.cosine(w), normTolerance); + +wData = new double[] {0, 1, 0}; +w = create(wData); +Assert.assertEquals(0, v.cosine(w), 0); + +wData = new double[] {-1, 0, 0}; +w = create(wData); +Assert.assertEquals(-1, v.cosine(w), normTolerance); +} + /* * TESTS OF THE VISITOR PATTERN */ Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorTest.java?rev=1346471&r1=1346470&r2=1346471&view=diff == --- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorTest.java Tue Jun 5 17:08:20 2012 @@ -108,16 +108,6 @@ public class RealVectorTest extends Real } @Override -public double dotProduct(RealVector v) { -throw unsupported(); -} - -@Override -public double getNorm() { -throw unsupported(); -} - -@Override public double getL1Norm() { throw unsupported(); }
svn commit: r1346475 - in /commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear: ArrayRealVectorTest.java RealVectorAbstractTest.java
Author: celestin Date: Tue Jun 5 17:11:15 2012 New Revision: 1346475 URL: http://svn.apache.org/viewvc?rev=1346475&view=rev Log: MATH-795: factored out testCosinePrecondition1(), testCosinePrecondition2() and testCosinePrecondition3(). Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/ArrayRealVectorTest.java commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/ArrayRealVectorTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/ArrayRealVectorTest.java?rev=1346475&r1=1346474&r2=1346475&view=diff == --- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/ArrayRealVectorTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/ArrayRealVectorTest.java Tue Jun 5 17:11:15 2012 @@ -506,25 +506,6 @@ public class ArrayRealVectorTest extends Assert.assertEquals(0, new ArrayRealVector(new double[0], false).getDimension()); } -@Test(expected=MathArithmeticException.class) -public void testCosinePrecondition1() { -final ArrayRealVector v = new ArrayRealVector(new double[] {0, 0, 0}); -final ArrayRealVector w = new ArrayRealVector(new double[] {1, 0, 0}); -v.cosine(w); -} -@Test(expected=MathArithmeticException.class) -public void testCosinePrecondition2() { -final ArrayRealVector v = new ArrayRealVector(new double[] {0, 0, 0}); -final ArrayRealVector w = new ArrayRealVector(new double[] {1, 0, 0}); -w.cosine(v); -} -@Test(expected=DimensionMismatchException.class) -public void testCosinePrecondition3() { -final ArrayRealVector v = new ArrayRealVector(new double[] {1, 2, 3}); -final ArrayRealVector w = new ArrayRealVector(new double[] {1, 2, 3, 4}); -v.cosine(w); -} - @Test(expected=DimensionMismatchException.class) public void testCombinePreconditionSameType() { final double a = 1d; Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java?rev=1346475&r1=1346474&r2=1346475&view=diff == --- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java Tue Jun 5 17:11:15 2012 @@ -45,6 +45,7 @@ import org.apache.commons.math3.analysis import org.apache.commons.math3.analysis.function.Tan; import org.apache.commons.math3.analysis.function.Tanh; import org.apache.commons.math3.analysis.function.Ulp; +import org.apache.commons.math3.exception.DimensionMismatchException; import org.apache.commons.math3.exception.MathArithmeticException; import org.apache.commons.math3.exception.MathIllegalArgumentException; import org.apache.commons.math3.exception.NumberIsTooSmallException; @@ -810,6 +811,27 @@ public abstract class RealVectorAbstract Assert.assertEquals(-1, v.cosine(w), normTolerance); } +@Test(expected=MathArithmeticException.class) +public void testCosinePrecondition1() { +final RealVector v = create(new double[] {0, 0, 0}); +final RealVector w = create(new double[] {1, 0, 0}); +v.cosine(w); +} + +@Test(expected=MathArithmeticException.class) +public void testCosinePrecondition2() { +final RealVector v = create(new double[] {0, 0, 0}); +final RealVector w = create(new double[] {1, 0, 0}); +w.cosine(v); +} + +@Test(expected=DimensionMismatchException.class) +public void testCosinePrecondition3() { +final RealVector v = create(new double[] {1, 2, 3}); +final RealVector w = create(new double[] {1, 2, 3, 4}); +v.cosine(w); +} + /* * TESTS OF THE VISITOR PATTERN */
svn commit: r1346523 - in /commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear: ArrayRealVectorTest.java RealVectorAbstractTest.java RealVectorTest.java
Author: celestin Date: Tue Jun 5 18:46:29 2012 New Revision: 1346523 URL: http://svn.apache.org/viewvc?rev=1346523&view=rev Log: MATH-795: factored out - testCombinePreconditionSameType() - testCombineSameType() - testCombinePreconditionMixedType() - testCombineMixedTypes() Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/ArrayRealVectorTest.java commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorTest.java Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/ArrayRealVectorTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/ArrayRealVectorTest.java?rev=1346523&r1=1346522&r2=1346523&view=diff == --- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/ArrayRealVectorTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/ArrayRealVectorTest.java Tue Jun 5 18:46:29 2012 @@ -507,90 +507,6 @@ public class ArrayRealVectorTest extends } @Test(expected=DimensionMismatchException.class) -public void testCombinePreconditionSameType() { -final double a = 1d; -final double b = 2d; -double[] aux = new double[] { 3d, 4d, 5d }; -final RealVector x = new ArrayRealVector(aux, false); -aux = new double[] { 6d, 7d }; -final RealVector y = new ArrayRealVector(aux, false); -x.combine(a, b, y); -} - -@Test -public void testCombineSameType() { -final Random random = new Random(20110726); -final int dim = 10; -final double a = (2 * random.nextDouble() - 1); -final double b = (2 * random.nextDouble() - 1); -final RealVector x = new ArrayRealVector(dim); -final RealVector y = new ArrayRealVector(dim); -final double[] expected = new double[dim]; -for (int i = 0; i < dim; i++) { -final double xi = 2 * random.nextDouble() - 1; -final double yi = 2 * random.nextDouble() - 1; -x.setEntry(i, xi); -y.setEntry(i, yi); -expected[i] = a * xi + b * yi; -} -final double[] actual = x.combine(a, b, y).toArray(); -for (int i = 0; i < dim; i++) { -final double delta; -if (expected[i] == 0d) { -delta = Math.ulp(1d); -} else { -delta = Math.ulp(expected[i]); -} -Assert.assertEquals("elements [" + i + "] differ", -expected[i], -actual[i], -delta); -} -} - -@Test(expected=DimensionMismatchException.class) -public void testCombinePreconditionMixedType() { -final double a = 1d; -final double b = 2d; -double[] aux = new double[] { 3d, 4d, 5d }; -final RealVector x = new ArrayRealVector(aux, false); -aux = new double[] { 6d, 7d }; -final RealVector y = new OpenMapRealVector(aux); -x.combine(a, b, y); -} - -@Test -public void testCombineMixedTypes() { -final Random random = new Random(20110726); -final int dim = 10; -final double a = (2 * random.nextDouble() - 1); -final double b = (2 * random.nextDouble() - 1); -final RealVector x = new ArrayRealVector(dim); -final RealVector y = new OpenMapRealVector(dim, 0d); -final double[] expected = new double[dim]; -for (int i = 0; i < dim; i++) { -final double xi = 2 * random.nextDouble() - 1; -final double yi = 2 * random.nextDouble() - 1; -x.setEntry(i, xi); -y.setEntry(i, yi); -expected[i] = a * xi + b * yi; -} -final double[] actual = x.combine(a, b, y).toArray(); -for (int i = 0; i < dim; i++) { -final double delta; -if (expected[i] == 0d) { -delta = Math.ulp(1d); -} else { -delta = Math.ulp(expected[i]); -} -Assert.assertEquals("elements [" + i + "] differ", -expected[i], -actual[i], -delta); -} -} - -@Test(expected=DimensionMismatchException.class) public void testCombineToSelfPreconditionSameType() { final double a = 1d; final double b = 2d; Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/
svn commit: r1346723 - in /commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear: ArrayRealVectorTest.java RealVectorAbstractTest.java
Author: celestin Date: Wed Jun 6 03:19:18 2012 New Revision: 1346723 URL: http://svn.apache.org/viewvc?rev=1346723&view=rev Log: MATH-795: factored out - testCombineToSelfPreconditionSameType() - testCombineToSelfSameType() - testCombineToSelfPreconditionMixeType() - testCombineToSelfMixedTypes() Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/ArrayRealVectorTest.java commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/ArrayRealVectorTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/ArrayRealVectorTest.java?rev=1346723&r1=1346722&r2=1346723&view=diff == --- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/ArrayRealVectorTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/ArrayRealVectorTest.java Wed Jun 6 03:19:18 2012 @@ -506,92 +506,6 @@ public class ArrayRealVectorTest extends Assert.assertEquals(0, new ArrayRealVector(new double[0], false).getDimension()); } -@Test(expected=DimensionMismatchException.class) -public void testCombineToSelfPreconditionSameType() { -final double a = 1d; -final double b = 2d; -double[] aux = new double[] { 3d, 4d, 5d }; -final RealVector x = new ArrayRealVector(aux, false); -aux = new double[] { 6d, 7d }; -final RealVector y = new ArrayRealVector(aux, false); -x.combineToSelf(a, b, y); -} - -@Test -public void testCombineToSelfSameType() { -final Random random = new Random(20110726); -final int dim = 10; -final double a = (2 * random.nextDouble() - 1); -final double b = (2 * random.nextDouble() - 1); -final RealVector x = new ArrayRealVector(dim); -final RealVector y = new ArrayRealVector(dim); -final double[] expected = new double[dim]; -for (int i = 0; i < dim; i++) { -final double xi = 2 * random.nextDouble() - 1; -final double yi = 2 * random.nextDouble() - 1; -x.setEntry(i, xi); -y.setEntry(i, yi); -expected[i] = a * xi + b * yi; -} -Assert.assertSame(x, x.combineToSelf(a, b, y)); -final double[] actual = x.toArray(); -for (int i = 0; i < dim; i++) { -final double delta; -if (expected[i] == 0d) { -delta = Math.ulp(1d); -} else { -delta = Math.ulp(expected[i]); -} -Assert.assertEquals("elements [" + i + "] differ", -expected[i], -actual[i], -delta); -} -} - -@Test(expected=DimensionMismatchException.class) -public void testCombineToSelfPreconditionMixedType() { -final double a = 1d; -final double b = 2d; -double[] aux = new double[] { 3d, 4d, 5d }; -final RealVector x = new ArrayRealVector(aux, false); -aux = new double[] { 6d, 7d }; -final RealVector y = new OpenMapRealVector(aux); -x.combineToSelf(a, b, y); -} - -@Test -public void testCombineToSelfMixedTypes() { -final Random random = new Random(20110726); -final int dim = 10; -final double a = (2 * random.nextDouble() - 1); -final double b = (2 * random.nextDouble() - 1); -final RealVector x = new ArrayRealVector(dim); -final RealVector y = new OpenMapRealVector(dim, 0d); -final double[] expected = new double[dim]; -for (int i = 0; i < dim; i++) { -final double xi = 2 * random.nextDouble() - 1; -final double yi = 2 * random.nextDouble() - 1; -x.setEntry(i, xi); -y.setEntry(i, yi); -expected[i] = a * xi + b * yi; -} -Assert.assertSame(x, x.combineToSelf(a, b, y)); -final double[] actual = x.toArray(); -for (int i = 0; i < dim; i++) { -final double delta; -if (expected[i] == 0d) { -delta = Math.ulp(1d); -} else { -delta = Math.ulp(expected[i]); -} -Assert.assertEquals("elements [" + i + "] differ", -expected[i], -actual[i], -delta); -} -} - @Override public RealVector create(final double[] data) { return new ArrayRealVector(data, true); Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java URL: http://svn.apache.o
svn commit: r1346725 - in /commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear: ArrayRealVectorTest.java RealVectorTest.java SparseRealVectorTest.java
Author: celestin Date: Wed Jun 6 03:23:39 2012 New Revision: 1346725 URL: http://svn.apache.org/viewvc?rev=1346725&view=rev Log: MATH-795: removed unused imports. Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/ArrayRealVectorTest.java commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorTest.java commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/SparseRealVectorTest.java Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/ArrayRealVectorTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/ArrayRealVectorTest.java?rev=1346725&r1=1346724&r2=1346725&view=diff == --- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/ArrayRealVectorTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/ArrayRealVectorTest.java Wed Jun 6 03:23:39 2012 @@ -18,14 +18,9 @@ package org.apache.commons.math3.linear; import java.io.Serializable; import java.util.Iterator; -import java.util.Random; -import org.apache.commons.math3.TestUtils; import org.apache.commons.math3.analysis.UnivariateFunction; -import org.apache.commons.math3.exception.DimensionMismatchException; -import org.apache.commons.math3.exception.MathArithmeticException; import org.apache.commons.math3.exception.MathIllegalArgumentException; -import org.apache.commons.math3.util.FastMath; import org.junit.Assert; import org.junit.Test; @@ -359,6 +354,16 @@ public class ArrayRealVectorTest extends } } +@Override +public RealVector create(final double[] data) { +return new ArrayRealVector(data, true); +} + +@Override +public RealVector createAlien(double[] data) { +return new RealVectorTestImpl(data); +} + @Test public void testConstructors() { @@ -505,14 +510,4 @@ public class ArrayRealVectorTest extends Assert.assertEquals(0, new ArrayRealVector(new double[0], true).getDimension()); Assert.assertEquals(0, new ArrayRealVector(new double[0], false).getDimension()); } - -@Override -public RealVector create(final double[] data) { -return new ArrayRealVector(data, true); -} - -@Override -public RealVector createAlien(double[] data) { -return new RealVectorTestImpl(data); -} } Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorTest.java?rev=1346725&r1=1346724&r2=1346725&view=diff == --- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorTest.java Wed Jun 6 03:23:39 2012 @@ -176,6 +176,16 @@ public class RealVectorTest extends Real } @Override +public RealVector create(final double[] data) { +return new TestVectorImpl(data); +} + +@Override +public RealVector createAlien(double[] data) { +return new TestVectorImpl(data); +} + +@Override public void testBasicFunctions() { /* * TODO this test is huge, and some of the methods being tested are not @@ -295,16 +305,6 @@ public class RealVectorTest extends Real } @Override -public RealVector create(final double[] data) { -return new TestVectorImpl(data); -} - -@Override -public RealVector createAlien(double[] data) { -return new TestVectorImpl(data); -} - -@Override public void testDataInOut() { /* * TODO Some of the tests carried out in testDataInOut() do not pass, Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/SparseRealVectorTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/SparseRealVectorTest.java?rev=1346725&r1=1346724&r2=1346725&view=diff == --- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/SparseRealVectorTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/SparseRealVectorTest.java Wed Jun 6 03:23:39 2012 @@ -18,13 +18,10 @@ package org.apache.commons.math3.linear; import java.io.Serializable; import java.util.Iterator; -import org.junit.Assert; -import org.junit.Test; -import org.apache.commons.math3.TestUtils; import org.apache.commons.math3.analysis.UnivariateFunction; -import org.apache.commons.math3.util.Fa
svn commit: r1346729 - /commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java
Author: celestin Date: Wed Jun 6 03:56:02 2012 New Revision: 1346729 URL: http://svn.apache.org/viewvc?rev=1346729&view=rev Log: MATH-795: in RealVectorAbstractTest, added method getPreferredEntryValue() which allows testing vectors with some entries set to a preferred value (e.g. 0 for sparse vectors). Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java?rev=1346729&r1=1346728&r2=1346729&view=diff == --- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java Wed Jun 6 03:56:02 2012 @@ -80,6 +80,21 @@ public abstract class RealVectorAbstract */ public abstract RealVector createAlien(double[] data); +/** + * Returns a preferred value of the entries, to be tested specifically. Some + * implementations of {@link RealVector} (e.g. {@link OpenMapRealVector}) do + * not store specific values of entries. In order to ensure that all tests + * take into account this specific value, some entries of the vectors to be + * tested are deliberately set to the value returned by the present method. + * The default implementation returns {@code 0.0}. + * + * @return a value which should be present in all vectors to be + * tested + */ +public double getPreferredEntryValue() { +return 0.0; +} + /** verifies that two vectors are close (sup norm) */ protected void assertClose(String msg, double[] m, double[] n, double tolerance) {
svn commit: r1346740 - in /commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear: RealVectorAbstractTest.java RealVectorTest.java
Author: celestin Date: Wed Jun 6 05:21:18 2012 New Revision: 1346740 URL: http://svn.apache.org/viewvc?rev=1346740&view=rev Log: MATH-795: - some methods are not implemented by RealVector, so they should not be tested: added @Ignore annotations in RealVectorTest. - in RealVectorAbstractTest, extracted + testAppendVector() + testAppendScalar() from testDataInOut(). Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorTest.java Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java?rev=1346740&r1=1346739&r2=1346740&view=diff == --- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java Wed Jun 6 05:21:18 2012 @@ -120,6 +120,56 @@ public abstract class RealVectorAbstract protected double entryTolerance = 10E-16; protected double normTolerance = 10E-14; +private void doTestAppendVector(final String message, final RealVector v1, +final RealVector v2, final double delta) { + +final int n1 = v1.getDimension(); +final int n2 = v2.getDimension(); +final RealVector v = v1.append(v2); +Assert.assertEquals(message, n1 + n2, v.getDimension()); +for (int i = 0; i < n1; i++) { +final String msg = message + ", entry #" + i; +Assert.assertEquals(msg, v1.getEntry(i), v.getEntry(i), delta); +} +for (int i = 0; i < n2; i++) { +final String msg = message + ", entry #" + (n1 + i); +Assert.assertEquals(msg, v2.getEntry(i), v.getEntry(n1 + i), delta); +} +} + +@Test +public void testAppendVector() { +final double x = getPreferredEntryValue(); +final double[] data1 = new double[] {x, 1d, 2d, x, x}; +final double[] data2 = new double[] {x, x, 3d, x, 4d, x}; + +doTestAppendVector("same type", create(data1), create(data2), 0d); +doTestAppendVector("mixed types", create(data1), createAlien(data2), 0d); +} + +private void doTestAppendScalar(final String message, final RealVector v, +final double d, final double delta) { + +final int n = v.getDimension(); +final RealVector w = v.append(d); +Assert.assertEquals(message, n + 1, w.getDimension()); +for (int i = 0; i < n; i++) { +final String msg = message + ", entry #" + i; +Assert.assertEquals(msg, v.getEntry(i), w.getEntry(i), delta); +} +final String msg = message + ", entry #" + n; +Assert.assertEquals(msg, d, w.getEntry(n), delta); +} + +@Test +public void testAppendScalar() { +final double x = getPreferredEntryValue(); +final double[] data = new double[] {x, 1d, 2d, x, x}; + +doTestAppendScalar("same type", create(data), 1d, 0d); +doTestAppendScalar("mixed types", create(data), x, 0d); +} + @Test public void testDataInOut() { final RealVector v1 = create(vec1); @@ -127,22 +177,6 @@ public abstract class RealVectorAbstract final RealVector v4 = create(vec4); final RealVector v2_t = createAlien(vec2); -final RealVector v_append_1 = v1.append(v2); -Assert.assertEquals("testData len", 6, v_append_1.getDimension()); -Assert.assertEquals("testData is 4.0 ", 4.0, v_append_1.getEntry(3), 0); - -final RealVector v_append_2 = v1.append(2.0); -Assert.assertEquals("testData len", 4, v_append_2.getDimension()); -Assert.assertEquals("testData is 2.0 ", 2.0, v_append_2.getEntry(3), 0); - -final RealVector v_append_4 = v1.append(v2_t); -Assert.assertEquals("testData len", 6, v_append_4.getDimension()); -Assert.assertEquals("testData is 4.0 ", 4.0, v_append_4.getEntry(3), 0); - -final RealVector v_append_5 = v1.append(v2); -Assert.assertEquals("testData len", 6, v_append_5.getDimension()); -Assert.assertEquals("testData is 4.0 ", 4.0, v_append_5.getEntry(3), 0); - final RealVector vout5 = v4.getSubVector(3, 3); Assert.assertEquals("testData len", 3, vout5.getDimension()); Assert.assertEquals("testData is 4.0 ", 5.0, vout5.getEntry(1), 0); Modified: commons/proper/math/trunk/src/test/java/org/apache/common
svn commit: r1346741 - /commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java
Author: celestin Date: Wed Jun 6 05:41:21 2012 New Revision: 1346741 URL: http://svn.apache.org/viewvc?rev=1346741&view=rev Log: MATH-795: in RealVectorAbstractTest - defined class variables data1 and data2 for the creation of test vectors. Attention has been paid to "special" values, which are interspersed with "normal" values (see e.g. sparse vectors). - created testGetDimension(). - created testGetEntry(). Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java?rev=1346741&r1=1346740&r2=1346741&view=diff == --- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java Wed Jun 6 05:41:21 2012 @@ -116,10 +116,44 @@ public abstract class RealVectorAbstract protected Double[] dvec1 = {1d, 2d, 3d, 4d, 5d, 6d, 7d, 8d, 9d}; protected double[][] mat1 = {{1d, 2d, 3d}, {4d, 5d, 6d},{ 7d, 8d, 9d}}; +/** + * Data which can be used to create a specific vector. The array is + * interspersed with the value returned by + * {@link #getPreferredEntryValue()}. + */ +private final double[] data1; + + +/** + * Data which can be used to create a specific vector. The array is + * interspersed with the value returned by + * {@link #getPreferredEntryValue()}. + */ +private final double[] data2; + +public RealVectorAbstractTest() { +final double x = getPreferredEntryValue(); +data1 = new double[] {x, 1d, 2d, x, x}; +data2 = new double[] {x, x, 3d, x, 4d, x}; +} + // tolerances protected double entryTolerance = 10E-16; protected double normTolerance = 10E-14; +@Test +public void testGetDimension() { +Assert.assertEquals(data1.length, create(data1).getDimension()); +} + +@Test +public void testGetEntry() { +final RealVector v = create(data1); +for (int i = 0; i < data1.length; i++) { +Assert.assertEquals("entry " + i, data1[i], v.getEntry(i), 0d); +} +} + private void doTestAppendVector(final String message, final RealVector v1, final RealVector v2, final double delta) { @@ -139,10 +173,6 @@ public abstract class RealVectorAbstract @Test public void testAppendVector() { -final double x = getPreferredEntryValue(); -final double[] data1 = new double[] {x, 1d, 2d, x, x}; -final double[] data2 = new double[] {x, x, 3d, x, 4d, x}; - doTestAppendVector("same type", create(data1), create(data2), 0d); doTestAppendVector("mixed types", create(data1), createAlien(data2), 0d); } @@ -163,11 +193,9 @@ public abstract class RealVectorAbstract @Test public void testAppendScalar() { -final double x = getPreferredEntryValue(); -final double[] data = new double[] {x, 1d, 2d, x, x}; -doTestAppendScalar("same type", create(data), 1d, 0d); -doTestAppendScalar("mixed types", create(data), x, 0d); +doTestAppendScalar("", create(data1), 1d, 0d); +doTestAppendScalar("", create(data1), getPreferredEntryValue(), 0d); } @Test
svn commit: r1347392 - /commons/proper/math/trunk/src/test/java/org/apache/commons/math3/TestUtils.java
Author: celestin Date: Thu Jun 7 05:05:33 2012 New Revision: 1347392 URL: http://svn.apache.org/viewvc?rev=1347392&view=rev Log: Utility method for testing for equality of expected double[] with RealVector. Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/TestUtils.java Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/TestUtils.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/TestUtils.java?rev=1347392&r1=1347391&r2=1347392&view=diff == --- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/TestUtils.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/TestUtils.java Thu Jun 7 05:05:33 2012 @@ -252,6 +252,27 @@ public class TestUtils { * and actual vectors for which both entries are still considered equal */ public static void assertEquals(final String message, +final double[] expected, final RealVector actual, final double delta) { +Assert.assertEquals(message + ", dimension", expected.length, +actual.getDimension()); +for (int i = 0; i < expected.length; i++) { +Assert.assertEquals(message + ", entry #" + i, expected[i], +actual.getEntry(i), delta); +} +} + +/** + * Asserts that all entries of the specified vectors are equal to within a + * positive {@code delta}. + * + * @param message the identifying message for the assertion error (can be + * {@code null}) + * @param expected expected value + * @param actual actual value + * @param delta the maximum difference between the entries of the expected + * and actual vectors for which both entries are still considered equal + */ +public static void assertEquals(final String message, final RealVector expected, final RealVector actual, final double delta) { Assert.assertEquals(message + ", dimension", expected.getDimension(), actual.getDimension());
svn commit: r1347393 - /commons/proper/math/trunk/src/test/java/org/apache/commons/math3/TestUtils.java
Author: celestin Date: Thu Jun 7 05:12:46 2012 New Revision: 1347393 URL: http://svn.apache.org/viewvc?rev=1347393&view=rev Log: In TestUtils, improved handling of error messages for - assertEquals(String, double[], RealVector, double), - assertEquals(String, RealVector, RealVector, double). Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/TestUtils.java Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/TestUtils.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/TestUtils.java?rev=1347393&r1=1347392&r2=1347393&view=diff == --- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/TestUtils.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/TestUtils.java Thu Jun 7 05:12:46 2012 @@ -253,10 +253,11 @@ public class TestUtils { */ public static void assertEquals(final String message, final double[] expected, final RealVector actual, final double delta) { -Assert.assertEquals(message + ", dimension", expected.length, +final String msgAndSep = message.equals("") ? "" : message + ", "; +Assert.assertEquals(msgAndSep + "dimension", expected.length, actual.getDimension()); for (int i = 0; i < expected.length; i++) { -Assert.assertEquals(message + ", entry #" + i, expected[i], +Assert.assertEquals(msgAndSep + "entry #" + i, expected[i], actual.getEntry(i), delta); } } @@ -274,11 +275,12 @@ public class TestUtils { */ public static void assertEquals(final String message, final RealVector expected, final RealVector actual, final double delta) { -Assert.assertEquals(message + ", dimension", expected.getDimension(), +final String msgAndSep = message.equals("") ? "" : message + ", "; +Assert.assertEquals(msgAndSep + "dimension", expected.getDimension(), actual.getDimension()); final int dim = expected.getDimension(); for (int i = 0; i < dim; i++) { -Assert.assertEquals(message + ", entry #" + i, +Assert.assertEquals(msgAndSep + "entry #" + i, expected.getEntry(i), actual.getEntry(i), delta); } }
svn commit: r1347395 - in /commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear: RealVectorAbstractTest.java RealVectorTest.java
Author: celestin Date: Thu Jun 7 05:22:52 2012 New Revision: 1347395 URL: http://svn.apache.org/viewvc?rev=1347395&view=rev Log: MATH-795: - added in RealVectorAbstractTest tests for RealVector.getEntry() preconditions, - modified exceptions thrown in RealVectorTest.TestVectorImpl accordingly. Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorTest.java Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java?rev=1347395&r1=1347394&r2=1347395&view=diff == --- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java Thu Jun 7 05:22:52 2012 @@ -154,6 +154,16 @@ public abstract class RealVectorAbstract } } +@Test(expected=OutOfRangeException.class) +public void testGetEntryInvalidIndex1() { +create(data1).getEntry(-1); +} + +@Test(expected=OutOfRangeException.class) +public void testGetEntryInvalidIndex2() { +create(data1).getEntry(data1.length); +} + private void doTestAppendVector(final String message, final RealVector v1, final RealVector v2, final double delta) { Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorTest.java?rev=1347395&r1=1347394&r2=1347395&view=diff == --- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorTest.java Thu Jun 7 05:22:52 2012 @@ -22,6 +22,8 @@ import org.junit.Test; import org.junit.Assert; import org.apache.commons.math3.analysis.UnivariateFunction; import org.apache.commons.math3.exception.DimensionMismatchException; +import org.apache.commons.math3.exception.OutOfRangeException; +import org.apache.commons.math3.exception.util.LocalizedFormats; import org.apache.commons.math3.linear.RealVector.Entry; import org.apache.commons.math3.util.MathArrays; @@ -125,12 +127,22 @@ public class RealVectorTest extends Real @Override public double getEntry(int index) { -return values[index]; +try { +return values[index]; +} catch (IndexOutOfBoundsException e) { +throw new OutOfRangeException(LocalizedFormats.INDEX, index, 0, +getDimension() - 1); +} } @Override public void setEntry(int index, double value) { -values[index] = value; +try { +values[index] = value; +} catch (IndexOutOfBoundsException e) { +throw new OutOfRangeException(LocalizedFormats.INDEX, index, 0, +getDimension() - 1); +} } @Override
svn commit: r1347401 - /commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java
Author: celestin Date: Thu Jun 7 05:45:44 2012 New Revision: 1347401 URL: http://svn.apache.org/viewvc?rev=1347401&view=rev Log: MATH-795: splitted tests for - RealVector.setEntry(int, double), - RealVector.addToEntry(int, double). Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java?rev=1347401&r1=1347400&r2=1347401&view=diff == --- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java Thu Jun 7 05:45:44 2012 @@ -52,6 +52,7 @@ import org.apache.commons.math3.exceptio import org.apache.commons.math3.exception.NumberIsTooSmallException; import org.apache.commons.math3.exception.OutOfRangeException; import org.apache.commons.math3.util.FastMath; +import org.apache.commons.math3.util.MathArrays; import org.junit.Test; @@ -164,6 +165,96 @@ public abstract class RealVectorAbstract create(data1).getEntry(data1.length); } +@Test +public void testSetEntry() { +final double[] expected = MathArrays.copyOf(data1); +final RealVector actual = create(data1); + +/* + * Try setting to any value. + */ +for (int i = 0; i < data1.length; i++) { +final double oldValue = data1[i]; +final double newValue = oldValue + 1d; +expected[i] = newValue; +actual.setEntry(i, newValue); +TestUtils.assertEquals("while setting entry #" + i, expected, +actual, 0d); +expected[i] = oldValue; +actual.setEntry(i, oldValue); +} + +/* + * Try setting to the preferred value. + */ +final double x = getPreferredEntryValue(); +for (int i = 0; i < data1.length; i++) { +final double oldValue = data1[i]; +final double newValue = x; +expected[i] = newValue; +actual.setEntry(i, newValue); +TestUtils.assertEquals("while setting entry #" + i, expected, +actual, 0d); +expected[i] = oldValue; +actual.setEntry(i, oldValue); +} +} + +@Test(expected=OutOfRangeException.class) +public void testSetEntryInvalidIndex1() { +create(data1).setEntry(-1, getPreferredEntryValue()); +} + +@Test(expected=OutOfRangeException.class) +public void testSetEntryInvalidIndex2() { +create(data1).setEntry(data1.length, getPreferredEntryValue()); +} + +@Test +public void testAddToEntry() { +final double[] expected = MathArrays.copyOf(data1); +final RealVector actual = create(data1); + +/* + * Try adding any value. + */ +double increment = 1d; +for (int i = 0; i < data1.length; i++) { +final double oldValue = data1[i]; +expected[i] += increment; +actual.addToEntry(i, increment); +TestUtils.assertEquals("while incrementing entry #" + i, expected, +actual, 0d); +expected[i] = oldValue; +actual.setEntry(i, oldValue); +} + +/* + * Try incrementing so that result is equal to preferred value. + */ +final double x = getPreferredEntryValue(); +for (int i = 0; i < data1.length; i++) { +final double oldValue = data1[i]; +increment = x - oldValue; +expected[i] = x; +actual.addToEntry(i, increment); +TestUtils.assertEquals("while incrementing entry #" + i, expected, +actual, 0d); +expected[i] = oldValue; +actual.setEntry(i, oldValue); +} +} + +@Test(expected=OutOfRangeException.class) +public void testAddToEntryInvalidIndex1() { +create(data1).addToEntry(-1, getPreferredEntryValue()); +} + +@Test(expected=OutOfRangeException.class) +public void testAddToEntryInvalidIndex2() { +create(data1).addToEntry(data1.length, getPreferredEntryValue()); +} + private void doTestAppendVector(final String message, final RealVector v1, final RealVector v2, final double delta) { @@ -842,19 +933,6 @@ public abstract class RealVectorAbstract } @Test -public void testAddToEntry() { -final double[] v = new double[] { 1, 2, 3 }; -final RealVector x = create(v); -final double inc = 7; -for (int i = 0; i < x.getDimensi
svn commit: r1347717 - /commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/ArrayRealVector.java
Author: celestin Date: Thu Jun 7 17:10:48 2012 New Revision: 1347717 URL: http://svn.apache.org/viewvc?rev=1347717&view=rev Log: MATH-795: RealVectorTest.testAddToEntryInvalidIndex1() and RealVectorTest.testAddToEntryInvalidIndex2() revealed a bug in ArrayRealVector.addToEntry(int, double) (method used to throw wrong type of exception). Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/ArrayRealVector.java Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/ArrayRealVector.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/ArrayRealVector.java?rev=1347717&r1=1347716&r2=1347717&view=diff == --- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/ArrayRealVector.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/ArrayRealVector.java Thu Jun 7 17:10:48 2012 @@ -690,7 +690,12 @@ public class ArrayRealVector extends Rea /** {@inheritDoc} */ @Override public void addToEntry(int index, double increment) { +try { data[index] += increment; +} catch(IndexOutOfBoundsException e){ +throw new OutOfRangeException(LocalizedFormats.INDEX, + index, 0, data.length - 1); +} } /** {@inheritDoc} */
svn commit: r1347877 - in /commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear: RealVectorAbstractTest.java RealVectorTest.java
Author: celestin Date: Fri Jun 8 03:24:01 2012 New Revision: 1347877 URL: http://svn.apache.org/viewvc?rev=1347877&view=rev Log: MATH-795: extracted testGetSubVector() from RealVectorAbstractTest.testDataInOut(). Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorTest.java Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java?rev=1347877&r1=1347876&r2=1347877&view=diff == --- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java Fri Jun 8 03:24:01 2012 @@ -300,15 +300,24 @@ public abstract class RealVectorAbstract } @Test +public void testGetSubvector() { +final double x = getPreferredEntryValue(); +final double[] data = {x, x, x, 1d, x, 2d, x, x, 3d, x, x, x, 4d, x, x, x}; +final int index = 1; +final int n = data.length - 5; +final RealVector actual = create(data).getSubVector(index, n); +final double[] expected = new double[n]; +System.arraycopy(data, index, expected, 0, n); +TestUtils.assertEquals("", expected, actual, 0d); +} + +@Test public void testDataInOut() { final RealVector v1 = create(vec1); final RealVector v2 = create(vec2); final RealVector v4 = create(vec4); final RealVector v2_t = createAlien(vec2); -final RealVector vout5 = v4.getSubVector(3, 3); -Assert.assertEquals("testData len", 3, vout5.getDimension()); -Assert.assertEquals("testData is 4.0 ", 5.0, vout5.getEntry(1), 0); try { v4.getSubVector(3, 7); Assert.fail("OutOfRangeException expected"); Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorTest.java?rev=1347877&r1=1347876&r2=1347877&view=diff == --- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorTest.java Fri Jun 8 03:24:01 2012 @@ -213,6 +213,13 @@ public class RealVectorTest extends Real } @Test +@Ignore("Abstract class RealVector does not implement getSubvector(int, int)") +@Override +public void testGetSubvector() { +// Do nothing +} + +@Test @Ignore @Override public void testBasicFunctions() {
svn commit: r1347883 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math3/exception/util/ main/java/org/apache/commons/math3/linear/ main/resources/assets/org/apache/commons/math3/e
Author: celestin Date: Fri Jun 8 05:50:11 2012 New Revision: 1347883 URL: http://svn.apache.org/viewvc?rev=1347883&view=rev Log: MATH-795: extracted - testSubVectorInvalidIndex1(), - testSubVectorInvalidIndex2(), - testSubVectorInvalidIndex3(), - testSubVectorInvalidIndex4() from RealVectorAbstractTest.testDataInOut(). This test revealed that positivity of the number of elements was not checked for in RealVector.getSubVector(int, int). This is corrected, and a NotPositiveException is now thrown (corresponding error message has been added to LocalizedFormats). Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/exception/util/LocalizedFormats.java commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/ArrayRealVector.java commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/OpenMapRealVector.java commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/RealVector.java commons/proper/math/trunk/src/main/resources/assets/org/apache/commons/math3/exception/util/LocalizedFormats_fr.properties commons/proper/math/trunk/src/test/java/org/apache/commons/math3/exception/util/LocalizedFormatsTest.java commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorTest.java Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/exception/util/LocalizedFormats.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/exception/util/LocalizedFormats.java?rev=1347883&r1=1347882&r2=1347883&view=diff == --- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/exception/util/LocalizedFormats.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/exception/util/LocalizedFormats.java Fri Jun 8 05:50:11 2012 @@ -200,6 +200,7 @@ public enum LocalizedFormats implements NOT_POSITIVE_DEGREES_OF_FREEDOM("degrees of freedom must be positive ({0})"), NOT_POSITIVE_ELEMENT_AT_INDEX("element {0} is not positive: {1}"), NOT_POSITIVE_EXPONENT("invalid exponent {0} (must be positive)"), +NUMBER_OF_ELEMENTS_SHOULD_BE_POSITIVE("number of elements should be positive ({0})"), EXPONENT("exponent ({0})"), /* keep */ NOT_POSITIVE_LENGTH("length must be positive ({0})"), LENGTH("length ({0})"), /* keep */ Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/ArrayRealVector.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/ArrayRealVector.java?rev=1347883&r1=1347882&r2=1347883&view=diff == --- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/ArrayRealVector.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/ArrayRealVector.java Fri Jun 8 05:50:11 2012 @@ -21,6 +21,7 @@ import java.util.Arrays; import java.util.Iterator; import org.apache.commons.math3.analysis.UnivariateFunction; +import org.apache.commons.math3.exception.NotPositiveException; import org.apache.commons.math3.exception.NullArgumentException; import org.apache.commons.math3.exception.DimensionMismatchException; import org.apache.commons.math3.exception.NumberIsTooLargeException; @@ -667,6 +668,9 @@ public class ArrayRealVector extends Rea /** {@inheritDoc} */ @Override public RealVector getSubVector(int index, int n) { +if (n < 0) { +throw new NotPositiveException(LocalizedFormats.NUMBER_OF_ELEMENTS_SHOULD_BE_POSITIVE, n); +} ArrayRealVector out = new ArrayRealVector(n); try { System.arraycopy(data, index, out.data, 0, n); Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/OpenMapRealVector.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/OpenMapRealVector.java?rev=1347883&r1=1347882&r2=1347883&view=diff == --- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/OpenMapRealVector.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/OpenMapRealVector.java Fri Jun 8 05:50:11 2012 @@ -19,6 +19,7 @@ package org.apache.commons.math3.linear; import java.io.Serializable; import org.apache.commons.math3.exception.MathArithmeticException; +import org.apache.commons.math3.exception.NotPositiveException; import org.apache.commons.math3.exception.util
svn commit: r1348211 - in /commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear: RealVectorAbstractTest.java RealVectorTest.java
Author: celestin Date: Fri Jun 8 19:56:42 2012 New Revision: 1348211 URL: http://svn.apache.org/viewvc?rev=1348211&view=rev Log: MATH-795: in RealVectorAbstractTest, added unit tests for RealVector.setSubVector(int, RealVector). Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorTest.java Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java?rev=1348211&r1=1348210&r2=1348211&view=diff == --- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java Fri Jun 8 19:56:42 2012 @@ -337,6 +337,51 @@ public abstract class RealVectorAbstract } @Test +public void testSetSubVectorSameType() { +final double x = getPreferredEntryValue(); +final double[] expected = {x, x, x, 1d, x, 2d, x, x, 3d, x, x, x, 4d, x, x, x}; +final double[] sub = {5d, x, 6d, 7d, 8d}; +final RealVector actual = create(expected); +final int index = 2; +actual.setSubVector(index, create(sub)); + +for (int i = 0; i < sub.length; i++){ +expected[index + i] = sub[i]; +} +TestUtils.assertEquals("", expected, actual, 0d); +} + +@Test +public void testSetSubVectorMixedType() { +final double x = getPreferredEntryValue(); +final double[] expected = {x, x, x, 1d, x, 2d, x, x, 3d, x, x, x, 4d, x, x, x}; +final double[] sub = {5d, x, 6d, 7d, 8d}; +final RealVector actual = create(expected); +final int index = 2; +actual.setSubVector(index, createAlien(sub)); + +for (int i = 0; i < sub.length; i++){ +expected[index + i] = sub[i]; +} +TestUtils.assertEquals("", expected, actual, 0d); +} + +@Test(expected = OutOfRangeException.class) +public void testSetSubVectorInvalidIndex1() { +create(new double[10]).setSubVector(-1, create(new double[2])); +} + +@Test(expected = OutOfRangeException.class) +public void testSetSubVectorInvalidIndex2() { +create(new double[10]).setSubVector(10, create(new double[2])); +} + +@Test(expected = OutOfRangeException.class) +public void testSetSubVectorInvalidIndex3() { +create(new double[10]).setSubVector(9, create(new double[2])); +} + +@Test public void testDataInOut() { final RealVector v1 = create(vec1); final RealVector v2 = create(vec2); Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorTest.java?rev=1348211&r1=1348210&r2=1348211&view=diff == --- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorTest.java Fri Jun 8 19:56:42 2012 @@ -248,6 +248,41 @@ public class RealVectorTest extends Real } @Test +@Ignore("Abstract class RealVector does not implement setSubvector(int, RealVector)") +@Override +public void testSetSubVectorSameType() { +// Do nothing +} + +@Test +@Ignore("Abstract class RealVector does not implement setSubvector(int, RealVector)") +@Override +public void testSetSubVectorMixedType() { +// Do nothing +} + +@Test +@Ignore("Abstract class RealVector does not implement setSubvector(int, RealVector)") +@Override +public void testSetSubVectorInvalidIndex1() { +// Do nothing +} + +@Test +@Ignore("Abstract class RealVector does not implement setSubvector(int, RealVector)") +@Override +public void testSetSubVectorInvalidIndex2() { +// Do nothing +} + +@Test +@Ignore("Abstract class RealVector does not implement setSubvector(int, RealVector)") +@Override +public void testSetSubVectorInvalidIndex3() { +// Do nothing +} + +@Test @Ignore @Override public void testBasicFunctions() {
svn commit: r1348225 - in /commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear: RealVectorAbstractTest.java RealVectorTest.java
Author: celestin Date: Fri Jun 8 20:10:49 2012 New Revision: 1348225 URL: http://svn.apache.org/viewvc?rev=1348225&view=rev Log: MATH-795: in RealVectorAbstractTest, extracted testIsNaN() from testPredicates(). Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorTest.java Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java?rev=1348225&r1=1348224&r2=1348225&view=diff == --- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java Fri Jun 8 20:10:49 2012 @@ -382,6 +382,15 @@ public abstract class RealVectorAbstract } @Test +public void testIsNaN() { +final RealVector v = create(new double[] {0, 1, 2}); + +Assert.assertFalse(v.isNaN()); +v.setEntry(1, Double.NaN); +Assert.assertTrue(v.isNaN()); +} + +@Test public void testDataInOut() { final RealVector v1 = create(vec1); final RealVector v2 = create(vec2); Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorTest.java?rev=1348225&r1=1348224&r2=1348225&view=diff == --- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorTest.java Fri Jun 8 20:10:49 2012 @@ -283,6 +283,13 @@ public class RealVectorTest extends Real } @Test +@Ignore("Abstract class RealVector does not implement isNaN()") +@Override +public void testIsNaN() { +// Do nothing +} + +@Test @Ignore @Override public void testBasicFunctions() {
svn commit: r1348228 - in /commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear: RealVectorAbstractTest.java RealVectorTest.java
Author: celestin Date: Fri Jun 8 20:18:10 2012 New Revision: 1348228 URL: http://svn.apache.org/viewvc?rev=1348228&view=rev Log: MATH-795: in RealVectorAbstractTest, extracted testIsInfinite() from testPredicates(). Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorTest.java Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java?rev=1348228&r1=1348227&r2=1348228&view=diff == --- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java Fri Jun 8 20:18:10 2012 @@ -391,6 +391,17 @@ public abstract class RealVectorAbstract } @Test +public void testIsInfinite() { +final RealVector v = create(new double[] { 0, 1, 2 }); + +Assert.assertFalse(v.isInfinite()); +v.setEntry(0, Double.POSITIVE_INFINITY); +Assert.assertTrue(v.isInfinite()); +v.setEntry(1, Double.NaN); +Assert.assertFalse(v.isInfinite()); +} + +@Test public void testDataInOut() { final RealVector v1 = create(vec1); final RealVector v2 = create(vec2); @@ -985,16 +996,6 @@ public abstract class RealVectorAbstract public void testPredicates() { final RealVector v = create(new double[] { 0, 1, 2 }); -Assert.assertFalse(v.isNaN()); -v.setEntry(1, Double.NaN); -Assert.assertTrue(v.isNaN()); - -Assert.assertFalse(v.isInfinite()); -v.setEntry(0, Double.POSITIVE_INFINITY); -Assert.assertFalse(v.isInfinite()); -v.setEntry(1, 1); -Assert.assertTrue(v.isInfinite()); - v.setEntry(0, 0); Assert.assertEquals(v, create(new double[] { 0, 1, 2 })); Assert.assertNotSame(v, create(new double[] { 0, 1, 2 + FastMath.ulp(2)})); Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorTest.java?rev=1348228&r1=1348227&r2=1348228&view=diff == --- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorTest.java Fri Jun 8 20:18:10 2012 @@ -290,6 +290,13 @@ public class RealVectorTest extends Real } @Test +@Ignore("Abstract class RealVector does not implement isNaN()") +@Override +public void testIsInfinite() { +// Do nothing +} + +@Test @Ignore @Override public void testBasicFunctions() {
svn commit: r1348396 - /commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/RealVector.java
Author: celestin Date: Sat Jun 9 13:11:38 2012 New Revision: 1348396 URL: http://svn.apache.org/viewvc?rev=1348396&view=rev Log: MATH-802. Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/RealVector.java Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/RealVector.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/RealVector.java?rev=1348396&r1=1348395&r2=1348396&view=diff == --- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/RealVector.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/RealVector.java Sat Jun 9 13:11:38 2012 @@ -248,12 +248,12 @@ public abstract class RealVector { * if {@code v} is not the same size as this vector. */ public RealVector subtract(RealVector v) { -RealVector result = v.copy(); +RealVector result = v.mapMultiply(-1d); Iterator it = sparseIterator(); while (it.hasNext()) { final Entry e = it.next(); final int index = e.getIndex(); -result.setEntry(index, e.getValue() - result.getEntry(index)); +result.setEntry(index, e.getValue() + result.getEntry(index)); } return result; }
svn commit: r1348438 - /commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/RealVector.java
Author: celestin Date: Sat Jun 9 16:00:05 2012 New Revision: 1348438 URL: http://svn.apache.org/viewvc?rev=1348438&view=rev Log: MATH-795: in RealVector.add(RealVector) and RealVector.subtract(RealVector) (default implementation), exceptional cases were not handled properly. Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/RealVector.java Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/RealVector.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/RealVector.java?rev=1348438&r1=1348437&r2=1348438&view=diff == --- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/RealVector.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/RealVector.java Sat Jun 9 16:00:05 2012 @@ -228,6 +228,7 @@ public abstract class RealVector { * if {@code v} is not the same size as this vector. */ public RealVector add(RealVector v) { +checkVectorDimensions(v); RealVector result = v.copy(); Iterator it = sparseIterator(); while (it.hasNext()) { @@ -248,6 +249,7 @@ public abstract class RealVector { * if {@code v} is not the same size as this vector. */ public RealVector subtract(RealVector v) { +checkVectorDimensions(v); RealVector result = v.mapMultiply(-1d); Iterator it = sparseIterator(); while (it.hasNext()) {
svn commit: r1348485 - in /commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear: RealVectorAbstractTest.java RealVectorTest.java
Author: celestin Date: Sat Jun 9 18:59:44 2012 New Revision: 1348485 URL: http://svn.apache.org/viewvc?rev=1348485&view=rev Log: MATH-795 - In RealVectorTest.TestVectorImpl, removed add(RealVector) and subtract(RealVector), as they prevented testing of default implementations (provided in the RealVector abstract class). - In RealVectorAbstractTest, extracted unit tests for + RealVector.add(RealVector), + RealVector.subtract(RealVector), + RealVector.ebeMultiply(RealVector), + RealVector.ebeDivide(RealVector). These tests fail with OpenMapRealVector. This is identified as a bug (see MATH-803). Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorTest.java Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java?rev=1348485&r1=1348484&r2=1348485&view=diff == --- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java Sat Jun 9 18:59:44 2012 @@ -19,8 +19,6 @@ package org.apache.commons.math3.linear; import java.util.Arrays; import java.util.Random; -import junit.framework.Assert; - import org.apache.commons.math3.TestUtils; import org.apache.commons.math3.analysis.function.Abs; import org.apache.commons.math3.analysis.function.Acos; @@ -54,10 +52,16 @@ import org.apache.commons.math3.exceptio import org.apache.commons.math3.exception.OutOfRangeException; import org.apache.commons.math3.util.FastMath; import org.apache.commons.math3.util.MathArrays; +import org.junit.Assert; import org.junit.Test; public abstract class RealVectorAbstractTest { + +private enum BinaryOperation { +ADD, SUB, MUL, DIV +}; + /** * Creates a new instance of {@link RealVector}, with specified entries. * The returned vector must be of the type currently tested. It should be @@ -401,6 +405,201 @@ public abstract class RealVectorAbstract Assert.assertFalse(v.isInfinite()); } +private void doTestEbeBinaryOperation(final BinaryOperation op, final boolean mixed) { +/* + * Make sure that x, y, z are three different values. Also, x is the + * preferred value (e.g. the value which is not stored in sparse + * implementations). + */ +final double x = getPreferredEntryValue(); +final double y = x + 1d; +final double z = y + 1d; + +/* + * This is an attempt at covering most particular cases of combining + * two values. + * + * 1. Addition + * + * The following cases should be covered + * (2 * x) + (-x) + * (-x) + 2 * x + * x + y + * y + x + * y + z + * y + (x - y) + * (y - x) + x + * + * The values to be considered are: x, y, z, 2 * x, -x, x - y, y - x. + * + * 2. Subtraction + *--- + * The following cases should be covered + * (2 * x) - x + * x - y + * y - x + * y - z + * y - (y - x) + * (y + x) - y + * + * The values to be considered are: x, y, z, x + y, y - x. + * + * 3. Multiplication + *-- + * (x * x) * (1 / x) + * (1 / x) * (x * x) + * x * y + * y * x + * y * z + * + * The values to be considered are: x, y, z, 1 / x, x * x. + * + * 4. Division + * + * (x * x) / x + * x / y + * y / x + * y / z + * + * The values to be considered are: x, y, z, x * x. + * + * Also to be considered NaN, POSITIVE_INFINITY, NEGATIVE_INFINITY. + */ +final double[] values = {x, y, z, 2 * x, -x, 1 / x, x * x, x + y, x - y, y - x}; +final double[] data1 = new double[values.length * values.length]; +final double[] data2 = new double[values.length * values.length]; +int k = 0; +for (int i = 0; i < values.length; i++) { +for (int j = 0; j < values.length; j++) { +data1[k] = values[i]; +data2[k] = values[j]; +++k; +} +} +final RealVector v1 = create(data1); +final RealVector v2 = mixed ? createAlien(data2) : create(data2); +final RealVector actual; +switch (op) { +case ADD: +actual = v1.add(v2);
svn commit: r1348721 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math3/linear/OpenMapRealVector.java test/java/org/apache/commons/math3/linear/SparseRealVectorTest.java
Author: celestin Date: Mon Jun 11 05:52:16 2012 New Revision: 1348721 URL: http://svn.apache.org/viewvc?rev=1348721&view=rev Log: MATH-803: - modified OpenMapRealVector.ebeMultiply() and ebeDivide() to handle special cases 0d * NaN, 0d * Infinity, 0d / 0d and 0d / NaN. - added implementation of isNaN() and isInfinite() to SparseRealVectorTest.SparseRealVectorTestImpl in order to allow for testing of OpenMapRealVector.ebeMultiply() and ebeDivide() with mixed types. Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/OpenMapRealVector.java commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/SparseRealVectorTest.java Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/OpenMapRealVector.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/OpenMapRealVector.java?rev=1348721&r1=1348720&r2=1348721&view=diff == --- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/OpenMapRealVector.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/OpenMapRealVector.java Mon Jun 11 05:52:16 2012 @@ -341,10 +341,14 @@ public class OpenMapRealVector extends S public OpenMapRealVector ebeDivide(RealVector v) { checkVectorDimensions(v.getDimension()); OpenMapRealVector res = new OpenMapRealVector(this); -Iterator iter = entries.iterator(); -while (iter.hasNext()) { -iter.advance(); -res.setEntry(iter.key(), iter.value() / v.getEntry(iter.key())); +/* + * MATH-803: it is not sufficient to loop through non zero entries of + * this only. Indeed, if this[i] = 0d and v[i] = 0d, then + * this[i] / v[i] = NaN, and not 0d. + */ +final int n = getDimension(); +for (int i = 0; i < n; i++) { +res.setEntry(i, this.getEntry(i) / v.getEntry(i)); } return res; } @@ -359,6 +363,25 @@ public class OpenMapRealVector extends S iter.advance(); res.setEntry(iter.key(), iter.value() * v.getEntry(iter.key())); } +/* + * MATH-803: the above loop assumes that 0d * x = 0d for any double x, + * which allows to consider only the non-zero entries of this. However, + * this fails if this[i] == 0d and (v[i] = NaN or v[i] = Infinity). + * + * These special cases are handled below. + */ +if (v.isNaN() || v.isInfinite()) { +final int n = getDimension(); +for (int i = 0; i < n; i++) { +final double y = v.getEntry(i); +if (Double.isNaN(y)) { +res.setEntry(i, Double.NaN); +} else if (Double.isInfinite(y)) { +final double x = this.getEntry(i); +res.setEntry(i, x * y); +} +} +} return res; } Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/SparseRealVectorTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/SparseRealVectorTest.java?rev=1348721&r1=1348720&r2=1348721&view=diff == --- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/SparseRealVectorTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/SparseRealVectorTest.java Mon Jun 11 05:52:16 2012 @@ -237,14 +237,25 @@ public class SparseRealVectorTest extend @Override public boolean isNaN() { -throw unsupported(); +boolean isNaN = false; +for (int i = 0; i < data.length; i++) { +isNaN |= Double.isNaN(data[i]); +} +return isNaN; } @Override public boolean isInfinite() { -throw unsupported(); +boolean isInfinite = false; +for (int i = 0; i < data.length; i++) { +final double x = data[i]; +if (Double.isNaN(x)) { +return false; +} +isInfinite |= Double.isInfinite(x); +} +return isInfinite; } - } @Override
svn commit: r1352782 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math3/linear/ test/java/org/apache/commons/math3/linear/
Author: celestin Date: Fri Jun 22 07:06:28 2012 New Revision: 1352782 URL: http://svn.apache.org/viewvc?rev=1352782&view=rev Log: MATH-803 : deprecated RealVector.ebeMultiply() and RealVector.ebeDivide(), and updated unit tests accordingly. Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/RealVector.java commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/UnmodifiableRealVectorAbstractTest.java Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/RealVector.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/RealVector.java?rev=1352782&r1=1352781&r2=1352782&view=diff == --- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/RealVector.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/RealVector.java Fri Jun 22 07:06:28 2012 @@ -336,7 +336,17 @@ public abstract class RealVector { * @return a vector containing this[i] / v[i] for all i. * @throws org.apache.commons.math3.exception.DimensionMismatchException * if {@code v} is not the same size as this vector. + * @deprecated As of version 3.1, this method is deprecated, and will be + * removed in version 4.0. This decision follows the discussion reported in + * https://issues.apache.org/jira/browse/MATH-803?focusedCommentId=13399150#comment-13399150";>MATH-803. + * Uses of this method involving sparse implementations of + * {@link RealVector} might lead to wrong results. Since there is no + * satisfactory correction to this bug, this method is deprecated. Users who + * want to preserve this feature are advised to implement + * {@link RealVectorPreservingVisitor} (possibly ignoring corner cases for + * the sake of efficiency). */ +@Deprecated public abstract RealVector ebeDivide(RealVector v); /** @@ -346,7 +356,17 @@ public abstract class RealVector { * @return a vector containing this[i] * v[i] for all i. * @throws org.apache.commons.math3.exception.DimensionMismatchException * if {@code v} is not the same size as this vector. + * @deprecated As of version 3.1, this method is deprecated, and will be + * removed in version 4.0. This decision follows the discussion reported in + * https://issues.apache.org/jira/browse/MATH-803?focusedCommentId=13399150#comment-13399150";>MATH-803. + * Uses of this method involving sparse implementations of + * {@link RealVector} might lead to wrong results. Since there is no + * satisfactory correction to this bug, this method is deprecated. Users who + * want to preserve this feature are advised to implement + * {@link RealVectorPreservingVisitor} (possibly ignoring corner cases for + * the sake of efficiency). */ +@Deprecated public abstract RealVector ebeMultiply(RealVector v); /** Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java?rev=1352782&r1=1352781&r2=1352782&view=diff == --- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java Fri Jun 22 07:06:28 2012 @@ -53,6 +53,7 @@ import org.apache.commons.math3.exceptio import org.apache.commons.math3.util.FastMath; import org.apache.commons.math3.util.MathArrays; import org.junit.Assert; +import org.junit.Ignore; import org.junit.Test; @@ -463,9 +464,14 @@ public abstract class RealVectorAbstract * * The values to be considered are: x, y, z, x * x. * - * Also to be considered NaN, POSITIVE_INFINITY, NEGATIVE_INFINITY. + * Also to be considered NaN, POSITIVE_INFINITY, NEGATIVE_INFINITY, + * +0.0, -0.0. */ -final double[] values = {x, y, z, 2 * x, -x, 1 / x, x * x, x + y, x - y, y - x}; +final double[] values = +{ +Double.NaN, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, +0d, -0d, x, y, z, 2 * x, -x, 1 / x, x * x, x + y, x - y, y - x +}; final double[] data1 = new double[values.length * values.length]; final double[] data2 = new double[values.length * values.length]; int k = 0; @@ -570,31 +576,37 @@ public abstract class RealVectorAbstract doTestEbeBinaryOp
svn commit: r1353140 - /commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/Incrementor.java
Author: celestin Date: Sat Jun 23 15:09:14 2012 New Revision: 1353140 URL: http://svn.apache.org/viewvc?rev=1353140&view=rev Log: In o.a.c.m3.Incrementor, modified constructor to allow for null values of the MaxCountExceededCallback. Null value was previously not checked wich could lead to a NullPointerException much later (at exhaustion of the counter). Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/Incrementor.java Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/Incrementor.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/Incrementor.java?rev=1353140&r1=1353139&r2=1353140&view=diff == --- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/Incrementor.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/Incrementor.java Sat Jun 23 15:09:14 2012 @@ -58,13 +58,7 @@ public class Incrementor { * @param max Maximal count. */ public Incrementor(int max) { -this(max, - new MaxCountExceededCallback() { - /** {@inheritDoc} */ - public void trigger(int max) { - throw new MaxCountExceededException(max); - } - }); +this(max, null); } /** @@ -72,12 +66,22 @@ public class Incrementor { * counter exhaustion. * * @param max Maximal count. - * @param cb Function to be called when the maximal count has been reached. + * @param cb Function to be called when the maximal count has been reached + * (can be {@code null}). */ public Incrementor(int max, MaxCountExceededCallback cb) { maximalCount = max; -maxCountCallback = cb; +if (cb != null) { +maxCountCallback = cb; +} else { +maxCountCallback = new MaxCountExceededCallback() { +/** {@inheritDoc} */ +public void trigger(int max) { +throw new MaxCountExceededException(max); +} +}; +} } /**
svn commit: r1353141 - in /commons/proper/math/trunk/src: changes/ main/java/org/apache/commons/math3/linear/ main/java/org/apache/commons/math3/util/
Author: celestin Date: Sat Jun 23 15:12:34 2012 New Revision: 1353141 URL: http://svn.apache.org/viewvc?rev=1353141&view=rev Log: MATH-807: in o.a.c.m3.util.IterationManager, created a new constructor which allows for the specification of a o.a.c.m3.util.Incrementor.MaxCountExceededCallback, to be called when the maximum number of iterations is reached. Updated the javadoc of iterative linear solvers accordingly. Modified: commons/proper/math/trunk/src/changes/changes.xml commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/IterativeLinearSolver.java commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/PreconditionedIterativeLinearSolver.java commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/SymmLQ.java commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/IterationManager.java Modified: commons/proper/math/trunk/src/changes/changes.xml URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/changes/changes.xml?rev=1353141&r1=1353140&r2=1353141&view=diff == --- commons/proper/math/trunk/src/changes/changes.xml (original) +++ commons/proper/math/trunk/src/changes/changes.xml Sat Jun 23 15:12:34 2012 @@ -52,6 +52,11 @@ If the output is not quite correct, chec + +Added a new constructor to o.a.c.m.utils.IterationManager, allowing +for the specification of a callback function in case the maximum +number of iteration is reached. + A new HermiteInterpolator class allow interpolation of vector-valued functions using both values and derivatives of the function at sample Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/IterativeLinearSolver.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/IterativeLinearSolver.java?rev=1353141&r1=1353140&r2=1353141&view=diff == --- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/IterativeLinearSolver.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/IterativeLinearSolver.java Sat Jun 23 15:12:34 2012 @@ -115,7 +115,7 @@ public abstract class IterativeLinearSol * @throws MaxCountExceededException at exhaustion of the iteration count, * unless a custom * {@link org.apache.commons.math3.util.Incrementor.MaxCountExceededCallback callback} - * has been set at construction + * has been set at construction of the {@link IterationManager} */ public RealVector solve(final RealLinearOperator a, final RealVector b) throws NullArgumentException, NonSquareOperatorException, @@ -141,7 +141,7 @@ public abstract class IterativeLinearSol * @throws MaxCountExceededException at exhaustion of the iteration count, * unless a custom * {@link org.apache.commons.math3.util.Incrementor.MaxCountExceededCallback callback} - * has been set at construction + * has been set at construction of the {@link IterationManager} */ public RealVector solve(RealLinearOperator a, RealVector b, RealVector x0) throws NullArgumentException, NonSquareOperatorException, @@ -166,7 +166,7 @@ public abstract class IterativeLinearSol * @throws MaxCountExceededException at exhaustion of the iteration count, * unless a custom * {@link org.apache.commons.math3.util.Incrementor.MaxCountExceededCallback callback} - * has been set at construction + * has been set at construction of the {@link IterationManager} */ public abstract RealVector solveInPlace(RealLinearOperator a, RealVector b, RealVector x0) throws NullArgumentException, NonSquareOperatorException, Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/PreconditionedIterativeLinearSolver.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/PreconditionedIterativeLinearSolver.java?rev=1353141&r1=1353140&r2=1353141&view=diff == --- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/PreconditionedIterativeLinearSolver.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/PreconditionedIterativeLinearSolver.java Sat Jun 23 15:12:34 2012 @@ -88,7 +88,7 @@ public abstract class PreconditionedIter * @throws MaxCountExceededException at exhaustion of the iteration count, * unless a custom * {@link org.apache.commons.math3.util.Incrementor.MaxCountExceededCallback callback} - * has been set at construction + * has been set at construction of the {@lin
svn commit: r1353386 - in /commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util: Incrementor.java IterationManager.java
Author: celestin Date: Mon Jun 25 05:22:58 2012 New Revision: 1353386 URL: http://svn.apache.org/viewvc?rev=1353386&view=rev Log: Reverted changes committed in r1353140. In o.a.c.m3.util.Incrementor, a NullPointerException is now thrown if the call-back function specified at construction is null. o.a.c.m3.util.IterationManager was updated accordingly (used to explicitely use the constructor with null argument). Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/Incrementor.java commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/IterationManager.java Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/Incrementor.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/Incrementor.java?rev=1353386&r1=1353385&r2=1353386&view=diff == --- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/Incrementor.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/Incrementor.java Mon Jun 25 05:22:58 2012 @@ -58,7 +58,13 @@ public class Incrementor { * @param max Maximal count. */ public Incrementor(int max) { -this(max, null); +this(max, + new MaxCountExceededCallback() { + /** {@inheritDoc} */ + public void trigger(int max) { + throw new MaxCountExceededException(max); + } + }); } /** @@ -66,22 +72,16 @@ public class Incrementor { * counter exhaustion. * * @param max Maximal count. - * @param cb Function to be called when the maximal count has been reached - * (can be {@code null}). + * @param cb Function to be called when the maximal count has been reached. + * @throws NullPointerException if {@code cb} is {@code null} */ public Incrementor(int max, MaxCountExceededCallback cb) { -maximalCount = max; -if (cb != null) { -maxCountCallback = cb; -} else { -maxCountCallback = new MaxCountExceededCallback() { -/** {@inheritDoc} */ -public void trigger(int max) { -throw new MaxCountExceededException(max); -} -}; +if (cb == null){ +throw new NullPointerException(); } +maximalCount = max; +maxCountCallback = cb; } /** Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/IterationManager.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/IterationManager.java?rev=1353386&r1=1353385&r2=1353386&view=diff == --- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/IterationManager.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/IterationManager.java Mon Jun 25 05:22:58 2012 @@ -43,7 +43,8 @@ public class IterationManager { * @param maxIterations the maximum number of iterations */ public IterationManager(final int maxIterations) { -this(maxIterations, null); +this.iterations = new Incrementor(maxIterations); +this.listeners = new CopyOnWriteArrayList(); } /** @@ -51,10 +52,14 @@ public class IterationManager { * * @param maxIterations the maximum number of iterations * @param callBack the function to be called when the maximum number of - * iterations has been reached (can be {@code null}) + * iterations has been reached + * @throws NullPointerException if {@code callBack} is {@code null} */ public IterationManager(final int maxIterations, final Incrementor.MaxCountExceededCallback callBack) { +if (callBack == null) { +throw new NullPointerException(); +} this.iterations = new Incrementor(maxIterations, callBack); this.listeners = new CopyOnWriteArrayList(); }
svn commit: r1353387 - /commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java
Author: celestin Date: Mon Jun 25 05:42:09 2012 New Revision: 1353387 URL: http://svn.apache.org/viewvc?rev=1353387&view=rev Log: MATH-795: factored out unit tests of getDistance and getNorm. Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java?rev=1353387&r1=1353386&r2=1353387&view=diff == --- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java Mon Jun 25 05:42:09 2012 @@ -612,6 +612,51 @@ public abstract class RealVectorAbstract doTestEbeBinaryOperationDimensionMismatch(BinaryOperation.DIV); } +private void doTestGetDistance(final boolean mixed) { +final double x = getPreferredEntryValue(); +final double[] data1 = new double[] { x, x, 1d, x, 2d, x, x, 3d, x }; +final double[] data2 = new double[] { 4d, x, x, 5d, 6d, 7d, x, x, 8d }; +final RealVector v1 = create(data1); +final RealVector v2; +if (mixed) { +v2 = createAlien(data2); +} else { +v2 = create(data2); +} +final double actual = v1.getDistance(v2); +double expected = 0d; +for (int i = 0; i < data1.length; i++) { +final double delta = data2[i] - data1[i]; +expected += delta * delta; +} +expected = FastMath.sqrt(expected); +Assert.assertEquals("", expected, actual, 0d); +} + +@Test +public void testGetDistanceSameType() { +doTestGetDistance(false); +} + +@Test +public void testGetDistanceMixedTypes() { +doTestGetDistance(true); +} + +@Test +public void testGetNorm() { +final double x = getPreferredEntryValue(); +final double[] data = new double[] { x, x, 1d, x, 2d, x, x, 3d, x }; +final RealVector v = create(data); +final double actual = v.getNorm(); +double expected = 0d; +for (int i = 0; i < data.length; i++) { +expected += data[i] * data[i]; +} +expected = FastMath.sqrt(expected); +Assert.assertEquals("", expected, actual, 0d); +} + @Test public void testDataInOut() { final RealVector v1 = create(vec1); @@ -1022,16 +1067,6 @@ public abstract class RealVectorAbstract Assert.assertEquals("compare values ", 6.0, d_getLInfNorm, normTolerance); -// octave = sqrt(sumsq(v1-v2)) -double dist = v1.getDistance(v2); -Assert.assertEquals("compare values ", v1.subtract(v2).getNorm(), -dist, normTolerance); - -// octave = sqrt(sumsq(v1-v2)) -double dist_2 = v1.getDistance(v2_t); -Assert.assertEquals("compare values ", v1.subtract(v2).getNorm(), -dist_2, normTolerance); - // octave = ??? double d_getL1Distance = v1.getL1Distance(v2); Assert.assertEquals("compare values ", 9d, d_getL1Distance,
svn commit: r1353388 - in /commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear: RealVectorAbstractTest.java RealVectorTest.java
Author: celestin Date: Mon Jun 25 05:57:14 2012 New Revision: 1353388 URL: http://svn.apache.org/viewvc?rev=1353388&view=rev Log: MATH-795: factored out test of getL1Norm, getL1Distance, getLInfNorm, getLInfDistance. Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorTest.java Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java?rev=1353388&r1=1353387&r2=1353388&view=diff == --- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java Mon Jun 25 05:57:14 2012 @@ -643,6 +643,11 @@ public abstract class RealVectorAbstract doTestGetDistance(true); } +@Test(expected = DimensionMismatchException.class) +public void testGetDistanceDimensionMismatch() { +create(new double[4]).getDistance(createAlien(new double[5])); +} + @Test public void testGetNorm() { final double x = getPreferredEntryValue(); @@ -657,6 +662,104 @@ public abstract class RealVectorAbstract Assert.assertEquals("", expected, actual, 0d); } +private void doTestGetL1Distance(final boolean mixed) { +final double x = getPreferredEntryValue(); +final double[] data1 = new double[] { x, x, 1d, x, 2d, x, x, 3d, x }; +final double[] data2 = new double[] { 4d, x, x, 5d, 6d, 7d, x, x, 8d }; +final RealVector v1 = create(data1); +final RealVector v2; +if (mixed) { +v2 = createAlien(data2); +} else { +v2 = create(data2); +} +final double actual = v1.getL1Distance(v2); +double expected = 0d; +for (int i = 0; i < data1.length; i++) { +final double delta = data2[i] - data1[i]; +expected += FastMath.abs(delta); +} +Assert.assertEquals("", expected, actual, 0d); +} + +@Test +public void testGetL1DistanceSameType() { +doTestGetL1Distance(false); +} + +@Test +public void testGetL1DistanceMixedTypes() { +doTestGetL1Distance(true); +} + +@Test(expected = DimensionMismatchException.class) +public void testGetL1DistanceDimensionMismatch() { +create(new double[4]).getL1Distance(createAlien(new double[5])); +} + +@Test +public void testGetL1Norm() { +final double x = getPreferredEntryValue(); +final double[] data = new double[] { x, x, 1d, x, 2d, x, x, 3d, x }; +final RealVector v = create(data); +final double actual = v.getL1Norm(); +double expected = 0d; +for (int i = 0; i < data.length; i++) { +expected += FastMath.abs(data[i]); +} +Assert.assertEquals("", expected, actual, 0d); + +} + +private void doTestGetLInfDistance(final boolean mixed) { +final double x = getPreferredEntryValue(); +final double[] data1 = new double[] { x, x, 1d, x, 2d, x, x, 3d, x }; +final double[] data2 = new double[] { 4d, x, x, 5d, 6d, 7d, x, x, 8d }; +final RealVector v1 = create(data1); +final RealVector v2; +if (mixed) { +v2 = createAlien(data2); +} else { +v2 = create(data2); +} +final double actual = v1.getLInfDistance(v2); +double expected = 0d; +for (int i = 0; i < data1.length; i++) { +final double delta = data2[i] - data1[i]; +expected = FastMath.max(expected, FastMath.abs(delta)); +} +Assert.assertEquals("", expected, actual, 0d); +} + +@Test +public void testGetLInfDistanceSameType() { +doTestGetLInfDistance(false); +} + +@Test +public void testGetLInfDistanceMixedTypes() { +doTestGetLInfDistance(true); +} + +@Test(expected = DimensionMismatchException.class) +public void testGetLInfDistanceDimensionMismatch() { +create(new double[4]).getLInfDistance(createAlien(new double[5])); +} + +@Test +public void testGetLInfNorm() { +final double x = getPreferredEntryValue(); +final double[] data = new double[] { x, x, 1d, x, 2d, x, x, 3d, x }; +final RealVector v = create(data); +final double actual = v.getLInfNorm(); +double expected = 0d; +for (int i = 0; i < data.length; i++) { +expected = FastMath.max(expected, FastMath.abs(data[i])); +} +Assert.assertEquals(""
svn commit: r1353451 - in /commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util: Incrementor.java IterationManager.java
Author: celestin Date: Mon Jun 25 10:44:38 2012 New Revision: 1353451 URL: http://svn.apache.org/viewvc?rev=1353451&view=rev Log: Replaced NullPointerException with NullArgumentException. Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/Incrementor.java commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/IterationManager.java Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/Incrementor.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/Incrementor.java?rev=1353451&r1=1353450&r2=1353451&view=diff == --- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/Incrementor.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/Incrementor.java Mon Jun 25 10:44:38 2012 @@ -17,6 +17,7 @@ package org.apache.commons.math3.util; import org.apache.commons.math3.exception.MaxCountExceededException; +import org.apache.commons.math3.exception.NullArgumentException; /** * Utility that increments a counter until a maximum is reached, at @@ -73,12 +74,12 @@ public class Incrementor { * * @param max Maximal count. * @param cb Function to be called when the maximal count has been reached. - * @throws NullPointerException if {@code cb} is {@code null} + * @throws NullArgumentException if {@code cb} is {@code null} */ public Incrementor(int max, MaxCountExceededCallback cb) { if (cb == null){ -throw new NullPointerException(); +throw new NullArgumentException(); } maximalCount = max; maxCountCallback = cb; Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/IterationManager.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/IterationManager.java?rev=1353451&r1=1353450&r2=1353451&view=diff == --- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/IterationManager.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/IterationManager.java Mon Jun 25 10:44:38 2012 @@ -20,6 +20,7 @@ import java.util.Collection; import java.util.concurrent.CopyOnWriteArrayList; import org.apache.commons.math3.exception.MaxCountExceededException; +import org.apache.commons.math3.exception.NullArgumentException; /** * This abstract class provides a general framework for managing iterative @@ -53,12 +54,12 @@ public class IterationManager { * @param maxIterations the maximum number of iterations * @param callBack the function to be called when the maximum number of * iterations has been reached - * @throws NullPointerException if {@code callBack} is {@code null} + * @throws NullArgumentException if {@code callBack} is {@code null} */ public IterationManager(final int maxIterations, final Incrementor.MaxCountExceededCallback callBack) { if (callBack == null) { -throw new NullPointerException(); +throw new NullArgumentException(); } this.iterations = new Incrementor(maxIterations, callBack); this.listeners = new CopyOnWriteArrayList();
svn commit: r1353586 - /commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/IterationManager.java
Author: celestin Date: Mon Jun 25 15:00:11 2012 New Revision: 1353586 URL: http://svn.apache.org/viewvc?rev=1353586&view=rev Log: In the constructor of IterationManager, removed the check for null argument (already carried out in the constructor of Incrementor). Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/IterationManager.java Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/IterationManager.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/IterationManager.java?rev=1353586&r1=1353585&r2=1353586&view=diff == --- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/IterationManager.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/IterationManager.java Mon Jun 25 15:00:11 2012 @@ -58,9 +58,6 @@ public class IterationManager { */ public IterationManager(final int maxIterations, final Incrementor.MaxCountExceededCallback callBack) { -if (callBack == null) { -throw new NullArgumentException(); -} this.iterations = new Incrementor(maxIterations, callBack); this.listeners = new CopyOnWriteArrayList(); }
svn commit: r1353824 - /commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java
Author: celestin Date: Tue Jun 26 05:45:13 2012 New Revision: 1353824 URL: http://svn.apache.org/viewvc?rev=1353824&view=rev Log: MATH-795: factored out unit tests for RealVector.mapAdd(double), RealVector.mapSubtract(double), RealVector.mapDivide(double), RealVector.mapSubtract(double). Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java?rev=1353824&r1=1353823&r2=1353824&view=diff == --- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java Tue Jun 26 05:45:13 2012 @@ -760,6 +760,117 @@ public abstract class RealVectorAbstract } +private void doTestMapBinaryOperation(final BinaryOperation op, final boolean inPlace) { +final double x = getPreferredEntryValue(); +final double y = x + 1d; +final double z = y + 1d; +final double[] data = +{ +Double.NaN, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, +0d, -0d, x, y, z, 2 * x, -x, 1 / x, x * x, x + y, x - y, y - x +}; +final double[] expected = new double[data.length]; +for (int i = 0; i < data.length; i++) { +final double d = data[i]; +for (int j = 0; j < expected.length; j++) { +switch (op) { +case ADD: +expected[j] = data[j] + d; +break; +case SUB: +expected[j] = data[j] - d; +break; +case MUL: +expected[j] = data[j] * d; +break; +case DIV: +expected[j] = data[j] / d; +break; +default: +throw new AssertionError("unexpected value"); +} +} +final RealVector v = create(data); +final RealVector actual; +if (inPlace) { +switch (op) { +case ADD: +actual = v.mapAddToSelf(d); +break; +case SUB: +actual = v.mapSubtractToSelf(d); +break; +case MUL: +actual = v.mapMultiplyToSelf(d); +break; +case DIV: +actual = v.mapDivideToSelf(d); +break; +default: +throw new AssertionError("unexpected value"); +} +} else { +switch (op) { +case ADD: +actual = v.mapAdd(d); +break; +case SUB: +actual = v.mapSubtract(d); +break; +case MUL: +actual = v.mapMultiply(d); +break; +case DIV: +actual = v.mapDivide(d); +break; +default: +throw new AssertionError("unexpected value"); +} +} +TestUtils.assertEquals(Double.toString(d), expected, actual, 0d); +} +} + +@Test +public void testMapAdd() { +doTestMapBinaryOperation(BinaryOperation.ADD, false); +} + +@Test +public void testMapAddToSelf() { +doTestMapBinaryOperation(BinaryOperation.ADD, true); +} + +@Test +public void testMapSubtract() { +doTestMapBinaryOperation(BinaryOperation.SUB, false); +} + +@Test +public void testMapSubtractToSelf() { +doTestMapBinaryOperation(BinaryOperation.SUB, true); +} + +@Test +public void testMapMultiply() { +doTestMapBinaryOperation(BinaryOperation.MUL, false); +} + +@Test +public void testMapMultiplyToSelf() { +doTestMapBinaryOperation(BinaryOperation.MUL, true); +} + +@Test +public void testMapDivide() { +doTestMapBinaryOperation(BinaryOperation.DIV, false); +} + +@Test +public void testMapDivideToSelf() { +doTestMapBinaryOperation(BinaryOperation.DIV, true); +} + @Test public void testDataInOut() { final RealVector v1 = create(vec1); @@ -821,51 +932,6 @@ publi
svn commit: r1353825 - in /commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear: RealVectorAbstractTest.java RealVectorTest.java
Author: celestin Date: Tue Jun 26 06:09:27 2012 New Revision: 1353825 URL: http://svn.apache.org/viewvc?rev=1353825&view=rev Log: MATH-795: factored out unit tests for RealVector.map(UnivariateFunction) and RealVector.mapToSelf(UnivariateFunction). Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorTest.java Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java?rev=1353825&r1=1353824&r2=1353825&view=diff == --- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java Tue Jun 26 06:09:27 2012 @@ -20,6 +20,7 @@ import java.util.Arrays; import java.util.Random; import org.apache.commons.math3.TestUtils; +import org.apache.commons.math3.analysis.UnivariateFunction; import org.apache.commons.math3.analysis.function.Abs; import org.apache.commons.math3.analysis.function.Acos; import org.apache.commons.math3.analysis.function.Asin; @@ -871,6 +872,59 @@ public abstract class RealVectorAbstract doTestMapBinaryOperation(BinaryOperation.DIV, true); } +private void doTestMapFunction(final UnivariateFunction f, +final boolean inPlace) { +final double x = getPreferredEntryValue(); +final double y = x + 1d; +final double z = y + 1d; +final double[] data = +{ +Double.NaN, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, +0d, -0d, x, y, z, 2 * x, -x, 1 / x, x * x, x + y, x - y, y - x, +0.5 * FastMath.PI, -0.5 * FastMath.PI, FastMath.E, -FastMath.E, +1.0, -1.0 +}; +final double[] expected = new double[data.length]; +for (int i = 0; i < data.length; i++) { +expected[i] = f.value(data[i]); +} +final RealVector v = create(data); +final RealVector actual; +if (inPlace) { +actual = v.mapToSelf(f); +Assert.assertSame(v, actual); +} else { +actual = v.map(f); +} +TestUtils.assertEquals(f.getClass().getSimpleName(), expected, actual, 1E-16); +} + +private UnivariateFunction[] createFunctions() { +return new UnivariateFunction[] { +new Power(2.0), new Exp(), new Expm1(), new Log(), new Log10(), +new Log1p(), new Cosh(), new Sinh(), new Tanh(), new Cos(), +new Sin(), new Tan(), new Acos(), new Asin(), new Atan(), +new Inverse(), new Abs(), new Sqrt(), new Cbrt(), new Ceil(), +new Floor(), new Rint(), new Signum(), new Ulp() +}; +} + +@Test +public void testMap() { +final UnivariateFunction[] functions = createFunctions(); +for (UnivariateFunction f : functions) { +doTestMapFunction(f, false); +} +} + +@Test +public void testMapToSelf() { +final UnivariateFunction[] functions = createFunctions(); +for (UnivariateFunction f : functions) { +doTestMapFunction(f, true); +} +} + @Test public void testDataInOut() { final RealVector v1 = create(vec1); @@ -929,290 +983,6 @@ public abstract class RealVectorAbstract } @Test -public void testMapFunctions() { -final RealVector v1 = create(vec1); - -//octave = v1 .^ 2.0 -RealVector v_mapPow = v1.map(new Power(2)); -double[] result_mapPow = {1d, 4d, 9d}; -assertClose("compare vectors" ,result_mapPow,v_mapPow.toArray(),normTolerance); - -//octave = v1 .^ 2.0 -RealVector v_mapPowToSelf = v1.copy(); -v_mapPowToSelf.mapToSelf(new Power(2)); -double[] result_mapPowToSelf = {1d, 4d, 9d}; -assertClose("compare vectors" ,result_mapPowToSelf,v_mapPowToSelf.toArray(),normTolerance); - -//octave = exp(v1) -RealVector v_mapExp = v1.map(new Exp()); -double[] result_mapExp = {2.718281828459045e+00d,7.389056098930650e+00d, 2.008553692318767e+01d}; -assertClose("compare vectors" ,result_mapExp,v_mapExp.toArray(),normTolerance); - -//octave = exp(v1) -RealVector v_mapExpToSelf = v1.copy(); -v_mapExpToSelf.mapToSelf(new Exp()); -double[] result_mapExpToSelf = {2.718281828459045e+00d,7.389056098930650e+00d, 2.008553692318767e+01d}; -assertClose("compare vectors" ,result_mapExpToSelf,v_mapExpToSelf.toArray(),normTolerance); - - -
svn propchange: r1353825 - svn:log
Author: celestin Revision: 1353825 Modified property: svn:log Modified: svn:log at Tue Jun 26 06:13:45 2012 -- --- svn:log (original) +++ svn:log Tue Jun 26 06:13:45 2012 @@ -1 +1,3 @@ MATH-795: factored out unit tests for RealVector.map(UnivariateFunction) and RealVector.mapToSelf(UnivariateFunction). + +This test fails with OpenMapRealVector. This is a known issue (sign of zero is lost in this class).
svn commit: r1354329 - /commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java
Author: celestin Date: Wed Jun 27 05:37:55 2012 New Revision: 1354329 URL: http://svn.apache.org/viewvc?rev=1354329&view=rev Log: MATH-795: in RealVectorAbstractTest, created an array of specific entry values to be tested. Generalized its use in some unit tests. Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java?rev=1354329&r1=1354328&r2=1354329&view=diff == --- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java Wed Jun 27 05:37:55 2012 @@ -65,6 +65,67 @@ public abstract class RealVectorAbstract }; /** + * + * This is an attempt at covering most particular cases of combining two + * values. Here {@code x} is the value returned by + * {@link #getPreferredEntryValue()}, while {@code y} and {@code z} are two + * "normal" values. + * + * + * + * Addition: the following cases should be covered + * + * {@code (2 * x) + (-x)} + * {@code (-x) + 2 * x} + * {@code x + y} + * {@code y + x} + * {@code y + z} + * {@code y + (x - y)} + * {@code (y - x) + x} + * + * The values to be considered are: + * {@code x, y, z, 2 * x, -x, x - y, y - x}. + * + * + * Subtraction: the following cases should be covered + * + * {@code (2 * x) - x} + * {@code x - y} + * {@code y - x} + * {@code y - z} + * {@code y - (y - x)} + * {@code (y + x) - y} + * + * The values to be considered are: {@code x, y, z, x + y, y - x}. + * + * + * Multiplication + * + * {@code (x * x) * (1 / x)} + * {@code (1 / x) * (x * x)} + * {@code x * y} + * {@code y * x} + * {@code y * z} + * + * The values to be considered are: {@code x, y, z, 1 / x, x * x}. + * + * + * Division + * + * {@code (x * x) / x} + * {@code x / y} + * {@code y / x} + * {@code y / z} + * + * The values to be considered are: {@code x, y, z, x * x}. + * + * + * Also to be considered {@code NaN}, {@code POSITIVE_INFINITY}, + * {@code NEGATIVE_INFINITY}, {@code +0.0}, {@code -0.0}. + */ +private final double[] values; + +/** * Creates a new instance of {@link RealVector}, with specified entries. * The returned vector must be of the type currently tested. It should be * noted that some tests assume that no references to the specified @@ -143,6 +204,19 @@ public abstract class RealVectorAbstract final double x = getPreferredEntryValue(); data1 = new double[] {x, 1d, 2d, x, x}; data2 = new double[] {x, x, 3d, x, 4d, x}; +/* + * Make sure that x, y, z are three different values. Also, x is the + * preferred value (e.g. the value which is not stored in sparse + * implementations). + */ +final double y = x + 1d; +final double z = y + 1d; + +values = +new double[] { +Double.NaN, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, +0d, -0d, x, y, z, 2 * x, -x, 1 / x, x * x, x + y, x - y, y - x +}; } // tolerances @@ -408,71 +482,6 @@ public abstract class RealVectorAbstract } private void doTestEbeBinaryOperation(final BinaryOperation op, final boolean mixed) { -/* - * Make sure that x, y, z are three different values. Also, x is the - * preferred value (e.g. the value which is not stored in sparse - * implementations). - */ -final double x = getPreferredEntryValue(); -final double y = x + 1d; -final double z = y + 1d; - -/* - * This is an attempt at covering most particular cases of combining - * two values. - * - * 1. Addition - * - * The following cases should be covered - * (2 * x) + (-x) - * (-x) + 2 * x - * x + y - * y + x - * y + z - * y + (x - y) - * (y - x) + x - * - * The values to be considered are: x, y, z, 2 * x, -x, x - y, y - x. - * - * 2. Subtraction - *--- - * The following cases should be cover
svn commit: r1354330 - /commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java
Author: celestin Date: Wed Jun 27 05:53:09 2012 New Revision: 1354330 URL: http://svn.apache.org/viewvc?rev=1354330&view=rev Log: MATH-795: factored out unit test of RealMatrix RealVector.outerProduct(RealVector) This test fails with the default implementation provided by the abstract class RealMatrix. Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java?rev=1354330&r1=1354329&r2=1354330&view=diff == --- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java Wed Jun 27 05:53:09 2012 @@ -924,6 +924,45 @@ public abstract class RealVectorAbstract } } +private void doTestOuterProduct(final boolean mixed) { +final double[] dataU = values; +final RealVector u = create(dataU); +final double[] dataV = new double[values.length + 3]; +System.arraycopy(values, 0, dataV, 0, values.length); +dataV[values.length] = 1d; +dataV[values.length] = -2d; +dataV[values.length] = 3d; +final RealVector v; +if (mixed) { +v = createAlien(dataV); +} else { +v = create(dataV); +} +final RealMatrix uv = u.outerProduct(v); +Assert.assertEquals("number of rows", dataU.length, uv +.getRowDimension()); +Assert.assertEquals("number of columns", dataV.length, uv +.getColumnDimension()); +for (int i = 0; i < dataU.length; i++) { +for (int j = 0; j < dataV.length; j++) { +final double expected = dataU[i] * dataV[j]; +final double actual = uv.getEntry(i, j); +Assert.assertEquals("[" + i + "][" + j + "]", expected, actual, +0d); +} +} +} + +@Test +public void testOuterProductSameType() { +doTestOuterProduct(false); +} + +@Test +public void testOuterProductMixedTypes() { +doTestOuterProduct(true); +} + @Test public void testDataInOut() { final RealVector v1 = create(vec1); @@ -998,14 +1037,6 @@ public abstract class RealVectorAbstract double dot_2 = v1.dotProduct(v2_t); Assert.assertEquals("compare val ", 32d, dot_2, normTolerance); -RealMatrix m_outerProduct = v1.outerProduct(v2); -Assert.assertEquals("compare val ", 4d, m_outerProduct.getEntry(0, 0), -normTolerance); - -RealMatrix m_outerProduct_2 = v1.outerProduct(v2_t); -Assert.assertEquals("compare val ", 4d, -m_outerProduct_2.getEntry(0, 0), normTolerance); - RealVector v_unitVector = v1.unitVector(); RealVector v_unitVector_2 = v1.mapDivide(v1.getNorm()); assertClose("compare vect", v_unitVector.toArray(), @@ -1038,22 +1069,6 @@ public abstract class RealVectorAbstract } @Test -public void testOuterProduct() { -final RealVector u = create(new double[] {1, 2, -3}); -final RealVector v = create(new double[] {4, -2}); - -final RealMatrix uv = u.outerProduct(v); - -final double tol = Math.ulp(1d); -Assert.assertEquals(4, uv.getEntry(0, 0), tol); -Assert.assertEquals(-2, uv.getEntry(0, 1), tol); -Assert.assertEquals(8, uv.getEntry(1, 0), tol); -Assert.assertEquals(-4, uv.getEntry(1, 1), tol); -Assert.assertEquals(-12, uv.getEntry(2, 0), tol); -Assert.assertEquals(6, uv.getEntry(2, 1), tol); -} - -@Test public void testMisc() { RealVector v1 = create(vec1); RealVector v4 = create(vec4);
svn commit: r1354822 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math3/linear/ test/java/org/apache/commons/math3/linear/
Author: celestin Date: Thu Jun 28 06:09:51 2012 New Revision: 1354822 URL: http://svn.apache.org/viewvc?rev=1354822&view=rev Log: MATH-795: In org.apache.commons.math3.linear.RealVectorAbstractTest - factored out unit tests of RealVector RealVector.set(double), - created unit tests of double[] RealVector.toArray(), - factored out unit tests of RealVector RealVector.unitVector(), - factored out unit tests of void RealVector.unitize(), - created unit tests of Iterator RealVector.iterator(). In org.apache.commons.math3.linear.ArrayRealVector, removed unnecessary overrides of unitVector() and unitize(). In org.apache.commons.math3.linear.RealVector - unitVector() and unitize() now throw an ArithmeticException when the norm is 0 (as specified in the Javadoc), - the returned iterator() returns NoSuchElementException as specified in the general contract of iterators. Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/ArrayRealVector.java commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/RealVector.java commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorTest.java Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/ArrayRealVector.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/ArrayRealVector.java?rev=1354822&r1=1354821&r2=1354822&view=diff == --- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/ArrayRealVector.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/ArrayRealVector.java Thu Jun 28 06:09:51 2012 @@ -568,26 +568,6 @@ public class ArrayRealVector extends Rea /** {@inheritDoc} */ @Override -public RealVector unitVector() { -final double norm = getNorm(); -if (norm == 0) { -throw new MathArithmeticException(LocalizedFormats.ZERO_NORM); -} -return mapDivide(norm); -} - -/** {@inheritDoc} */ -@Override -public void unitize() { -final double norm = getNorm(); -if (norm == 0) { -throw new MathArithmeticException(LocalizedFormats.ZERO_NORM); -} -mapDivideToSelf(norm); -} - -/** {@inheritDoc} */ -@Override public RealVector projection(RealVector v) { return v.mapMultiply(dotProduct(v) / v.dotProduct(v)); } Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/RealVector.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/RealVector.java?rev=1354822&r1=1354821&r2=1354822&view=diff == --- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/RealVector.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/RealVector.java Thu Jun 28 06:09:51 2012 @@ -709,9 +709,11 @@ public abstract class RealVector { * @throws ArithmeticException if the norm is {@code null}. */ public RealVector unitVector() { -RealVector copy = copy(); -copy.unitize(); -return copy; +final double norm = getNorm(); +if (norm == 0) { +throw new MathArithmeticException(LocalizedFormats.ZERO_NORM); +} +return mapDivide(norm); } /** @@ -722,6 +724,10 @@ public abstract class RealVector { * if the norm is zero. */ public void unitize() { +final double norm = getNorm(); +if (norm == 0) { +throw new MathArithmeticException(LocalizedFormats.ZERO_NORM); +} mapDivideToSelf(getNorm()); } @@ -771,8 +777,12 @@ public abstract class RealVector { /** {@inheritDoc} */ public Entry next() { -e.setIndex(i++); -return e; +if (i < dim) { +e.setIndex(i++); +return e; +} else { +throw new NoSuchElementException(); +} } /** {@inheritDoc} */ Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java?rev=1354822&r1=1354821&r2=1354822&view=diff == --- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java (original) +++ commons/proper/math/t