You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mahout.apache.org by sr...@apache.org on 2011/09/15 21:50:10 UTC
svn commit: r1171239 [2/2] - in /mahout/trunk:
core/src/main/java/org/apache/mahout/cf/taste/hadoop/
core/src/main/java/org/apache/mahout/cf/taste/hadoop/als/eval/
core/src/main/java/org/apache/mahout/cf/taste/hadoop/item/
core/src/main/java/org/apache...
Modified: mahout/trunk/core/src/test/java/org/apache/mahout/graph/GraphTestCase.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/test/java/org/apache/mahout/graph/GraphTestCase.java?rev=1171239&r1=1171238&r2=1171239&view=diff
==============================================================================
--- mahout/trunk/core/src/test/java/org/apache/mahout/graph/GraphTestCase.java (original)
+++ mahout/trunk/core/src/test/java/org/apache/mahout/graph/GraphTestCase.java Thu Sep 15 19:50:07 2011
@@ -32,8 +32,10 @@ import java.io.IOException;
public abstract class GraphTestCase extends MahoutTestCase {
- protected <T extends WritableComparable> void writeComponents(File destination, Configuration conf,
- Class<T> componentClass, T... components) throws IOException {
+ protected static <T extends WritableComparable> void writeComponents(File destination,
+ Configuration conf,
+ Class<T> componentClass, T... components)
+ throws IOException {
Path path = new Path(destination.getAbsolutePath());
FileSystem fs = FileSystem.get(path.toUri(), conf);
Modified: mahout/trunk/core/src/test/java/org/apache/mahout/graph/linkanalysis/PageRankJobTest.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/test/java/org/apache/mahout/graph/linkanalysis/PageRankJobTest.java?rev=1171239&r1=1171238&r2=1171239&view=diff
==============================================================================
--- mahout/trunk/core/src/test/java/org/apache/mahout/graph/linkanalysis/PageRankJobTest.java (original)
+++ mahout/trunk/core/src/test/java/org/apache/mahout/graph/linkanalysis/PageRankJobTest.java Thu Sep 15 19:50:07 2011
@@ -22,9 +22,6 @@ import com.google.common.collect.Iterabl
import com.google.common.collect.Maps;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
-import org.apache.hadoop.io.IntWritable;
-import org.apache.hadoop.io.NullWritable;
-import org.apache.hadoop.mapreduce.Mapper;
import org.apache.mahout.common.iterator.FileLineIterable;
import org.apache.mahout.graph.GraphTestCase;
import org.apache.mahout.graph.model.Edge;
@@ -32,15 +29,13 @@ import org.apache.mahout.graph.preproces
import org.apache.mahout.math.DenseMatrix;
import org.apache.mahout.math.Matrix;
import org.apache.mahout.math.hadoop.MathHelper;
-import org.apache.mahout.math.map.OpenLongIntHashMap;
-import org.easymock.EasyMock;
import org.junit.Test;
import java.io.File;
import java.util.Map;
/** example from "Mining Massive Datasets" */
-public class PageRankJobTest extends GraphTestCase {
+public final class PageRankJobTest extends GraphTestCase {
@Test
public void toyIntegrationTest() throws Exception {
@@ -73,14 +68,14 @@ public class PageRankJobTest extends Gra
pageRank.setConf(conf);
pageRank.run(new String[] { "--vertexIndex", indexedVerticesFile.getAbsolutePath(),
"--edges", edgesFile.getAbsolutePath(), "--output", outputDir.getAbsolutePath(),
- "--numVertices", String.valueOf(numVertices), "--numIterations", String.valueOf(3),
- "--stayingProbability", String.valueOf(0.8), "--tempDir", tempDir.getAbsolutePath() });
+ "--numVertices", String.valueOf(numVertices), "--numIterations", "3",
+ "--stayingProbability", "0.8", "--tempDir", tempDir.getAbsolutePath() });
Matrix expectedAdjacenyMatrix = new DenseMatrix(new double[][] {
- { 0, 0.4, 0, 0 },
- { 0.266666667, 0, 0, 0.4 },
- { 0.266666667, 0, 0.8, 0.4 },
- { 0.266666667, 0.4, 0, 0 } });
+ { 0.0, 0.4, 0.0, 0.0 },
+ { 0.266666667, 0.0, 0.0, 0.4 },
+ { 0.266666667, 0.0, 0.8, 0.4 },
+ { 0.266666667, 0.4, 0.0, 0.0 } });
Matrix actualAdjacencyMatrix = MathHelper.readMatrix(conf, new Path(tempDir.getAbsolutePath(),
"adjacencyMatrix/part-r-00000"), numVertices, numVertices);
@@ -88,7 +83,7 @@ public class PageRankJobTest extends Gra
assertMatrixEquals(expectedAdjacenyMatrix, actualAdjacencyMatrix);
Map<Long,Double> rankPerVertex = Maps.newHashMap();
- for (String line : new FileLineIterable(new File(outputDir, "part-m-00000"))) {
+ for (CharSequence line : new FileLineIterable(new File(outputDir, "part-m-00000"))) {
String[] tokens = Iterables.toArray(Splitter.on("\t").split(line), String.class);
rankPerVertex.put(Long.parseLong(tokens[0]), Double.parseDouble(tokens[1]));
}
Modified: mahout/trunk/core/src/test/java/org/apache/mahout/math/hadoop/decomposer/TestDistributedLanczosSolver.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/test/java/org/apache/mahout/math/hadoop/decomposer/TestDistributedLanczosSolver.java?rev=1171239&r1=1171238&r2=1171239&view=diff
==============================================================================
--- mahout/trunk/core/src/test/java/org/apache/mahout/math/hadoop/decomposer/TestDistributedLanczosSolver.java (original)
+++ mahout/trunk/core/src/test/java/org/apache/mahout/math/hadoop/decomposer/TestDistributedLanczosSolver.java Thu Sep 15 19:50:07 2011
@@ -26,7 +26,6 @@ import org.apache.mahout.math.decomposer
import org.apache.mahout.math.hadoop.DistributedRowMatrix;
import org.apache.mahout.math.hadoop.TestDistributedRowMatrix;
import org.junit.Before;
-import org.junit.Test;
import java.io.File;
import java.io.IOException;
Modified: mahout/trunk/core/src/test/java/org/apache/mahout/math/hadoop/similarity/TestVectorDistanceSimilarityJob.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/test/java/org/apache/mahout/math/hadoop/similarity/TestVectorDistanceSimilarityJob.java?rev=1171239&r1=1171238&r2=1171239&view=diff
==============================================================================
--- mahout/trunk/core/src/test/java/org/apache/mahout/math/hadoop/similarity/TestVectorDistanceSimilarityJob.java (original)
+++ mahout/trunk/core/src/test/java/org/apache/mahout/math/hadoop/similarity/TestVectorDistanceSimilarityJob.java Thu Sep 15 19:50:07 2011
@@ -1,4 +1,3 @@
-package org.apache.mahout.math.hadoop.similarity;
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
@@ -16,6 +15,7 @@ package org.apache.mahout.math.hadoop.si
* limitations under the License.
*/
+package org.apache.mahout.math.hadoop.similarity;
import com.google.common.collect.Lists;
import org.apache.hadoop.conf.Configuration;
@@ -24,7 +24,6 @@ import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.DoubleWritable;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
-import org.apache.hadoop.io.Writable;
import org.apache.hadoop.io.WritableComparable;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.util.ToolRunner;
@@ -46,13 +45,10 @@ import org.junit.Before;
import org.junit.Test;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.List;
import java.util.Map;
-/**
- *
- *
- **/
public class TestVectorDistanceSimilarityJob extends MahoutTestCase {
private FileSystem fs;
@@ -68,8 +64,7 @@ public class TestVectorDistanceSimilarit
public void testVectorDistanceMapper() throws Exception {
Mapper<WritableComparable<?>, VectorWritable, StringTuple, DoubleWritable>.Context context =
EasyMock.createMock(Mapper.Context.class);
- StringTuple tuple;
- tuple = new StringTuple();
+ StringTuple tuple = new StringTuple();
tuple.add("foo");
tuple.add("123");
context.write(tuple, new DoubleWritable(Math.sqrt(2.0)));
@@ -86,7 +81,7 @@ public class TestVectorDistanceSimilarit
VectorDistanceMapper mapper = new VectorDistanceMapper();
setField(mapper, "measure", new EuclideanDistanceMeasure());
- List<NamedVector> seedVectors = new ArrayList<NamedVector>();
+ Collection<NamedVector> seedVectors = new ArrayList<NamedVector>();
Vector seed1 = new RandomAccessSparseVector(2);
seed1.set(0, 1);
seed1.set(1, 1);
@@ -117,7 +112,7 @@ public class TestVectorDistanceSimilarit
VectorDistanceInvertedMapper mapper = new VectorDistanceInvertedMapper();
setField(mapper, "measure", new EuclideanDistanceMeasure());
- List<NamedVector> seedVectors = new ArrayList<NamedVector>();
+ Collection<NamedVector> seedVectors = new ArrayList<NamedVector>();
Vector seed1 = new RandomAccessSparseVector(2);
seed1.set(0, 1);
seed1.set(1, 1);
@@ -135,11 +130,11 @@ public class TestVectorDistanceSimilarit
}
- public static final double[][] REFERENCE = {
+ private static final double[][] REFERENCE = {
{1, 1}, {2, 1}, {1, 2}, {2, 2}, {3, 3}, {4, 4}, {5, 4}, {4, 5}, {5, 5}
};
- public static final double[][] SEEDS = {
+ private static final double[][] SEEDS = {
{1, 1}, {10, 10}
};
Modified: mahout/trunk/core/src/test/java/org/apache/mahout/math/hadoop/similarity/cooccurrence/measures/VectorSimilarityMeasuresTest.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/test/java/org/apache/mahout/math/hadoop/similarity/cooccurrence/measures/VectorSimilarityMeasuresTest.java?rev=1171239&r1=1171238&r2=1171239&view=diff
==============================================================================
--- mahout/trunk/core/src/test/java/org/apache/mahout/math/hadoop/similarity/cooccurrence/measures/VectorSimilarityMeasuresTest.java (original)
+++ mahout/trunk/core/src/test/java/org/apache/mahout/math/hadoop/similarity/cooccurrence/measures/VectorSimilarityMeasuresTest.java Thu Sep 15 19:50:07 2011
@@ -25,7 +25,9 @@ import org.junit.Test;
public class VectorSimilarityMeasuresTest extends MahoutTestCase {
- double distributedSimilarity(double[] one, double[] two, Class<? extends VectorSimilarityMeasure> similarityMeasureClass) {
+ static double distributedSimilarity(double[] one,
+ double[] two,
+ Class<? extends VectorSimilarityMeasure> similarityMeasureClass) {
VectorSimilarityMeasure similarityMeasure = ClassUtils.instantiateAs(similarityMeasureClass,
VectorSimilarityMeasure.class);
Vector oneNormalized = similarityMeasure.normalize(asSparseVector(one));
@@ -43,7 +45,7 @@ public class VectorSimilarityMeasuresTes
return similarityMeasure.similarity(dot, normOne, normTwo, one.length);
}
- Vector asSparseVector(double[] values) {
+ static Vector asSparseVector(double[] values) {
Vector vector = new RandomAccessSparseVector(Integer.MAX_VALUE);
for (int dim = 0; dim < values.length; dim++) {
if (values[dim] != 0) {
@@ -59,7 +61,7 @@ public class VectorSimilarityMeasuresTes
new double[] { 0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0 },
new double[] { 1, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1 }, CooccurrenceCountSimilarity.class);
- assertEquals(5d, similarity, 0);
+ assertEquals(5.0, similarity, 0);
}
@Test
Modified: mahout/trunk/core/src/test/java/org/apache/mahout/math/hadoop/stochasticsvd/LocalSSVDSolverDenseTest.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/test/java/org/apache/mahout/math/hadoop/stochasticsvd/LocalSSVDSolverDenseTest.java?rev=1171239&r1=1171238&r2=1171239&view=diff
==============================================================================
--- mahout/trunk/core/src/test/java/org/apache/mahout/math/hadoop/stochasticsvd/LocalSSVDSolverDenseTest.java (original)
+++ mahout/trunk/core/src/test/java/org/apache/mahout/math/hadoop/stochasticsvd/LocalSSVDSolverDenseTest.java Thu Sep 15 19:50:07 2011
@@ -28,6 +28,7 @@ import org.apache.hadoop.fs.Path;
import org.apache.mahout.common.MahoutTestCase;
import org.apache.mahout.math.DenseMatrix;
import org.apache.mahout.math.DenseVector;
+import org.apache.mahout.math.Vector;
import org.junit.Test;
/**
@@ -86,10 +87,7 @@ public class LocalSSVDSolverDenseTest ex
// With oversampling of 100, i don't get any error at all.
int n = 1000;
int m = 2000;
- int ablockRows = 867;
- int p = 10;
- int k = 3;
- DenseVector singularValues =
+ Vector singularValues =
new DenseVector(new double[] { 10, 4, 1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1,
0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1,
0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1,
@@ -115,6 +113,9 @@ public class LocalSSVDSolverDenseTest ex
// Solver starts here:
System.out.println("Input prepared, starting solver...");
+ int ablockRows = 867;
+ int p = 10;
+ int k = 3;
SSVDSolver ssvd =
new SSVDSolver(conf,
new Path[] { aPath },
Modified: mahout/trunk/core/src/test/java/org/apache/mahout/math/hadoop/stochasticsvd/LocalSSVDSolverSparseSequentialTest.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/test/java/org/apache/mahout/math/hadoop/stochasticsvd/LocalSSVDSolverSparseSequentialTest.java?rev=1171239&r1=1171238&r2=1171239&view=diff
==============================================================================
--- mahout/trunk/core/src/test/java/org/apache/mahout/math/hadoop/stochasticsvd/LocalSSVDSolverSparseSequentialTest.java (original)
+++ mahout/trunk/core/src/test/java/org/apache/mahout/math/hadoop/stochasticsvd/LocalSSVDSolverSparseSequentialTest.java Thu Sep 15 19:50:07 2011
@@ -95,9 +95,6 @@ public class LocalSSVDSolverSparseSequen
int n = 100;
int m = 20000;
- int ablockRows = 867;
- int p = 60;
- int k = 40;
double percent = 5;
VectorWritable vw = new VectorWritable();
@@ -130,6 +127,9 @@ public class LocalSSVDSolverSparseSequen
// Solver starts here:
System.out.println("Input prepared, starting solver...");
+ int ablockRows = 867;
+ int p = 60;
+ int k = 40;
SSVDSolver ssvd =
new SSVDSolver(conf,
new Path[] { aPath },
Modified: mahout/trunk/core/src/test/java/org/apache/mahout/math/hadoop/stochasticsvd/SSVDPrototypeTest.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/test/java/org/apache/mahout/math/hadoop/stochasticsvd/SSVDPrototypeTest.java?rev=1171239&r1=1171238&r2=1171239&view=diff
==============================================================================
--- mahout/trunk/core/src/test/java/org/apache/mahout/math/hadoop/stochasticsvd/SSVDPrototypeTest.java (original)
+++ mahout/trunk/core/src/test/java/org/apache/mahout/math/hadoop/stochasticsvd/SSVDPrototypeTest.java Thu Sep 15 19:50:07 2011
@@ -34,14 +34,13 @@ import org.junit.Test;
* Tests parts of of Stochastic SVD solver code in local mode
* using "prototype" code (class that simulates processes
* actually happenning in the MR jobs).
- *
- *
*/
public class SSVDPrototypeTest extends MahoutTestCase {
private static final double SCALE = 1000;
private static final double SVD_EPSILON = 1.0e-10;
+ @Test
public void testSSVDPrototype() throws Exception {
SSVDPrototype.main(null);
}
Modified: mahout/trunk/core/src/test/java/org/apache/mahout/math/hadoop/stochasticsvd/SSVDTestsHelper.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/test/java/org/apache/mahout/math/hadoop/stochasticsvd/SSVDTestsHelper.java?rev=1171239&r1=1171238&r2=1171239&view=diff
==============================================================================
--- mahout/trunk/core/src/test/java/org/apache/mahout/math/hadoop/stochasticsvd/SSVDTestsHelper.java (original)
+++ mahout/trunk/core/src/test/java/org/apache/mahout/math/hadoop/stochasticsvd/SSVDTestsHelper.java Thu Sep 15 19:50:07 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.hadoop.stochasticsvd;
import java.io.IOException;
@@ -8,6 +25,7 @@ import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.SequenceFile;
+import org.apache.hadoop.io.Writable;
import org.apache.mahout.math.DenseMatrix;
import org.apache.mahout.math.DenseVector;
import org.apache.mahout.math.Matrix;
@@ -17,6 +35,9 @@ import org.apache.mahout.math.hadoop.sto
public class SSVDTestsHelper {
+ private SSVDTestsHelper() {
+ }
+
static void generateDenseInput(Path outputPath,
FileSystem dfs,
Vector svalues,
@@ -47,8 +68,9 @@ public class SSVDTestsHelper {
// apply singular values
Matrix mx = m > n ? v : u;
- for (int i = 0; i < svCnt; i++)
+ for (int i = 0; i < svCnt; i++) {
mx.assignColumn(i, mx.viewColumn(i).times(svalues.getQuick(i)));
+ }
SequenceFile.Writer w =
SequenceFile.createWriter(dfs,
@@ -59,13 +81,14 @@ public class SSVDTestsHelper {
try {
Vector outV = new DenseVector(n);
- VectorWritable vw = new VectorWritable(outV);
+ Writable vw = new VectorWritable(outV);
IntWritable iw = new IntWritable();
for (int i = 0; i < m; i++) {
iw.set(startRowKey + i);
- for (int j = 0; j < n; j++)
+ for (int j = 0; j < n; j++) {
outV.setQuick(j, u.viewRow(i).dot(v.viewRow(j)));
+ }
w.append(iw, vw);
}
@@ -76,14 +99,14 @@ public class SSVDTestsHelper {
}
static Matrix generateDenseOrthonormalRandom(int m, int n, Random rnd) {
- DenseMatrix result = new DenseMatrix(m, n);
+ Matrix result = new DenseMatrix(m, n);
for (int j = 0; j < n; j++) {
for (int i = 0; i < m; i++) {
result.setQuick(i, j, rnd.nextDouble() - 0.5);
}
}
GrammSchmidt.orthonormalizeColumns(result);
- SSVDPrototypeTest.assertOrthonormality(result, false, 1E-10);
+ SSVDPrototypeTest.assertOrthonormality(result, false, 1.0e-10);
return result;
}
Modified: mahout/trunk/core/src/test/java/org/apache/mahout/math/hadoop/stochasticsvd/UpperTriangularTest.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/test/java/org/apache/mahout/math/hadoop/stochasticsvd/UpperTriangularTest.java?rev=1171239&r1=1171238&r2=1171239&view=diff
==============================================================================
--- mahout/trunk/core/src/test/java/org/apache/mahout/math/hadoop/stochasticsvd/UpperTriangularTest.java (original)
+++ mahout/trunk/core/src/test/java/org/apache/mahout/math/hadoop/stochasticsvd/UpperTriangularTest.java Thu Sep 15 19:50:07 2011
@@ -28,22 +28,24 @@ public class UpperTriangularTest extends
@Test
public void testBasics() {
Matrix a = new UpperTriangular(new double[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, false);
- assertEquals(0, a.viewDiagonal().minus(new DenseVector(new double[]{1, 5, 8, 10})).norm(1), 1e-10);
- assertEquals(0, a.viewPart(0, 3, 1, 3).viewDiagonal().minus(new DenseVector(new double[]{2, 6, 9})).norm(1), 1e-10);
- assertEquals(4, a.get(0, 3), 1e-10);
+ assertEquals(0, a.viewDiagonal().minus(new DenseVector(new double[]{1, 5, 8, 10})).norm(1), 1.0e-10);
+ assertEquals(0, a.viewPart(0, 3, 1, 3).viewDiagonal().minus(
+ new DenseVector(new double[]{2, 6, 9})).norm(1), 1.0e-10);
+ assertEquals(4, a.get(0, 3), 1.0e-10);
print(a);
Matrix m = new DenseMatrix(4, 4).assign(a);
- assertEquals(0, m.minus(a).aggregate(Functions.PLUS, Functions.ABS), 1e-10);
+ assertEquals(0, m.minus(a).aggregate(Functions.PLUS, Functions.ABS), 1.0e-10);
print(m);
- assertEquals(0, m.transpose().times(m).minus(a.transpose().times(a)).aggregate(Functions.PLUS, Functions.ABS), 1e-10);
- assertEquals(0, m.plus(m).minus(a.plus(a)).aggregate(Functions.PLUS, Functions.ABS), 1e-10);
+ assertEquals(0, m.transpose().times(m).minus(a.transpose().times(a)).aggregate(
+ Functions.PLUS, Functions.ABS), 1.0e-10);
+ assertEquals(0, m.plus(m).minus(a.plus(a)).aggregate(Functions.PLUS, Functions.ABS), 1.0e-10);
}
- private void print(Matrix m) {
+ private static void print(Matrix m) {
for (int i = 0; i < m.rowSize(); i++) {
for (int j = 0; j < m.columnSize(); j++) {
- if (Math.abs(m.get(i, j)) > 1e-10) {
+ if (Math.abs(m.get(i, j)) > 1.0e-10) {
System.out.printf("%10.3f ", m.get(i, j));
} else {
System.out.printf("%10s ", (i + j) % 3 == 0 ? "." : "");
Modified: mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/kddcup/track1/svd/Track1SVDRunner.java
URL: http://svn.apache.org/viewvc/mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/kddcup/track1/svd/Track1SVDRunner.java?rev=1171239&r1=1171238&r2=1171239&view=diff
==============================================================================
--- mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/kddcup/track1/svd/Track1SVDRunner.java (original)
+++ mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/kddcup/track1/svd/Track1SVDRunner.java Thu Sep 15 19:50:07 2011
@@ -55,7 +55,7 @@ public class Track1SVDRunner {
if (args.length != 2) {
System.err.println("Necessary arguments: <kddDataFileDirectory> <resultFile>");
- System.exit(-1);
+ return;
}
File dataFileDirectory = new File(args[0]);
Modified: mahout/trunk/examples/src/main/java/org/apache/mahout/clustering/syntheticcontrol/dirichlet/Job.java
URL: http://svn.apache.org/viewvc/mahout/trunk/examples/src/main/java/org/apache/mahout/clustering/syntheticcontrol/dirichlet/Job.java?rev=1171239&r1=1171238&r2=1171239&view=diff
==============================================================================
--- mahout/trunk/examples/src/main/java/org/apache/mahout/clustering/syntheticcontrol/dirichlet/Job.java (original)
+++ mahout/trunk/examples/src/main/java/org/apache/mahout/clustering/syntheticcontrol/dirichlet/Job.java Thu Sep 15 19:50:07 2011
@@ -59,7 +59,7 @@ public final class Job extends AbstractJ
RandomAccessSparseVector.class.getName(),
null,
60);
- new Job().run(new Path("testdata"), output, description, 10, 5, 1.0, true, 0);
+ run(new Path("testdata"), output, description, 10, 5, 1.0, true, 0);
}
}
@@ -128,14 +128,14 @@ public final class Job extends AbstractJ
* @param alpha0
* the alpha0 value for the DirichletDistribution
*/
- public void run(Path input,
- Path output,
- DistributionDescription description,
- int numModels,
- int maxIterations,
- double alpha0,
- boolean emitMostLikely,
- double threshold)
+ public static void run(Path input,
+ Path output,
+ DistributionDescription description,
+ int numModels,
+ int maxIterations,
+ double alpha0,
+ boolean emitMostLikely,
+ double threshold)
throws IOException, ClassNotFoundException, InterruptedException {
Path directoryContainingConvertedInput = new Path(output, DIRECTORY_CONTAINING_CONVERTED_INPUT);
InputDriver.runJob(input, directoryContainingConvertedInput, "org.apache.mahout.math.RandomAccessSparseVector");
Modified: mahout/trunk/examples/src/main/java/org/apache/mahout/clustering/syntheticcontrol/kmeans/Job.java
URL: http://svn.apache.org/viewvc/mahout/trunk/examples/src/main/java/org/apache/mahout/clustering/syntheticcontrol/kmeans/Job.java?rev=1171239&r1=1171238&r2=1171239&view=diff
==============================================================================
--- mahout/trunk/examples/src/main/java/org/apache/mahout/clustering/syntheticcontrol/kmeans/Job.java (original)
+++ mahout/trunk/examples/src/main/java/org/apache/mahout/clustering/syntheticcontrol/kmeans/Job.java Thu Sep 15 19:50:07 2011
@@ -133,8 +133,8 @@ public final class Job extends AbstractJ
* @param maxIterations
* the int maximum number of iterations
*/
- public void run(Configuration conf, Path input, Path output,
- DistanceMeasure measure, int k, double convergenceDelta, int maxIterations)
+ public static void run(Configuration conf, Path input, Path output,
+ DistanceMeasure measure, int k, double convergenceDelta, int maxIterations)
throws IOException, InterruptedException, ClassNotFoundException {
Path directoryContainingConvertedInput = new Path(output,
DIRECTORY_CONTAINING_CONVERTED_INPUT);
@@ -181,16 +181,11 @@ public final class Job extends AbstractJ
* the double convergence criteria for iterations
* @param maxIterations
* the int maximum number of iterations
- * @throws IOException
- * @throws InterruptedException
- * @throws ClassNotFoundException
- * @throws IllegalAccessException
- * @throws InstantiationException
*/
- public void run(Configuration conf, Path input, Path output,
- DistanceMeasure measure, double t1, double t2, double convergenceDelta,
- int maxIterations) throws IOException, InterruptedException,
- ClassNotFoundException, InstantiationException, IllegalAccessException {
+ public static void run(Configuration conf, Path input, Path output,
+ DistanceMeasure measure, double t1, double t2, double convergenceDelta,
+ int maxIterations)
+ throws IOException, InterruptedException, ClassNotFoundException, InstantiationException, IllegalAccessException {
Path directoryContainingConvertedInput = new Path(output,
DIRECTORY_CONTAINING_CONVERTED_INPUT);
log.info("Preparing Input");
Modified: mahout/trunk/examples/src/test/java/org/apache/mahout/ga/watchmaker/cd/CDFitnessTest.java
URL: http://svn.apache.org/viewvc/mahout/trunk/examples/src/test/java/org/apache/mahout/ga/watchmaker/cd/CDFitnessTest.java?rev=1171239&r1=1171238&r2=1171239&view=diff
==============================================================================
--- mahout/trunk/examples/src/test/java/org/apache/mahout/ga/watchmaker/cd/CDFitnessTest.java (original)
+++ mahout/trunk/examples/src/test/java/org/apache/mahout/ga/watchmaker/cd/CDFitnessTest.java Thu Sep 15 19:50:07 2011
@@ -39,8 +39,8 @@ public final class CDFitnessTest extends
int fn = rng.nextInt(1000);
CDFitness fitness = new CDFitness(tp, fp, tn, fn);
- double se = ((double) tp) / (tp + fn);
- double sp = ((double) tn) / (tn + fp);
+ double se = (double) tp / (tp + fn);
+ double sp = (double) tn / (tn + fp);
assertEquals(se * sp, fitness.get(), EPSILON);
}
Modified: mahout/trunk/examples/src/test/java/org/apache/mahout/ga/watchmaker/cd/FileInfosDatasetTest.java
URL: http://svn.apache.org/viewvc/mahout/trunk/examples/src/test/java/org/apache/mahout/ga/watchmaker/cd/FileInfosDatasetTest.java?rev=1171239&r1=1171238&r2=1171239&view=diff
==============================================================================
--- mahout/trunk/examples/src/test/java/org/apache/mahout/ga/watchmaker/cd/FileInfosDatasetTest.java (original)
+++ mahout/trunk/examples/src/test/java/org/apache/mahout/ga/watchmaker/cd/FileInfosDatasetTest.java Thu Sep 15 19:50:07 2011
@@ -39,7 +39,7 @@ public final class FileInfosDatasetTest
DataSet.initialize(dataset);
DataLine dl = new DataLine();
- for (String line : new FileLineIterable(new File(Resources.getResource("wdbc/wdbc.data").getPath()))) {
+ for (CharSequence line : new FileLineIterable(new File(Resources.getResource("wdbc/wdbc.data").getPath()))) {
dl.set(line);
for (int index = 0; index < dataset.getNbAttributes(); index++) {
if (dataset.isNumerical(index)) {
Modified: mahout/trunk/examples/src/test/java/org/apache/mahout/ga/watchmaker/cd/tool/ToolCombinerTest.java
URL: http://svn.apache.org/viewvc/mahout/trunk/examples/src/test/java/org/apache/mahout/ga/watchmaker/cd/tool/ToolCombinerTest.java?rev=1171239&r1=1171238&r2=1171239&view=diff
==============================================================================
--- mahout/trunk/examples/src/test/java/org/apache/mahout/ga/watchmaker/cd/tool/ToolCombinerTest.java (original)
+++ mahout/trunk/examples/src/test/java/org/apache/mahout/ga/watchmaker/cd/tool/ToolCombinerTest.java Thu Sep 15 19:50:07 2011
@@ -22,7 +22,6 @@ import org.apache.mahout.examples.Mahout
import org.junit.Test;
import java.util.List;
-import java.util.StringTokenizer;
public final class ToolCombinerTest extends MahoutTestCase {
@@ -58,10 +57,9 @@ public final class ToolCombinerTest exte
List<Text> values = ToolReducerTest.asList("val1", "val2", "val1", "val3", "val2");
String descriptor = combiner.createDescription(2, values.iterator());
- StringTokenizer tokenizer = new StringTokenizer(descriptor, ",");
int nbvalues = 0;
- while (tokenizer.hasMoreTokens()) {
- String value = tokenizer.nextToken().trim();
+ for (String value : descriptor.split(",")) {
+ value = value.trim();
if (!"val1".equals(value) && !"val2".equals(value) && !"val3".equals(value)) {
fail("Incorrect value : " + value);
}
Modified: mahout/trunk/integration/src/main/java/org/apache/mahout/cf/taste/impl/model/mongodb/MongoDBDataModel.java
URL: http://svn.apache.org/viewvc/mahout/trunk/integration/src/main/java/org/apache/mahout/cf/taste/impl/model/mongodb/MongoDBDataModel.java?rev=1171239&r1=1171238&r2=1171239&view=diff
==============================================================================
--- mahout/trunk/integration/src/main/java/org/apache/mahout/cf/taste/impl/model/mongodb/MongoDBDataModel.java (original)
+++ mahout/trunk/integration/src/main/java/org/apache/mahout/cf/taste/impl/model/mongodb/MongoDBDataModel.java Thu Sep 15 19:50:07 2011
@@ -710,7 +710,9 @@ public final class MongoDBDataModel impl
return (Date) date;
} else if (date.getClass().getName().contains("String")) {
try {
- return dateFormat.parse(date.toString());
+ synchronized (dateFormat) {
+ return dateFormat.parse(date.toString());
+ }
} catch (ParseException ioe) {
log.warn("Error parsing timestamp", ioe);
}
Modified: mahout/trunk/integration/src/main/java/org/apache/mahout/text/SequenceFilesFromCsvFilter.java
URL: http://svn.apache.org/viewvc/mahout/trunk/integration/src/main/java/org/apache/mahout/text/SequenceFilesFromCsvFilter.java?rev=1171239&r1=1171238&r2=1171239&view=diff
==============================================================================
--- mahout/trunk/integration/src/main/java/org/apache/mahout/text/SequenceFilesFromCsvFilter.java (original)
+++ mahout/trunk/integration/src/main/java/org/apache/mahout/text/SequenceFilesFromCsvFilter.java Thu Sep 15 19:50:07 2011
@@ -39,8 +39,8 @@ public final class SequenceFilesFromCsvF
private static final Logger log = LoggerFactory.getLogger(SequenceFilesFromCsvFilter.class);
private static final Pattern TAB = Pattern.compile("\t");
- public static final String[] KEY_COLUMN_OPTION = {"keyColumn", "kcol"};
- public static final String[] VALUE_COLUMN_OPTION = {"valueColumn", "vcol"};
+ private static final String[] KEY_COLUMN_OPTION = {"keyColumn", "kcol"};
+ private static final String[] VALUE_COLUMN_OPTION = {"valueColumn", "vcol"};
private volatile int keyColumn;
private volatile int valueColumn;
Modified: mahout/trunk/integration/src/main/java/org/apache/mahout/text/SequenceFilesFromDirectory.java
URL: http://svn.apache.org/viewvc/mahout/trunk/integration/src/main/java/org/apache/mahout/text/SequenceFilesFromDirectory.java?rev=1171239&r1=1171238&r2=1171239&view=diff
==============================================================================
--- mahout/trunk/integration/src/main/java/org/apache/mahout/text/SequenceFilesFromDirectory.java (original)
+++ mahout/trunk/integration/src/main/java/org/apache/mahout/text/SequenceFilesFromDirectory.java Thu Sep 15 19:50:07 2011
@@ -44,10 +44,10 @@ public class SequenceFilesFromDirectory
private static final String PREFIX_ADDITION_FILTER = PrefixAdditionFilter.class.getName();
- public static final String[] CHUNK_SIZE_OPTION = {"chunkSize", "chunk"};
- public static final String[] FILE_FILTER_CLASS_OPTION = {"fileFilterClass","filter"};
- public static final String[] KEY_PREFIX_OPTION = {"keyPrefix", "prefix"};
- public static final String[] CHARSET_OPTION = {"charset", "c"};
+ private static final String[] CHUNK_SIZE_OPTION = {"chunkSize", "chunk"};
+ static final String[] FILE_FILTER_CLASS_OPTION = {"fileFilterClass","filter"};
+ private static final String[] KEY_PREFIX_OPTION = {"keyPrefix", "prefix"};
+ static final String[] CHARSET_OPTION = {"charset", "c"};
public static void run(Configuration conf,
String keyPrefix,
Modified: mahout/trunk/integration/src/test/java/org/apache/mahout/clustering/TestClusterDumper.java
URL: http://svn.apache.org/viewvc/mahout/trunk/integration/src/test/java/org/apache/mahout/clustering/TestClusterDumper.java?rev=1171239&r1=1171238&r2=1171239&view=diff
==============================================================================
--- mahout/trunk/integration/src/test/java/org/apache/mahout/clustering/TestClusterDumper.java (original)
+++ mahout/trunk/integration/src/test/java/org/apache/mahout/clustering/TestClusterDumper.java Thu Sep 15 19:50:07 2011
@@ -195,7 +195,6 @@ public final class TestClusterDumper ext
ClusterDumper clusterDumper = new ClusterDumper(new Path(output,
"clusters-0"), new Path(output, "clusteredPoints"));
clusterDumper.printClusters(termDictionary);
- assertTrue(true);
}
@Test
@@ -225,7 +224,7 @@ public final class TestClusterDumper ext
4, false, true);
// now run the Fuzzy KMeans job
FuzzyKMeansDriver.run(conf, getTestTempDirPath("testdata"), new Path(
- output, "clusters-0"), output, measure, 0.001, 10, ((float) 1.1), true,
+ output, "clusters-0"), output, measure, 0.001, 10, 1.1f, true,
true, 0, true);
// run ClusterDumper
ClusterDumper clusterDumper = new ClusterDumper(finalClusterPath(conf,
Modified: mahout/trunk/integration/src/test/java/org/apache/mahout/clustering/dirichlet/TestL1ModelClustering.java
URL: http://svn.apache.org/viewvc/mahout/trunk/integration/src/test/java/org/apache/mahout/clustering/dirichlet/TestL1ModelClustering.java?rev=1171239&r1=1171238&r2=1171239&view=diff
==============================================================================
--- mahout/trunk/integration/src/test/java/org/apache/mahout/clustering/dirichlet/TestL1ModelClustering.java (original)
+++ mahout/trunk/integration/src/test/java/org/apache/mahout/clustering/dirichlet/TestL1ModelClustering.java Thu Sep 15 19:50:07 2011
@@ -53,15 +53,14 @@ public final class TestL1ModelClustering
private class MapElement implements Comparable<MapElement> {
+ private final Double pdf;
+ private final String doc;
+
MapElement(double pdf, String doc) {
this.pdf = pdf;
this.doc = doc;
}
- private final Double pdf;
-
- private final String doc;
-
@Override
// reverse compare to sort in reverse order
public int compareTo(MapElement e) {
@@ -75,6 +74,25 @@ public final class TestL1ModelClustering
}
@Override
+ public int hashCode() {
+ int hash = pdf == null ? 0 : pdf.hashCode();
+ hash ^= doc == null ? 0 : doc.hashCode();
+ return hash;
+ }
+
+ @Override
+ public boolean equals(Object other) {
+ if (!(other instanceof MapElement)) {
+ return false;
+ }
+ MapElement otherElement = (MapElement) other;
+ if ((pdf == null && otherElement.pdf != null) || (pdf != null && !pdf.equals(otherElement.pdf))) {
+ return false;
+ }
+ return doc == null ? otherElement.doc == null : doc.equals(otherElement.doc);
+ }
+
+ @Override
public String toString() {
return pdf.toString() + ' ' + doc;
}
Modified: mahout/trunk/integration/src/test/java/org/apache/mahout/text/SequenceFilesFromMailArchivesTest.java
URL: http://svn.apache.org/viewvc/mahout/trunk/integration/src/test/java/org/apache/mahout/text/SequenceFilesFromMailArchivesTest.java?rev=1171239&r1=1171238&r2=1171239&view=diff
==============================================================================
--- mahout/trunk/integration/src/test/java/org/apache/mahout/text/SequenceFilesFromMailArchivesTest.java (original)
+++ mahout/trunk/integration/src/test/java/org/apache/mahout/text/SequenceFilesFromMailArchivesTest.java Thu Sep 15 19:50:07 2011
@@ -133,15 +133,14 @@ public final class SequenceFilesFromMail
"Message-ID: <"+testVars[0][0]+">\n"+
"From: \"Testy McTester\" <us...@example.com>\n"+
"To: <an...@jakarta.apache.org>\n"+
- "Subject: "+testVars[0][1]+"\n"+
+ "Subject: "+testVars[0][1]+ '\n' +
"Date: Mon, 24 Jul 2000 12:24:56 -0700\n"+
"MIME-Version: 1.0\n"+
"Content-Type: text/plain;\n"+
" charset=\"Windows-1252\"\n"+
"Content-Transfer-Encoding: 7bit\n"+
"X-Spam-Rating: locus.apache.org 1.6.2 0/1000/N\n"+
- testVars[0][2]+
- "\n"+
+ testVars[0][2]+'\n' +
"From somebody@example.com Wed Jul 26 11:32:16 2000\n"+
"Return-Path: <so...@example.com>\n"+
"Mailing-List: contact ant-user-help@jakarta.apache.org; run by ezmlm\n"+
@@ -149,7 +148,7 @@ public final class SequenceFilesFromMail
"Received: (qmail 73966 invoked from network); 26 Jul 2000 11:32:16 -0000\n"+
"User-Agent: Microsoft-Outlook-Express-Macintosh-Edition/5.02.2022\n"+
"Date: Wed, 26 Jul 2000 13:32:08 +0200\n"+
- "Subject: "+testVars[1][1]+"\n"+
+ "Subject: "+testVars[1][1]+ '\n' +
"From: Another Test <so...@example.com>\n"+
"To: <an...@jakarta.apache.org>\n"+
"Message-Id: <"+testVars[1][0]+">\n"+
Modified: mahout/trunk/integration/src/test/java/org/apache/mahout/utils/vectors/lucene/LuceneIterableTest.java
URL: http://svn.apache.org/viewvc/mahout/trunk/integration/src/test/java/org/apache/mahout/utils/vectors/lucene/LuceneIterableTest.java?rev=1171239&r1=1171238&r2=1171239&view=diff
==============================================================================
--- mahout/trunk/integration/src/test/java/org/apache/mahout/utils/vectors/lucene/LuceneIterableTest.java (original)
+++ mahout/trunk/integration/src/test/java/org/apache/mahout/utils/vectors/lucene/LuceneIterableTest.java Thu Sep 15 19:50:07 2011
@@ -114,11 +114,9 @@ public final class LuceneIterableTest ex
//0 percent tolerance
LuceneIterable iterable = new LuceneIterable(reader, "id", "content", mapper);
try {
- Iterator<Vector> iterator = iterable.iterator();
- while (iterator.hasNext()) {
- iterator.next();
- }
- exceptionThrown = false;
+ for (Object a : iterable) {
+ }
+ exceptionThrown = false;
}
catch(IllegalStateException ise) {
exceptionThrown = true;
@@ -128,11 +126,9 @@ public final class LuceneIterableTest ex
//100 percent tolerance
iterable = new LuceneIterable(reader, "id", "content", mapper, -1, 1.0);
try {
- Iterator<Vector> iterator = iterable.iterator();
- while (iterator.hasNext()) {
- iterator.next();
- }
- exceptionThrown = false;
+ for (Object a : iterable) {
+ }
+ exceptionThrown = false;
}
catch(IllegalStateException ise) {
exceptionThrown = true;
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/ConstantVector.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/ConstantVector.java?rev=1171239&r1=1171238&r2=1171239&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/ConstantVector.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/ConstantVector.java Thu Sep 15 19:50:07 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;
import com.google.common.collect.AbstractIterator;
@@ -8,7 +25,7 @@ import java.util.Iterator;
* Implements a vector with all the same values.
*/
public class ConstantVector extends AbstractVector {
- private double value;
+ private final double value;
public ConstantVector(double value, int size) {
super(size);
@@ -57,7 +74,7 @@ public class ConstantVector extends Abst
public Iterator<Element> iterator() {
return new AbstractIterator<Element>() {
int i = 0;
- int n = size();
+ final int n = size();
@Override
protected Element computeNext() {
if (i < n) {
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/DiagonalMatrix.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/DiagonalMatrix.java?rev=1171239&r1=1171238&r2=1171239&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/DiagonalMatrix.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/DiagonalMatrix.java Thu Sep 15 19:50:07 2011
@@ -17,12 +17,8 @@
package org.apache.mahout.math;
-/**
- * Created by IntelliJ IDEA. User: tdunning Date: 8/9/11 Time: 10:36 PM To change this template use
- * File | Settings | File Templates.
- */
public class DiagonalMatrix extends AbstractMatrix {
- private Vector diagonal;
+ private final Vector diagonal;
public DiagonalMatrix(Vector values) {
super(values.size(), values.size());
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/NamedVector.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/NamedVector.java?rev=1171239&r1=1171238&r2=1171239&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/NamedVector.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/NamedVector.java Thu Sep 15 19:50:07 2011
@@ -51,6 +51,7 @@ public class NamedVector implements Vect
return delegate;
}
+ @Override
public int hashCode() {
return delegate.hashCode();
}
@@ -58,6 +59,7 @@ public class NamedVector implements Vect
/**
* To not break transitivity with other {@link Vector}s, this does not compare name.
*/
+ @Override
public boolean equals(Object other) {
return delegate.equals(other);
}
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/PermutedVectorView.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/PermutedVectorView.java?rev=1171239&r1=1171238&r2=1171239&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/PermutedVectorView.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/PermutedVectorView.java Thu Sep 15 19:50:07 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;
import com.google.common.collect.AbstractIterator;
@@ -8,9 +25,9 @@ import java.util.Iterator;
* Provides a permuted view of a vector.
*/
public class PermutedVectorView extends AbstractVector {
- private Vector vector; // the vector containing the data
- private int[] pivot; // convert from external index to internal
- private int[] unpivot; // convert from internal index to external
+ private final Vector vector; // the vector containing the data
+ private final int[] pivot; // convert from external index to internal
+ private final int[] unpivot; // convert from internal index to external
public PermutedVectorView(Vector vector, int[] pivot, int[] unpivot) {
super(vector.size());
@@ -76,14 +93,14 @@ public class PermutedVectorView extends
@Override
public Iterator<Element> iterator() {
return new AbstractIterator<Element>() {
- Iterator<Element> i = vector.iterator();
+ final Iterator<Element> i = vector.iterator();
@Override
protected Vector.Element computeNext() {
if (i.hasNext()) {
final Element x = i.next();
return new Element() {
- int index = unpivot[x.index()];
+ final int index = unpivot[x.index()];
@Override
public double get() {
@@ -117,14 +134,14 @@ public class PermutedVectorView extends
@Override
public Iterator<Element> iterateNonZero() {
return new AbstractIterator<Element>() {
- Iterator<Element> i = vector.iterateNonZero();
+ final Iterator<Element> i = vector.iterateNonZero();
@Override
protected Vector.Element computeNext() {
if (i.hasNext()) {
final Element x = i.next();
return new Element() {
- int index = unpivot[x.index()];
+ final int index = unpivot[x.index()];
@Override
public double get() {
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/PivotedMatrix.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/PivotedMatrix.java?rev=1171239&r1=1171238&r2=1171239&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/PivotedMatrix.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/PivotedMatrix.java Thu Sep 15 19:50:07 2011
@@ -23,12 +23,12 @@ import com.google.common.base.Preconditi
* Matrix that allows transparent row and column permutation.
*/
public class PivotedMatrix extends AbstractMatrix {
- private Matrix base;
- private int[] rowPivot;
- private int[] rowUnpivot;
- private int[] columnPivot;
- private int[] columnUnpivot;
+ private final Matrix base;
+ private final int[] rowPivot;
+ private final int[] rowUnpivot;
+ private final int[] columnPivot;
+ private final int[] columnUnpivot;
public PivotedMatrix(Matrix base, int[] pivot) {
this(base, pivot, java.util.Arrays.copyOf(pivot, pivot.length));
@@ -80,7 +80,7 @@ public class PivotedMatrix extends Abstr
swap(columnPivot, columnUnpivot, i, j);
}
- private void swap(int[] pivot, int[] unpivot, int i, int j) {
+ private static void swap(int[] pivot, int[] unpivot, int i, int j) {
Preconditions.checkPositionIndex(i, pivot.length);
Preconditions.checkPositionIndex(j, pivot.length);
if (i != j) {
@@ -263,7 +263,7 @@ public class PivotedMatrix extends Abstr
return pivot;
}
- private int[] invert(int[] pivot) {
+ private static int[] invert(int[] pivot) {
int[] x = new int[pivot.length];
for (int i = 0; i < pivot.length; i++) {
x[pivot[i]] = i;
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/QRDecomposition.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/QRDecomposition.java?rev=1171239&r1=1171238&r2=1171239&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/QRDecomposition.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/QRDecomposition.java Thu Sep 15 19:50:07 2011
@@ -223,6 +223,7 @@ public class QRDecomposition {
/**
* Returns a rough string rendition of a QR.
*/
+ @Override
public String toString() {
return String.format(Locale.ENGLISH, "QR(%d,%d,fullRank=%s)", originalColumns, originalRows, hasFullRank());
}
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/RandomTrinaryMatrix.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/RandomTrinaryMatrix.java?rev=1171239&r1=1171238&r2=1171239&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/RandomTrinaryMatrix.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/RandomTrinaryMatrix.java Thu Sep 15 19:50:07 2011
@@ -30,14 +30,14 @@ import java.util.concurrent.atomic.Atomi
* which uses a murmur hash of the coordinates.
*/
public class RandomTrinaryMatrix extends AbstractMatrix {
- private static AtomicInteger id = new AtomicInteger();
+ private static final AtomicInteger id = new AtomicInteger();
private static final int PRIME1 = 104047;
private static final int PRIME2 = 101377;
private static final int PRIME3 = 64661;
-
- private int seed;
private static final long SCALE = 1L << 32;
+ private final int seed;
+
// set this to true to use a high quality hash
private boolean highQuality = false;
@@ -76,10 +76,10 @@ public class RandomTrinaryMatrix extends
buf.putInt(row);
buf.putInt(column);
buf.flip();
- return (MurmurHash.hash64A(buf, seed) & (SCALE - 1)) / ((double) SCALE);
+ return (MurmurHash.hash64A(buf, seed) & (SCALE - 1)) / (double) SCALE;
} else {
// this isn't a fantastic random number generator, but it is just fine for random projections
- return ((((row * PRIME1) + (column * PRIME2 + row * column * PRIME3)) & 8) * 0.25) - 1;
+ return ((((row * PRIME1) + column * PRIME2 + row * column * PRIME3) & 8) * 0.25) - 1;
}
}
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/SequentialAccessSparseVector.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/SequentialAccessSparseVector.java?rev=1171239&r1=1171238&r2=1171239&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/SequentialAccessSparseVector.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/SequentialAccessSparseVector.java Thu Sep 15 19:50:07 2011
@@ -65,20 +65,20 @@ public class SequentialAccessSparseVecto
public SequentialAccessSparseVector(Vector other) {
this(other.size(), other.getNumNondefaultElements());
-
- if (!other.isSequentialAccess()) {
- // If the incoming Vector to copy is random, then adding items
- // from the Iterator can degrade performance dramatically if
- // the number of elements is large as this Vector tries to stay
- // in order as items are added, so it's better to sort the other
- // Vector's elements by index and then add them to this
- copySortedRandomAccessSparseVector(other);
- } else {
+
+ if (other.isSequentialAccess()) {
Iterator<Element> it = other.iterateNonZero();
Element e;
while (it.hasNext() && (e = it.next()) != null) {
set(e.index(), e.get());
}
+ } else {
+ // If the incoming Vector to copy is random, then adding items
+ // from the Iterator can degrade performance dramatically if
+ // the number of elements is large as this Vector tries to stay
+ // in order as items are added, so it's better to sort the other
+ // Vector's elements by index and then add them to this
+ copySortedRandomAccessSparseVector(other);
}
}
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/SingularValueDecomposition.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/SingularValueDecomposition.java?rev=1171239&r1=1171238&r2=1171239&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/SingularValueDecomposition.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/SingularValueDecomposition.java Thu Sep 15 19:50:07 2011
@@ -611,6 +611,7 @@ public class SingularValueDecomposition
* trace : 0
* </pre>
*/
+ @Override
public String toString() {
StringBuilder buf = new StringBuilder();
buf.append("---------------------------------------------------------------------\n");
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/SparseRowMatrix.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/SparseRowMatrix.java?rev=1171239&r1=1171238&r2=1171239&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/SparseRowMatrix.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/SparseRowMatrix.java Thu Sep 15 19:50:07 2011
@@ -24,7 +24,7 @@ package org.apache.mahout.math;
public class SparseRowMatrix extends AbstractMatrix {
private Vector[] rowVectors;
- private boolean randomAccessRows;
+ private final boolean randomAccessRows;
/**
* Construct a sparse matrix starting with the provided row vectors.
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/decomposer/SimpleEigenVerifier.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/decomposer/SimpleEigenVerifier.java?rev=1171239&r1=1171238&r2=1171239&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/decomposer/SimpleEigenVerifier.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/decomposer/SimpleEigenVerifier.java Thu Sep 15 19:50:07 2011
@@ -26,8 +26,15 @@ public class SimpleEigenVerifier impleme
Vector resultantVector = corpus.timesSquared(vector);
double newNorm = resultantVector.norm(2);
double oldNorm = vector.norm(2);
- double eigenValue = (newNorm > 0 && oldNorm > 0) ? newNorm / oldNorm : 1;
- double cosAngle = (newNorm > 0 && oldNorm > 0) ? resultantVector.dot(vector) / (newNorm * oldNorm) : 0;
+ double eigenValue;
+ double cosAngle;
+ if (newNorm > 0 && oldNorm > 0) {
+ eigenValue = newNorm / oldNorm;
+ cosAngle = resultantVector.dot(vector) / newNorm * oldNorm;
+ } else {
+ eigenValue = 1.0;
+ cosAngle = 0.0;
+ }
return new EigenStatus(eigenValue, cosAngle, false);
}
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=1171239&r1=1171238&r2=1171239&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 Thu Sep 15 19:50:07 2011
@@ -23,7 +23,6 @@ import java.util.Random;
import com.google.common.collect.Lists;
import org.apache.mahout.common.RandomUtils;
-import org.apache.mahout.math.AbstractMatrix;
import org.apache.mahout.math.DenseMatrix;
import org.apache.mahout.math.DenseVector;
import org.apache.mahout.math.Matrix;
@@ -319,7 +318,7 @@ public class HebbianSolver {
int rank = Integer.parseInt(props.getProperty("solver.output.desiredRank"));
double convergence = Double.parseDouble(props.getProperty("solver.convergence"));
int maxPasses = Integer.parseInt(props.getProperty("solver.maxPasses"));
- int numThreads = Integer.parseInt(props.getProperty("solver.verifier.numThreads"));
+ //int numThreads = Integer.parseInt(props.getProperty("solver.verifier.numThreads"));
HebbianUpdater updater = new HebbianUpdater();
SingularVectorVerifier verifier = new AsyncEigenVerifier();
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/decomposer/lanczos/LanczosState.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/decomposer/lanczos/LanczosState.java?rev=1171239&r1=1171238&r2=1171239&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/decomposer/lanczos/LanczosState.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/decomposer/lanczos/LanczosState.java Thu Sep 15 19:50:07 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.decomposer.lanczos;
import com.google.common.collect.Maps;
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/function/Functions.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/function/Functions.java?rev=1171239&r1=1171238&r2=1171239&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/function/Functions.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/function/Functions.java Thu Sep 15 19:50:07 2011
@@ -485,7 +485,7 @@ public final class Functions {
@Override
public double apply(double a) {
- return (from <= a && a <= to) ? 1 : 0;
+ return from <= a && a <= to ? 1 : 0;
}
};
}
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Exponential.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Exponential.java?rev=1171239&r1=1171238&r2=1171239&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Exponential.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Exponential.java Thu Sep 15 19:50:07 2011
@@ -73,6 +73,7 @@ public class Exponential extends Abstrac
/**
* Returns a String representation of the receiver.
*/
+ @Override
public String toString() {
return String.format(Locale.ENGLISH, "%s(%.4f)", this.getClass().getName(), lambda);
}
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Gamma.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Gamma.java?rev=1171239&r1=1171238&r2=1171239&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Gamma.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Gamma.java Thu Sep 15 19:50:07 2011
@@ -266,6 +266,7 @@ public class Gamma extends AbstractConti
return rate * Math.exp((alpha - 1.0) * Math.log(x * rate) - x * rate - logGamma(alpha));
}
+ @Override
public String toString() {
return this.getClass().getName() + '(' + rate + ',' + alpha + ')';
}
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/NegativeBinomial.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/NegativeBinomial.java?rev=1171239&r1=1171238&r2=1171239&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/NegativeBinomial.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/NegativeBinomial.java Thu Sep 15 19:50:07 2011
@@ -98,6 +98,7 @@ public final class NegativeBinomial exte
/**
* Returns a String representation of the receiver.
*/
+ @Override
public String toString() {
return this.getClass().getName() + '(' + r + ',' + p + ')';
}
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Normal.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Normal.java?rev=1171239&r1=1171238&r2=1171239&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Normal.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Normal.java Thu Sep 15 19:50:07 2011
@@ -103,6 +103,7 @@ public class Normal extends AbstractCont
}
/** Returns a String representation of the receiver. */
+ @Override
public String toString() {
return String.format(Locale.ENGLISH, "%s(m=%f, sd=%f)", this.getClass().getName(), mean, standardDeviation);
}
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Uniform.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Uniform.java?rev=1171239&r1=1171238&r2=1171239&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Uniform.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Uniform.java Thu Sep 15 19:50:07 2011
@@ -157,6 +157,7 @@ public class Uniform extends AbstractCon
/** Returns a String representation of the receiver. */
+ @Override
public String toString() {
return this.getClass().getName() + '(' + min + ',' + max + ')';
}
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/DoubleMatrix1D.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/DoubleMatrix1D.java?rev=1171239&r1=1171238&r2=1171239&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/DoubleMatrix1D.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/DoubleMatrix1D.java Thu Sep 15 19:50:07 2011
@@ -327,6 +327,7 @@ public abstract class DoubleMatrix1D ext
* @param obj the object to compare with.
* @return {@code true} if the objects are the same; {@code false} otherwise.
*/
+ @Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/DoubleMatrix2D.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/DoubleMatrix2D.java?rev=1171239&r1=1171238&r2=1171239&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/DoubleMatrix2D.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/DoubleMatrix2D.java Thu Sep 15 19:50:07 2011
@@ -290,6 +290,7 @@ public abstract class DoubleMatrix2D ext
* @param obj the object to compare with.
* @return {@code true} if the objects are the same; {@code false} otherwise.
*/
+ @Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/EigenvalueDecomposition.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/EigenvalueDecomposition.java?rev=1171239&r1=1171238&r2=1171239&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/EigenvalueDecomposition.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/EigenvalueDecomposition.java Thu Sep 15 19:50:07 2011
@@ -738,6 +738,7 @@ public final class EigenvalueDecompositi
* trace : 0
* </pre>
*/
+ @Override
public String toString() {
StringBuilder buf = new StringBuilder();
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/stats/OnlineSummarizer.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/stats/OnlineSummarizer.java?rev=1171239&r1=1171238&r2=1171239&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/stats/OnlineSummarizer.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/stats/OnlineSummarizer.java Thu Sep 15 19:50:07 2011
@@ -82,7 +82,7 @@ public class OnlineSummarizer {
double rate = 2 * (q[3] - q[1]) / n;
q[1] += (Math.signum(sample - q[1]) - 0.5) * rate;
- q[2] += (Math.signum(sample - q[2])) * rate;
+ q[2] += Math.signum(sample - q[2]) * rate;
q[3] += (Math.signum(sample - q[3]) + 0.5) * rate;
if (q[1] < q[0]) {
Modified: mahout/trunk/math/src/test/java/org/apache/mahout/math/AbstractTestVector.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/test/java/org/apache/mahout/math/AbstractTestVector.java?rev=1171239&r1=1171238&r2=1171239&view=diff
==============================================================================
--- mahout/trunk/math/src/test/java/org/apache/mahout/math/AbstractTestVector.java (original)
+++ mahout/trunk/math/src/test/java/org/apache/mahout/math/AbstractTestVector.java Thu Sep 15 19:50:07 2011
@@ -84,7 +84,7 @@ public abstract class AbstractTestVector
private static void checkIterator(Iterator<Vector.Element> nzIter, double[] values) {
while (nzIter.hasNext()) {
Vector.Element elt = nzIter.next();
- assertEquals((elt.index()) + " Value: " + values[elt.index()]
+ assertEquals(elt.index() + " Value: " + values[elt.index()]
+ " does not equal: " + elt.get(), values[elt.index()], elt.get(), 0.0);
}
}
@@ -159,7 +159,7 @@ public abstract class AbstractTestVector
}
@Test
- public void testSize() throws Exception {
+ public void testSize() {
assertEquals("size", 3, test.getNumNondefaultElements());
}
Modified: mahout/trunk/math/src/test/java/org/apache/mahout/math/PermutedVectorViewTest.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/test/java/org/apache/mahout/math/PermutedVectorViewTest.java?rev=1171239&r1=1171238&r2=1171239&view=diff
==============================================================================
--- mahout/trunk/math/src/test/java/org/apache/mahout/math/PermutedVectorViewTest.java (original)
+++ mahout/trunk/math/src/test/java/org/apache/mahout/math/PermutedVectorViewTest.java Thu Sep 15 19:50:07 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;
import org.apache.mahout.common.RandomUtils;
@@ -14,7 +31,7 @@ public class PermutedVectorViewTest exte
int[] pivot = pivot();
- PermutedVectorView pvv = new PermutedVectorView(v, pivot);
+ Vector pvv = new PermutedVectorView(v, pivot);
// verify the view has the same contents
for (int i = 0; i < 20; i++) {
@@ -59,11 +76,11 @@ public class PermutedVectorViewTest exte
}
}
- private int[] pivot() {
+ private static int[] pivot() {
return new int[]{11, 7, 10, 9, 8, 3, 17, 0, 19, 13, 12, 1, 5, 6, 16, 2, 4, 14, 18, 15};
}
- private int[] unpivot() {
+ private static int[] unpivot() {
int[] pivot = pivot();
int[] unpivot = new int[20];
@@ -73,10 +90,10 @@ public class PermutedVectorViewTest exte
return unpivot;
}
- private Vector randomVector() {
+ private static Vector randomVector() {
Vector v = new DenseVector(20);
v.assign(new DoubleFunction() {
- Random gen = RandomUtils.getRandom();
+ final Random gen = RandomUtils.getRandom();
@Override
public double apply(double arg1) {
Modified: mahout/trunk/math/src/test/java/org/apache/mahout/math/PivotedMatrixTest.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/test/java/org/apache/mahout/math/PivotedMatrixTest.java?rev=1171239&r1=1171238&r2=1171239&view=diff
==============================================================================
--- mahout/trunk/math/src/test/java/org/apache/mahout/math/PivotedMatrixTest.java (original)
+++ mahout/trunk/math/src/test/java/org/apache/mahout/math/PivotedMatrixTest.java Thu Sep 15 19:50:07 2011
@@ -1,14 +1,27 @@
+/**
+ * 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;
-import org.apache.mahout.common.RandomUtils;
import org.junit.Test;
-import java.util.Random;
-
public class PivotedMatrixTest extends MatrixTest {
@Override
public Matrix matrixFactory(double[][] values) {
- Random gen = RandomUtils.getRandom();
Matrix base = new DenseMatrix(values);
@@ -36,13 +49,17 @@ public class PivotedMatrixTest extends M
pm.swap(3, 5);
- assertEquals(0, pm.viewDiagonal().minus(new DenseVector(new double[]{0, 11, 22, 55, 44, 33, 66, 77, 88, 99})).norm(1), 1e-10);
+ assertEquals(0, pm.viewDiagonal().minus(
+ new DenseVector(new double[]{0, 11, 22, 55, 44, 33, 66, 77, 88, 99})).norm(1), 1.0e-10);
pm.swap(2, 7);
- assertEquals(0, pm.viewDiagonal().minus(new DenseVector(new double[]{0, 11, 77, 55, 44, 33, 66, 22, 88, 99})).norm(1), 1e-10);
+ assertEquals(0, pm.viewDiagonal().minus(
+ new DenseVector(new double[]{0, 11, 77, 55, 44, 33, 66, 22, 88, 99})).norm(1), 1.0e-10);
pm.swap(5, 8);
- assertEquals(0, pm.viewColumn(4).minus(new DenseVector(new double[]{4.0,14.0,74.0,54.0,44.0,84.0,64.0,24.0,34.0,94.0})).norm(1), 1e-10);
- assertEquals(0, pm.viewDiagonal().minus(new DenseVector(new double[]{0, 11, 77, 55, 44, 88, 66, 22, 33, 99})).norm(1), 1e-10);
+ assertEquals(0, pm.viewColumn(4).minus(
+ new DenseVector(new double[]{4.0,14.0,74.0,54.0,44.0,84.0,64.0,24.0,34.0,94.0})).norm(1), 1.0e-10);
+ assertEquals(0, pm.viewDiagonal().minus(
+ new DenseVector(new double[]{0, 11, 77, 55, 44, 88, 66, 22, 33, 99})).norm(1), 1.0e-10);
}
}
Modified: mahout/trunk/math/src/test/java/org/apache/mahout/math/TestDenseVector.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/test/java/org/apache/mahout/math/TestDenseVector.java?rev=1171239&r1=1171238&r2=1171239&view=diff
==============================================================================
--- mahout/trunk/math/src/test/java/org/apache/mahout/math/TestDenseVector.java (original)
+++ mahout/trunk/math/src/test/java/org/apache/mahout/math/TestDenseVector.java Thu Sep 15 19:50:07 2011
@@ -25,7 +25,7 @@ public final class TestDenseVector exten
}
@Override
- public void testSize() throws Exception {
+ public void testSize() {
assertEquals("size", 7, getTestVector().getNumNondefaultElements());
}
Modified: mahout/trunk/math/src/test/java/org/apache/mahout/math/TestMatrixView.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/test/java/org/apache/mahout/math/TestMatrixView.java?rev=1171239&r1=1171238&r2=1171239&view=diff
==============================================================================
--- mahout/trunk/math/src/test/java/org/apache/mahout/math/TestMatrixView.java (original)
+++ mahout/trunk/math/src/test/java/org/apache/mahout/math/TestMatrixView.java Thu Sep 15 19:50:07 2011
@@ -100,7 +100,6 @@ public final class TestMatrixView extend
@Test
public void testSize() {
- int[] c = test.getNumNondefaultElements();
assertEquals("row size", values.length - 2, test.rowSize());
assertEquals("col size", values[0].length - 1, test.columnSize());
}
Modified: mahout/trunk/math/src/test/java/org/apache/mahout/math/TestVectorView.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/test/java/org/apache/mahout/math/TestVectorView.java?rev=1171239&r1=1171238&r2=1171239&view=diff
==============================================================================
--- mahout/trunk/math/src/test/java/org/apache/mahout/math/TestVectorView.java (original)
+++ mahout/trunk/math/src/test/java/org/apache/mahout/math/TestVectorView.java Thu Sep 15 19:50:07 2011
@@ -82,7 +82,7 @@ public final class TestVectorView extend
int i = 0;
while (iter.hasNext()) {
Vector.Element elt = iter.next();
- assertEquals((elt.index()) + " Value: " + gold[i]
+ assertEquals(elt.index() + " Value: " + gold[i]
+ " does not equal: " + elt.get(), gold[i], elt.get(), 0.0);
i++;
}
Modified: mahout/trunk/math/src/test/java/org/apache/mahout/math/VectorTest.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/test/java/org/apache/mahout/math/VectorTest.java?rev=1171239&r1=1171238&r2=1171239&view=diff
==============================================================================
--- mahout/trunk/math/src/test/java/org/apache/mahout/math/VectorTest.java (original)
+++ mahout/trunk/math/src/test/java/org/apache/mahout/math/VectorTest.java Thu Sep 15 19:50:07 2011
@@ -57,8 +57,7 @@ public final class VectorTest extends Ma
}
assertEquals(n, elements);
- Vector empty = new SequentialAccessSparseVector(0);
- assertFalse(empty.iterator().hasNext());
+ assertFalse(new SequentialAccessSparseVector(0).iterator().hasNext());
}
@Test
@@ -519,7 +518,7 @@ public final class VectorTest extends Ma
}
try {
- norm = vec2.logNormalize(Double.POSITIVE_INFINITY);
+ vec2.logNormalize(Double.POSITIVE_INFINITY);
fail("Should fail with positive infinity norm");
} catch (IllegalArgumentException e) {
// expected
@@ -542,10 +541,10 @@ public final class VectorTest extends Ma
vec1.setQuick(2, -2);
double max = vec1.maxValue();
- assertEquals(max + " does not equal: " + (-1.0), -1.0, max, 0.0);
+ assertEquals(-1.0, max, 0.0);
int idx = vec1.maxValueIndex();
- assertEquals(idx + " does not equal: " + 0, 0, idx);
+ assertEquals(0, idx);
vec1 = new RandomAccessSparseVector(3);
@@ -553,10 +552,10 @@ public final class VectorTest extends Ma
vec1.setQuick(2, -2);
max = vec1.maxValue();
- assertEquals(max + " does not equal: " + 0, 0.0, max, 0.0);
+ assertEquals(0.0, max, 0.0);
idx = vec1.maxValueIndex();
- assertEquals(idx + " does not equal: " + 1, 1, idx);
+ assertEquals(1, idx);
vec1 = new SequentialAccessSparseVector(3);
@@ -564,10 +563,10 @@ public final class VectorTest extends Ma
vec1.setQuick(2, -2);
max = vec1.maxValue();
- assertEquals(max + " does not equal: " + 0, 0.0, max, 0.0);
+ assertEquals(0.0, max, 0.0);
idx = vec1.maxValueIndex();
- assertEquals(idx + " does not equal: " + 1, 1, idx);
+ assertEquals(1, idx);
vec1 = new DenseVector(3);
@@ -575,34 +574,34 @@ public final class VectorTest extends Ma
vec1.setQuick(2, -2);
max = vec1.maxValue();
- assertEquals(max + " does not equal: " + 0, 0.0, max, 0.0);
+ assertEquals(0.0, max, 0.0);
idx = vec1.maxValueIndex();
- assertEquals(idx + " does not equal: " + 1, 1, idx);
+ assertEquals(1, idx);
vec1 = new RandomAccessSparseVector(3);
max = vec1.maxValue();
- assertEquals(max + " does not equal 0", 0.0, max, EPSILON);
+ assertEquals(0.0, max, EPSILON);
vec1 = new DenseVector(3);
max = vec1.maxValue();
- assertEquals(max + " does not equal 0", 0.0, max, EPSILON);
+ assertEquals(0.0, max, EPSILON);
vec1 = new SequentialAccessSparseVector(3);
max = vec1.maxValue();
- assertEquals(max + " does not equal 0", 0.0, max, EPSILON);
+ assertEquals(0.0, max, EPSILON);
vec1 = new RandomAccessSparseVector(0);
max = vec1.maxValue();
- assertEquals(max + " does not equal -inf", Double.NEGATIVE_INFINITY, max, EPSILON);
+ assertEquals(Double.NEGATIVE_INFINITY, max, EPSILON);
vec1 = new DenseVector(0);
max = vec1.maxValue();
- assertEquals(max + " does not equal -inf", Double.NEGATIVE_INFINITY, max, EPSILON);
+ assertEquals(Double.NEGATIVE_INFINITY, max, EPSILON);
vec1 = new SequentialAccessSparseVector(0);
max = vec1.maxValue();
- assertEquals(max + " does not equal -inf", Double.NEGATIVE_INFINITY, max, EPSILON);
+ assertEquals(Double.NEGATIVE_INFINITY, max, EPSILON);
}
@@ -615,10 +614,10 @@ public final class VectorTest extends Ma
vec1.setQuick(2, 2);
double max = vec1.minValue();
- assertEquals(max + " does not equal: " + (1.0), 1.0, max, 0.0);
+ assertEquals(1.0, max, 0.0);
int idx = vec1.maxValueIndex();
- assertEquals(idx + " does not equal: " + 1, 1, idx);
+ assertEquals(1, idx);
vec1 = new RandomAccessSparseVector(3);
@@ -626,10 +625,10 @@ public final class VectorTest extends Ma
vec1.setQuick(2, -2);
max = vec1.maxValue();
- assertEquals(max + " does not equal: " + 0, 0.0, max, 0.0);
+ assertEquals(0.0, max, 0.0);
idx = vec1.maxValueIndex();
- assertEquals(idx + " does not equal: " + 1, 1, idx);
+ assertEquals(1, idx);
vec1 = new SequentialAccessSparseVector(3);
@@ -637,10 +636,10 @@ public final class VectorTest extends Ma
vec1.setQuick(2, -2);
max = vec1.maxValue();
- assertEquals(max + " does not equal: " + 0, 0.0, max, 0.0);
+ assertEquals(0.0, max, 0.0);
idx = vec1.maxValueIndex();
- assertEquals(idx + " does not equal: " + 1, 1, idx);
+ assertEquals(1, idx);
vec1 = new DenseVector(3);
@@ -648,34 +647,34 @@ public final class VectorTest extends Ma
vec1.setQuick(2, -2);
max = vec1.maxValue();
- assertEquals(max + " does not equal: " + 0, 0.0, max, 0.0);
+ assertEquals(0.0, max, 0.0);
idx = vec1.maxValueIndex();
- assertEquals(idx + " does not equal: " + 1, 1, idx);
+ assertEquals(1, idx);
vec1 = new RandomAccessSparseVector(3);
max = vec1.maxValue();
- assertEquals(max + " does not equal 0", 0.0, max, EPSILON);
+ assertEquals(0.0, max, EPSILON);
vec1 = new DenseVector(3);
max = vec1.maxValue();
- assertEquals(max + " does not equal 0", 0.0, max, EPSILON);
+ assertEquals(0.0, max, EPSILON);
vec1 = new SequentialAccessSparseVector(3);
max = vec1.maxValue();
- assertEquals(max + " does not equal 0", 0.0, max, EPSILON);
+ assertEquals(0.0, max, EPSILON);
vec1 = new RandomAccessSparseVector(0);
max = vec1.maxValue();
- assertEquals(max + " does not equal -inf", Double.NEGATIVE_INFINITY, max, EPSILON);
+ assertEquals(Double.NEGATIVE_INFINITY, max, EPSILON);
vec1 = new DenseVector(0);
max = vec1.maxValue();
- assertEquals(max + " does not equal -inf", Double.NEGATIVE_INFINITY, max, EPSILON);
+ assertEquals(Double.NEGATIVE_INFINITY, max, EPSILON);
vec1 = new SequentialAccessSparseVector(0);
max = vec1.maxValue();
- assertEquals(max + " does not equal -inf", Double.NEGATIVE_INFINITY, max, EPSILON);
+ assertEquals(Double.NEGATIVE_INFINITY, max, EPSILON);
}
Modified: mahout/trunk/math/src/test/java/org/apache/mahout/math/decomposer/hebbian/TestHebbianSolver.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/test/java/org/apache/mahout/math/decomposer/hebbian/TestHebbianSolver.java?rev=1171239&r1=1171238&r2=1171239&view=diff
==============================================================================
--- mahout/trunk/math/src/test/java/org/apache/mahout/math/decomposer/hebbian/TestHebbianSolver.java (original)
+++ mahout/trunk/math/src/test/java/org/apache/mahout/math/decomposer/hebbian/TestHebbianSolver.java Thu Sep 15 19:50:07 2011
@@ -63,7 +63,7 @@ public final class TestHebbianSolver ext
long time = 0L;
time += System.nanoTime() - start;
assertEquals(state.getCurrentEigens().numRows(), desiredRank);
- return (time / 1000000L);
+ return time / 1000000L;
}
Modified: mahout/trunk/math/src/test/java/org/apache/mahout/math/decomposer/lanczos/TestLanczosSolver.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/test/java/org/apache/mahout/math/decomposer/lanczos/TestLanczosSolver.java?rev=1171239&r1=1171238&r2=1171239&view=diff
==============================================================================
--- mahout/trunk/math/src/test/java/org/apache/mahout/math/decomposer/lanczos/TestLanczosSolver.java (original)
+++ mahout/trunk/math/src/test/java/org/apache/mahout/math/decomposer/lanczos/TestLanczosSolver.java Thu Sep 15 19:50:07 2011
@@ -36,11 +36,11 @@ public final class TestLanczosSolver ext
public void testEigenvalueCheck() throws Exception {
int size = 100;
Matrix m = randomHierarchicalSymmetricMatrix(size);
- int desiredRank = 80;
Vector initialVector = new DenseVector(size);
- initialVector.assign(1d / Math.sqrt(size));
+ initialVector.assign(1.0 / Math.sqrt(size));
LanczosSolver solver = new LanczosSolver();
+ int desiredRank = 80;
LanczosState state = new LanczosState(m, size, desiredRank, initialVector);
// set initial vector?
solver.solve(state, desiredRank, true);
@@ -68,9 +68,9 @@ public final class TestLanczosSolver ext
int numRows = 800;
int numColumns = 500;
Matrix corpus = randomHierarchicalMatrix(numRows, numColumns, false);
- int rank = 50;
Vector initialVector = new DenseVector(numColumns);
- initialVector.assign(1d / Math.sqrt(numColumns));
+ initialVector.assign(1.0 / Math.sqrt(numColumns));
+ int rank = 50;
LanczosState state = new LanczosState(corpus, numColumns, rank, initialVector);
long time = timeLanczos(corpus, state, rank, false);
assertTrue("Lanczos taking too long! Are you in the debugger? :)", time < 10000);
@@ -85,9 +85,9 @@ public final class TestLanczosSolver ext
public void testLanczosSolverSymmetric() throws Exception {
int numCols = 500;
Matrix corpus = randomHierarchicalSymmetricMatrix(numCols);
- int rank = 30;
Vector initialVector = new DenseVector(numCols);
- initialVector.assign(1d / Math.sqrt(numCols));
+ initialVector.assign(1.0 / Math.sqrt(numCols));
+ int rank = 30;
LanczosState state = new LanczosState(corpus, numCols, rank, initialVector);
long time = timeLanczos(corpus, state, rank, true);
assertTrue("Lanczos taking too long! Are you in the debugger? :)", time < 10000);