Repository: mahout Updated Branches: refs/heads/master 99fd9ba4f -> 0844e69d6
MAHOUT-1576 - Fix several low hanging warnings, the most important have to do with over-ridable operations in a constructor Project: http://git-wip-us.apache.org/repos/asf/mahout/repo Commit: http://git-wip-us.apache.org/repos/asf/mahout/commit/0844e69d Tree: http://git-wip-us.apache.org/repos/asf/mahout/tree/0844e69d Diff: http://git-wip-us.apache.org/repos/asf/mahout/diff/0844e69d Branch: refs/heads/master Commit: 0844e69d6cbdc7bbfd54ba01dc9c829764eaeb6d Parents: 99fd9ba Author: Ted Dunning <[email protected]> Authored: Sun Jun 8 18:24:48 2014 -0700 Committer: Ted Dunning <[email protected]> Committed: Sun Jun 8 18:24:48 2014 -0700 ---------------------------------------------------------------------- .../mahout/text/LuceneStorageConfiguration.java | 96 ++++++++++++++++---- .../SequenceFilesFromLuceneStorageTest.java | 2 +- .../mahout/math/list/ValueTypeArrayList.java.t | 2 +- .../math/map/OpenKeyTypeValueTypeHashMap.java.t | 2 - .../org/apache/mahout/math/SparseRowMatrix.java | 5 +- .../org/apache/mahout/math/set/OpenHashSet.java | 4 +- .../apache/mahout/math/TestSparseRowMatrix.java | 20 ++++ .../recommender/svd/ParallelSGDFactorizer.java | 4 +- .../mahout/classifier/mlp/NeuralNetwork.java | 6 +- .../sgd/AdaptiveLogisticRegression.java | 2 +- .../mahout/clustering/AbstractCluster.java | 30 +++--- .../org/apache/mahout/math/MatrixWritable.java | 2 +- 12 files changed, 127 insertions(+), 48 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mahout/blob/0844e69d/integration/src/main/java/org/apache/mahout/text/LuceneStorageConfiguration.java ---------------------------------------------------------------------- diff --git a/integration/src/main/java/org/apache/mahout/text/LuceneStorageConfiguration.java b/integration/src/main/java/org/apache/mahout/text/LuceneStorageConfiguration.java index 57586d5..88f86c5 100644 --- a/integration/src/main/java/org/apache/mahout/text/LuceneStorageConfiguration.java +++ b/integration/src/main/java/org/apache/mahout/text/LuceneStorageConfiguration.java @@ -93,8 +93,8 @@ public class LuceneStorageConfiguration implements Writable { this.idField = idField; this.fields = fields; - setQuery(DEFAULT_QUERY); - setMaxHits(DEFAULT_MAX_HITS); + this.query = DEFAULT_QUERY; + this.maxHits = DEFAULT_MAX_HITS; } public LuceneStorageConfiguration() { @@ -236,22 +236,86 @@ public class LuceneStorageConfiguration implements Writable { if (fields != null ? !fields.equals(that.fields) : that.fields != null) { return false; } - if (idField != null ? !idField.equals(that.idField) : that.idField != null) { - return false; - } - if (indexPaths != null ? !indexPaths.equals(that.indexPaths) : that.indexPaths != null) { - return false; - } - if (query != null ? !query.equals(that.query) : that.query != null) { - return false; - } - if (sequenceFilesOutputPath != null - ? !sequenceFilesOutputPath.equals(that.sequenceFilesOutputPath) - : that.sequenceFilesOutputPath != null) { - return false; + if (idField != null) { + if (!idField.equals(that.idField)) { + return false; + } else { + if (indexPaths != null) { + if (query != null) { + if (sequenceFilesOutputPath != null) { + return indexPaths.equals(that.indexPaths) && sequenceFilesOutputPath.equals(that.sequenceFilesOutputPath) && query.equals(that.query); + } else { + return indexPaths.equals(that.indexPaths) && that.sequenceFilesOutputPath == null && query.equals(that.query); + } + } else { + // query == null + if (that.query == null && indexPaths.equals(that.indexPaths)) { + if (sequenceFilesOutputPath != null) { + return sequenceFilesOutputPath.equals(that.sequenceFilesOutputPath); + } else { + return that.sequenceFilesOutputPath == null; + } + } else { + return false; + } + } + } else { + // indexPaths == null + if (that.indexPaths == null) { + if (query != null) { + if (sequenceFilesOutputPath != null) { + return sequenceFilesOutputPath.equals(that.sequenceFilesOutputPath) && query.equals(that.query); + } else { + return that.sequenceFilesOutputPath == null && query.equals(that.query); + } + } else { + if (that.query == null) { + if (sequenceFilesOutputPath != null) { + return sequenceFilesOutputPath.equals(that.sequenceFilesOutputPath); + } else { + return that.sequenceFilesOutputPath == null; + } + } else { + return false; + } + } + } else { + return false; + } + } + } + } else { + if (that.idField != null) { + return false; + } else { + if (indexPaths != null) { + if (query != null) { + if (sequenceFilesOutputPath != null) { + return !!indexPaths.equals(that.indexPaths) && !!query.equals(that.query) && !!sequenceFilesOutputPath.equals(that.sequenceFilesOutputPath); + } else { + return !!indexPaths.equals(that.indexPaths) && !!query.equals(that.query) && !(that.sequenceFilesOutputPath != null); + } + } else { + if (sequenceFilesOutputPath != null) { + return !!indexPaths.equals(that.indexPaths) && !(that.query != null) && !!sequenceFilesOutputPath.equals(that.sequenceFilesOutputPath); + } else { + return !!indexPaths.equals(that.indexPaths) && !(that.query != null) && !(that.sequenceFilesOutputPath != null); + } + } + } else { + if (query != null) { + if (sequenceFilesOutputPath != null) { + return that.indexPaths == null && query.equals(that.query) && sequenceFilesOutputPath.equals(that.sequenceFilesOutputPath); + } else { + return that.indexPaths == null && query.equals(that.query) && that.sequenceFilesOutputPath == null; + } + } else { + return that.indexPaths == null && that.query == null && (sequenceFilesOutputPath != null ? sequenceFilesOutputPath.equals(that.sequenceFilesOutputPath) : that.sequenceFilesOutputPath == null); + } + } + } } - return true; } @Override http://git-wip-us.apache.org/repos/asf/mahout/blob/0844e69d/integration/src/test/java/org/apache/mahout/text/SequenceFilesFromLuceneStorageTest.java ---------------------------------------------------------------------- diff --git a/integration/src/test/java/org/apache/mahout/text/SequenceFilesFromLuceneStorageTest.java b/integration/src/test/java/org/apache/mahout/text/SequenceFilesFromLuceneStorageTest.java index ba2c7ee..ccff1d6 100644 --- a/integration/src/test/java/org/apache/mahout/text/SequenceFilesFromLuceneStorageTest.java +++ b/integration/src/test/java/org/apache/mahout/text/SequenceFilesFromLuceneStorageTest.java @@ -102,7 +102,7 @@ public class SequenceFilesFromLuceneStorageTest extends AbstractLuceneStorageTes } @Test(expected = IllegalArgumentException.class) - public void testRun_UnstoredFields() throws IOException { + public void testRunUnstoredFields() throws IOException { commitDocuments(getDirectory(getIndexPath1AsFile()), new UnstoredFieldsDocument("5", "This is test document 5")); LuceneStorageConfiguration lucene2SeqConf = new LuceneStorageConfiguration(configuration, http://git-wip-us.apache.org/repos/asf/mahout/blob/0844e69d/math/src/main/java-templates/org/apache/mahout/math/list/ValueTypeArrayList.java.t ---------------------------------------------------------------------- diff --git a/math/src/main/java-templates/org/apache/mahout/math/list/ValueTypeArrayList.java.t b/math/src/main/java-templates/org/apache/mahout/math/list/ValueTypeArrayList.java.t index 9c537db..af14c0f 100644 --- a/math/src/main/java-templates/org/apache/mahout/math/list/ValueTypeArrayList.java.t +++ b/math/src/main/java-templates/org/apache/mahout/math/list/ValueTypeArrayList.java.t @@ -215,7 +215,7 @@ public class ${valueTypeCap}ArrayList extends Abstract${valueTypeCap}List implem * @param elements the new elements to be stored. * @return the receiver itself. */ - public Abstract${valueTypeCap}List elements(${valueType}[] elements) { + public final Abstract${valueTypeCap}List elements(${valueType}[] elements) { this.elements = elements; this.size = elements.length; return this; http://git-wip-us.apache.org/repos/asf/mahout/blob/0844e69d/math/src/main/java-templates/org/apache/mahout/math/map/OpenKeyTypeValueTypeHashMap.java.t ---------------------------------------------------------------------- diff --git a/math/src/main/java-templates/org/apache/mahout/math/map/OpenKeyTypeValueTypeHashMap.java.t b/math/src/main/java-templates/org/apache/mahout/math/map/OpenKeyTypeValueTypeHashMap.java.t index be1faf0..57d442e 100644 --- a/math/src/main/java-templates/org/apache/mahout/math/map/OpenKeyTypeValueTypeHashMap.java.t +++ b/math/src/main/java-templates/org/apache/mahout/math/map/OpenKeyTypeValueTypeHashMap.java.t @@ -31,10 +31,8 @@ import java.util.Arrays; import java.util.Iterator; import java.util.NoSuchElementException; -import org.apache.mahout.math.Vector.Element; import org.apache.mahout.math.function.${keyTypeCap}${valueTypeCap}Procedure; import org.apache.mahout.math.function.${keyTypeCap}Procedure; -import org.apache.mahout.math.function.IntProcedure; import org.apache.mahout.math.list.${keyTypeCap}ArrayList; #if (${keyType} != ${valueType}) http://git-wip-us.apache.org/repos/asf/mahout/blob/0844e69d/math/src/main/java/org/apache/mahout/math/SparseRowMatrix.java ---------------------------------------------------------------------- diff --git a/math/src/main/java/org/apache/mahout/math/SparseRowMatrix.java b/math/src/main/java/org/apache/mahout/math/SparseRowMatrix.java index 3eba39a..3021f3b 100644 --- a/math/src/main/java/org/apache/mahout/math/SparseRowMatrix.java +++ b/math/src/main/java/org/apache/mahout/math/SparseRowMatrix.java @@ -17,7 +17,6 @@ package org.apache.mahout.math; -import com.google.common.base.Preconditions; import org.apache.mahout.math.function.Functions; /** @@ -67,8 +66,8 @@ public class SparseRowMatrix extends AbstractMatrix { * Construct a matrix of the given cardinality, with rows defaulting to RandomAccessSparseVector * implementation * - * @param rows - * @param columns + * @param rows Number of rows in result + * @param columns Number of columns in result */ public SparseRowMatrix(int rows, int columns) { this(rows, columns, true); http://git-wip-us.apache.org/repos/asf/mahout/blob/0844e69d/math/src/main/java/org/apache/mahout/math/set/OpenHashSet.java ---------------------------------------------------------------------- diff --git a/math/src/main/java/org/apache/mahout/math/set/OpenHashSet.java b/math/src/main/java/org/apache/mahout/math/set/OpenHashSet.java index 073fb34..892a17d 100644 --- a/math/src/main/java/org/apache/mahout/math/set/OpenHashSet.java +++ b/math/src/main/java/org/apache/mahout/math/set/OpenHashSet.java @@ -366,7 +366,7 @@ public class OpenHashSet<T> extends AbstractSet implements Set<T> { * maxLoadFactor)</tt>. */ @Override - protected void setUp(int initialCapacity, double minLoadFactor, double maxLoadFactor) { + protected final void setUp(int initialCapacity, double minLoadFactor, double maxLoadFactor) { int capacity = initialCapacity; super.setUp(capacity, minLoadFactor, maxLoadFactor); capacity = nextPrime(capacity); @@ -536,7 +536,7 @@ public class OpenHashSet<T> extends AbstractSet implements Set<T> { } @Override - public <T> T[] toArray(T[] a) { + public <T1> T1[] toArray(T1[] a) { return keys().toArray(a); } http://git-wip-us.apache.org/repos/asf/mahout/blob/0844e69d/math/src/test/java/org/apache/mahout/math/TestSparseRowMatrix.java ---------------------------------------------------------------------- diff --git a/math/src/test/java/org/apache/mahout/math/TestSparseRowMatrix.java b/math/src/test/java/org/apache/mahout/math/TestSparseRowMatrix.java index 08174be..28b72f6 100644 --- a/math/src/test/java/org/apache/mahout/math/TestSparseRowMatrix.java +++ b/math/src/test/java/org/apache/mahout/math/TestSparseRowMatrix.java @@ -158,4 +158,24 @@ public final class TestSparseRowMatrix extends MatrixTest { } } } + + + @Test(timeout=5000) + public void testTimesCorrect() { + Random raw = RandomUtils.getRandom(); + Gamma gen = new Gamma(0.1, 0.1, raw); + + // build two large sequential sparse matrices and multiply them + Matrix x = new SparseRowMatrix(100, 2000, false) + .assign(Functions.random()); + + Matrix y = new SparseRowMatrix(2000, 100, false) + .assign(Functions.random()); + + Matrix xd = new DenseMatrix(100, 2000).assign(x); + Matrix yd = new DenseMatrix(2000, 100).assign(y); + assertEquals(0, xd.times(yd).minus(x.times(y)).aggregate(Functions.PLUS, Functions.ABS), 1e-15); + assertEquals(0, x.times(yd).minus(x.times(y)).aggregate(Functions.PLUS, Functions.ABS), 1e-15); + assertEquals(0, xd.times(y).minus(x.times(y)).aggregate(Functions.PLUS, Functions.ABS), 1e-15); + } } http://git-wip-us.apache.org/repos/asf/mahout/blob/0844e69d/mrlegacy/src/main/java/org/apache/mahout/cf/taste/impl/recommender/svd/ParallelSGDFactorizer.java ---------------------------------------------------------------------- diff --git a/mrlegacy/src/main/java/org/apache/mahout/cf/taste/impl/recommender/svd/ParallelSGDFactorizer.java b/mrlegacy/src/main/java/org/apache/mahout/cf/taste/impl/recommender/svd/ParallelSGDFactorizer.java index eb4a2a0..8a6a702 100644 --- a/mrlegacy/src/main/java/org/apache/mahout/cf/taste/impl/recommender/svd/ParallelSGDFactorizer.java +++ b/mrlegacy/src/main/java/org/apache/mahout/cf/taste/impl/recommender/svd/ParallelSGDFactorizer.java @@ -121,7 +121,7 @@ public class ParallelSGDFactorizer extends AbstractFactorizer { } } - public void shuffle() { + public final void shuffle() { unstagedPreferences = preferences.clone(); /* Durstenfeld shuffle */ for (int i = unstagedPreferences.length - 1; i > 0; i--) { @@ -138,7 +138,7 @@ public class ParallelSGDFactorizer extends AbstractFactorizer { unstagedPreferences[y] = p; } - public void stage() { + public final void stage() { preferences = unstagedPreferences; } http://git-wip-us.apache.org/repos/asf/mahout/blob/0844e69d/mrlegacy/src/main/java/org/apache/mahout/classifier/mlp/NeuralNetwork.java ---------------------------------------------------------------------- diff --git a/mrlegacy/src/main/java/org/apache/mahout/classifier/mlp/NeuralNetwork.java b/mrlegacy/src/main/java/org/apache/mahout/classifier/mlp/NeuralNetwork.java index dda73a0..cfbe5c4 100644 --- a/mrlegacy/src/main/java/org/apache/mahout/classifier/mlp/NeuralNetwork.java +++ b/mrlegacy/src/main/java/org/apache/mahout/classifier/mlp/NeuralNetwork.java @@ -160,7 +160,7 @@ public abstract class NeuralNetwork { * @param learningRate Learning rate must be a non-negative value. Recommend in range (0, 0.5). * @return The model instance. */ - public NeuralNetwork setLearningRate(double learningRate) { + public final NeuralNetwork setLearningRate(double learningRate) { Preconditions.checkArgument(learningRate > 0, "Learning rate must be larger than 0."); this.learningRate = learningRate; return this; @@ -182,7 +182,7 @@ public abstract class NeuralNetwork { * @param regularizationWeight regularization must be in the range [0, 0.1). * @return The model instance. */ - public NeuralNetwork setRegularizationWeight(double regularizationWeight) { + public final NeuralNetwork setRegularizationWeight(double regularizationWeight) { Preconditions.checkArgument(regularizationWeight >= 0 && regularizationWeight < 0.1, "Regularization weight must be in range [0, 0.1)"); this.regularizationWeight = regularizationWeight; @@ -204,7 +204,7 @@ public abstract class NeuralNetwork { * @param momentumWeight momentumWeight must be in range [0, 0.5]. * @return The model instance. */ - public NeuralNetwork setMomentumWeight(double momentumWeight) { + public final NeuralNetwork setMomentumWeight(double momentumWeight) { Preconditions.checkArgument(momentumWeight >= 0 && momentumWeight <= 1.0, "Momentum weight must be in range [0, 1.0]"); this.momentumWeight = momentumWeight; http://git-wip-us.apache.org/repos/asf/mahout/blob/0844e69d/mrlegacy/src/main/java/org/apache/mahout/classifier/sgd/AdaptiveLogisticRegression.java ---------------------------------------------------------------------- diff --git a/mrlegacy/src/main/java/org/apache/mahout/classifier/sgd/AdaptiveLogisticRegression.java b/mrlegacy/src/main/java/org/apache/mahout/classifier/sgd/AdaptiveLogisticRegression.java index 8a5011a..d00b021 100644 --- a/mrlegacy/src/main/java/org/apache/mahout/classifier/sgd/AdaptiveLogisticRegression.java +++ b/mrlegacy/src/main/java/org/apache/mahout/classifier/sgd/AdaptiveLogisticRegression.java @@ -268,7 +268,7 @@ public class AdaptiveLogisticRegression implements OnlineLearner, Writable { bufferSize = Math.min(minInterval, bufferSize); } - public void setPoolSize(int poolSize) { + public final void setPoolSize(int poolSize) { this.poolSize = poolSize; setupOptimizer(poolSize); } http://git-wip-us.apache.org/repos/asf/mahout/blob/0844e69d/mrlegacy/src/main/java/org/apache/mahout/clustering/AbstractCluster.java ---------------------------------------------------------------------- diff --git a/mrlegacy/src/main/java/org/apache/mahout/clustering/AbstractCluster.java b/mrlegacy/src/main/java/org/apache/mahout/clustering/AbstractCluster.java index 9d6b135..582ac0d 100644 --- a/mrlegacy/src/main/java/org/apache/mahout/clustering/AbstractCluster.java +++ b/mrlegacy/src/main/java/org/apache/mahout/clustering/AbstractCluster.java @@ -22,7 +22,6 @@ import java.io.DataOutput; import java.io.IOException; import java.util.Collection; import java.util.Collections; -import java.util.Locale; import java.util.List; import java.util.Map; import java.util.HashMap; @@ -31,7 +30,6 @@ import com.google.common.collect.Lists; import com.google.common.collect.Maps; import org.apache.hadoop.conf.Configuration; import org.apache.mahout.common.parameters.Parameter; -import org.apache.mahout.math.NamedVector; import org.apache.mahout.math.RandomAccessSparseVector; import org.apache.mahout.math.SequentialAccessSparseVector; import org.apache.mahout.math.Vector; @@ -66,24 +64,24 @@ public abstract class AbstractCluster implements Cluster { protected AbstractCluster() {} protected AbstractCluster(Vector point, int id2) { - setNumObservations(0); - setTotalObservations(0); - setCenter(point.clone()); - setRadius(center.like()); - setS0(0); - setS1(center.like()); - setS2(center.like()); + this.numObservations = (long) 0; + this.totalObservations = (long) 0; + this.center = point.clone(); + this.radius = center.like(); + this.s0 = (double) 0; + this.s1 = center.like(); + this.s2 = center.like(); this.id = id2; } protected AbstractCluster(Vector center2, Vector radius2, int id2) { - setNumObservations(0); - setTotalObservations(0); - setCenter(new RandomAccessSparseVector(center2)); - setRadius(new RandomAccessSparseVector(radius2)); - setS0(0); - setS1(center.like()); - setS2(center.like()); + this.numObservations = (long) 0; + this.totalObservations = (long) 0; + this.center = new RandomAccessSparseVector(center2); + this.radius = new RandomAccessSparseVector(radius2); + this.s0 = (double) 0; + this.s1 = center.like(); + this.s2 = center.like(); this.id = id2; } http://git-wip-us.apache.org/repos/asf/mahout/blob/0844e69d/mrlegacy/src/main/java/org/apache/mahout/math/MatrixWritable.java ---------------------------------------------------------------------- diff --git a/mrlegacy/src/main/java/org/apache/mahout/math/MatrixWritable.java b/mrlegacy/src/main/java/org/apache/mahout/math/MatrixWritable.java index 857fce9..7f0c1bc 100644 --- a/mrlegacy/src/main/java/org/apache/mahout/math/MatrixWritable.java +++ b/mrlegacy/src/main/java/org/apache/mahout/math/MatrixWritable.java @@ -40,7 +40,7 @@ public class MatrixWritable implements Writable { public MatrixWritable() {} public MatrixWritable(Matrix m) { - set(m); + this.matrix = m; } public Matrix get() {
