Modified: mahout/trunk/integration/src/test/java/org/apache/mahout/utils/nlp/collocations/llr/BloomTokenFilterTest.java URL: http://svn.apache.org/viewvc/mahout/trunk/integration/src/test/java/org/apache/mahout/utils/nlp/collocations/llr/BloomTokenFilterTest.java?rev=1196818&r1=1196817&r2=1196818&view=diff ============================================================================== --- mahout/trunk/integration/src/test/java/org/apache/mahout/utils/nlp/collocations/llr/BloomTokenFilterTest.java (original) +++ mahout/trunk/integration/src/test/java/org/apache/mahout/utils/nlp/collocations/llr/BloomTokenFilterTest.java Wed Nov 2 21:50:15 2011 @@ -20,6 +20,7 @@ package org.apache.mahout.utils.nlp.collocations.llr; import java.io.IOException; +import java.io.Reader; import java.io.StringReader; import java.nio.ByteBuffer; import java.nio.CharBuffer; @@ -30,6 +31,7 @@ import org.apache.hadoop.util.bloom.Bloo import org.apache.hadoop.util.bloom.Filter; import org.apache.hadoop.util.bloom.Key; import org.apache.hadoop.util.hash.Hash; +import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.TokenStream; import org.apache.lucene.analysis.WhitespaceAnalyzer; import org.apache.lucene.analysis.shingle.ShingleFilter; @@ -76,8 +78,8 @@ public final class BloomTokenFilterTest /** normal case, unfiltered analyzer */ @Test public void testAnalyzer() throws IOException { - StringReader reader = new StringReader(input); - WhitespaceAnalyzer analyzer = new WhitespaceAnalyzer(Version.LUCENE_31); + Reader reader = new StringReader(input); + Analyzer analyzer = new WhitespaceAnalyzer(Version.LUCENE_31); TokenStream ts = analyzer.tokenStream(null, reader); validateTokens(allTokens, ts); } @@ -85,31 +87,31 @@ public final class BloomTokenFilterTest /** filtered analyzer */ @Test public void testNonKeepdAnalyzer() throws IOException { - StringReader reader = new StringReader(input); - WhitespaceAnalyzer analyzer = new WhitespaceAnalyzer(Version.LUCENE_31); + Reader reader = new StringReader(input); + Analyzer analyzer = new WhitespaceAnalyzer(Version.LUCENE_31); TokenStream ts = analyzer.tokenStream(null, reader); - BloomTokenFilter f = new BloomTokenFilter(getFilter(filterTokens), false /* toss matching tokens */, ts); + TokenStream f = new BloomTokenFilter(getFilter(filterTokens), false /* toss matching tokens */, ts); validateTokens(expectedNonKeepTokens, f); } /** keep analyzer */ @Test public void testKeepAnalyzer() throws IOException { - StringReader reader = new StringReader(input); - WhitespaceAnalyzer analyzer = new WhitespaceAnalyzer(Version.LUCENE_31); + Reader reader = new StringReader(input); + Analyzer analyzer = new WhitespaceAnalyzer(Version.LUCENE_31); TokenStream ts = analyzer.tokenStream(null, reader); - BloomTokenFilter f = new BloomTokenFilter(getFilter(filterTokens), true /* keep matching tokens */, ts); + TokenStream f = new BloomTokenFilter(getFilter(filterTokens), true /* keep matching tokens */, ts); validateTokens(expectedKeepTokens, f); } /** shingles, keep those matching whitelist */ @Test public void testShingleFilteredAnalyzer() throws IOException { - StringReader reader = new StringReader(input); - WhitespaceAnalyzer analyzer = new WhitespaceAnalyzer(Version.LUCENE_31); + Reader reader = new StringReader(input); + Analyzer analyzer = new WhitespaceAnalyzer(Version.LUCENE_31); TokenStream ts = analyzer.tokenStream(null, reader); ShingleFilter sf = new ShingleFilter(ts, 3); - BloomTokenFilter f = new BloomTokenFilter(getFilter(shingleKeepTokens), true, sf); + TokenStream f = new BloomTokenFilter(getFilter(shingleKeepTokens), true, sf); validateTokens(expectedShingleTokens, f); }
Modified: mahout/trunk/integration/src/test/java/org/apache/mahout/utils/vectors/arff/ARFFVectorIterableTest.java URL: http://svn.apache.org/viewvc/mahout/trunk/integration/src/test/java/org/apache/mahout/utils/vectors/arff/ARFFVectorIterableTest.java?rev=1196818&r1=1196817&r2=1196818&view=diff ============================================================================== --- mahout/trunk/integration/src/test/java/org/apache/mahout/utils/vectors/arff/ARFFVectorIterableTest.java (original) +++ mahout/trunk/integration/src/test/java/org/apache/mahout/utils/vectors/arff/ARFFVectorIterableTest.java Wed Nov 2 21:50:15 2011 @@ -134,7 +134,7 @@ public final class ARFFVectorIterableTes ARFFVectorIterable iterable = new ARFFVectorIterable(NON_NUMERIC_ARFF, model); Iterator<Vector> iter = iterable.iterator(); Vector firstVector = iter.next(); - assertEquals(firstVector.get(2),1.0,0); + assertEquals(1.0, firstVector.get(2),0); DateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH); Date date = format.parse("1973-10-23"); long result = date.getTime(); Modified: mahout/trunk/integration/src/test/java/org/apache/mahout/utils/vectors/io/VectorWriterTest.java URL: http://svn.apache.org/viewvc/mahout/trunk/integration/src/test/java/org/apache/mahout/utils/vectors/io/VectorWriterTest.java?rev=1196818&r1=1196817&r2=1196818&view=diff ============================================================================== --- mahout/trunk/integration/src/test/java/org/apache/mahout/utils/vectors/io/VectorWriterTest.java (original) +++ mahout/trunk/integration/src/test/java/org/apache/mahout/utils/vectors/io/VectorWriterTest.java Wed Nov 2 21:50:15 2011 @@ -68,7 +68,7 @@ public final class VectorWriterTest exte } String buffer = strWriter.toString(); assertNotNull(buffer); - assertTrue(buffer.length() > 0); + assertFalse(buffer.isEmpty()); } } Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/Algebra.java URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/Algebra.java?rev=1196818&r1=1196817&r2=1196818&view=diff ============================================================================== --- mahout/trunk/math/src/main/java/org/apache/mahout/math/Algebra.java (original) +++ mahout/trunk/math/src/main/java/org/apache/mahout/math/Algebra.java Wed Nov 2 21:50:15 2011 @@ -61,7 +61,7 @@ public final class Algebra { int sum = 0; Vector cv = m.viewRow(i); for (int j = 0; j < cv.size(); j++) { - sum += Math.abs(cv.getQuick(j)); + sum += (int) Math.abs(cv.getQuick(j)); } if (sum > max) { max = sum; Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/MurmurHash3.java URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/MurmurHash3.java?rev=1196818&r1=1196817&r2=1196818&view=diff ============================================================================== --- mahout/trunk/math/src/main/java/org/apache/mahout/math/MurmurHash3.java (original) +++ mahout/trunk/math/src/main/java/org/apache/mahout/math/MurmurHash3.java Wed Nov 2 21:50:15 2011 @@ -25,11 +25,14 @@ package org.apache.mahout.math; */ public class MurmurHash3 { + private MurmurHash3() { + } + /** Returns the MurmurHash3_x86_32 hash. */ public static int murmurhash3_x86_32(byte[] data, int offset, int len, int seed) { - final int c1 = 0xcc9e2d51; - final int c2 = 0x1b873593; + int c1 = 0xcc9e2d51; + int c2 = 0x1b873593; int h1 = seed; int roundedEnd = offset + (len & 0xfffffffc); // round down to 4 byte block Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/decomposer/hebbian/HebbianSolver.java URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/decomposer/hebbian/HebbianSolver.java?rev=1196818&r1=1196817&r2=1196818&view=diff ============================================================================== --- mahout/trunk/math/src/main/java/org/apache/mahout/math/decomposer/hebbian/HebbianSolver.java (original) +++ mahout/trunk/math/src/main/java/org/apache/mahout/math/decomposer/hebbian/HebbianSolver.java Wed Nov 2 21:50:15 2011 @@ -310,7 +310,7 @@ public class HebbianSolver { String corpusDir = props.getProperty("solver.input.dir"); String outputDir = props.getProperty("solver.output.dir"); - if (corpusDir == null || corpusDir.length() == 0 || outputDir == null || outputDir.length() == 0) { + if (corpusDir == null || corpusDir.isEmpty() || outputDir == null || outputDir.isEmpty()) { log.error("{} must contain values for solver.input.dir and solver.output.dir", propertiesFile); return; } Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/solver/ConjugateGradientSolver.java URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/solver/ConjugateGradientSolver.java?rev=1196818&r1=1196817&r2=1196818&view=diff ============================================================================== --- mahout/trunk/math/src/main/java/org/apache/mahout/math/solver/ConjugateGradientSolver.java (original) +++ mahout/trunk/math/src/main/java/org/apache/mahout/math/solver/ConjugateGradientSolver.java Wed Nov 2 21:50:15 2011 @@ -1,13 +1,28 @@ +/** + * 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.mahout.math.solver; import org.apache.mahout.math.CardinalityException; import org.apache.mahout.math.DenseVector; -import org.apache.mahout.math.Matrix; import org.apache.mahout.math.Vector; import org.apache.mahout.math.VectorIterable; import org.apache.mahout.math.function.Functions; import org.apache.mahout.math.function.PlusMult; -import org.apache.mahout.math.function.TimesFunction; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -39,7 +54,7 @@ import org.slf4j.LoggerFactory; public class ConjugateGradientSolver { - public static final double DEFAULT_MAX_ERROR = 1e-9; + public static final double DEFAULT_MAX_ERROR = 1.0e-9; private static final Logger log = LoggerFactory.getLogger(ConjugateGradientSolver.class); private static final PlusMult plusMult = new PlusMult(1.0); @@ -129,14 +144,12 @@ public class ConjugateGradientSolver Vector residual = b.minus(a.times(x)); residualNormSquared = residual.dot(residual); - double conditionedNormSqr; + log.info("Conjugate gradient initial residual norm = " + Math.sqrt(residualNormSquared)); double previousConditionedNormSqr = 0.0; - Vector updateDirection = null; - - log.info("Conjugate gradient initial residual norm = " + Math.sqrt(residualNormSquared)); while (Math.sqrt(residualNormSquared) > maxError && iterations < maxIterations) { Vector conditionedResidual; + double conditionedNormSqr; if (preconditioner == null) { conditionedResidual = residual; conditionedNormSqr = residualNormSquared; Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/solver/JacobiConditioner.java URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/solver/JacobiConditioner.java?rev=1196818&r1=1196817&r2=1196818&view=diff ============================================================================== --- mahout/trunk/math/src/main/java/org/apache/mahout/math/solver/JacobiConditioner.java (original) +++ mahout/trunk/math/src/main/java/org/apache/mahout/math/solver/JacobiConditioner.java Wed Nov 2 21:50:15 2011 @@ -1,3 +1,20 @@ +/** + * 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.mahout.math.solver; import org.apache.mahout.math.DenseVector; @@ -5,13 +22,11 @@ import org.apache.mahout.math.Matrix; import org.apache.mahout.math.Vector; /** - * * Implements the Jacobi preconditioner for a matrix A. This is defined as inv(diag(A)). - * */ -public class JacobiConditioner implements Preconditioner -{ - private DenseVector inverseDiagonal; +public final class JacobiConditioner implements Preconditioner { + + private final DenseVector inverseDiagonal; public JacobiConditioner(Matrix a) { if (a.numCols() != a.numRows()) { @@ -25,8 +40,7 @@ public class JacobiConditioner implement } @Override - public Vector precondition(Vector v) - { + public Vector precondition(Vector v) { return v.times(inverseDiagonal); } Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/solver/LSMR.java URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/solver/LSMR.java?rev=1196818&r1=1196817&r2=1196818&view=diff ============================================================================== --- mahout/trunk/math/src/main/java/org/apache/mahout/math/solver/LSMR.java (original) +++ mahout/trunk/math/src/main/java/org/apache/mahout/math/solver/LSMR.java Wed Nov 2 21:50:15 2011 @@ -99,7 +99,9 @@ import org.slf4j.LoggerFactory; * MS&E, Stanford University. ----------------------------------------------------------------------- */ public class LSMR { - private Logger log = LoggerFactory.getLogger(LSMR.class); + + private static final Logger log = LoggerFactory.getLogger(LSMR.class); + private double lambda; private int localSize; private int iterationLimit; @@ -107,12 +109,9 @@ public class LSMR { private double bTolerance; private double aTolerance; private int localPointer; - private Vector v; - private boolean localVQueueFull; private Vector[] localV; private double residualNorm; private double normalEquationResidual; - private double aNorm; private double xNorm; private int iteration; private double normA; @@ -160,12 +159,12 @@ public class LSMR { public LSMR() { // Set default parameters. - setLambda(0); - setAtolerance(1e-6); - setBtolerance(1e-6); - setConditionLimit(1e8); - setIterationLimit(-1); - setLocalSize(0); + lambda = 0; + aTolerance = 1.0e-6; + bTolerance = 1.0e-6; + conditionLimit = 1.0e8; + iterationLimit = -1; + localSize = 0; } public Vector solve(Matrix A, Vector b) { @@ -193,20 +192,20 @@ public class LSMR { u = u.divide(beta); } - v = transposedA.times(u); + Vector v = transposedA.times(u); int m = A.numRows(); int n = A.numCols(); int minDim = Math.min(m, n); if (iterationLimit == -1) { - setIterationLimit(minDim); + iterationLimit = minDim; } if (log.isDebugEnabled()) { log.debug("LSMR - Least-squares solution of Ax = b, based on Matlab Version 1.02, 14 Apr 2010, Mahout version {}", this.getClass().getPackage().getImplementationVersion()); log.debug(String.format("The matrix A has %d rows and %d cols, lambda = %.4g, atol = %g, btol = %g", - m, n, getLambda(), getAtolerance(), getBtolerance())); + m, n, lambda, aTolerance, bTolerance)); } double alpha = v.norm(2); @@ -216,15 +215,14 @@ public class LSMR { // Initialization for local reorthogonalization - boolean localOrtho = false; localPointer = 0; - localVQueueFull = false; // Preallocate storage for storing the last few v_k. Since with // orthogonal v_k's, Krylov subspace method would converge in not // more iterations than the number of singular values, more // space is not necessary. localV = new Vector[Math.min(localSize, minDim)]; + boolean localOrtho = false; if (localSize > 0) { localOrtho = true; localV[0] = v; @@ -236,10 +234,6 @@ public class LSMR { iteration = 0; double zetabar = alpha * beta; double alphabar = alpha; - double rho = 1; - double rhobar = 1; - double cbar = 1; - double sbar = 0; Vector h = v; Vector hbar = zeros(n); @@ -248,25 +242,14 @@ public class LSMR { // Initialize variables for estimation of ||r||. double betadd = beta; - double betad = 0; - double rhodold = 1; - double tautildeold = 0; - double thetatilde = 0; - double zeta = 0; - double d = 0; // Initialize variables for estimation of ||A|| and cond(A) - aNorm = alpha * alpha; - double maxrbar = 0; - double minrbar = 1e+100; + double aNorm = alpha * alpha; // Items for use in stopping rules. double normb = beta; - int istop = 0; - StopCode stop = StopCode.CONTINUE; - double ctol = 0; if (conditionLimit > 0) { ctol = 1 / conditionLimit; @@ -284,11 +267,11 @@ public class LSMR { if (log.isDebugEnabled()) { - double test1 = 1; double test2 = alpha / beta; // log.debug('{} {}', hdg1, hdg2); log.debug("{} {}", iteration, x.get(0)); log.debug("{} {}", residualNorm, normalEquationResidual); + double test1 = 1; log.debug("{} {}", test1, test2); } @@ -296,9 +279,23 @@ public class LSMR { //------------------------------------------------------------------ // Main iteration loop. //------------------------------------------------------------------ + double rho = 1; + double rhobar = 1; + double cbar = 1; + double sbar = 0; + double betad = 0; + double rhodold = 1; + double tautildeold = 0; + double thetatilde = 0; + double zeta = 0; + double d = 0; + double maxrbar = 0; + double minrbar = 1.0e+100; + int istop = 0; + StopCode stop = StopCode.CONTINUE; while (iteration <= iterationLimit && stop == StopCode.CONTINUE) { - iteration = iteration + 1; + iteration++; // Perform the next step of the bidiagonalization to obtain the // next beta, u, alpha, v. These satisfy the relations @@ -388,13 +385,13 @@ public class LSMR { tautildeold = (zetaold - thetatildeold * tautildeold) / rhotildeold; double taud = (zeta - thetatilde * tautildeold) / rhodold; - d = d + betacheck * betacheck; + d += betacheck * betacheck; residualNorm = Math.sqrt(d + (betad - taud) * (betad - taud) + betadd * betadd); // Estimate ||A||. - aNorm = aNorm + beta * beta; + aNorm += beta * beta; normA = Math.sqrt(aNorm); - aNorm = aNorm + alpha * alpha; + aNorm += alpha * alpha; // Estimate cond(A). maxrbar = Math.max(maxrbar, rhobarold); @@ -494,7 +491,7 @@ public class LSMR { log.debug("{} {}", normA, condA); } - private Vector zeros(int n) { + private static Vector zeros(int n) { return new DenseVector(n); } @@ -533,9 +530,9 @@ public class LSMR { CONDITION_MACHINE_TOLERANCE("Cond(Abar) seems to be too large for this machine"), ITERATION_LIMIT("The iteration limit has been reached"); - private String message; + private final String message; - private StopCode(String message) { + StopCode(String message) { this.message = message; } Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/solver/Preconditioner.java URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/solver/Preconditioner.java?rev=1196818&r1=1196817&r2=1196818&view=diff ============================================================================== --- mahout/trunk/math/src/main/java/org/apache/mahout/math/solver/Preconditioner.java (original) +++ mahout/trunk/math/src/main/java/org/apache/mahout/math/solver/Preconditioner.java Wed Nov 2 21:50:15 2011 @@ -1,20 +1,36 @@ +/** + * 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.mahout.math.solver; import org.apache.mahout.math.Vector; /** - * - * <p>Interface for defining preconditioners used for improving the performance and/or stability of linear + * Interface for defining preconditioners used for improving the performance and/or stability of linear * system solvers. - * */ -public interface Preconditioner -{ +public interface Preconditioner { + /** * Preconditions the specified vector. * * @param v The vector to precondition. * @return The preconditioned vector. */ - public Vector precondition(Vector v); + Vector precondition(Vector v); + } Modified: mahout/trunk/math/src/test/java/org/apache/mahout/math/decomposer/SolverTest.java URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/test/java/org/apache/mahout/math/decomposer/SolverTest.java?rev=1196818&r1=1196817&r2=1196818&view=diff ============================================================================== --- mahout/trunk/math/src/test/java/org/apache/mahout/math/decomposer/SolverTest.java (original) +++ mahout/trunk/math/src/test/java/org/apache/mahout/math/decomposer/SolverTest.java Wed Nov 2 21:50:15 2011 @@ -18,6 +18,7 @@ package org.apache.mahout.math.decomposer; import com.google.common.collect.Lists; +import org.apache.mahout.common.RandomUtils; import org.apache.mahout.math.DenseMatrix; import org.apache.mahout.math.DenseVector; import org.apache.mahout.math.MahoutTestCase; @@ -129,10 +130,9 @@ public abstract class SolverTest extends double entryMean) { Matrix m = new SparseRowMatrix(numRows, numCols); //double n = 0; - //Random r = RandomUtils.getRandom(); - Random r = new Random(1234L); + Random r = RandomUtils.getRandom(); for (int i = 0; i < nonNullRows; i++) { - SequentialAccessSparseVector v = new SequentialAccessSparseVector(numCols); + Vector v = new SequentialAccessSparseVector(numCols); for (int j = 0; j < entriesPerRow; j++) { int col = r.nextInt(numCols); double val = r.nextGaussian(); Modified: mahout/trunk/math/src/test/java/org/apache/mahout/math/jet/random/engine/MersenneTwisterTest.java URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/test/java/org/apache/mahout/math/jet/random/engine/MersenneTwisterTest.java?rev=1196818&r1=1196817&r2=1196818&view=diff ============================================================================== --- mahout/trunk/math/src/test/java/org/apache/mahout/math/jet/random/engine/MersenneTwisterTest.java (original) +++ mahout/trunk/math/src/test/java/org/apache/mahout/math/jet/random/engine/MersenneTwisterTest.java Wed Nov 2 21:50:15 2011 @@ -70,7 +70,7 @@ public final class MersenneTwisterTest e @Test public void testRegression() { - MersenneTwister r = new MersenneTwister(42); + RandomEngine r = new MersenneTwister(42); int i = 0; for (double x : reference3) { assertEquals("t-regression-"+i, x, r.nextDouble(), 1.0e-7); @@ -81,8 +81,8 @@ public final class MersenneTwisterTest e @Test public void testDateConstructor() { - MersenneTwister r1 = new MersenneTwister(1275264362); - MersenneTwister r2 = new MersenneTwister(new Date(1275264362)); + RandomEngine r1 = new MersenneTwister(1275264362); + RandomEngine r2 = new MersenneTwister(new Date(1275264362)); for (int i = 0; i < 100; i++) { assertEquals("date-"+i, r1.nextInt(), r2.nextInt()); } Modified: mahout/trunk/math/src/test/java/org/apache/mahout/math/solver/LSMRTest.java URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/test/java/org/apache/mahout/math/solver/LSMRTest.java?rev=1196818&r1=1196817&r2=1196818&view=diff ============================================================================== --- mahout/trunk/math/src/test/java/org/apache/mahout/math/solver/LSMRTest.java (original) +++ mahout/trunk/math/src/test/java/org/apache/mahout/math/solver/LSMRTest.java Wed Nov 2 21:50:15 2011 @@ -17,22 +17,14 @@ package org.apache.mahout.math.solver; -import org.apache.mahout.common.RandomUtils; import org.apache.mahout.math.DenseMatrix; import org.apache.mahout.math.DenseVector; import org.apache.mahout.math.MahoutTestCase; import org.apache.mahout.math.Matrix; import org.apache.mahout.math.Vector; -import org.apache.mahout.math.solver.LSMR; import org.junit.Test; -import java.util.Random; - -/** - * Created by IntelliJ IDEA. User: tdunning Date: Sep 15, 2010 Time: 7:32:27 PM To change this - * template use File | Settings | File Templates. - */ -public class LSMRTest extends MahoutTestCase { +public final class LSMRTest extends MahoutTestCase { @Test public void basics() { Matrix m = hilbert(5); @@ -40,14 +32,14 @@ public class LSMRTest extends MahoutTest // make sure it is the hilbert matrix we know and love assertEquals(1, m.get(0, 0), 0); assertEquals(0.5, m.get(0, 1), 0); - assertEquals(1 / 6.0, m.get(2, 3), 1e-9); + assertEquals(1 / 6.0, m.get(2, 3), 1.0e-9); Vector x = new DenseVector(new double[]{5, -120, 630, -1120, 630}); Vector b = new DenseVector(5); b.assign(1); - assertEquals(0, m.times(x).minus(b).norm(2), 1e-9); + assertEquals(0, m.times(x).minus(b).norm(2), 1.0e-9); LSMR r = new LSMR(); Vector x1 = r.solve(m, b); @@ -58,15 +50,15 @@ public class LSMRTest extends MahoutTest // a fast iterative solution. // Thus, we have to check the residuals rather than testing that the answer matched // the ideal. - assertEquals(m.times(x1).minus(b).norm(2), 0, 1e-2); - assertEquals(0, m.transpose().times(m).times(x1).minus(m.transpose().times(b)).norm(2), 1e-7); + assertEquals(0, m.times(x1).minus(b).norm(2), 1.0e-2); + assertEquals(0, m.transpose().times(m).times(x1).minus(m.transpose().times(b)).norm(2), 1.0e-7); // and we need to check that the error estimates are pretty good. - assertEquals(m.times(x1).minus(b).norm(2), r.getResidualNorm(), 1e-5); - assertEquals(m.transpose().times(m).times(x1).minus(m.transpose().times(b)).norm(2), r.getNormalEquationResidual(), 1e-9); + assertEquals(m.times(x1).minus(b).norm(2), r.getResidualNorm(), 1.0e-5); + assertEquals(m.transpose().times(m).times(x1).minus(m.transpose().times(b)).norm(2), r.getNormalEquationResidual(), 1.0e-9); } - private Matrix hilbert(int n) { + private static Matrix hilbert(int n) { Matrix r = new DenseMatrix(n, n); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { @@ -76,6 +68,7 @@ public class LSMRTest extends MahoutTest return r; } + /* private Matrix overDetermined(int n) { Random rand = RandomUtils.getRandom(); Matrix r = new DenseMatrix(2 * n, n); @@ -86,4 +79,5 @@ public class LSMRTest extends MahoutTest } return r; } + */ }
