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 2010/01/21 20:51:51 UTC
svn commit: r901839 [2/3] - in /lucene/mahout/trunk:
collections-codegen-plugin/src/main/java/org/apache/mahout/collection_codegen/
core/src/main/java/org/apache/mahout/cf/taste/hadoop/item/
core/src/main/java/org/apache/mahout/cf/taste/impl/eval/ core...
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/math/DenseMatrixWritable.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/math/DenseMatrixWritable.java?rev=901839&r1=901838&r2=901839&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/math/DenseMatrixWritable.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/math/DenseMatrixWritable.java Thu Jan 21 19:51:44 2010
@@ -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.hadoop.io.Writable;
@@ -10,6 +27,7 @@
public class DenseMatrixWritable extends DenseMatrix implements Writable {
+ @Override
public void readFields(DataInput in) throws IOException {
columnLabelBindings = new HashMap<String, Integer>();
rowLabelBindings = new HashMap<String, Integer>();
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/math/MatrixWritable.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/math/MatrixWritable.java?rev=901839&r1=901838&r2=901839&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/math/MatrixWritable.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/math/MatrixWritable.java Thu Jan 21 19:51:44 2010
@@ -1,7 +1,23 @@
+/**
+ * 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.hadoop.io.Writable;
-import org.apache.mahout.math.Matrix;
import java.io.DataInput;
import java.io.DataOutput;
Modified: lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/model/file/FileDataModelTest.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/model/file/FileDataModelTest.java?rev=901839&r1=901838&r2=901839&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/model/file/FileDataModelTest.java (original)
+++ lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/model/file/FileDataModelTest.java Thu Jan 21 19:51:44 2010
@@ -56,12 +56,14 @@
private DataModel model;
private File testFile;
+ private File tmpLoc;
@Override
public void setUp() throws Exception {
super.setUp();
File tmpDir = new File(System.getProperty("java.io.tmpdir"));
- File tmpLoc = new File(tmpDir, "fileDataModel");
+ tmpLoc = new File(tmpDir, "fileDataModel");
+ tmpLoc.deleteOnExit();
if (tmpLoc.exists()) {
if (tmpLoc.isFile()) {
throw new IOException("Temp directory is a file");
@@ -85,6 +87,13 @@
model = new FileDataModel(testFile);
}
+ @Override
+ public void tearDown() throws Exception {
+ testFile.delete();
+ tmpLoc.delete();
+ super.tearDown();
+ }
+
public void testFile() throws Exception {
UserSimilarity userSimilarity = new PearsonCorrelationSimilarity(model);
UserNeighborhood neighborhood = new NearestNUserNeighborhood(2, userSimilarity, model);
Modified: lucene/mahout/trunk/core/src/test/java/org/apache/mahout/classifier/bayes/BayesFileFormatterTest.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/test/java/org/apache/mahout/classifier/bayes/BayesFileFormatterTest.java?rev=901839&r1=901838&r2=901839&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/test/java/org/apache/mahout/classifier/bayes/BayesFileFormatterTest.java (original)
+++ lucene/mahout/trunk/core/src/test/java/org/apache/mahout/classifier/bayes/BayesFileFormatterTest.java Thu Jan 21 19:51:44 2010
@@ -43,6 +43,8 @@
File tmpDir = new File(System.getProperty("java.io.tmpdir"));
input = new File(tmpDir, "bayes/input");
out = new File(tmpDir, "bayes/out");
+ input.deleteOnExit();
+ out.deleteOnExit();
input.mkdirs();
out.mkdirs();
File[] files = out.listFiles();
@@ -58,6 +60,13 @@
}
}
+ @Override
+ public void tearDown() throws Exception {
+ input.delete();
+ out.delete();
+ super.tearDown();
+ }
+
public void test() throws IOException {
Analyzer analyzer = new WhitespaceAnalyzer();
File[] files = out.listFiles();
Modified: lucene/mahout/trunk/core/src/test/java/org/apache/mahout/df/mapred/partial/PartialSequentialBuilder.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/test/java/org/apache/mahout/df/mapred/partial/PartialSequentialBuilder.java?rev=901839&r1=901838&r2=901839&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/test/java/org/apache/mahout/df/mapred/partial/PartialSequentialBuilder.java (original)
+++ lucene/mahout/trunk/core/src/test/java/org/apache/mahout/df/mapred/partial/PartialSequentialBuilder.java Thu Jan 21 19:51:44 2010
@@ -94,7 +94,7 @@
// retrieve the splits
TextInputFormat input = (TextInputFormat) job.getInputFormat();
InputSplit[] splits = input.getSplits(job, job.getNumMapTasks());
- log.debug("Nb splits : " + splits.length);
+ log.debug("Nb splits : {}", splits.length);
InputSplit[] sorted = Arrays.copyOf(splits, splits.length);
Builder.sortSplits(sorted);
@@ -134,14 +134,14 @@
mapper.close();
time = System.currentTimeMillis() - time;
- log.info("Duration : " + DFUtils.elapsedTime(time));
+ log.info("Duration : {}", DFUtils.elapsedTime(time));
if (time > slowest) {
slowest = time;
}
}
- log.info("Longest duration : " + DFUtils.elapsedTime(slowest));
+ log.info("Longest duration : {}", DFUtils.elapsedTime(slowest));
}
@Override
@@ -207,7 +207,7 @@
// retrieve the splits
TextInputFormat input = (TextInputFormat) job.getInputFormat();
InputSplit[] splits = input.getSplits(job, job.getNumMapTasks());
- log.debug("Nb splits : " + splits.length);
+ log.debug("Nb splits : {}", splits.length);
Builder.sortSplits(splits);
@@ -253,14 +253,14 @@
mapper.close();
time = System.currentTimeMillis() - time;
- log.info("Duration : " + DFUtils.elapsedTime(time));
+ log.info("Duration : {}", DFUtils.elapsedTime(time));
if (time > slowest) {
slowest = time;
}
}
- log.info("Longest duration : " + DFUtils.elapsedTime(slowest));
+ log.info("Longest duration : {}", DFUtils.elapsedTime(slowest));
}
/**
Modified: lucene/mahout/trunk/core/src/test/java/org/apache/mahout/df/mapreduce/partial/PartialSequentialBuilder.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/test/java/org/apache/mahout/df/mapreduce/partial/PartialSequentialBuilder.java?rev=901839&r1=901838&r2=901839&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/test/java/org/apache/mahout/df/mapreduce/partial/PartialSequentialBuilder.java (original)
+++ lucene/mahout/trunk/core/src/test/java/org/apache/mahout/df/mapreduce/partial/PartialSequentialBuilder.java Thu Jan 21 19:51:44 2010
@@ -99,7 +99,7 @@
List<InputSplit> splits = input.getSplits(job);
int nbSplits = splits.size();
- log.debug("Nb splits : " + nbSplits);
+ log.debug("Nb splits : {}", nbSplits);
InputSplit[] sorted = new InputSplit[nbSplits];
splits.toArray(sorted);
@@ -140,14 +140,14 @@
mapper.cleanup(firstOutput);
time = System.currentTimeMillis() - time;
- log.info("Duration : " + DFUtils.elapsedTime(time));
+ log.info("Duration : {}", DFUtils.elapsedTime(time));
if (time > slowest) {
slowest = time;
}
}
- log.info("Longest duration : " + DFUtils.elapsedTime(slowest));
+ log.info("Longest duration : {}", DFUtils.elapsedTime(slowest));
return true;
}
@@ -216,7 +216,7 @@
List<InputSplit> splits = input.getSplits(jobContext);
int nbSplits = splits.size();
- log.debug("Nb splits : " + nbSplits);
+ log.debug("Nb splits : {}", nbSplits);
InputSplit[] sorted = new InputSplit[nbSplits];
splits.toArray(sorted);
@@ -261,14 +261,14 @@
mapper.cleanup(secondOutput);
time = System.currentTimeMillis() - time;
- log.info("Duration : " + DFUtils.elapsedTime(time));
+ log.info("Duration : {}", DFUtils.elapsedTime(time));
if (time > slowest) {
slowest = time;
}
}
- log.info("Longest duration : " + DFUtils.elapsedTime(slowest));
+ log.info("Longest duration : {}", DFUtils.elapsedTime(slowest));
}
/**
Modified: lucene/mahout/trunk/core/src/test/java/org/apache/mahout/fpm/pfpgrowth/TransactionTreeTest.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/test/java/org/apache/mahout/fpm/pfpgrowth/TransactionTreeTest.java?rev=901839&r1=901838&r2=901839&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/test/java/org/apache/mahout/fpm/pfpgrowth/TransactionTreeTest.java (original)
+++ lucene/mahout/trunk/core/src/test/java/org/apache/mahout/fpm/pfpgrowth/TransactionTreeTest.java Thu Jan 21 19:51:44 2010
@@ -75,10 +75,10 @@
nodes += tree.addPattern(array, 1 + gen.nextInt(MAX_DUPLICATION));
}
- log.info("Input integers: " + total);
- log.info("Input data Size: " + total * SIZE_INT / (double) MEGABYTE);
- log.info("Nodes in Tree: " + nodes);
- log.info("Size of Tree: " + (nodes * SIZE_INT * NUM_OF_FPTREE_FIELDS + tree.childCount() * SIZE_INT)
+ log.info("Input integers: {}", total);
+ log.info("Input data Size: P{", total * SIZE_INT / (double) MEGABYTE);
+ log.info("Nodes in Tree: {}", nodes);
+ log.info("Size of Tree: {}", (nodes * SIZE_INT * NUM_OF_FPTREE_FIELDS + tree.childCount() * SIZE_INT)
/ (double) MEGABYTE);
TransactionTree vtree = new TransactionTree();
Iterator<Pair<List<Integer>, Long>> it = tree.getIterator();
@@ -94,9 +94,9 @@
sb.append(s);
}
- log.info("Number of transaction integers: " + items);
- log.info("Size of Transactions: " + (items * SIZE_INT + count * SIZE_LONG) / (double) MEGABYTE);
- log.info("Number of Transactions: " + count);
+ log.info("Number of transaction integers: {}", items);
+ log.info("Size of Transactions: {}", (items * SIZE_INT + count * SIZE_LONG) / (double) MEGABYTE);
+ log.info("Number of Transactions: {}", count);
tree.getCompressedTree();
it = vtree.getIterator();
StringBuilder sb1 = new StringBuilder();
Modified: lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/bayes/TestClassifier.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/bayes/TestClassifier.java?rev=901839&r1=901838&r2=901839&view=diff
==============================================================================
--- lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/bayes/TestClassifier.java (original)
+++ lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/bayes/TestClassifier.java Thu Jan 21 19:51:44 2010
@@ -261,7 +261,7 @@
for (File file : subdirs) {
log.info("--------------");
- log.info("Testing: " + file);
+ log.info("Testing: {}", file);
String correctLabel = file.getName().split(".txt")[0];
TimingStatistics operationStats = new TimingStatistics();
@@ -285,11 +285,14 @@
classifiedLabel);
if (verbose) {
// We have one document per line
- log.info("Line Number: " + lineNum + " Line(30): "
- + (line.length() > 30 ? line.substring(0, 30) : line)
- + " Expected Label: " + correctLabel
- + " Classified Label: " + classifiedLabel.getLabel()
- + " Correct: " + correct);
+ log.info("Line Number: {} Line(30): {} Expected Label: {} Classified Label: {} Correct: {}",
+ new Object[] {
+ lineNum,
+ (line.length() > 30 ? line.substring(0, 30) : line),
+ correctLabel,
+ classifiedLabel.getLabel(),
+ correct,
+ });
}
// log.info("{} {}", correctLabel, classifiedLabel);
Modified: lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/bayes/WikipediaDatasetCreatorDriver.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/bayes/WikipediaDatasetCreatorDriver.java?rev=901839&r1=901838&r2=901839&view=diff
==============================================================================
--- lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/bayes/WikipediaDatasetCreatorDriver.java (original)
+++ lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/bayes/WikipediaDatasetCreatorDriver.java Thu Jan 21 19:51:44 2010
@@ -167,8 +167,7 @@
JobClient client = new JobClient();
JobConf conf = new JobConf(WikipediaDatasetCreatorDriver.class);
if (log.isInfoEnabled()) {
- log.info("Input: " + input + " Out: " + output + " Categories: "
- + catFile);
+ log.info("Input: {} Out: {} Categories: {}", new Object[] {input, output, catFile});
}
conf.set("key.value.separator.in.input.line", " ");
conf.set("xmlinput.start", "<text xml:space=\"preserve\">");
Modified: lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/bayes/WikipediaDatasetCreatorMapper.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/bayes/WikipediaDatasetCreatorMapper.java?rev=901839&r1=901838&r2=901839&view=diff
==============================================================================
--- lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/bayes/WikipediaDatasetCreatorMapper.java (original)
+++ lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/bayes/WikipediaDatasetCreatorMapper.java Thu Jan 21 19:51:44 2010
@@ -143,8 +143,7 @@
} catch (InstantiationException e) {
throw new IllegalStateException(e);
}
- log.info("Configure: Input Categories size: " + inputCategories.size()
- + " Exact Match: " + exactMatchOnly + " Analyzer: "
- + analyzer.getClass().getName());
+ log.info("Configure: Input Categories size: {} Exact Match: {} Analyzer: {}",
+ new Object[] {inputCategories.size(), exactMatchOnly, analyzer.getClass().getName()});
}
}
Modified: lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/df/BreimanExample.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/df/BreimanExample.java?rev=901839&r1=901838&r2=901839&view=diff
==============================================================================
--- lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/df/BreimanExample.java (original)
+++ lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/df/BreimanExample.java Thu Jan 21 19:51:44 2010
@@ -106,7 +106,7 @@
treeBuilder.setM(m);
long time = System.currentTimeMillis();
- log.info("Growing a forest with m=" + m);
+ log.info("Growing a forest with m={}", m);
DecisionForest forestM = forestBuilder.build(nbtrees, errorM);
sumTimeM += System.currentTimeMillis() - time;
numNodesM += forestM.nbNodes();
@@ -218,20 +218,18 @@
Random rng = RandomUtils.getRandom();
for (int iteration = 0; iteration < nbIterations; iteration++) {
- log.info("Iteration " + iteration);
+ log.info("Iteration {}", iteration);
runIteration(rng, data, m, nbTrees);
}
log.info("********************************************");
- log.info("Selection error : " + sumTestErr / nbIterations);
- log.info("Single Input error : " + sumOneErr / nbIterations);
- log.info("One Tree error : " + sumTreeErr / nbIterations);
- log.info("");
- log.info("Mean Random Input Time : " + DFUtils.elapsedTime(sumTimeM / nbIterations));
- log.info("Mean Single Input Time : " + DFUtils.elapsedTime(sumTimeOne / nbIterations));
- log.info("");
- log.info("Mean Random Input Num Nodes : " + numNodesM / nbIterations);
- log.info("Mean Single Input Num Nodes : " + numNodesOne / nbIterations);
+ log.info("Selection error : {}", sumTestErr / nbIterations);
+ log.info("Single Input error : {}", sumOneErr / nbIterations);
+ log.info("One Tree error : {}", sumTreeErr / nbIterations);
+ log.info("Mean Random Input Time : {}", DFUtils.elapsedTime(sumTimeM / nbIterations));
+ log.info("Mean Single Input Time : {}", DFUtils.elapsedTime(sumTimeOne / nbIterations));
+ log.info("Mean Random Input Num Nodes : {}", numNodesM / nbIterations);
+ log.info("Mean Single Input Num Nodes : {}", numNodesOne / nbIterations);
return 0;
}
Modified: lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/df/mapred/BuildForest.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/df/mapred/BuildForest.java?rev=901839&r1=901838&r2=901839&view=diff
==============================================================================
--- lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/df/mapred/BuildForest.java (original)
+++ lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/df/mapred/BuildForest.java Thu Jan 21 19:51:44 2010
@@ -137,13 +137,13 @@
seed = Long.valueOf(cmdLine.getValue(seedOpt).toString());
}
- log.debug("data : " + dataName);
- log.debug("dataset : " + datasetName);
- log.debug("m : " + m);
- log.debug("seed : " + seed);
- log.debug("nbtrees : " + nbTrees);
- log.debug("isPartial : " + isPartial);
- log.debug("isOob : " + isOob);
+ log.debug("data : {}", dataName);
+ log.debug("dataset : {}", datasetName);
+ log.debug("m : {}", m);
+ log.debug("seed : {}", seed);
+ log.debug("nbtrees : {}", nbTrees);
+ log.debug("isPartial : {}", isPartial);
+ log.debug("isOob : {}", isOob);
dataPath = new Path(dataName);
datasetPath = new Path(datasetName);
@@ -186,7 +186,7 @@
DecisionForest forest = forestBuilder.build(nbTrees, callback);
time = System.currentTimeMillis() - time;
- log.info("Build Time: " + DFUtils.elapsedTime(time));
+ log.info("Build Time: {}", DFUtils.elapsedTime(time));
if (isOob) {
Random rng;
Modified: lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/df/mapreduce/BuildForest.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/df/mapreduce/BuildForest.java?rev=901839&r1=901838&r2=901839&view=diff
==============================================================================
--- lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/df/mapreduce/BuildForest.java (original)
+++ lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/df/mapreduce/BuildForest.java Thu Jan 21 19:51:44 2010
@@ -152,13 +152,13 @@
seed = Long.valueOf(cmdLine.getValue(seedOpt).toString());
}
- log.debug("data : " + dataName);
- log.debug("dataset : " + datasetName);
- log.debug("m : " + m);
- log.debug("seed : " + seed);
- log.debug("nbtrees : " + nbTrees);
- log.debug("isPartial : " + isPartial);
- log.debug("isOob : " + isOob);
+ log.debug("data : {}", dataName);
+ log.debug("dataset : {}", datasetName);
+ log.debug("m : {}", m);
+ log.debug("seed : {}", seed);
+ log.debug("nbtrees : {}", nbTrees);
+ log.debug("isPartial : {}", isPartial);
+ log.debug("isOob : {}", isOob);
dataPath = new Path(dataName);
datasetPath = new Path(datasetName);
@@ -199,7 +199,7 @@
DecisionForest forest = forestBuilder.build(nbTrees, callback);
time = System.currentTimeMillis() - time;
- log.info("Build Time: " + DFUtils.elapsedTime(time));
+ log.info("Build Time: {}", DFUtils.elapsedTime(time));
if (isOob) {
Random rng;
Modified: lucene/mahout/trunk/math/src/main/java-templates/org/apache/mahout/math/list/AbstractValueTypeList.java.t
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/math/src/main/java-templates/org/apache/mahout/math/list/AbstractValueTypeList.java.t?rev=901839&r1=901838&r2=901839&view=diff
==============================================================================
--- lucene/mahout/trunk/math/src/main/java-templates/org/apache/mahout/math/list/AbstractValueTypeList.java.t (original)
+++ lucene/mahout/trunk/math/src/main/java-templates/org/apache/mahout/math/list/AbstractValueTypeList.java.t Thu Jan 21 19:51:44 2010
@@ -41,7 +41,7 @@
/**
Abstract base class for resizable lists holding <code>${valueType}</code> elements; abstract.
*/
-public abstract class Abstract${valueTypeCap}List extends AbstractList implements ${valueTypeCap}BufferConsumer {
+public abstract class Abstract${valueTypeCap}List extends AbstractList implements ${valueTypeCap}BufferConsumer, Cloneable {
/**
* The size of the list. This is a READ_ONLY variable for all methods but setSizeRaw(int newSize) !!! If you violate
@@ -593,6 +593,7 @@
* @throws IndexOutOfBoundsException index is out of range (<tt>size()>0 && (from<0 || from>to ||
* to>=size())</tt>).
*/
+ @Override
public void removeFromTo(int from, int to) {
checkRangeFromTo(from, to, size);
int numMoved = size - to - 1;
Modified: lucene/mahout/trunk/math/src/main/java-templates/org/apache/mahout/math/list/ValueTypeArrayList.java.t
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/math/src/main/java-templates/org/apache/mahout/math/list/ValueTypeArrayList.java.t?rev=901839&r1=901838&r2=901839&view=diff
==============================================================================
--- lucene/mahout/trunk/math/src/main/java-templates/org/apache/mahout/math/list/ValueTypeArrayList.java.t (original)
+++ lucene/mahout/trunk/math/src/main/java-templates/org/apache/mahout/math/list/ValueTypeArrayList.java.t Thu Jan 21 19:51:44 2010
@@ -35,7 +35,7 @@
Resizable list holding <code>${valueType}</code> elements; implemented with arrays.
*/
-public class ${valueTypeCap}ArrayList extends Abstract${valueTypeCap}List {
+public class ${valueTypeCap}ArrayList extends Abstract${valueTypeCap}List implements Cloneable {
/**
* The array buffer into which the elements of the list are stored. The capacity of the list is the length of this
Modified: lucene/mahout/trunk/math/src/main/java-templates/org/apache/mahout/math/map/AbstractObjectValueTypeMap.java.t
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/math/src/main/java-templates/org/apache/mahout/math/map/AbstractObjectValueTypeMap.java.t?rev=901839&r1=901838&r2=901839&view=diff
==============================================================================
--- lucene/mahout/trunk/math/src/main/java-templates/org/apache/mahout/math/map/AbstractObjectValueTypeMap.java.t (original)
+++ lucene/mahout/trunk/math/src/main/java-templates/org/apache/mahout/math/map/AbstractObjectValueTypeMap.java.t Thu Jan 21 19:51:44 2010
@@ -286,7 +286,7 @@
@SuppressWarnings("unchecked")
public void pairsSortedByKey(List<T> keyList, ${valueTypeCap}ArrayList valueList) {
keys(keyList);
- if (keyList.size() == 0) {
+ if (keyList.isEmpty()) {
return;
}
T k = keyList.get(0);
@@ -294,9 +294,7 @@
if (!(k instanceof Comparable)) {
throw new UnsupportedOperationException("The key type for this map does not implement comparable");
}
- // go raw
- List rawKeyList = keyList;
- Collections.sort(rawKeyList);
+ Collections.sort((List) keyList);
valueList.setSize(keyList.size());
for (int i = keyList.size(); --i >= 0;) {
valueList.setQuick(i, get(keyList.get(i)));
Modified: lucene/mahout/trunk/math/src/main/java-templates/org/apache/mahout/math/map/OpenKeyTypeValueTypeHashMap.java.t
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/math/src/main/java-templates/org/apache/mahout/math/map/OpenKeyTypeValueTypeHashMap.java.t?rev=901839&r1=901838&r2=901839&view=diff
==============================================================================
--- lucene/mahout/trunk/math/src/main/java-templates/org/apache/mahout/math/map/OpenKeyTypeValueTypeHashMap.java.t (original)
+++ lucene/mahout/trunk/math/src/main/java-templates/org/apache/mahout/math/map/OpenKeyTypeValueTypeHashMap.java.t Thu Jan 21 19:51:44 2010
@@ -399,10 +399,6 @@
if (this.distinct > this.highWaterMark) {
int newCapacity = chooseGrowCapacity(this.distinct + 1, this.minLoadFactor, this.maxLoadFactor);
- /*
- log.info("grow rehashing ");
- log.info("at distinct="+distinct+", capacity="+table.length+" to newCapacity="+newCapacity+" ...");
- */
rehash(newCapacity);
return put(key, value);
}
@@ -491,12 +487,6 @@
if (this.distinct < this.lowWaterMark) {
int newCapacity = chooseShrinkCapacity(this.distinct, this.minLoadFactor, this.maxLoadFactor);
- /*
- if (table.length != newCapacity) {
- log.info("shrink rehashing ");
- log.info("at distinct="+distinct+", capacity="+table.length+" to newCapacity="+newCapacity+" ...");
- }
- */
rehash(newCapacity);
}
Modified: lucene/mahout/trunk/math/src/main/java-templates/org/apache/mahout/math/map/OpenObjectValueTypeHashMap.java.t
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/math/src/main/java-templates/org/apache/mahout/math/map/OpenObjectValueTypeHashMap.java.t?rev=901839&r1=901838&r2=901839&view=diff
==============================================================================
--- lucene/mahout/trunk/math/src/main/java-templates/org/apache/mahout/math/map/OpenObjectValueTypeHashMap.java.t (original)
+++ lucene/mahout/trunk/math/src/main/java-templates/org/apache/mahout/math/map/OpenObjectValueTypeHashMap.java.t Thu Jan 21 19:51:44 2010
@@ -392,10 +392,6 @@
if (this.distinct > this.highWaterMark) {
int newCapacity = chooseGrowCapacity(this.distinct + 1, this.minLoadFactor, this.maxLoadFactor);
- /*
- log.info("grow rehashing ");
- log.info("at distinct="+distinct+", capacity="+table.length+" to newCapacity="+newCapacity+" ...");
- */
rehash(newCapacity);
return put(key, value);
}
@@ -485,12 +481,6 @@
if (this.distinct < this.lowWaterMark) {
int newCapacity = chooseShrinkCapacity(this.distinct, this.minLoadFactor, this.maxLoadFactor);
- /*
- if (table.length != newCapacity) {
- log.info("shrink rehashing ");
- log.info("at distinct="+distinct+", capacity="+table.length+" to newCapacity="+newCapacity+" ...");
- }
- */
rehash(newCapacity);
}
Modified: lucene/mahout/trunk/math/src/main/java-templates/org/apache/mahout/math/set/OpenKeyTypeHashSet.java.t
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/math/src/main/java-templates/org/apache/mahout/math/set/OpenKeyTypeHashSet.java.t?rev=901839&r1=901838&r2=901839&view=diff
==============================================================================
--- lucene/mahout/trunk/math/src/main/java-templates/org/apache/mahout/math/set/OpenKeyTypeHashSet.java.t (original)
+++ lucene/mahout/trunk/math/src/main/java-templates/org/apache/mahout/math/set/OpenKeyTypeHashSet.java.t Thu Jan 21 19:51:44 2010
@@ -281,16 +281,12 @@
public boolean add(${keyType} key) {
int i = indexOfInsertion(key);
if (i < 0) { //already contained
- i = -i - 1;
+ //i = -i - 1;
return false;
}
if (this.distinct > this.highWaterMark) {
int newCapacity = chooseGrowCapacity(this.distinct + 1, this.minLoadFactor, this.maxLoadFactor);
- /*
- log.info("grow rehashing ");
- log.info("at distinct="+distinct+", capacity="+table.length+" to newCapacity="+newCapacity+" ...");
- */
rehash(newCapacity);
return add(key);
}
@@ -360,12 +356,6 @@
if (this.distinct < this.lowWaterMark) {
int newCapacity = chooseShrinkCapacity(this.distinct, this.minLoadFactor, this.maxLoadFactor);
- /*
- if (table.length != newCapacity) {
- log.info("shrink rehashing ");
- log.info("at distinct="+distinct+", capacity="+table.length+" to newCapacity="+newCapacity+" ...");
- }
- */
rehash(newCapacity);
}
Modified: lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/AbstractVector.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/AbstractVector.java?rev=901839&r1=901838&r2=901839&view=diff
==============================================================================
--- lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/AbstractVector.java (original)
+++ lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/AbstractVector.java Thu Jan 21 19:51:44 2010
@@ -194,7 +194,7 @@
Iterator<Element> it = iterateNonZero();
Element e;
while(it.hasNext() && (e = it.next()) != null) {
- final double diff = e.get() - v.getQuick(e.index());
+ double diff = e.get() - v.getQuick(e.index());
d += (diff * diff);
}
return d;
@@ -486,7 +486,7 @@
@Override
public int hashCode() {
- final int prime = 31;
+ int prime = 31;
int result = prime + ((name == null) ? 0 : name.hashCode());
result = prime * result + size();
Iterator<Element> iter = iterateNonZero();
Modified: lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/DenseVector.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/DenseVector.java?rev=901839&r1=901838&r2=901839&view=diff
==============================================================================
--- lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/DenseVector.java (original)
+++ lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/DenseVector.java Thu Jan 21 19:51:44 2010
@@ -67,9 +67,8 @@
super(vector.getName());
values = new double[vector.size()];
Iterator<Vector.Element> it = vector.iterateNonZero();
- Vector.Element e = null;
while(it.hasNext()) {
- e = it.next();
+ Vector.Element e = it.next();
values[e.index()] = e.get();
}
}
@@ -105,7 +104,7 @@
@Override
public Vector like(int cardinality) {
- DenseVector denseVector = new DenseVector(cardinality);
+ Vector denseVector = new DenseVector(cardinality);
denseVector.setLabelBindings(getLabelBindings());
return denseVector;
}
Modified: lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/MatrixView.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/MatrixView.java?rev=901839&r1=901838&r2=901839&view=diff
==============================================================================
--- lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/MatrixView.java (original)
+++ lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/MatrixView.java Thu Jan 21 19:51:44 2010
@@ -17,10 +17,6 @@
package org.apache.mahout.math;
-import java.io.DataInput;
-import java.io.DataOutput;
-import java.io.IOException;
-
/** Implements subset view of a Matrix */
public class MatrixView extends AbstractMatrix {
Modified: lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/Partitioning.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/Partitioning.java?rev=901839&r1=901838&r2=901839&view=diff
==============================================================================
--- lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/Partitioning.java (original)
+++ lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/Partitioning.java Thu Jan 21 19:51:44 2010
@@ -697,7 +697,7 @@
}
int splitter = splitters[medianIndex];
- //log.info("medianIndex="+medianIndex);
+
// Partition the list according to the splitter, i.e.
// Establish invariant: list[i] < splitter <= list[j] for i=from..medianIndex and j=medianIndex+1 .. to
// Could simply call:
@@ -718,7 +718,7 @@
*/
- //log.info("splitIndex="+splitIndex);
+
splitIndexes[medianIndex] = splitIndex;
//if (splitFrom == splitTo) return; // done
@@ -742,13 +742,11 @@
// recursively partition left half
if (splitFrom <= medianIndex - 1) {
- //log.info("1.recursive: from="+from+", to="+splitIndex+", splitFrom="+splitFrom+", splitTo="+(medianIndex-1));
partition(list, from, splitIndex, splitters, splitFrom, medianIndex - 1, splitIndexes);
}
// recursively partition right half
if (medianIndex + 1 <= splitTo) {
- //log.info("2.recursive: from="+(splitIndex+1)+", to="+to+", splitFrom="+(medianIndex+1)+", splitTo="+splitTo);
partition(list, splitIndex + 1, to, splitters, medianIndex + 1, splitTo, splitIndexes);
}
//log.info("BACK TRACKING\n\n");
@@ -782,31 +780,6 @@
public static int partition(int[] list, int from, int to, int splitter) {
steps += to - from + 1;
- /*
- log.info();
- if (from<=to) {
- log.info("SORT WORKING: from="+from+", to="+to+", splitter="+splitter);
- }
- else {
- log.info("SORT WORKING: NOTHING TO DO.");
- }
- */
-
-
- // returns index of last element < splitter
-
-
- /*
- for (int i=from-1; ++i<=to; ) {
- if (list[i] < splitter) {
- int element = list[i];
- list[i] = list[from];
- list[from++] = element;
- }
- }
- */
-
-
for (int i = from - 1; ++i <= to;) {
int element = list[i];
if (element < splitter) {
@@ -816,102 +789,8 @@
//swappedElements++;
}
}
- //if (from<=to) log.info("Swapped "+(head-from)+" elements");
-
-
- /*
- //JAL:
- int first = from;
- int last = to+1;
- --first;
- while (true) {
- while (++first < last && list[first] < splitter);
- while (first < --last && !(list[last] < splitter));
- if (first >= last) return first-1;
- int tmp = list[first];
- list[first] = list[last];
- list[last] = tmp;
- }
- */
-
-
- /*
- log.info("splitter="+splitter);
- log.info("before="+new IntArrayList(list));
- int head = from;
- int trail = to;
- int element;
- while (head<=trail) {
- head--;
- while (++head < trail && list[head] < splitter);
-
- trail++;
- while (--trail > head && list[trail] >= splitter);
-
- if (head != trail) {
- element = list[head];
- list[head] = list[trail];
- list[trail] = element;
- }
- head++;
- trail--;
- log.info("after ="+new IntArrayList(list)+", head="+head);
- }
- */
-
-
- /*
- //log.info("splitter="+splitter);
- //log.info("before="+new IntArrayList(list));
- to++;
- //int head = from;
- int element;
- //int oldHead;
- while (--to >= from) {
- element = list[to];
- if (element < splitter) {
- from--;
- while (++from < to && list[from] < splitter);
- //if (head != to) {
- list[to] = list[from];
- list[from++] = element;
- //oldHead = list[head];
- //list[head] = element;
- //list[i] = oldHead;
-
- //head++;
- //}
- //head++;
- }
- //log.info("after ="+new IntArrayList(list)+", head="+head);
- }
- */
-
- /*
- int i=from-1;
- int head = from;
- int trail = to;
- while (++i <= trail) {
- int element = list[i];
- if (element < splitter) {
- if (head == i) head++;
- else {
- // swap list[i] with list[from]
- int oldHead = list[head];
- int oldTrail = list[trail];
- list[head++] = element;
- list[i--] = oldTrail;
- list[trail--] = oldHead;
- }
- }
- //log.info(new IntArrayList(list));
-
- }
- */
-
return from - 1;
- //return head-1;
}
/**
Modified: lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/RandomAccessSparseVector.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/RandomAccessSparseVector.java?rev=901839&r1=901838&r2=901839&view=diff
==============================================================================
--- lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/RandomAccessSparseVector.java (original)
+++ lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/RandomAccessSparseVector.java Thu Jan 21 19:51:44 2010
@@ -202,9 +202,9 @@
private int offset = 0;
private final Element element = new Element(0);
- private IntArrayList intArrList = values.keys();
+ private final IntArrayList intArrList = values.keys();
- public NonZeroIterator(boolean sorted) {
+ private NonZeroIterator(boolean sorted) {
if (sorted) {
intArrList.sort();
}
@@ -259,10 +259,10 @@
}
private class DistanceSquared implements IntDoubleProcedure {
- Vector v;
+ final Vector v;
public double result = 0.0;
- public DistanceSquared(Vector v) {
+ DistanceSquared(Vector v) {
this.v = v;
}
@@ -281,14 +281,13 @@
DistanceSquared distanceSquared = new DistanceSquared(v);
values.forEachPair(distanceSquared);
- double result = distanceSquared.result;
- return result;
+ return distanceSquared.result;
}
private class AddToVector implements IntDoubleProcedure {
- Vector v;
+ final Vector v;
- public AddToVector(Vector v) {
+ private AddToVector(Vector v) {
this.v = v;
}
@@ -304,8 +303,7 @@
if (v.size() != size()) {
throw new CardinalityException();
}
- AddToVector addToVector = new AddToVector(v);
- values.forEachPair(addToVector);
+ values.forEachPair(new AddToVector(v));
}
}
Modified: lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/SequentialAccessSparseVector.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/SequentialAccessSparseVector.java?rev=901839&r1=901838&r2=901839&view=diff
==============================================================================
--- lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/SequentialAccessSparseVector.java (original)
+++ lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/SequentialAccessSparseVector.java Thu Jan 21 19:51:44 2010
@@ -18,6 +18,7 @@
package org.apache.mahout.math;
import java.util.Iterator;
+import java.util.NoSuchElementException;
/** Implements vector that only stores non-zero doubles */
public class SequentialAccessSparseVector extends AbstractVector {
@@ -51,8 +52,8 @@
public SequentialAccessSparseVector(Vector other) {
this(other.getName(), other.size(), other.getNumNondefaultElements());
- Iterator<Vector.Element> it = other.iterateNonZero();
- Vector.Element e;
+ Iterator<Element> it = other.iterateNonZero();
+ Element e;
while(it.hasNext() && (e = it.next()) != null) {
set(e.index(), e.get());
}
@@ -91,16 +92,16 @@
return values.getNumMappings();
}
- private class DistanceSquarer implements Iterator<Element> {
- Iterator<Element> it1;
- Iterator<Element> it2;
+ private static class DistanceSquarer implements Iterator<Element> {
+ final Iterator<Element> it1;
+ final Iterator<Element> it2;
Element e1 = null;
Element e2 = null;
boolean firstIteration = true;
Iterator<Element> notExhausted = null;
double v = 0;
- public DistanceSquarer(Iterator<Element> it1, Iterator<Element> it2) {
+ DistanceSquarer(Iterator<Element> it1, Iterator<Element> it2) {
this.it1 = it1;
this.it2 = it2;
}
@@ -207,12 +208,12 @@
}
@Override
- public java.util.Iterator<Vector.Element> iterateNonZero() {
+ public java.util.Iterator<Element> iterateNonZero() {
return new IntDoublePairIterator(values);
}
@Override
- public Iterator<Vector.Element> iterateAll() {
+ public Iterator<Element> iterateAll() {
return new IntDoublePairIterator(values, size());
}
@@ -256,7 +257,7 @@
}
- private static final class IntDoublePairIterator implements java.util.Iterator<Vector.Element> {
+ private static final class IntDoublePairIterator implements java.util.Iterator<Element> {
private int offset = 0;
private final AbstractElement element;
private final int maxOffset;
@@ -275,7 +276,10 @@
}
@Override
- public Vector.Element next() {
+ public Element next() {
+ if (offset >= maxOffset) {
+ throw new NoSuchElementException();
+ }
element.offset = offset++;
return element;
}
@@ -287,18 +291,18 @@
}
@Override
- public Vector.Element getElement(int index) {
+ public Element getElement(int index) {
return new DenseElement(index, values);
}
- private static abstract class AbstractElement implements Vector.Element {
+ private abstract static class AbstractElement implements Element {
int offset;
final OrderedIntDoubleMapping mapping;
final int[] indices;
final double[] values;
- public AbstractElement(int ind, OrderedIntDoubleMapping m) {
+ AbstractElement(int ind, OrderedIntDoubleMapping m) {
offset = ind;
mapping = m;
values = m.getValues();
@@ -309,13 +313,13 @@
private static final class DenseElement extends AbstractElement {
int index;
- public DenseElement(int ind, OrderedIntDoubleMapping mapping) {
+ DenseElement(int ind, OrderedIntDoubleMapping mapping) {
super(ind, mapping);
index = ind;
}
@Override
- public final double get() {
+ public double get() {
if(index >= indices.length) return 0.0;
int cur = indices[index];
while(cur < offset && index < indices.length - 1) cur = indices[++index];
@@ -324,34 +328,34 @@
}
@Override
- public final int index() {
+ public int index() {
return offset;
}
@Override
- public final void set(double value) {
+ public void set(double value) {
if(value != 0.0) mapping.set(indices[offset], value);
}
}
private static final class SparseElement extends AbstractElement {
- public SparseElement(int ind, OrderedIntDoubleMapping mapping) {
+ SparseElement(int ind, OrderedIntDoubleMapping mapping) {
super(ind, mapping);
}
@Override
- public final double get() {
+ public double get() {
return values[offset];
}
@Override
- public final int index() {
+ public int index() {
return indices[offset];
}
@Override
- public final void set(double value) {
+ public void set(double value) {
values[offset] = value;
}
}
Modified: lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/Sorting.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/Sorting.java?rev=901839&r1=901838&r2=901839&view=diff
==============================================================================
--- lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/Sorting.java (original)
+++ lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/Sorting.java Thu Jan 21 19:51:44 2010
@@ -375,7 +375,7 @@
if (double1 > double2) {
return false;
}
- if (double1 == double2 && 0.0d != double1) {
+ if (double1 == double2 && double1 != 0.0) {
return false;
}
@@ -402,7 +402,7 @@
if (float1 > float2) {
return false;
}
- if (float1 == float2 && 0.0f != float1) {
+ if (float1 == float2 && float1 != 0.0f) {
return false;
}
@@ -491,13 +491,12 @@
* @return
*/
private static int med3(int a, int b, int c, IntComparator comp) {
- int x = a, y = b, z = c;
- int comparisonxy = comp.compare(x, y);
- int comparisonxz = comp.compare(x, z);
- int comparisonyz = comp.compare(y, z);
- return comparisonxy < 0 ? (comparisonyz < 0 ? b
- : (comparisonxz < 0 ? c : a)) : (comparisonyz > 0 ? b
- : (comparisonxz > 0 ? c : a));
+ int comparisonab = comp.compare(a, b);
+ int comparisonac = comp.compare(a, c);
+ int comparisonbc = comp.compare(b, c);
+ return comparisonab < 0 ?
+ (comparisonbc < 0 ? b : (comparisonac < 0 ? c : a)) :
+ (comparisonbc > 0 ? b : (comparisonac > 0 ? c : a));
}
private static int med3(long[] array, int a, int b, int c, LongComparator comp) {
@@ -1344,7 +1343,7 @@
quickSort0(start, end, array, comp);
}
- private final static class ComparableAdaptor<T extends Comparable<? super T>>
+ private static final class ComparableAdaptor<T extends Comparable<? super T>>
implements Comparator<T> {
@Override
@@ -1710,7 +1709,7 @@
return l - 1;
}
- private final static ByteComparator naturalByteComparison = new ByteComparator() {
+ private static final ByteComparator naturalByteComparison = new ByteComparator() {
@Override
public int compare(byte o1, byte o2) {
return o1 - o2;
@@ -1826,7 +1825,7 @@
return l - 1;
}
- private final static CharComparator naturalCharComparison = new CharComparator() {
+ private static final CharComparator naturalCharComparison = new CharComparator() {
@Override
public int compare(char o1, char o2) {
return o1 - o2;
@@ -1942,7 +1941,7 @@
return l - 1;
}
- private final static ShortComparator naturalShortComparison = new ShortComparator() {
+ private static final ShortComparator naturalShortComparison = new ShortComparator() {
@Override
public int compare(short o1, short o2) {
return o1 - o2;
@@ -2059,7 +2058,7 @@
return l - 1;
}
- private final static IntComparator naturalIntComparison = new IntComparator() {
+ private static final IntComparator naturalIntComparison = new IntComparator() {
@Override
public int compare(int o1, int o2) {
return o1 < o2 ? -1 : o1 > o2 ? 1 : 0;
@@ -2177,7 +2176,7 @@
}
- private final static LongComparator naturalLongComparison = new LongComparator() {
+ private static final LongComparator naturalLongComparison = new LongComparator() {
@Override
public int compare(long o1, long o2) {
return o1 < o2 ? -1 : o1 > o2 ? 1 : 0;
@@ -2294,7 +2293,7 @@
return l - 1;
}
- private final static FloatComparator naturalFloatComparison = new FloatComparator() {
+ private static final FloatComparator naturalFloatComparison = new FloatComparator() {
@Override
public int compare(float o1, float o2) {
return Float.compare(o1, o2);
@@ -2411,7 +2410,7 @@
return l - 1;
}
- private final static DoubleComparator naturalDoubleComparison = new DoubleComparator() {
+ private static final DoubleComparator naturalDoubleComparison = new DoubleComparator() {
@Override
public int compare(double o1, double o2) {
return Double.compare(o1, o2);
Modified: lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/Timer.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/Timer.java?rev=901839&r1=901838&r2=901839&view=diff
==============================================================================
--- lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/Timer.java (original)
+++ lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/Timer.java Thu Jan 21 19:51:44 2010
@@ -137,7 +137,6 @@
}
t.stop();
t.display();
- log.info("I finished the test using " + t);
//do something we do not want to benchmark
Modified: lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/VectorView.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/VectorView.java?rev=901839&r1=901838&r2=901839&view=diff
==============================================================================
--- lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/VectorView.java (original)
+++ lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/VectorView.java Thu Jan 21 19:51:44 2010
@@ -17,9 +17,6 @@
package org.apache.mahout.math;
-import java.io.DataInput;
-import java.io.DataOutput;
-import java.io.IOException;
import java.util.Iterator;
import java.util.NoSuchElementException;
Modified: lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/bitvector/BitVector.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/bitvector/BitVector.java?rev=901839&r1=901838&r2=901839&view=diff
==============================================================================
--- lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/bitvector/BitVector.java (original)
+++ lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/bitvector/BitVector.java Thu Jan 21 19:51:44 2010
@@ -363,9 +363,6 @@
return true;
}
checkRangeFromTo(from, to, nbits);
- //log.info("\n");
- //log.info(this);
- //log.info("from="+from+", to="+to+", bit="+state);
// Cache some vars for speed.
long[] theBits = this.bits;
@@ -381,7 +378,6 @@
int partialWidth;
if (bitIndex > 0) { // There exists a leading partial unit.
partialWidth = Math.min(to - from + 1, bitsPerUnit - bitIndex);
- //log.info("partialWidth1="+partialWidth);
for (; --partialWidth >= 0; i++) {
if (QuickBitVector.get(theBits, i) == state) {
if (!procedure.apply(i)) {
@@ -404,7 +400,6 @@
} else {
partialWidth = 0;
}
- //log.info("partialWidth2="+partialWidth);
// Iterate over all full units, if any.
// (It does not matter that iterating over partial units is a little bit slow,
@@ -416,7 +411,6 @@
comparator = ~0L;
} // all 64 bits set
- //log.info("fromUnit="+fromUnit+", toUnit="+toUnit);
for (int unit = fromUnit; unit <= toUnit; unit++) {
long val = theBits[unit];
if (val != comparator) {
@@ -444,8 +438,6 @@
}
}
- //log.info("trail with i="+i);
-
// Iterate over trailing partial unit, if any.
for (; --partialWidth >= 0; i++) {
if (QuickBitVector.get(theBits, i) == state) {
Modified: lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/bitvector/QuickBitVector.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/bitvector/QuickBitVector.java?rev=901839&r1=901838&r2=901839&view=diff
==============================================================================
--- lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/bitvector/QuickBitVector.java (original)
+++ lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/bitvector/QuickBitVector.java Thu Jan 21 19:51:44 2010
@@ -156,8 +156,7 @@
public static long[] makeBitVector(int size, int bitsPerElement) {
int nBits = size * bitsPerElement;
int unitIndex = (nBits - 1) >> ADDRESS_BITS_PER_UNIT;
- long[] bitVector = new long[unitIndex + 1];
- return bitVector;
+ return new long[unitIndex + 1];
}
/**
@@ -191,31 +190,9 @@
long value = ~0L;
for (int i = BITS_PER_UNIT + 1; --i >= 1;) {
pows[i] = value >>> (BITS_PER_UNIT - i);
- //log.info((i)+":"+pows[i]);
}
pows[0] = 0L;
- //log.info((0)+":"+pows[0]);
return pows;
-
- //OLD STUFF
- /*
- for (int i=BITS_PER_UNIT+1; --i >= 0; ) {
- pows[i]=value;
- value = value >>> 1;
- log.info((i)+":"+pows[i]);
- }
- */
-
- /*
- long[] pows=new long[BITS_PER_UNIT];
- for (int i=0; i<BITS_PER_UNIT-1; i++) {
- pows[i]=Math.round(Math.pow(2.0,i+1))-1;
- log.info((i)+":"+pows[i]);
- }
- pows[BITS_PER_UNIT-1] = ~0L;
- log.info((BITS_PER_UNIT-1)+":"+pows[BITS_PER_UNIT-1]);
- return pows;
- */
}
/**
Modified: lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/buffer/ObjectBuffer.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/buffer/ObjectBuffer.java?rev=901839&r1=901838&r2=901839&view=diff
==============================================================================
--- lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/buffer/ObjectBuffer.java (original)
+++ lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/buffer/ObjectBuffer.java Thu Jan 21 19:51:44 2010
@@ -19,7 +19,7 @@
private final Object[] elements;
// vars cached for speed
- private final ObjectArrayList list;
+ private final ObjectArrayList<Object> list;
private final int capacity;
private int size;
@@ -34,7 +34,7 @@
this.target = target;
this.capacity = capacity;
this.elements = new Object[capacity];
- this.list = new ObjectArrayList(elements);
+ this.list = new ObjectArrayList<Object>(elements);
this.size = 0;
}
Modified: lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/buffer/ObjectBufferConsumer.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/buffer/ObjectBufferConsumer.java?rev=901839&r1=901838&r2=901839&view=diff
==============================================================================
--- lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/buffer/ObjectBufferConsumer.java (original)
+++ lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/buffer/ObjectBufferConsumer.java Thu Jan 21 19:51:44 2010
@@ -19,5 +19,5 @@
*
* @param list the list of which all elements shall be added.
*/
- void addAllOf(ObjectArrayList list);
+ void addAllOf(ObjectArrayList<Object> list);
}
Modified: lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/decomposer/hebbian/HebbianSolver.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/decomposer/hebbian/HebbianSolver.java?rev=901839&r1=901838&r2=901839&view=diff
==============================================================================
--- lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/decomposer/hebbian/HebbianSolver.java (original)
+++ lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/decomposer/hebbian/HebbianSolver.java Thu Jan 21 19:51:44 2010
@@ -41,18 +41,16 @@
*/
public class HebbianSolver {
- /**
- * Logger for this class.
- */
private static final Logger log = LoggerFactory.getLogger(HebbianSolver.class);
- protected final EigenUpdater updater;
- protected final SingularVectorVerifier verifier;
- protected final double convergenceTarget;
- protected final int maxPassesPerEigen;
+ private final EigenUpdater updater;
+ private final SingularVectorVerifier verifier;
+ private final double convergenceTarget;
+ private final int maxPassesPerEigen;
+ private final Random rng = new Random();
- protected int numPasses = 0;
- protected boolean debug = false;
+ private int numPasses = 0;
+ private final boolean debug = false;
/**
* Creates a new HebbianSolver
@@ -190,8 +188,10 @@
previousEigen = currentEigen.clone();
} else {
double dot = currentEigen.dot(previousEigen);
- if (dot > 0) dot /= (currentEigen.norm(2) * previousEigen.norm(2));
- // log.info("Current pass * previous pass = " + dot);
+ if (dot > 0) {
+ dot /= (currentEigen.norm(2) * previousEigen.norm(2));
+ }
+ // log.info("Current pass * previous pass = {}", dot);
}
}
}
@@ -203,7 +203,7 @@
eigens.assignRow(i, currentEigen);
eigenValues.add(eigenValue);
state.setCurrentEigenValues(eigenValues);
- log.info("Found eigenvector " + i + ", eigenvalue: " + eigenValue);
+ log.info("Found eigenvector {}, eigenvalue: {}", i, eigenValue);
/**
* TODO: Persist intermediate output!
@@ -229,9 +229,9 @@
*/
private int getRandomStartingIndex(Matrix corpus, Matrix eigens) {
int index;
- Vector v = null;
+ Vector v;
do {
- double r = new Random(System.nanoTime()).nextDouble();
+ double r = rng.nextDouble();
index = (int) (r * corpus.numRows());
v = corpus.getRow(index);
}
@@ -256,7 +256,7 @@
return true;
}
Matrix previousEigens = state.getCurrentEigens();
- log.info("Have made " + numPasses + " passes through the corpus, checking convergence...");
+ log.info("Have made {} passes through the corpus, checking convergence...", numPasses);
/*
* Step 1: orthogonalize currentPseudoEigen by subtracting off eigen(i) * helper.get(i)
* Step 2: zero-out the helper vector because it has already helped.
@@ -269,7 +269,7 @@
if (debug && currentPseudoEigen.norm(2) > 0) {
for (int i = 0; i < state.getNumEigensProcessed(); i++) {
Vector previousEigen = previousEigens.getRow(i);
- log.info("dot with previous: " + (previousEigen.dot(currentPseudoEigen)) / currentPseudoEigen.norm(2));
+ log.info("dot with previous: {}", (previousEigen.dot(currentPseudoEigen)) / currentPseudoEigen.norm(2));
}
}
/*
@@ -282,7 +282,7 @@
if (status.getCosAngle() == 0) {
log.info("Verifier not finished, making another pass...");
} else {
- log.info("Has 1 - cosAngle: " + (1 - status.getCosAngle()) + ", convergence target is: " + convergenceTarget);
+ log.info("Has 1 - cosAngle: {}, convergence target is: {}", (1 - status.getCosAngle()), convergenceTarget);
state.getStatusProgress().add(status);
}
return (state.getStatusProgress().size() <= maxPassesPerEigen && 1 - status.getCosAngle() > convergenceTarget);
@@ -292,16 +292,16 @@
return verifier.verify(corpus, currentPseudoEigen);
}
- public static void main(String args[]) {
+ public static void main(String[] args) {
Properties props = new Properties();
String propertiesFile = args.length > 0 ? args[0] : "config/solver.properties";
// props.load(new FileInputStream(propertiesFile));
String corpusDir = props.getProperty("solver.input.dir");
String outputDir = props.getProperty("solver.output.dir");
- if (corpusDir == null || corpusDir.equals("") || outputDir == null || outputDir.equals("")) {
- log.error(propertiesFile + " must contain values for solver.input.dir and solver.output.dir");
- System.exit(1);
+ if (corpusDir == null || corpusDir.length() == 0 || outputDir == null || outputDir.length() == 0) {
+ log.error("{} must contain values for solver.input.dir and solver.output.dir", propertiesFile);
+ return;
}
int inBufferSize = Integer.parseInt(props.getProperty("solver.input.bufferSize"));
int rank = Integer.parseInt(props.getProperty("solver.output.desiredRank"));
@@ -323,9 +323,9 @@
}
long now = System.currentTimeMillis();
TrainingState finalState = solver.solve(corpus, rank);
- long time = (long) ((System.currentTimeMillis() - now) / 1000);
- log.info("Solved " + finalState.getCurrentEigens().size()[AbstractMatrix.ROW] + " eigenVectors in " + time + " seconds. Persisted to " + outputDir);
- System.exit(0);
+ long time = (System.currentTimeMillis() - now) / 1000;
+ log.info("Solved {} eigenVectors in {} seconds. Persisted to {}",
+ new Object[] {finalState.getCurrentEigens().size()[AbstractMatrix.ROW], time, outputDir});
}
}
Modified: lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/decomposer/hebbian/HebbianUpdater.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/decomposer/hebbian/HebbianUpdater.java?rev=901839&r1=901838&r2=901839&view=diff
==============================================================================
--- lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/decomposer/hebbian/HebbianUpdater.java (original)
+++ lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/decomposer/hebbian/HebbianUpdater.java Thu Jan 21 19:51:44 2010
@@ -21,17 +21,10 @@
import org.apache.mahout.math.PlusFunction;
import org.apache.mahout.math.PlusWithScaleFunction;
import org.apache.mahout.math.Vector;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
public class HebbianUpdater implements EigenUpdater {
- /**
- * Logger for this class.
- */
- private static final Logger log = LoggerFactory.getLogger(HebbianUpdater.class);
-
+ @Override
public void update(Vector pseudoEigen,
Vector trainingVector,
TrainingState currentState) {
@@ -64,9 +57,9 @@
pseudoEigen.assign(trainingVector, new PlusWithScaleFunction(activation));
}
- private void updateTrainingProjectionsVector(TrainingState state,
- Vector trainingVector,
- int previousEigenIndex) {
+ private static void updateTrainingProjectionsVector(TrainingState state,
+ Vector trainingVector,
+ int previousEigenIndex) {
Vector previousEigen = state.mostRecentEigen();
Vector currentTrainingVectorProjection = state.currentTrainingProjection();
double projection = previousEigen.dot(trainingVector);
Modified: lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/decomposer/hebbian/MultiThreadedEigenVerifier.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/decomposer/hebbian/MultiThreadedEigenVerifier.java?rev=901839&r1=901838&r2=901839&view=diff
==============================================================================
--- lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/decomposer/hebbian/MultiThreadedEigenVerifier.java (original)
+++ lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/decomposer/hebbian/MultiThreadedEigenVerifier.java Thu Jan 21 19:51:44 2010
@@ -25,10 +25,11 @@
public class MultiThreadedEigenVerifier extends SimpleEigenVerifier {
- protected final Executor threadPool;
- protected EigenStatus status = null;
- protected boolean finished = false;
- protected boolean started = false;
+
+ private final Executor threadPool;
+ private EigenStatus status = null;
+ private boolean finished = false;
+ private boolean started = false;
public MultiThreadedEigenVerifier() {
threadPool = Executors.newFixedThreadPool(1);
@@ -54,15 +55,16 @@
return super.verify(eigenMatrix, vector);
}
- protected class VerifierRunnable implements Runnable {
- Matrix eigenMatrix;
- Vector vector;
+ private class VerifierRunnable implements Runnable {
+ private final Matrix eigenMatrix;
+ private final Vector vector;
- public VerifierRunnable(Matrix eigenMatrix, Vector vector) {
+ protected VerifierRunnable(Matrix eigenMatrix, Vector vector) {
this.eigenMatrix = eigenMatrix;
this.vector = vector;
}
+ @Override
public void run() {
EigenStatus status = innerVerify(eigenMatrix, vector);
synchronized (MultiThreadedEigenVerifier.this.status) {
Modified: lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/decomposer/hebbian/SimpleEigenVerifier.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/decomposer/hebbian/SimpleEigenVerifier.java?rev=901839&r1=901838&r2=901839&view=diff
==============================================================================
--- lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/decomposer/hebbian/SimpleEigenVerifier.java (original)
+++ lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/decomposer/hebbian/SimpleEigenVerifier.java Thu Jan 21 19:51:44 2010
@@ -16,19 +16,12 @@
*/
package org.apache.mahout.math.decomposer.hebbian;
-
import org.apache.mahout.math.Matrix;
import org.apache.mahout.math.Vector;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
public class SimpleEigenVerifier implements SingularVectorVerifier {
- /**
- * Logger for this class.
- */
- private static final Logger log = LoggerFactory.getLogger(SimpleEigenVerifier.class);
+ @Override
public EigenStatus verify(Matrix eigenMatrix, Vector vector) {
Vector resultantVector = eigenMatrix.timesSquared(vector);
double newNorm = resultantVector.norm(2);
Modified: lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/decomposer/lanczos/LanczosSolver.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/decomposer/lanczos/LanczosSolver.java?rev=901839&r1=901838&r2=901839&view=diff
==============================================================================
--- lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/decomposer/lanczos/LanczosSolver.java (original)
+++ lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/decomposer/lanczos/LanczosSolver.java Thu Jan 21 19:51:44 2010
@@ -64,24 +64,29 @@
* Matrix.timesSquared(Vector) as a Map-Reduce call.
*/
public class LanczosSolver {
- /**
- * Logger for this class.
- */
+
private static final Logger log = LoggerFactory.getLogger(LanczosSolver.class);
- public static double SAFE_MAX = 1e150;
+ public static final double SAFE_MAX = 1.0e150;
+
+ private static final double NANOS_IN_MILLI = 1.0e6;
- private static final double NANOS_IN_MILLI = 1e6;
+ public enum TimingSection {
+ ITERATE, ORTHOGANLIZE, TRIDIAG_DECOMP, FINAL_EIGEN_CREATE
+ }
+ private final Map<TimingSection, Long> startTimes = new EnumMap<TimingSection, Long>(TimingSection.class);
+ private final Map<TimingSection, Long> times = new EnumMap<TimingSection, Long>(TimingSection.class);
private double scaleFactor = 0;
private static final class Scale implements UnaryFunction {
private final double d;
- public Scale(double d) {
+ private Scale(double d) {
this.d = d;
}
+ @Override
public double apply(double arg1) {
return arg1 * d;
}
@@ -91,7 +96,7 @@
int desiredRank,
Matrix eigenVectors,
List<Double> eigenValues) {
- log.info("Finding " + desiredRank + " singular vectors of matrix with " + corpus.numRows() + " rows, via Lanczos");
+ log.info("Finding {} singular vectors of matrix with {} rows, via Lanczos", desiredRank, corpus.numRows());
Vector currentVector = getInitialVector(corpus);
Vector previousVector = new DenseVector(currentVector.size());
Matrix basis = new SparseRowMatrix(new int[]{desiredRank, corpus.numCols()});
@@ -102,7 +107,7 @@
for (int i = 1; i < desiredRank; i++) {
startTime(TimingSection.ITERATE);
Vector nextVector = corpus.timesSquared(currentVector);
- log.info(i + " passes through the corpus so far...");
+ log.info("{} passes through the corpus so far...", i);
nextVector.assign(new Scale(1 / scaleFactor));
nextVector.assign(previousVector, new PlusWithScaleFunction(-beta));
// now orthogonalize
@@ -115,7 +120,7 @@
// and normalize
beta = nextVector.norm(2);
if (outOfRange(beta) || outOfRange(alpha)) {
- log.warn("Lanczos parameters out of range: alpha = " + alpha + ", beta = " + beta + ". Bailing out early!");
+ log.warn("Lanczos parameters out of range: alpha = {}, beta = {}. Bailing out early!", alpha, beta);
break;
}
final double b = beta;
@@ -151,7 +156,7 @@
}
realEigen = realEigen.normalize();
eigenVectors.assignRow(i, realEigen);
- log.info("Eigenvector " + i + " found with eigenvalue " + eigenVals.get(i));
+ log.info("Eigenvector {} found with eigenvalue {}", i, eigenVals.get(i));
eigenValues.add(eigenVals.get(i));
}
log.info("LanczosSolver finished.");
@@ -162,7 +167,7 @@
return Double.isNaN(d) || d > SAFE_MAX || -d > SAFE_MAX;
}
- private void orthoganalizeAgainstAllButLast(Vector nextVector, Matrix basis) {
+ private static void orthoganalizeAgainstAllButLast(Vector nextVector, Matrix basis) {
for (int i = 0; i < basis.numRows() - 1; i++) {
double alpha = nextVector.dot(basis.getRow(i));
nextVector.assign(basis.getRow(i), new PlusWithScaleFunction(-alpha));
@@ -181,7 +186,7 @@
v.assign(vector, new PlusWithScaleFunction(1));
}
}
- v.assign(new Scale(1d / v.norm(2)));
+ v.assign(new Scale(1.0 / v.norm(2)));
return v;
}
@@ -198,10 +203,4 @@
return ((double) times.get(section)) / NANOS_IN_MILLI;
}
- public static enum TimingSection {
- ITERATE, ORTHOGANLIZE, TRIDIAG_DECOMP, FINAL_EIGEN_CREATE
- }
-
- private Map<TimingSection, Long> startTimes = new EnumMap<TimingSection, Long>(TimingSection.class);
- private Map<TimingSection, Long> times = new EnumMap<TimingSection, Long>(TimingSection.class);
}
Modified: lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/math/Functions.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/math/Functions.java?rev=901839&r1=901838&r2=901839&view=diff
==============================================================================
--- lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/math/Functions.java (original)
+++ lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/math/Functions.java Thu Jan 21 19:51:44 2010
@@ -420,8 +420,7 @@
}
};
- /** Makes this class non instantiable, but still let's others inherit from it. */
- protected Functions() {
+ private Functions() {
}
/**
Modified: lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/math/IntFunctions.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/math/IntFunctions.java?rev=901839&r1=901838&r2=901839&view=diff
==============================================================================
--- lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/math/IntFunctions.java (original)
+++ lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/math/IntFunctions.java Thu Jan 21 19:51:44 2010
@@ -164,8 +164,7 @@
}
};
- /** Makes this class non instantiable, but still let's others inherit from it. */
- protected IntFunctions() {
+ private IntFunctions() {
}
/** Constructs a function that returns <tt>a & b</tt>. <tt>a</tt> is a variable, <tt>b</tt> is fixed. */
Modified: lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/AbstractDiscreteDistribution.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/AbstractDiscreteDistribution.java?rev=901839&r1=901838&r2=901839&view=diff
==============================================================================
--- lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/AbstractDiscreteDistribution.java (original)
+++ lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/AbstractDiscreteDistribution.java Thu Jan 21 19:51:44 2010
@@ -27,7 +27,4 @@
return (double) nextInt();
}
- /** Returns a random number from the distribution. */
- @Override
- public abstract int nextInt();
}
Modified: lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Beta.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Beta.java?rev=901839&r1=901838&r2=901839&view=diff
==============================================================================
--- lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Beta.java (original)
+++ lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Beta.java Thu Jan 21 19:51:44 2010
@@ -393,42 +393,31 @@
* with unsigned long integer *seed, double a, b. *
* *
******************************************************************/
- double a = alpha;
- double b = beta;
- if (a > 1.0) {
- if (b > 1.0) {
- return (b1prs(a, b, randomGenerator));
+ if (alpha > 1.0) {
+ if (beta > 1.0) {
+ return (b1prs(alpha, beta, randomGenerator));
}
- if (b < 1.0) {
- return (1.0 - b01(b, a, randomGenerator));
- }
- if (b == 1.0) {
- return (Math.exp(Math.log(randomGenerator.raw()) / a));
+ if (beta < 1.0) {
+ return (1.0 - b01(beta, alpha, randomGenerator));
}
+ return (Math.exp(Math.log(randomGenerator.raw()) / alpha));
}
- if (a < 1.0) {
- if (b > 1.0) {
- return (b01(a, b, randomGenerator));
- }
- if (b < 1.0) {
- return (b00(a, b, randomGenerator));
+ if (alpha < 1.0) {
+ if (beta > 1.0) {
+ return (b01(alpha, beta, randomGenerator));
}
- if (b == 1.0) {
- return (Math.exp(Math.log(randomGenerator.raw()) / a));
+ if (beta < 1.0) {
+ return (b00(alpha, beta, randomGenerator));
}
+ return (Math.exp(Math.log(randomGenerator.raw()) / alpha));
}
- if (a == 1.0) {
- if (b != 1.0) {
- return (1.0 - Math.exp(Math.log(randomGenerator.raw()) / b));
- }
- if (b == 1.0) {
- return (randomGenerator.raw());
- }
+ if (beta != 1.0) {
+ return (1.0 - Math.exp(Math.log(randomGenerator.raw()) / beta));
+ } else {
+ return (randomGenerator.raw());
}
-
- return 0.0;
}
/** Returns the cumulative distribution function. */
Modified: lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Distributions.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Distributions.java?rev=901839&r1=901838&r2=901839&view=diff
==============================================================================
--- lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Distributions.java (original)
+++ lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Distributions.java Thu Jan 21 19:51:44 2010
@@ -217,8 +217,7 @@
}
double u = randomGenerator.raw(); // U(0/1)
- double x = l_sign * (Math.exp(Math.log(u) * l3) - Math.exp(Math.log(1.0 - u) * l4));
- return x;
+ return l_sign * (Math.exp(Math.log(u) * l3) - Math.exp(Math.log(1.0 - u) * l4));
}
/**
Modified: lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Fun.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Fun.java?rev=901839&r1=901838&r2=901839&view=diff
==============================================================================
--- lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Fun.java (original)
+++ lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Fun.java Thu Jan 21 19:51:44 2010
@@ -23,8 +23,7 @@
private static double _fkt_value(double lambda, double z1, double z2, double x_value) {
- double y_value = Math.cos(z1 * x_value) / (Math.pow((x_value * x_value + z2 * z2), (lambda + 0.5)));
- return y_value;
+ return Math.cos(z1 * x_value) / (Math.pow((x_value * x_value + z2 * z2), (lambda + 0.5)));
}
public static double bessel2_fkt(double lambda, double beta) {
@@ -384,8 +383,7 @@
private static double fkt2_value(double lambda, double beta, double x_value) {
- double y_value = cosh(lambda * x_value) * Math.exp(-beta * cosh(x_value));
- return y_value;
+ return cosh(lambda * x_value) * Math.exp(-beta * cosh(x_value));
}
private static double cosh(double x) {
Modified: lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Gamma.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Gamma.java?rev=901839&r1=901838&r2=901839&view=diff
==============================================================================
--- lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Gamma.java (original)
+++ lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Gamma.java Thu Jan 21 19:51:44 2010
@@ -66,11 +66,10 @@
* - NORMAL(seed) ... Normal generator N(0,1). *
* *
******************************************************************/
- double a = alpha;
// Check for invalid input values
- if (a <= 0.0) {
+ if (alpha <= 0.0) {
throw new IllegalArgumentException();
}
if (lambda <= 0.0) {
@@ -79,18 +78,18 @@
double gds;
double b = 0.0;
- if (a < 1.0) { // CASE A: Acceptance rejection algorithm gs
- b = 1.0 + 0.36788794412 * a; // Step 1
+ if (alpha < 1.0) { // CASE A: Acceptance rejection algorithm gs
+ b = 1.0 + 0.36788794412 * alpha; // Step 1
while (true) {
double p = b * randomGenerator.raw();
if (p <= 1.0) { // Step 2. Case gds <= 1
- gds = Math.exp(Math.log(p) / a);
+ gds = Math.exp(Math.log(p) / alpha);
if (Math.log(randomGenerator.raw()) <= -gds) {
return (gds / lambda);
}
} else { // Step 3. Case gds > 1
- gds = -Math.log((b - p) / a);
- if (Math.log(randomGenerator.raw()) <= ((a - 1.0) * Math.log(gds))) {
+ gds = -Math.log((b - p) / alpha);
+ if (Math.log(randomGenerator.raw()) <= ((alpha - 1.0) * Math.log(gds))) {
return (gds / lambda);
}
}
@@ -100,9 +99,9 @@
double s = 0.0;
double d = 0.0;
double aa = -1.0;
- if (a != aa) { // Step 1. Preparations
- aa = a;
- ss = a - 0.5;
+ if (alpha != aa) { // Step 1. Preparations
+ aa = alpha;
+ ss = alpha - 0.5;
s = Math.sqrt(ss);
d = 5.656854249 - 12.0 * s;
}
@@ -130,9 +129,9 @@
double si = 0.0;
double c = 0.0;
double aaa = -1.0;
- if (a != aaa) { // Step 4. Set-up for hat case
- aaa = a;
- double r = 1.0 / a;
+ if (alpha != aaa) { // Step 4. Set-up for hat case
+ aaa = alpha;
+ double r = 1.0 / alpha;
double q9 = 0.0001710320;
double q8 = -0.0004701849;
double q7 = 0.0006053049;
@@ -144,8 +143,8 @@
double q1 = 0.0416666664;
q0 = ((((((((q9 * r + q8) * r + q7) * r + q6) * r + q5) * r + q4) *
r + q3) * r + q2) * r + q1) * r;
- if (a > 3.686) {
- if (a > 13.022) {
+ if (alpha > 3.686) {
+ if (alpha > 13.022) {
b = 1.77;
si = 0.75;
c = 0.1515 / s;
Modified: lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Hyperbolic.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Hyperbolic.java?rev=901839&r1=901838&r2=901839&view=diff
==============================================================================
--- lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Hyperbolic.java (original)
+++ lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Hyperbolic.java Thu Jan 21 19:51:44 2010
@@ -20,10 +20,6 @@
// cached values shared for generateHyperbolic(...)
private double a_setup = 0.0;
private double b_setup = -1.0;
- private double x;
- private double u;
- private double v;
- private double e;
private double hr;
private double hl;
private double s;
@@ -69,22 +65,20 @@
* unsigned long integer *seed. *
* *
******************************************************************/
- double a = alpha;
- double b = beta;
- if ((a_setup != a) || (b_setup != b)) { // SET-UP
+ if ((a_setup != alpha) || (b_setup != beta)) { // SET-UP
//double pl;
- double amb = a * a - b * b;
+ double amb = alpha * alpha - beta * beta;
samb = Math.sqrt(amb); // -log(f(mode))
- double mode = b / samb;
- double help_1 = a * Math.sqrt(2.0 * samb + 1.0);
- double help_2 = b * (samb + 1.0);
+ double mode = beta / samb;
+ double help_1 = alpha * Math.sqrt(2.0 * samb + 1.0);
+ double help_2 = beta * (samb + 1.0);
double mpa = (help_2 + help_1) / amb;
double mmb = (help_2 - help_1) / amb;
double a_ = mpa - mode;
double b_ = -mmb + mode;
- hr = -1.0 / (-a * mpa / Math.sqrt(1.0 + mpa * mpa) + b);
- hl = 1.0 / (-a * mmb / Math.sqrt(1.0 + mmb * mmb) + b);
+ hr = -1.0 / (-alpha * mpa / Math.sqrt(1.0 + mpa * mpa) + beta);
+ hl = 1.0 / (-alpha * mmb / Math.sqrt(1.0 + mmb * mmb) + beta);
double a_1 = a_ - hr;
double b_1 = b_ - hl;
mmb_1 = mode - b_1; // lower border
@@ -95,33 +89,35 @@
pr = hr / s;
pmr = pm + pr;
- a_setup = a;
- b_setup = b;
+ a_setup = alpha;
+ b_setup = beta;
}
// GENERATOR
+ double x;
while (true) {
- u = randomGenerator.raw();
- v = randomGenerator.raw();
+ double u = randomGenerator.raw();
+ double v = randomGenerator.raw();
if (u <= pm) { // Rejection with a uniform majorizing function
// over the body of the distribution
x = mmb_1 + u * s;
- if (Math.log(v) <= (-a * Math.sqrt(1.0 + x * x) + b * x + samb)) {
+ if (Math.log(v) <= (-alpha * Math.sqrt(1.0 + x * x) + beta * x + samb)) {
break;
}
} else {
+ double e;
if (u <= pmr) { // Rejection with an exponential envelope on the
// right side of the mode
e = -Math.log((u - pm) / pr);
x = mpa_1 + hr * e;
- if ((Math.log(v) - e) <= (-a * Math.sqrt(1.0 + x * x) + b * x + samb)) {
+ if ((Math.log(v) - e) <= (-alpha * Math.sqrt(1.0 + x * x) + beta * x + samb)) {
break;
}
} else { // Rejection with an exponential envelope on the
// left side of the mode
e = Math.log((u - pmr) / (1.0 - pmr));
x = mmb_1 + hl * e;
- if ((Math.log(v) + e) <= (-a * Math.sqrt(1.0 + x * x) + b * x + samb)) {
+ if ((Math.log(v) + e) <= (-alpha * Math.sqrt(1.0 + x * x) + beta * x + samb)) {
break;
}
}
Modified: lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Logarithmic.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Logarithmic.java?rev=901839&r1=901838&r2=901839&view=diff
==============================================================================
--- lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Logarithmic.java (original)
+++ lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Logarithmic.java Thu Jan 21 19:51:44 2010
@@ -85,7 +85,6 @@
k = 1;
double p = t;
while (u > p) {
- //log.info("u="+u+", p="+p);
u -= p;
k++;
p *= a * (k - 1.0) / (double) k;
Modified: lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Poisson.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Poisson.java?rev=901839&r1=901838&r2=901839&view=diff
==============================================================================
--- lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Poisson.java (original)
+++ lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Poisson.java Thu Jan 21 19:51:44 2010
@@ -55,7 +55,6 @@
private double p6;
// cache for both;
- private int m;
private static final double MEAN_MAX = Integer.MAX_VALUE;
@@ -131,6 +130,7 @@
//static double p,q,p0,pp[36];
//static long ll,m;
+ int m;
if (my < SWITCH_MEAN) { // CASE B: Inversion- start new table and calculate p0
if (my != my_old) {
my_old = my;
Modified: lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/sampling/RandomSampler.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/sampling/RandomSampler.java?rev=901839&r1=901838&r2=901839&view=diff
==============================================================================
--- lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/sampling/RandomSampler.java (original)
+++ lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/sampling/RandomSampler.java Thu Jan 21 19:51:44 2010
@@ -9,7 +9,6 @@
package org.apache.mahout.math.jet.random.sampling;
import org.apache.mahout.math.PersistentObject;
-import org.apache.mahout.math.Timer;
import org.apache.mahout.math.jet.random.engine.RandomEngine;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Modified: lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/sampling/WeightedRandomSampler.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/sampling/WeightedRandomSampler.java?rev=901839&r1=901838&r2=901839&view=diff
==============================================================================
--- lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/sampling/WeightedRandomSampler.java (original)
+++ lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/sampling/WeightedRandomSampler.java Thu Jan 21 19:51:44 2010
@@ -12,8 +12,7 @@
import org.apache.mahout.math.jet.random.Uniform;
import org.apache.mahout.math.jet.random.engine.RandomEngine;
import org.apache.mahout.math.list.IntArrayList;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+
/**
* Conveniently computes a stable subsequence of elements from a given input sequence;
* Picks (samples) exactly one random element from successive blocks of <tt>weight</tt> input elements each.
@@ -28,9 +27,6 @@
@Deprecated
public class WeightedRandomSampler extends PersistentObject {
- private static final Logger log = LoggerFactory.getLogger(WeightedRandomSampler.class);
-
-
//public class BlockedRandomSampler extends Object implements java.io.Serializable {
private int skip;
private int nextTriggerPos;
@@ -136,8 +132,6 @@
sample.add(i);
}
}
-
- log.info("Sample = " + sample);
}
}