You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mahout.apache.org by sr...@apache.org on 2011/05/02 20:14:25 UTC
svn commit: r1098706 [4/5] - in /mahout/trunk: core/src/main/java/
core/src/main/java/org/apache/mahout/
core/src/main/java/org/apache/mahout/cf/taste/eval/
core/src/main/java/org/apache/mahout/cf/taste/hadoop/
core/src/main/java/org/apache/mahout/cf/t...
Modified: mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/kddcup/track1/svd/ParallelArraysSGDFactorizer.java
URL: http://svn.apache.org/viewvc/mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/kddcup/track1/svd/ParallelArraysSGDFactorizer.java?rev=1098706&r1=1098705&r2=1098706&view=diff
==============================================================================
--- mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/kddcup/track1/svd/ParallelArraysSGDFactorizer.java (original)
+++ mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/kddcup/track1/svd/ParallelArraysSGDFactorizer.java Mon May 2 18:14:18 2011
@@ -35,12 +35,12 @@ import java.util.Collection;
import java.util.Random;
/**
- * {@link org.apache.mahout.cf.taste.impl.recommender.svd.Factorizer} based on Simon Funk's famous article "Netflix Update: Try this at home"
- * {@see http://sifter.org/~simon/journal/20061211.html}.
- *
- * Attempts to be as memory efficient as possible, only iterating once through the {@link FactorizablePreferences} or {@link DataModel} while
- * copying everything to primitive arrays. Learning works in place on these datastructures after that.
+ * {@link Factorizer} based on Simon Funk's famous article <a href="http://sifter.org/~simon/journal/20061211.html">
+ * "Netflix Update: Try this at home"</a>.
*
+ * Attempts to be as memory efficient as possible, only iterating once through the
+ * {@link FactorizablePreferences} or {@link DataModel} while copying everything to primitive arrays.
+ * Learning works in place on these datastructures after that.
*/
public class ParallelArraysSGDFactorizer implements Factorizer {
@@ -149,8 +149,8 @@ public class ParallelArraysSGDFactorizer
log.info("Average preference value is {}", averagePreference);
double prefInterval = factorizablePreferences.getMaxPreference() - factorizablePreferences.getMinPreference();
- defaultValue = Math.sqrt((averagePreference - (prefInterval * 0.1)) / numFeatures);
- interval = (prefInterval * 0.1) / numFeatures;
+ defaultValue = Math.sqrt((averagePreference - prefInterval * 0.1) / numFeatures);
+ interval = prefInterval * 0.1 / numFeatures;
userFeatures = new double[numUsers][numFeatures];
itemFeatures = new double[numItems][numFeatures];
@@ -173,11 +173,11 @@ public class ParallelArraysSGDFactorizer
shufflePreferences();
log.info("Starting training of feature {} ...", feature);
for (int currentIteration = 0; currentIteration < numIterations; currentIteration++) {
- if (currentIteration != (numIterations - 1)) {
- trainingIteration(feature);
- } else {
+ if (currentIteration == numIterations - 1) {
double rmse = trainingIterationWithRmse(feature);
log.info("Finished training feature {} with RMSE {}", feature, rmse);
+ } else {
+ trainingIteration(feature);
}
}
if (feature < numFeatures - 1) {
@@ -202,7 +202,7 @@ public class ParallelArraysSGDFactorizer
double rmse = 0;
for (int index = 0; index < userIndexes.length; index++) {
double error = train(userIndexes[index], itemIndexes[index], feature, values[index], cachedEstimates[index]);
- rmse += (error * error);
+ rmse += error * error;
}
return Math.sqrt(rmse / (double) userIndexes.length);
}
@@ -211,7 +211,7 @@ public class ParallelArraysSGDFactorizer
double sum = cachedEstimate;
sum += userFeatures[userIndex][feature] * itemFeatures[itemIndex][feature];
if (trailing) {
- sum += (numFeatures - feature - 1) * ((defaultValue + interval) * (defaultValue + interval));
+ sum += (numFeatures - feature - 1) * (defaultValue + interval) * (defaultValue + interval);
if (sum > maxPreference) {
sum = maxPreference;
} else if (sum < minPreference) {
Modified: mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/kddcup/track1/svd/Track1SVDRunner.java
URL: http://svn.apache.org/viewvc/mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/kddcup/track1/svd/Track1SVDRunner.java?rev=1098706&r1=1098705&r2=1098706&view=diff
==============================================================================
--- mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/kddcup/track1/svd/Track1SVDRunner.java (original)
+++ mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/kddcup/track1/svd/Track1SVDRunner.java Mon May 2 18:14:18 2011
@@ -47,6 +47,9 @@ public class Track1SVDRunner {
private static final Logger log = LoggerFactory.getLogger(Track1SVDRunner.class);
+ private Track1SVDRunner() {
+ }
+
public static void main(String[] args) throws Exception {
if (args.length != 2) {
Modified: mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/kddcup/track2/Track2Runner.java
URL: http://svn.apache.org/viewvc/mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/kddcup/track2/Track2Runner.java?rev=1098706&r1=1098705&r2=1098706&view=diff
==============================================================================
--- mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/kddcup/track2/Track2Runner.java (original)
+++ mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/kddcup/track2/Track2Runner.java Mon May 2 18:14:18 2011
@@ -39,7 +39,7 @@ import org.slf4j.LoggerFactory;
* <p>Runs "track 2" of the KDD Cup competition using whatever recommender is inside {@link Track2Recommender}
* and attempts to output the result in the correct contest format.</p>
*
- * <p>Run as: <code>Track2Runner [track 2 data file directory] [output file]</code></p>
+ * <p>Run as: {@code Track2Runner [track 2 data file directory] [output file]}</p>
*/
public final class Track2Runner {
Modified: mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/bayes/SplitBayesInput.java
URL: http://svn.apache.org/viewvc/mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/bayes/SplitBayesInput.java?rev=1098706&r1=1098705&r2=1098706&view=diff
==============================================================================
--- mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/bayes/SplitBayesInput.java (original)
+++ mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/bayes/SplitBayesInput.java Mon May 2 18:14:18 2011
@@ -77,8 +77,7 @@ import org.slf4j.LoggerFactory;
* the {@link #setTestRandomSelectionSize(int)} or
* {@link #setTestRandomSelectionPct(int)} methods, each choosing a fixed test
* set size or percentage of the input set size as described above. The
- * {@link org.apache.mahout.math.jet.random.sampling.RandomSampler
- * RandomSampler} class from <code>mahout-math</code> is used to create a sample
+ * {@link RandomSampler} class from {@code mahout-math} is used to create a sample
* of the appropriate size.</li>
* </ul>
* <p>
@@ -304,7 +303,7 @@ public class SplitBayesInput {
testSplitSize = this.testRandomSelectionSize;
if (testRandomSelectionPct > 0) {
- testSplitSize = Math.round(lineCount * (testRandomSelectionPct / 100.0f));
+ testSplitSize = Math.round(lineCount * testRandomSelectionPct / 100.0f);
}
log.info("{} test split size is {} based on random selection percentage {}",
new Object[] {inputFile.getName(), testSplitSize, testRandomSelectionPct});
@@ -316,7 +315,7 @@ public class SplitBayesInput {
}
} else {
if (testSplitPct > 0) { // calculate split size based on percentage
- testSplitSize = Math.round(lineCount * (testSplitPct / 100.0f));
+ testSplitSize = Math.round(lineCount * testSplitPct / 100.0f);
log.info("{} test split size is {} based on percentage {}",
new Object[] {inputFile.getName(), testSplitSize, testSplitPct});
} else {
@@ -324,7 +323,7 @@ public class SplitBayesInput {
}
if (splitLocation > 0) { // calculate start of split based on percentage
- testSplitStart = Math.round(lineCount * (splitLocation / 100.0f));
+ testSplitStart = Math.round(lineCount * splitLocation / 100.0f);
if (lineCount - testSplitStart < testSplitSize) {
// adjust split start downwards based on split size.
testSplitStart = lineCount - testSplitSize;
@@ -336,7 +335,7 @@ public class SplitBayesInput {
if (testSplitStart < 0) {
throw new IllegalArgumentException("test split size for " + inputFile + " is too large, it would produce an "
+ "empty training set from the initial set of " + lineCount + " examples");
- } else if ((lineCount - testSplitSize) < testSplitSize) {
+ } else if (lineCount - testSplitSize < testSplitSize) {
log.warn("Test set size for {} may be too large, {} is larger than the number of "
+ "lines remaining in the training set: {}",
new Object[] {inputFile, testSplitSize, lineCount - testSplitSize});
@@ -518,13 +517,13 @@ public class SplitBayesInput {
public void validate() throws IOException {
Preconditions.checkArgument(testSplitSize >= 1 || testSplitSize == -1,
"Invalid testSplitSize", testSplitSize);
- Preconditions.checkArgument((splitLocation >= 0 && splitLocation <= 100) || splitLocation == -1,
+ Preconditions.checkArgument(splitLocation >= 0 && splitLocation <= 100 || splitLocation == -1,
"Invalid splitLocation percentage", splitLocation);
- Preconditions.checkArgument((testSplitPct >= 0 && testSplitPct <= 100) || testSplitPct == -1,
+ Preconditions.checkArgument(testSplitPct >= 0 && testSplitPct <= 100 || testSplitPct == -1,
"Invalid testSplitPct percentage", testSplitPct);
- Preconditions.checkArgument((splitLocation >= 0 && splitLocation <= 100) || splitLocation == -1,
+ Preconditions.checkArgument(splitLocation >= 0 && splitLocation <= 100 || splitLocation == -1,
"Invalid splitLocation percentage", splitLocation);
- Preconditions.checkArgument((testRandomSelectionPct >= 0 && testRandomSelectionPct <= 100)
+ Preconditions.checkArgument(testRandomSelectionPct >= 0 && testRandomSelectionPct <= 100
|| testRandomSelectionPct == -1,
"Invalid testRandomSelectionPct percentage", testRandomSelectionPct);
@@ -558,17 +557,17 @@ public class SplitBayesInput {
}
/**
- * Count the lines in the file specified as returned by <code>BufferedReader.readLine()</code>
- *
- * @param inputFile
+ * Count the lines in the file specified as returned by {@code BufferedReader.readLine()}
+ *
+ * @param inputFile
* the file whose lines will be counted
- *
+ *
* @param charset
* the charset of the file to read
- *
+ *
* @return the number of lines in the input file.
- *
- * @throws IOException
+ *
+ * @throws IOException
* if there is a problem opening or reading the file.
*/
public static int countLines(FileSystem fs, Path inputFile, Charset charset) throws IOException {
Added: mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/bayes/package-info.java
URL: http://svn.apache.org/viewvc/mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/bayes/package-info.java?rev=1098706&view=auto
==============================================================================
--- mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/bayes/package-info.java (added)
+++ mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/bayes/package-info.java Mon May 2 18:14:18 2011
@@ -0,0 +1,26 @@
+/**
+ * <p>The Bayes example package provides some helper classes for training the Naive Bayes classifier
+ * on the Twenty Newsgroups data. See {@link org.apache.mahout.classifier.bayes.PrepareTwentyNewsgroups}
+ * for details on running the trainer and
+ * formatting the Twenty Newsgroups data properly for the training.</p>
+ *
+ * <p>The easiest way to prepare the data is to use the ant task in core/build.xml:</p>
+ *
+ * <p>{@code ant extract-20news-18828}</p>
+ *
+ * <p>This runs the arg line:</p>
+ *
+ * <p>{@code -p $\{working.dir\}/20news-18828/ -o $\{working.dir\}/20news-18828-collapse -a $\{analyzer\} -c UTF-8}</p>
+ *
+ * <p>To Run the Wikipedia examples (assumes you've built the Mahout Job jar):</p>
+ *
+ * <ol>
+ * <li>Download the Wikipedia Dataset. Use the Ant target: {@code ant enwiki-files}</li>
+ * <li>Chunk the data using the WikipediaXmlSplitter (from the Hadoop home):
+ * {@code bin/hadoop jar $MAHOUT_HOME/target/mahout-examples-0.x
+ * org.apache.mahout.classifier.bayes.WikipediaXmlSplitter
+ * -d $MAHOUT_HOME/examples/temp/enwiki-latest-pages-articles.xml
+ * -o $MAHOUT_HOME/examples/work/wikipedia/chunks/ -c 64}</li>
+ * </ol>
+ */
+package org.apache.mahout.classifier.bayes;
Modified: mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sequencelearning/hmm/PosTagger.java
URL: http://svn.apache.org/viewvc/mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sequencelearning/hmm/PosTagger.java?rev=1098706&r1=1098705&r2=1098706&view=diff
==============================================================================
--- mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sequencelearning/hmm/PosTagger.java (original)
+++ mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sequencelearning/hmm/PosTagger.java Mon May 2 18:14:18 2011
@@ -155,8 +155,8 @@ public final class PosTagger {
Integer wordID = wordIDs.get(tags[0]);
Integer tagID = tagIDs.get(tags[1]);
// handle unknown values
- wordID = (wordID == null) ? 0 : wordID;
- tagID = (tagID == null) ? 0 : tagID;
+ wordID = wordID == null ? 0 : wordID;
+ tagID = tagID == null ? 0 : tagID;
// now construct the current sequence
observedSequence.add(wordID);
hiddenSequence.add(tagID);
Modified: mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/SimpleCsvExamples.java
URL: http://svn.apache.org/viewvc/mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/SimpleCsvExamples.java?rev=1098706&r1=1098705&r2=1098706&view=diff
==============================================================================
--- mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/SimpleCsvExamples.java (original)
+++ mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/SimpleCsvExamples.java Mon May 2 18:14:18 2011
@@ -78,7 +78,7 @@ public final class SimpleCsvExamples {
}
long t0 = System.currentTimeMillis();
Vector v = new DenseVector(1000);
- if (args[0].equals("--generate")) {
+ if ("--generate".equals(args[0])) {
PrintWriter out = new PrintWriter(new File(args[2]));
try {
int n = Integer.parseInt(args[1]);
@@ -241,8 +241,7 @@ public final class SimpleCsvExamples {
}
}
- private static final
- class FastLineReader implements Closeable {
+ private static final class FastLineReader implements Closeable {
private final InputStream in;
private final ByteBuffer buf = ByteBuffer.allocate(100000);
Modified: mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/TrainNewsGroups.java
URL: http://svn.apache.org/viewvc/mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/TrainNewsGroups.java?rev=1098706&r1=1098705&r2=1098706&view=diff
==============================================================================
--- mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/TrainNewsGroups.java (original)
+++ mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/TrainNewsGroups.java Mon May 2 18:14:18 2011
@@ -53,6 +53,7 @@ import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.List;
+import java.util.Locale;
import java.util.Map;
import java.util.Random;
import java.util.Set;
@@ -114,9 +115,9 @@ public final class TrainNewsGroups {
private static final String[] LEAK_LABELS = {"none", "month-year", "day-month-year"};
private static final SimpleDateFormat[] DATE_FORMATS = {
- new SimpleDateFormat(""),
- new SimpleDateFormat("MMM-yyyy"),
- new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss")
+ new SimpleDateFormat("", Locale.ENGLISH),
+ new SimpleDateFormat("MMM-yyyy", Locale.ENGLISH),
+ new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss", Locale.ENGLISH)
};
private static final Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_30);
@@ -291,7 +292,7 @@ public final class TrainNewsGroups {
while (line != null && line.length() > 0) {
boolean countHeader = (
line.startsWith("From:") || line.startsWith("Subject:") ||
- line.startsWith("Keywords:") || line.startsWith("Summary:")) && (leakType < 6);
+ line.startsWith("Keywords:") || line.startsWith("Summary:")) && leakType < 6;
do {
Reader in = new StringReader(line);
if (countHeader) {
Modified: mahout/trunk/examples/src/main/java/org/apache/mahout/clustering/minhash/LastfmClusterEvaluator.java
URL: http://svn.apache.org/viewvc/mahout/trunk/examples/src/main/java/org/apache/mahout/clustering/minhash/LastfmClusterEvaluator.java?rev=1098706&r1=1098705&r2=1098706&view=diff
==============================================================================
--- mahout/trunk/examples/src/main/java/org/apache/mahout/clustering/minhash/LastfmClusterEvaluator.java (original)
+++ mahout/trunk/examples/src/main/java/org/apache/mahout/clustering/minhash/LastfmClusterEvaluator.java Mon May 2 18:14:18 2011
@@ -41,7 +41,7 @@ public final class LastfmClusterEvaluato
/* Calculate used JVM memory */
private static String usedMemory() {
Runtime runtime = Runtime.getRuntime();
- return "Used Memory: [" + ((runtime.totalMemory() - runtime.freeMemory()) / (1024 * 1024)) + " MB] ";
+ return "Used Memory: [" + (runtime.totalMemory() - runtime.freeMemory()) / (1024 * 1024) + " MB] ";
}
/**
@@ -63,7 +63,7 @@ public final class LastfmClusterEvaluato
first.addAll(second);
double unionSize = first.size();
- return (unionSize == 0) ? 0.0 : (intersectSize / unionSize);
+ return unionSize == 0 ? 0.0 : intersectSize / unionSize;
}
/**
@@ -114,7 +114,7 @@ public final class LastfmClusterEvaluato
List<Integer> listenerVector2 = listenerVectors.get(j);
double similarity = computeSimilarity(listenerVector1,
listenerVector2);
- similarListeners += (similarity >= threshold) ? 1 : 0;
+ similarListeners += similarity >= threshold ? 1 : 0;
}
}
listenerVectors.clear();
@@ -134,7 +134,7 @@ public final class LastfmClusterEvaluato
System.out.println(" (B) All listeners: " + allListeners);
NumberFormat format = NumberFormat.getInstance();
format.setMaximumFractionDigits(2);
- double precision = ((double) similarListeners / allListeners) * 100.0;
+ double precision = (double) similarListeners / allListeners * 100.0;
System.out.println(" Average cluster precision: A/B = " + format.format(precision));
}
Modified: mahout/trunk/examples/src/main/java/org/apache/mahout/clustering/minhash/LastfmDataConverter.java
URL: http://svn.apache.org/viewvc/mahout/trunk/examples/src/main/java/org/apache/mahout/clustering/minhash/LastfmDataConverter.java?rev=1098706&r1=1098705&r2=1098706&view=diff
==============================================================================
--- mahout/trunk/examples/src/main/java/org/apache/mahout/clustering/minhash/LastfmDataConverter.java (original)
+++ mahout/trunk/examples/src/main/java/org/apache/mahout/clustering/minhash/LastfmDataConverter.java Mon May 2 18:14:18 2011
@@ -62,7 +62,7 @@ public final class LastfmDataConverter {
private static String usedMemory() {
Runtime runtime = Runtime.getRuntime();
- return "Used Memory: [" + ((runtime.totalMemory() - runtime.freeMemory()) / (1024 * 1024)) + " MB] ";
+ return "Used Memory: [" + (runtime.totalMemory() - runtime.freeMemory()) / (1024 * 1024) + " MB] ";
}
/* Get the feature from the parsed record */
@@ -92,7 +92,6 @@ public final class LastfmDataConverter {
* Lastfm dataset file on the local file system.
* @param dataSet
* Type of dataset - 360K Users or 1K Users
- * @return
*/
public static Map<String, List<Integer>> convertToItemFeatures(String inputFile, Lastfm dataSet) throws IOException {
long totalRecords = dataSet.totalRecords;
@@ -125,7 +124,7 @@ public final class LastfmDataConverter {
features.add(featureIdx);
parsedRecords++;
// Update the progress
- percentDone = (parsedRecords * 100.0) / totalRecords;
+ percentDone = parsedRecords * 100.0 / totalRecords;
msg = usedMemory() + "Converting data to internal vector format: ";
if (percentDone > prevPercentDone) {
System.out.print('\r' + msg + percentDone + '%');
@@ -173,9 +172,9 @@ public final class LastfmDataConverter {
featuresWritable.set(featureVector);
writer.append(itemWritable, featuresWritable);
// Update the progress
- double percentDone = ((++doneRecords) * 100.0) / totalRecords;
+ double percentDone = ++doneRecords * 100.0 / totalRecords;
if (percentDone > prevPercentDone) {
- System.out.print('\r' + msg + percentDone + "% " + ((percentDone >= 100) ? "Completed\n" : ""));
+ System.out.print('\r' + msg + percentDone + "% " + (percentDone >= 100 ? "Completed\n" : ""));
prevPercentDone++;
}
}
Modified: mahout/trunk/examples/src/main/java/org/apache/mahout/df/mapreduce/TestForest.java
URL: http://svn.apache.org/viewvc/mahout/trunk/examples/src/main/java/org/apache/mahout/df/mapreduce/TestForest.java?rev=1098706&r1=1098705&r2=1098706&view=diff
==============================================================================
--- mahout/trunk/examples/src/main/java/org/apache/mahout/df/mapreduce/TestForest.java (original)
+++ mahout/trunk/examples/src/main/java/org/apache/mahout/df/mapreduce/TestForest.java Mon May 2 18:14:18 2011
@@ -116,7 +116,7 @@ public class TestForest extends Configur
String dataName = cmdLine.getValue(inputOpt).toString();
String datasetName = cmdLine.getValue(datasetOpt).toString();
String modelName = cmdLine.getValue(modelOpt).toString();
- String outputName = (cmdLine.hasOption(outputOpt)) ? cmdLine.getValue(outputOpt).toString() : null;
+ String outputName = cmdLine.hasOption(outputOpt) ? cmdLine.getValue(outputOpt).toString() : null;
analyze = cmdLine.hasOption(analyzeOpt);
useMapreduce = cmdLine.hasOption(mrOpt);
@@ -230,7 +230,7 @@ public class TestForest extends Configur
for (Path path : infiles) {
log.info("Classifying : " + path);
- Path outfile = (outPath != null) ? new Path(outPath, path.getName()).suffix(".out") : null;
+ Path outfile = outPath != null ? new Path(outPath, path.getName()).suffix(".out") : null;
testFile(path, outfile, converter, forest, dataset, analyzer, rng);
}
}
Modified: mahout/trunk/examples/src/main/java/org/apache/mahout/ga/watchmaker/cd/CDRule.java
URL: http://svn.apache.org/viewvc/mahout/trunk/examples/src/main/java/org/apache/mahout/ga/watchmaker/cd/CDRule.java?rev=1098706&r1=1098705&r2=1098706&view=diff
==============================================================================
--- mahout/trunk/examples/src/main/java/org/apache/mahout/ga/watchmaker/cd/CDRule.java (original)
+++ mahout/trunk/examples/src/main/java/org/apache/mahout/ga/watchmaker/cd/CDRule.java Mon May 2 18:14:18 2011
@@ -24,21 +24,19 @@ import org.uncommons.maths.binary.BitStr
/**
* Binary classification rule of the form:
- *
+ *
* <pre>
* if (condition1 && condition2 && ... ) then
* class = 1
* else
* class = 0
* </pre>
- *
+ *
* where conditioni = (wi): attributi oi vi <br>
* <ul>
* <li>wi is the weight of the condition: <br>
- * <code>
- * if (wi < a given threshold) then conditioni is not taken into
- * consideration
- * </code></li>
+ * {@code if (wi < a given threshold) then conditioni is not taken into consideration}
+ * </li>
* <li>oi is an operator ('<' or '>=')</li>
* </ul>
*/
Modified: mahout/trunk/examples/src/main/java/org/apache/mahout/ga/watchmaker/cd/DataSet.java
URL: http://svn.apache.org/viewvc/mahout/trunk/examples/src/main/java/org/apache/mahout/ga/watchmaker/cd/DataSet.java?rev=1098706&r1=1098705&r2=1098706&view=diff
==============================================================================
--- mahout/trunk/examples/src/main/java/org/apache/mahout/ga/watchmaker/cd/DataSet.java (original)
+++ mahout/trunk/examples/src/main/java/org/apache/mahout/ga/watchmaker/cd/DataSet.java Mon May 2 18:14:18 2011
@@ -135,11 +135,11 @@ public class DataSet {
}
/**
- * Converts a string value of a nominal attribute to an <code>int</code>.
- *
+ * Converts a string value of a nominal attribute to an {@code int}.
+ *
* @param index of the attribute
* @param value
- * @return an <code>int</code> representing the value
+ * @return an {@code int} representing the value
* @throws IllegalArgumentException if the value is not found.
*/
public int valueIndex(int index, String value) {
Modified: mahout/trunk/examples/src/main/java/org/apache/mahout/ga/watchmaker/cd/FileInfoParser.java
URL: http://svn.apache.org/viewvc/mahout/trunk/examples/src/main/java/org/apache/mahout/ga/watchmaker/cd/FileInfoParser.java?rev=1098706&r1=1098705&r2=1098706&view=diff
==============================================================================
--- mahout/trunk/examples/src/main/java/org/apache/mahout/ga/watchmaker/cd/FileInfoParser.java (original)
+++ mahout/trunk/examples/src/main/java/org/apache/mahout/ga/watchmaker/cd/FileInfoParser.java Mon May 2 18:14:18 2011
@@ -19,11 +19,12 @@ package org.apache.mahout.ga.watchmaker.
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
+import java.util.Iterator;
import java.util.List;
-import java.util.NoSuchElementException;
import java.util.Scanner;
-import java.util.StringTokenizer;
+import java.util.regex.Pattern;
import com.google.common.base.Preconditions;
import org.apache.hadoop.fs.FSDataInputStream;
@@ -34,26 +35,24 @@ import org.apache.hadoop.fs.Path;
* Initializes a DataSet using a special format file.<br>
* The file contains for each attribute one of the following:<br>
* <ul>
- * <li><code>IGNORED</code><br>
+ * <li>{@code IGNORED}<br>
* if the attribute is ignored</li>
- * <li><code>LABEL, val1, val2, ...</code><br>
+ * <li>{@code LABEL, val1, val2, ...}<br>
* if the attribute is the label, and its possible values</li>
- * <li><code>CATEGORICAL, val1, val2, ...</code><br>
+ * <li>{@code CATEGORICAL, val1, val2, ...}<br>
* if the attribute is nominal, and its possible values</li>
- * <li><code>NUMERICAL, min, max</code><br>
+ * <li>{@code NUMERICAL, min, max}<br>
* if the attribute is numerical, and its min and max values</li>
* </ul>
*/
public final class FileInfoParser {
public static final String IGNORED_TOKEN = "IGNORED";
-
public static final String LABEL_TOKEN = "LABEL";
-
public static final String NOMINAL_TOKEN = "CATEGORICAL";
-
public static final String NUMERICAL_TOKEN = "NUMERICAL";
-
+ private static final Pattern COMMA_SPACE = Pattern.compile("[, ]");
+
private FileInfoParser() { }
/**
@@ -79,17 +78,17 @@ public final class FileInfoParser {
while (reader.hasNextLine()) {
String line = reader.nextLine();
- StringTokenizer tokenizer = new StringTokenizer(line, ", ");
- String token = nextToken(tokenizer);
+ Iterator<String> tokens = Arrays.asList(COMMA_SPACE.split(line)).iterator();
+ String token = tokens.next();
if (IGNORED_TOKEN.equals(token)) {
ignored.add(index);
} else if (LABEL_TOKEN.equals(token)) {
labelIndex = index;
- attributes.add(parseNominal(tokenizer));
+ attributes.add(parseNominal(tokens));
} else if (NOMINAL_TOKEN.equals(token)) {
- attributes.add(parseNominal(tokenizer));
+ attributes.add(parseNominal(tokens));
} else if (NUMERICAL_TOKEN.equals(token)) {
- attributes.add(parseNumerical(tokenizer));
+ attributes.add(parseNumerical(tokens));
} else {
throw new IllegalArgumentException("Unknown token (" + token
+ ") encountered while parsing the info file");
@@ -122,10 +121,10 @@ public final class FileInfoParser {
/**
* Parse a nominal attribute.
*/
- private static NominalAttr parseNominal(StringTokenizer tokenizer) {
+ private static NominalAttr parseNominal(Iterator<String> tokens) {
Collection<String> vlist = new ArrayList<String>();
- while (tokenizer.hasMoreTokens()) {
- vlist.add(nextToken(tokenizer));
+ while (tokens.hasNext()) {
+ vlist.add(tokens.next());
}
String[] values = new String[vlist.size()];
@@ -137,35 +136,11 @@ public final class FileInfoParser {
/**
* Parse a numerical attribute.
*/
- private static NumericalAttr parseNumerical(StringTokenizer tokenizer) {
- double min = nextDouble(tokenizer);
- double max = nextDouble(tokenizer);
+ private static NumericalAttr parseNumerical(Iterator<String> tokens) {
+ double min = Double.parseDouble(tokens.next());
+ double max = Double.parseDouble(tokens.next());
Preconditions.checkArgument(min <= max, "min > max");
return new NumericalAttr(min, max);
}
- private static double nextDouble(StringTokenizer tokenizer) {
- String token = nextToken(tokenizer);
- double value;
-
- try {
- value = Double.parseDouble(token);
- } catch (NumberFormatException e) {
- throw new IllegalArgumentException("Exception while parsing info file", e);
- }
-
- return value;
- }
-
- private static String nextToken(StringTokenizer tokenizer) {
- String token;
- try {
- token = tokenizer.nextToken();
- } catch (NoSuchElementException e) {
- throw new IllegalArgumentException("Exception while parsing info file", e);
- }
-
- return token;
- }
-
}
Modified: mahout/trunk/examples/src/main/java/org/apache/mahout/ga/watchmaker/cd/NominalAttr.java
URL: http://svn.apache.org/viewvc/mahout/trunk/examples/src/main/java/org/apache/mahout/ga/watchmaker/cd/NominalAttr.java?rev=1098706&r1=1098705&r2=1098706&view=diff
==============================================================================
--- mahout/trunk/examples/src/main/java/org/apache/mahout/ga/watchmaker/cd/NominalAttr.java (original)
+++ mahout/trunk/examples/src/main/java/org/apache/mahout/ga/watchmaker/cd/NominalAttr.java Mon May 2 18:14:18 2011
@@ -38,10 +38,10 @@ class NominalAttr implements Attribute {
}
/**
- * Converts a string value of a nominal attribute to an <code>int</code>.
+ * Converts a string value of a nominal attribute to an {@code int}.
*
* @param value
- * @return an <code>int</code> representing the value
+ * @return an {@code int} representing the value
* @throws IllegalArgumentException if the value is not found.
*/
public int valueIndex(String value) {
Modified: mahout/trunk/examples/src/main/java/org/apache/mahout/ga/watchmaker/cd/hadoop/CDMahoutEvaluator.java
URL: http://svn.apache.org/viewvc/mahout/trunk/examples/src/main/java/org/apache/mahout/ga/watchmaker/cd/hadoop/CDMahoutEvaluator.java?rev=1098706&r1=1098705&r2=1098706&view=diff
==============================================================================
--- mahout/trunk/examples/src/main/java/org/apache/mahout/ga/watchmaker/cd/hadoop/CDMahoutEvaluator.java (original)
+++ mahout/trunk/examples/src/main/java/org/apache/mahout/ga/watchmaker/cd/hadoop/CDMahoutEvaluator.java Mon May 2 18:14:18 2011
@@ -55,11 +55,11 @@ public final class CDMahoutEvaluator {
/**
* Uses Mahout to evaluate the classification rules using the given evaluator.
* The input path contains the dataset
- *
+ *
* @param rules classification rules to evaluate
* @param target label value to evaluate the rules for
* @param inpath input path (the dataset)
- * @param evaluations <code>List<CDFitness></code> that contains the
+ * @param evaluations {@code List<CDFitness>} that contains the
* evaluated fitness for each candidate from the input population,
* sorted in the same order as the candidates.
* @param split DatasetSplit used to separate training and testing input
@@ -115,11 +115,11 @@ public final class CDMahoutEvaluator {
/**
* Use all the dataset for training.
- *
+ *
* @param rules classification rules to evaluate
* @param target label value to evaluate the rules for
* @param inpath input path (the dataset)
- * @param evaluations <code>List<CDFitness></code> that contains the
+ * @param evaluations {@code List<CDFitness>} that contains the
* evaluated fitness for each candidate from the input population,
* sorted in the same order as the candidates.
*/
@@ -134,12 +134,12 @@ public final class CDMahoutEvaluator {
/**
* Configure the job
- *
+ *
* @param job Job to configure
* @param rules classification rules to evaluate
* @param target label value to evaluate the rules for
* @param inpath input path (the dataset)
- * @param outpath output <code>Path</code>
+ * @param outpath output {@code Path}
* @param split DatasetSplit used to separate training and testing input
*/
private static void configureJob(Job job,
@@ -173,11 +173,11 @@ public final class CDMahoutEvaluator {
/**
* Reads back the evaluations.
- *
+ *
* @param fs File System
* @param conf Job configuration
- * @param outpath output <code>Path</code>
- * @param evaluations <code>List<Fitness></code> that contains the
+ * @param outpath output {@code Path}
+ * @param evaluations {@code List<Fitness>} that contains the
* evaluated fitness for each candidate from the input population,
* sorted in the same order as the candidates.
*/
Modified: mahout/trunk/examples/src/main/java/org/apache/mahout/ga/watchmaker/cd/hadoop/DatasetSplit.java
URL: http://svn.apache.org/viewvc/mahout/trunk/examples/src/main/java/org/apache/mahout/ga/watchmaker/cd/hadoop/DatasetSplit.java?rev=1098706&r1=1098705&r2=1098706&view=diff
==============================================================================
--- mahout/trunk/examples/src/main/java/org/apache/mahout/ga/watchmaker/cd/hadoop/DatasetSplit.java (original)
+++ mahout/trunk/examples/src/main/java/org/apache/mahout/ga/watchmaker/cd/hadoop/DatasetSplit.java Mon May 2 18:14:18 2011
@@ -30,7 +30,6 @@ import org.apache.hadoop.mapreduce.TaskA
import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
import org.apache.mahout.common.RandomUtils;
import org.apache.mahout.common.RandomWrapper;
-import org.apache.mahout.common.StringUtils;
/**
* Separate the input data into a training and testing set.
@@ -197,8 +196,7 @@ public final class DatasetSplit {
*/
public static class DatasetTextInputFormat extends TextInputFormat {
@Override
- public RecordReader<LongWritable, Text> createRecordReader(InputSplit split,
- TaskAttemptContext context) {
+ public RecordReader<LongWritable, Text> createRecordReader(InputSplit split, TaskAttemptContext context) {
return new RndLineRecordReader(super.createRecordReader(split, context), context.getConfiguration());
}
}
Modified: mahout/trunk/examples/src/main/java/org/apache/mahout/ga/watchmaker/cd/tool/CDInfosTool.java
URL: http://svn.apache.org/viewvc/mahout/trunk/examples/src/main/java/org/apache/mahout/ga/watchmaker/cd/tool/CDInfosTool.java?rev=1098706&r1=1098705&r2=1098706&view=diff
==============================================================================
--- mahout/trunk/examples/src/main/java/org/apache/mahout/ga/watchmaker/cd/tool/CDInfosTool.java (original)
+++ mahout/trunk/examples/src/main/java/org/apache/mahout/ga/watchmaker/cd/tool/CDInfosTool.java Mon May 2 18:14:18 2011
@@ -49,7 +49,6 @@ import org.apache.hadoop.mapreduce.lib.i
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.mapreduce.lib.output.SequenceFileOutputFormat;
import org.apache.mahout.common.CommandLineUtil;
-import org.apache.mahout.common.StringUtils;
import org.apache.mahout.common.commandline.DefaultOptionCreator;
import org.apache.mahout.common.iterator.sequencefile.SequenceFileValueIterable;
import org.apache.mahout.ga.watchmaker.OutputUtils;
@@ -70,10 +69,10 @@ public final class CDInfosTool {
/**
* Uses Mahout to gather the information about a dataset.
- *
+ *
* @param descriptors about the available attributes
* @param inpath input path (the dataset)
- * @param descriptions <code>List<String></code> that contains the
+ * @param descriptions {@code List<String>} that contains the
* generated descriptions for each non ignored attribute
*/
public static void gatherInfos(Descriptors descriptors, Path inpath, Path output, Collection<String> descriptions)
@@ -93,10 +92,10 @@ public final class CDInfosTool {
/**
* Configure the job
- *
+ *
* @param descriptors attributes's descriptors
- * @param inpath input <code>Path</code>
- * @param outpath output <code>Path</code>
+ * @param inpath input {@code Path}
+ * @param outpath output {@code Path}
*/
private static void configureJob(Job job, Descriptors descriptors, Path inpath, Path outpath) throws IOException {
FileInputFormat.setInputPaths(job, inpath);
@@ -119,10 +118,10 @@ public final class CDInfosTool {
/**
* Reads back the descriptions.
- *
+ *
* @param fs file system
* @param conf job configuration
- * @param outpath output <code>Path</code>
+ * @param outpath output {@code Path}
* @param descriptions List of attribute's descriptions
*/
private static void importDescriptions(FileSystem fs,
Modified: mahout/trunk/examples/src/main/java/org/apache/mahout/ga/watchmaker/cd/tool/ToolCombiner.java
URL: http://svn.apache.org/viewvc/mahout/trunk/examples/src/main/java/org/apache/mahout/ga/watchmaker/cd/tool/ToolCombiner.java?rev=1098706&r1=1098705&r2=1098706&view=diff
==============================================================================
--- mahout/trunk/examples/src/main/java/org/apache/mahout/ga/watchmaker/cd/tool/ToolCombiner.java (original)
+++ mahout/trunk/examples/src/main/java/org/apache/mahout/ga/watchmaker/cd/tool/ToolCombiner.java Mon May 2 18:14:18 2011
@@ -26,7 +26,6 @@ import com.google.common.base.Preconditi
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;
-import org.apache.mahout.common.StringUtils;
/**
* Combines attribute values into a String.<br>
Modified: mahout/trunk/examples/src/main/java/org/apache/mahout/ga/watchmaker/cd/tool/ToolMapper.java
URL: http://svn.apache.org/viewvc/mahout/trunk/examples/src/main/java/org/apache/mahout/ga/watchmaker/cd/tool/ToolMapper.java?rev=1098706&r1=1098705&r2=1098706&view=diff
==============================================================================
--- mahout/trunk/examples/src/main/java/org/apache/mahout/ga/watchmaker/cd/tool/ToolMapper.java (original)
+++ mahout/trunk/examples/src/main/java/org/apache/mahout/ga/watchmaker/cd/tool/ToolMapper.java Mon May 2 18:14:18 2011
@@ -19,15 +19,13 @@ package org.apache.mahout.ga.watchmaker.
import java.io.IOException;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.List;
-import java.util.StringTokenizer;
+import java.util.regex.Pattern;
import com.google.common.base.Preconditions;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
-import org.apache.mahout.common.StringUtils;
/**
* Extract the attribute values from a dataline. Skip ignored attributes<br>
@@ -43,19 +41,18 @@ import org.apache.mahout.common.StringUt
* <li>Text : attribute value</li>
* </ul>
*
- * See Descriptors, for more informations about the job parameter
+ * See Descriptors, for more information about the job parameter
*/
public class ToolMapper extends Mapper<LongWritable, Text, LongWritable, Text> {
public static final String ATTRIBUTES = "cdtool.attributes";
-
- private final List<String> attributes = new ArrayList<String>();
+ private static final Pattern COMMA = Pattern.compile(",");
private Descriptors descriptors;
@Override
protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
- extractAttributes(value, attributes);
+ List<String> attributes = extractAttributes(value);
Preconditions.checkArgument(attributes.size() == descriptors.size(),
"Attributes number should be equal to the descriptors's array length");
@@ -88,12 +85,11 @@ public class ToolMapper extends Mapper<L
* Extract attribute values from the input Text. The attributes are separated by a colon ','. Skips ignored
* attributes.
*/
- static void extractAttributes(Text value, Collection<String> attributes) {
- StringTokenizer tokenizer = new StringTokenizer(value.toString(), ",");
-
- attributes.clear();
- while (tokenizer.hasMoreTokens()) {
- attributes.add(tokenizer.nextToken().trim());
+ static List<String> extractAttributes(Text value) {
+ List<String> result = new ArrayList<String>();
+ for (String token : COMMA.split(value.toString())) {
+ result.add(token.trim());
}
+ return result;
}
}
Modified: mahout/trunk/examples/src/main/java/org/apache/mahout/ga/watchmaker/cd/tool/ToolReducer.java
URL: http://svn.apache.org/viewvc/mahout/trunk/examples/src/main/java/org/apache/mahout/ga/watchmaker/cd/tool/ToolReducer.java?rev=1098706&r1=1098705&r2=1098706&view=diff
==============================================================================
--- mahout/trunk/examples/src/main/java/org/apache/mahout/ga/watchmaker/cd/tool/ToolReducer.java (original)
+++ mahout/trunk/examples/src/main/java/org/apache/mahout/ga/watchmaker/cd/tool/ToolReducer.java Mon May 2 18:14:18 2011
@@ -26,7 +26,6 @@ import com.google.common.base.Preconditi
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;
-import org.apache.mahout.common.StringUtils;
/**
* Combines attribute description strings into a String.<br>
Modified: mahout/trunk/examples/src/main/java/org/apache/mahout/ga/watchmaker/travellingsalesman/StrategyPanel.java
URL: http://svn.apache.org/viewvc/mahout/trunk/examples/src/main/java/org/apache/mahout/ga/watchmaker/travellingsalesman/StrategyPanel.java?rev=1098706&r1=1098705&r2=1098706&view=diff
==============================================================================
--- mahout/trunk/examples/src/main/java/org/apache/mahout/ga/watchmaker/travellingsalesman/StrategyPanel.java (original)
+++ mahout/trunk/examples/src/main/java/org/apache/mahout/ga/watchmaker/travellingsalesman/StrategyPanel.java Mon May 2 18:14:18 2011
@@ -49,10 +49,10 @@ import org.uncommons.watchmaker.framewor
/**
* Panel for configuring a route-finding strategy for the travelling salesman problem.
- *
+ *
* <br>
* The original code is from <b>the Watchmaker project</b> (https://watchmaker.dev.java.net/).<br>
- * The <code>EvolutionPanel</code> has been modified to add a "distributed (mahout)" JCheckBox.
+ * The {@code EvolutionPanel} has been modified to add a "distributed (mahout)" JCheckBox.
*/
final class StrategyPanel extends JPanel {
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/common/RandomUtils.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/common/RandomUtils.java?rev=1098706&r1=1098705&r2=1098706&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/common/RandomUtils.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/common/RandomUtils.java Mon May 2 18:14:18 2011
@@ -82,7 +82,7 @@ public final class RandomUtils {
public static long seedBytesToLong(byte[] seed) {
long result = 0L;
for (int i = 0; i < 8; i++) {
- result |= (seed[i] & 0xFFL) << (8 * (7 - i));
+ result |= (seed[i] & 0xFFL) << (long) (8 * (7 - i));
}
return result;
}
@@ -135,7 +135,7 @@ public final class RandomUtils {
return n;
}
- /** @return <code>true</code> iff n is not a prime */
+ /** @return {@code true} iff n is not a prime */
public static boolean isNotPrime(int n) {
if (n < 2 || (n & 0x1) == 0) { // < 2 or even
return n != 2;
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/AbstractVector.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/AbstractVector.java?rev=1098706&r1=1098705&r2=1098706&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/AbstractVector.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/AbstractVector.java Mon May 2 18:14:18 2011
@@ -271,7 +271,7 @@ public abstract class AbstractVector imp
double value = e.get();
d += value * (value - 2.0 * randomlyAccessed.getQuick(e.index()));
}
- assert d > -1.0e-9; // round-off errors should never be too far off!
+ //assert d > -1.0e-9; // round-off errors should never be too far off!
return Math.abs(d);
}
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/SingularValueDecomposition.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/SingularValueDecomposition.java?rev=1098706&r1=1098705&r2=1098706&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/SingularValueDecomposition.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/SingularValueDecomposition.java Mon May 2 18:14:18 2011
@@ -98,7 +98,7 @@ public class SingularValueDecomposition
s[k] = -s[k];
}
for (int j = k + 1; j < n; j++) {
- if ((k < nct) && (s[k] != 0.0)) {
+ if (k < nct && s[k] != 0.0) {
// Apply the transformation.
@@ -117,7 +117,7 @@ public class SingularValueDecomposition
e[j] = a[k][j];
}
- if (wantu && (k < nct)) {
+ if (wantu && k < nct) {
// Place the transformation in U for subsequent back
// multiplication.
@@ -145,7 +145,7 @@ public class SingularValueDecomposition
e[k + 1] += 1.0;
}
e[k] = -e[k];
- if ((k + 1 < m) && (e[k] != 0.0)) {
+ if (k + 1 < m && e[k] != 0.0) {
// Apply the transformation.
@@ -231,7 +231,7 @@ public class SingularValueDecomposition
if (wantv) {
for (int k = n - 1; k >= 0; k--) {
- if ((k < nrt) && (e[k] != 0.0)) {
+ if (k < nrt && e[k] != 0.0) {
for (int j = k + 1; j < nu; j++) {
double t = 0;
for (int i = k + 1; i < n; i++) {
@@ -372,9 +372,9 @@ public class SingularValueDecomposition
double sk = s[k] / scale;
double ek = e[k] / scale;
double b = ((spm1 + sp) * (spm1 - sp) + epm1 * epm1) / 2.0;
- double c = (sp * epm1) * (sp * epm1);
+ double c = sp * epm1 * sp * epm1;
double shift = 0.0;
- if ((b != 0.0) || (c != 0.0)) {
+ if (b != 0.0 || c != 0.0) {
shift = Math.sqrt(b * b + c);
if (b < 0.0) {
shift = -shift;
@@ -412,7 +412,7 @@ public class SingularValueDecomposition
s[j + 1] = -sn * e[j] + cs * s[j + 1];
g = sn * e[j + 1];
e[j + 1] = cs * e[j + 1];
- if (wantu && (j < m - 1)) {
+ if (wantu && j < m - 1) {
for (int i = 0; i < m; i++) {
t = cs * u[i][j] + sn * u[i][j + 1];
u[i][j + 1] = -sn * u[i][j] + cs * u[i][j + 1];
@@ -449,14 +449,14 @@ public class SingularValueDecomposition
double t = s[k];
s[k] = s[k + 1];
s[k + 1] = t;
- if (wantv && (k < n - 1)) {
+ if (wantv && k < n - 1) {
for (int i = 0; i < n; i++) {
t = v[i][k + 1];
v[i][k + 1] = v[i][k];
v[i][k] = t;
}
}
- if (wantu && (k < m - 1)) {
+ if (wantu && k < m - 1) {
for (int i = 0; i < m; i++) {
t = u[i][k + 1];
u[i][k + 1] = u[i][k];
@@ -582,7 +582,7 @@ public class SingularValueDecomposition
Matrix j = new DenseMatrix(s.length,s.length);
Matrix vMat = new DenseMatrix(this.v);
for (int i = 0; i < s.length; i++) {
- j.set(i, i, (s[i] >= minSingularValue) ? 1 / (s[i] * s[i]) : 0.0);
+ j.set(i, i, s[i] >= minSingularValue ? 1 / (s[i] * s[i]) : 0.0);
}
return vMat.times(j).times(vMat.transpose());
}
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/Vector.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/Vector.java?rev=1098706&r1=1098705&r2=1098706&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/Vector.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/Vector.java Mon May 2 18:14:18 2011
@@ -385,7 +385,7 @@ public interface Vector extends Cloneabl
/** Get the square of the distance between this vector and the other vector. */
double getDistanceSquared(Vector v);
- /** Add the elements of this Vector to the vector <code>v</code> and store the results in the vector <code>v</code>.
+ /** Add the elements of this Vector to the vector {@code v} and store the results in the vector {@code v}.
* @param v The Vector that this Vector gets added to. The results of the addition will be stored in v.
* */
void addTo(Vector v);
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/als/AlternateLeastSquaresSolver.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/als/AlternateLeastSquaresSolver.java?rev=1098706&r1=1098705&r2=1098706&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/als/AlternateLeastSquaresSolver.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/als/AlternateLeastSquaresSolver.java Mon May 2 18:14:18 2011
@@ -27,7 +27,8 @@ import java.util.Iterator;
import java.util.List;
/**
- * {@see http://www.hpl.hp.com/personal/Robert_Schreiber/papers/2008%20AAIM%20Netflix/netflix_aaim08(submitted).pdf}
+ * See <a href="http://www.hpl.hp.com/personal/Robert_Schreiber/papers/2008%20AAIM%20Netflix/netflix_aaim08(submitted).pdf">
+ * this paper.</a>
*/
public class AlternateLeastSquaresSolver {
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/decomposer/hebbian/HebbianSolver.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/decomposer/hebbian/HebbianSolver.java?rev=1098706&r1=1098705&r2=1098706&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/decomposer/hebbian/HebbianSolver.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/decomposer/hebbian/HebbianSolver.java Mon May 2 18:14:18 2011
@@ -283,7 +283,7 @@ public class HebbianSolver {
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));
}
}
/*
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/decomposer/hebbian/HebbianUpdater.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/decomposer/hebbian/HebbianUpdater.java?rev=1098706&r1=1098705&r2=1098706&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/decomposer/hebbian/HebbianUpdater.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/decomposer/hebbian/HebbianUpdater.java Mon May 2 18:14:18 2011
@@ -46,11 +46,15 @@ public class HebbianUpdater implements E
return;
}
currentState.setActivationNumerator(pseudoEigen.dot(trainingVector));
- currentState.setActivationNumerator(currentState.getActivationNumerator() - currentState.getHelperVector().dot(currentState.currentTrainingProjection()));
+ currentState.setActivationNumerator(
+ currentState.getActivationNumerator()
+ - currentState.getHelperVector().dot(currentState.currentTrainingProjection()));
double activation = currentState.getActivationNumerator() / Math.sqrt(currentState.getActivationDenominatorSquared());
- currentState.setActivationDenominatorSquared(currentState.getActivationDenominatorSquared() + 2 * activation * currentState.getActivationNumerator()
- + (activation * activation) * (trainingVector.getLengthSquared() - currentState.currentTrainingProjection().getLengthSquared()));
+ currentState.setActivationDenominatorSquared(
+ currentState.getActivationDenominatorSquared()
+ + 2 * activation * currentState.getActivationNumerator()
+ + activation * activation * (trainingVector.getLengthSquared() - currentState.currentTrainingProjection().getLengthSquared()));
if (numPreviousEigens > 0) {
currentState.getHelperVector().assign(currentState.currentTrainingProjection(), new PlusMult(activation));
}
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/decomposer/lanczos/LanczosSolver.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/decomposer/lanczos/LanczosSolver.java?rev=1098706&r1=1098705&r2=1098706&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/decomposer/lanczos/LanczosSolver.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/decomposer/lanczos/LanczosSolver.java Mon May 2 18:14:18 2011
@@ -216,11 +216,11 @@ public class LanczosSolver {
if (!times.containsKey(section)) {
times.put(section, 0L);
}
- times.put(section, times.get(section) + (System.nanoTime() - startTimes.get(section)));
+ times.put(section, times.get(section) + System.nanoTime() - startTimes.get(section));
}
public double getTimeMillis(TimingSection section) {
- return ((double) times.get(section)) / NANOS_IN_MILLI;
+ return (double) times.get(section) / NANOS_IN_MILLI;
}
}
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/function/Functions.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/function/Functions.java?rev=1098706&r1=1098705&r2=1098706&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/function/Functions.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/function/Functions.java Mon May 2 18:14:18 2011
@@ -794,8 +794,8 @@ public final class Functions {
}
/**
- * Constructs a function that returns a new uniform random number in the open unit interval <code>(0.0,1.0)</code>
- * (excluding 0.0 and 1.0). Currently the engine is {@link org.apache.mahout.math.jet.random.engine.MersenneTwister} and is
+ * Constructs a function that returns a new uniform random number in the open unit interval {@code (0.0,1.0)}
+ * (excluding 0.0 and 1.0). Currently the engine is {@link MersenneTwister} and is
* seeded with the current time. <p> Note that any random engine derived from {@link
* org.apache.mahout.math.jet.random.engine.RandomEngine} and any random distribution derived from {@link
* org.apache.mahout.math.jet.random.AbstractDistribution} are function objects, because they implement the proper
Added: mahout/trunk/math/src/main/java/org/apache/mahout/math/function/package-info.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/function/package-info.java?rev=1098706&view=auto
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/function/package-info.java (added)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/function/package-info.java Mon May 2 18:14:18 2011
@@ -0,0 +1,4 @@
+/**
+ * Core interfaces for functions, comparisons and procedures on objects and primitive data types.
+ */
+package org.apache.mahout.math.function;
\ No newline at end of file
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/math/Arithmetic.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/math/Arithmetic.java?rev=1098706&r1=1098705&r2=1098706&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/math/Arithmetic.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/math/Arithmetic.java Mon May 2 18:14:18 2011
@@ -270,7 +270,7 @@ public final class Arithmetic {
long b = 1;
double binomial = 1;
for (long i = k; i-- > 0;) {
- binomial *= ((double) (a++)) / (b++);
+ binomial *= (double) a++ / b++;
}
return binomial;
}
Added: mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/math/package-info.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/math/package-info.java?rev=1098706&view=auto
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/math/package-info.java (added)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/math/package-info.java Mon May 2 18:14:18 2011
@@ -0,0 +1,5 @@
+/**
+ * Tools for basic and advanced mathematics: Arithmetics and Algebra, Polynomials and Chebyshev series, Bessel and Airy
+ * functions, Function Objects for generic function evaluation, etc.
+ */
+package org.apache.mahout.math.jet.math;
\ No newline at end of file
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Gamma.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Gamma.java?rev=1098706&r1=1098705&r2=1098706&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Gamma.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Gamma.java Mon May 2 18:14:18 2011
@@ -111,7 +111,7 @@ public class Gamma extends AbstractConti
}
} else { // Step 3. Case gds > 1
gds = -Math.log((b - p) / alpha);
- if (Math.log(randomGenerator.nextDouble()) <= ((alpha - 1.0) * Math.log(gds))) {
+ if (Math.log(randomGenerator.nextDouble()) <= (alpha - 1.0) * Math.log(gds)) {
return gds / rate;
}
}
@@ -214,8 +214,8 @@ public class Gamma extends AbstractConti
e = -Math.log(randomGenerator.nextDouble());
u = randomGenerator.nextDouble();
u = u + u - 1.0;
- sign_u = (u > 0) ? 1.0 : -1.0;
- t = b + (e * si) * sign_u;
+ sign_u = u > 0 ? 1.0 : -1.0;
+ t = b + e * si * sign_u;
} while (t <= -0.71874483771719); // Step 9. Rejection of t
v = t / (s + s); // Step 10. New q(t)
if (Math.abs(v) > 0.25) {
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Poisson.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Poisson.java?rev=1098706&r1=1098705&r2=1098706&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Poisson.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Poisson.java Mon May 2 18:14:18 2011
@@ -114,7 +114,7 @@ public final class Poisson extends Abstr
p0 = p;
//for (k=pp.length; --k >=0; ) pp[k] = 0;
}
- m = (theMean > 1.0) ? (int) theMean : 1;
+ m = theMean > 1.0 ? (int) theMean : 1;
while (true) {
double u = gen.nextDouble();
int k = 0;
@@ -122,7 +122,7 @@ public final class Poisson extends Abstr
return k;
}
if (llll != 0) { // Step T. Table comparison
- int i = (u > 0.458) ? Math.min(llll, m) : 1;
+ int i = u > 0.458 ? Math.min(llll, m) : 1;
for (k = i; k <= llll; k++) {
if (u <= pp[k]) {
return k;
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Uniform.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Uniform.java?rev=1098706&r1=1098705&r2=1098706&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Uniform.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Uniform.java Mon May 2 18:14:18 2011
@@ -103,14 +103,14 @@ public class Uniform extends AbstractCon
// first the most likely and also the fastest case.
if (from >= 0 && to < Long.MAX_VALUE) {
- return from + (long) (nextDoubleFromTo(0.0, to - from + 1));
+ return from + (long) nextDoubleFromTo(0.0, to - from + 1);
}
// would we get a numeric overflow?
// if not, we can still handle the case rather efficient.
- double diff = ((double) to) - (double) from + 1.0;
+ double diff = (double) to - (double) from + 1.0;
if (diff <= Long.MAX_VALUE) {
- return from + (long) (nextDoubleFromTo(0.0, diff));
+ return from + (long) nextDoubleFromTo(0.0, diff);
}
// now the pathologic boundary cases.
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/engine/RandomEngine.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/engine/RandomEngine.java?rev=1098706&r1=1098705&r2=1098706&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/engine/RandomEngine.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/engine/RandomEngine.java Mon May 2 18:14:18 2011
@@ -75,7 +75,7 @@ public abstract class RandomEngine imple
}
/**
- * @return a 64 bit uniformly distributed random number in the open unit interval <code>(0.0,1.0)</code> (excluding
+ * @return a 64 bit uniformly distributed random number in the open unit interval {@code (0.0,1.0)} (excluding
* 0.0 and 1.0).
*/
public double nextDouble() {
@@ -109,7 +109,7 @@ public abstract class RandomEngine imple
}
/**
- * @return a 32 bit uniformly distributed random number in the open unit interval <code>(0.0f,1.0f)</code> (excluding
+ * @return a 32 bit uniformly distributed random number in the open unit interval {@code (0.0f, 1.0f)} (excluding
* 0.0f and 1.0f).
*/
public float nextFloat() {
@@ -138,12 +138,11 @@ public abstract class RandomEngine imple
*/
public long nextLong() {
// concatenate two 32-bit strings into one 64-bit string
- return ((nextInt() & 0xFFFFFFFFL) << 32)
- | ((nextInt() & 0xFFFFFFFFL));
+ return ((nextInt() & 0xFFFFFFFFL) << 32) | (nextInt() & 0xFFFFFFFFL);
}
/**
- * @return a 32 bit uniformly distributed random number in the open unit interval <code>(0.0,1.0)</code> (excluding
+ * @return a 32 bit uniformly distributed random number in the open unit interval {@code (0.0, 1.0)} (excluding
* 0.0 and 1.0).
*/
public double raw() {
Added: mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/engine/package-info.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/engine/package-info.java?rev=1098706&view=auto
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/engine/package-info.java (added)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/engine/package-info.java Mon May 2 18:14:18 2011
@@ -0,0 +1,7 @@
+/**
+ * Engines generating strong uniformly distributed pseudo-random numbers;
+ * Needed by all JET probability distributions since they rely on uniform random numbers to generate random
+ * numbers from their own distribution.
+ * Thus, the classes of this package are at the core of computational statistics, simulations, Monte Carlo methods, etc.
+ */
+package org.apache.mahout.math.jet.random.engine;
\ No newline at end of file
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/sampling/RandomSampler.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/sampling/RandomSampler.java?rev=1098706&r1=1098705&r2=1098706&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/sampling/RandomSampler.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/sampling/RandomSampler.java Mon May 2 18:14:18 2011
@@ -212,11 +212,11 @@ public class RandomSampler {
* @param n the total number of elements to choose (must be >= 0).
* @param N the interval to choose random numbers from is <tt>[low,low+N-1]</tt>.
* @param count the number of elements to be filled into <tt>values</tt> by this call (must be >= 0 and
-* <=<tt>n</tt>). Normally, you will set <tt>count=n</tt>.
+ * <=<tt>n</tt>). Normally, you will set <tt>count=n</tt>.
* @param low the interval to choose random numbers from is <tt>[low,low+N-1]</tt>. Hint: If
-* <tt>low==0</tt>, then draws random numbers from the interval <tt>[0,N-1]</tt>.
+ * <tt>low==0</tt>, then draws random numbers from the interval <tt>[0,N-1]</tt>.
* @param values the array into which the random numbers are to be filled; must have a length <tt>>=
-* count+fromIndex</tt>.
+ * count+fromIndex</tt>.
* @param fromIndex the first index within <tt>values</tt> to be filled with numbers (inclusive).
* @param randomGenerator a random number generator.
*/
@@ -268,7 +268,7 @@ public class RandomSampler {
//step D3: Accept?
double y1 = Math.exp(Math.log(U * Nreal / qu1real) * nmin1inv);
- Vprime = y1 * (-X / Nreal + 1.0) * (qu1real / (negSreal + qu1real));
+ Vprime = y1 * (-X / Nreal + 1.0) * qu1real / (negSreal + qu1real);
if (Vprime <= 1.0) {
break;
} //break inner loop
@@ -286,7 +286,7 @@ public class RandomSampler {
}
double y2 = 1.0;
for (long t = N - 1; t >= limit; t--) {
- y2 = (y2 * top) / bottom;
+ y2 *= top / bottom;
top--;
bottom--;
}
@@ -311,7 +311,7 @@ public class RandomSampler {
chosen++;
N -= S + 1;
- Nreal = negSreal + (-1.0 + Nreal);
+ Nreal = negSreal - 1.0 + Nreal;
n--;
nreal--;
ninv = nmin1inv;
@@ -412,11 +412,11 @@ public class RandomSampler {
* @param n the total number of elements to choose (must be >= 0).
* @param N the interval to choose random numbers from is <tt>[low,low+N-1]</tt>.
* @param count the number of elements to be filled into <tt>values</tt> by this call (must be >= 0 and
-* <=<tt>n</tt>). Normally, you will set <tt>count=n</tt>.
+ * <=<tt>n</tt>). Normally, you will set <tt>count=n</tt>.
* @param low the interval to choose random numbers from is <tt>[low,low+N-1]</tt>. Hint: If
-* <tt>low==0</tt>, then draws random numbers from the interval <tt>[0,N-1]</tt>.
+ * <tt>low==0</tt>, then draws random numbers from the interval <tt>[0,N-1]</tt>.
* @param values the array into which the random numbers are to be filled; must have a length <tt>>=
-* count+fromIndex</tt>.
+ * count+fromIndex</tt>.
* @param fromIndex the first index within <tt>values</tt> to be filled with numbers (inclusive).
* @param randomGenerator a random number generator.
*/
@@ -435,7 +435,7 @@ public class RandomSampler {
S++;
top--;
Nreal--;
- quot = (quot * top) / Nreal;
+ quot *= top / Nreal;
}
chosen += S + 1;
values[fromIndex++] = chosen;
@@ -464,11 +464,11 @@ public class RandomSampler {
* @param n the total number of elements to choose (must be >= 0).
* @param N the interval to choose random numbers from is <tt>[low,low+N-1]</tt>.
* @param count the number of elements to be filled into <tt>values</tt> by this call (must be >= 0 and
-* <=<tt>n</tt>). Normally, you will set <tt>count=n</tt>.
+ * <=<tt>n</tt>). Normally, you will set <tt>count=n</tt>.
* @param low the interval to choose random numbers from is <tt>[low,low+N-1]</tt>. Hint: If
-* <tt>low==0</tt>, then draws random numbers from the interval <tt>[0,N-1]</tt>.
+ * <tt>low==0</tt>, then draws random numbers from the interval <tt>[0,N-1]</tt>.
* @param values the array into which the random numbers are to be filled; must have a length <tt>>=
-* count+fromIndex</tt>.
+ * count+fromIndex</tt>.
* @param fromIndex the first index within <tt>values</tt> to be filled with numbers (inclusive).
* @param randomGenerator a random number generator.
*/
@@ -506,7 +506,7 @@ public class RandomSampler {
//step D3: Accept?
double y1 = Math.exp(Math.log(U * Nreal / qu1real) * nmin1inv);
- vprime = y1 * (-X / Nreal + 1.0) * (qu1real / (negSreal + qu1real));
+ vprime = y1 * (-X / Nreal + 1.0) * qu1real / (negSreal + qu1real);
if (vprime <= 1.0) {
break;
} //break inner loop
@@ -524,7 +524,7 @@ public class RandomSampler {
}
double y2 = 1.0;
for (long t = N - 1; t >= limit; t--) {
- y2 = (y2 * top) / bottom;
+ y2 *= top / bottom;
top--;
bottom--;
}
@@ -550,7 +550,7 @@ public class RandomSampler {
count--;
N -= S + 1;
- Nreal = negSreal + (-1.0 + Nreal);
+ Nreal = negSreal - 1.0 + Nreal;
n--;
nreal--;
ninv = nmin1inv;
Added: mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/sampling/package-info.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/sampling/package-info.java?rev=1098706&view=auto
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/sampling/package-info.java (added)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/sampling/package-info.java Mon May 2 18:14:18 2011
@@ -0,0 +1,4 @@
+/**
+ * Samples (picks) random subsets of data sequences.
+ */
+package org.apache.mahout.math.jet.random.sampling;
\ No newline at end of file
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/stat/Probability.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/stat/Probability.java?rev=1098706&r1=1098705&r2=1098706&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/stat/Probability.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/stat/Probability.java Mon May 2 18:14:18 2011
@@ -104,7 +104,7 @@ public final class Probability {
* @param p the probability of success (must be in <tt>(0.0,1.0)</tt>).
*/
public static double negativeBinomial(int k, int n, double p) {
- if ((p < 0.0) || (p > 1.0)) {
+ if (p < 0.0 || p > 1.0) {
throw new IllegalArgumentException();
}
if (k < 0) {
Added: mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/stat/package-info.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/stat/package-info.java?rev=1098706&view=auto
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/stat/package-info.java (added)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/stat/package-info.java Mon May 2 18:14:18 2011
@@ -0,0 +1,5 @@
+/**
+ * Tools for basic and advanced statistics: Estimators, Gamma functions, Beta functions, Probabilities,
+ * Special integrals, etc.
+ */
+package org.apache.mahout.math.jet.stat;
\ No newline at end of file
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/DoubleMatrix1D.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/DoubleMatrix1D.java?rev=1098706&r1=1098705&r2=1098706&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/DoubleMatrix1D.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/DoubleMatrix1D.java Mon May 2 18:14:18 2011
@@ -320,12 +320,12 @@ public abstract class DoubleMatrix1D ext
}
/**
- * Compares this object against the specified object. The result is <code>true</code> if and only if the argument is
- * not <code>null</code> and is at least a <code>DoubleMatrix1D</code> object that has the same sizes as the receiver
+ * Compares this object against the specified object. The result is {@code true} if and only if the argument is
+ * not {@code null} and is at least a {@code DoubleMatrix1D} object that has the same sizes as the receiver
* and has exactly the same values at the same indexes.
*
* @param obj the object to compare with.
- * @return <code>true</code> if the objects are the same; <code>false</code> otherwise.
+ * @return {@code true} if the objects are the same; {@code false} otherwise.
*/
public boolean equals(Object obj) {
if (this == obj) {
@@ -591,7 +591,7 @@ public abstract class DoubleMatrix1D ext
}
/**
- * Constructs and returns a new view equal to the receiver. The view is a shallow clone. Calls <code>clone()</code>
+ * Constructs and returns a new view equal to the receiver. The view is a shallow clone. Calls {@code clone()}
* and casts the result. <p> <b>Note that the view is not a deep copy.</b> The returned matrix is backed by this
* matrix, so changes in the returned matrix are reflected in this matrix, and vice-versa. <p> Use {@link #copy()} to
* construct an independent deep copy rather than a new view.
@@ -623,7 +623,7 @@ public abstract class DoubleMatrix1D ext
* @throws IndexOutOfBoundsException if <tt>index<0 || width<0 || index+width>size()</tt>.
*/
public DoubleMatrix1D viewPart(int index, int width) {
- return (DoubleMatrix1D) (view().vPart(index, width));
+ return (DoubleMatrix1D) view().vPart(index, width);
}
/**
@@ -707,14 +707,14 @@ public abstract class DoubleMatrix1D ext
int s = nonZeroIndexes.size();
// skip to start
- while ((index < s) && nonZeroIndexElements[index] < from) {
+ while (index < s && nonZeroIndexElements[index] < from) {
index++;
}
// now the sparse dot product
int i;
double sum = 0;
- while ((--length >= 0) && (index < s) && ((i = nonZeroIndexElements[index]) < tail)) {
+ while (--length >= 0 && index < s && (i = nonZeroIndexElements[index]) < tail) {
sum += getQuick(i) * y.getQuick(i);
index++;
}
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/DoubleMatrix2D.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/DoubleMatrix2D.java?rev=1098706&r1=1098705&r2=1098706&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/DoubleMatrix2D.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/DoubleMatrix2D.java Mon May 2 18:14:18 2011
@@ -283,12 +283,12 @@ public abstract class DoubleMatrix2D ext
}
/**
- * Compares this object against the specified object. The result is <code>true</code> if and only if the argument is
- * not <code>null</code> and is at least a <code>DoubleMatrix2D</code> object that has the same number of columns and
+ * Compares this object against the specified object. The result is {@code true} if and only if the argument is
+ * not {@code null} and is at least a {@code DoubleMatrix2D} object that has the same number of columns and
* rows as the receiver and has exactly the same values at the same coordinates.
*
* @param obj the object to compare with.
- * @return <code>true</code> if the objects are the same; <code>false</code> otherwise.
+ * @return {@code true} if the objects are the same; {@code false} otherwise.
*/
public boolean equals(Object obj) {
if (this == obj) {
@@ -476,7 +476,7 @@ public abstract class DoubleMatrix2D ext
}
/**
- * Constructs and returns a new view equal to the receiver. The view is a shallow clone. Calls <code>clone()</code>
+ * Constructs and returns a new view equal to the receiver. The view is a shallow clone. Calls {@code clone()}
* and casts the result. <p> <b>Note that the view is not a deep copy.</b> The returned matrix is backed by this
* matrix, so changes in the returned matrix are reflected in this matrix, and vice-versa. <p> Use {@link #copy()} to
* construct an independent deep copy rather than a new view.
@@ -523,7 +523,7 @@ public abstract class DoubleMatrix2D ext
* @see #viewRowFlip()
*/
public DoubleMatrix2D viewColumnFlip() {
- return (DoubleMatrix2D) (view().vColumnFlip());
+ return (DoubleMatrix2D) view().vColumnFlip();
}
/**
@@ -539,7 +539,7 @@ public abstract class DoubleMatrix2D ext
* @return a new dice view.
*/
public DoubleMatrix2D viewDice() {
- return (DoubleMatrix2D) (view().vDice());
+ return (DoubleMatrix2D) view().vDice();
}
/**
@@ -565,7 +565,7 @@ public abstract class DoubleMatrix2D ext
* row+height>rows()</tt>
*/
public DoubleMatrix2D viewPart(int row, int column, int height, int width) {
- return (DoubleMatrix2D) (view().vPart(row, column, height, width));
+ return (DoubleMatrix2D) view().vPart(row, column, height, width);
}
/**
@@ -600,7 +600,7 @@ public abstract class DoubleMatrix2D ext
* @see #viewColumnFlip()
*/
public DoubleMatrix2D viewRowFlip() {
- return (DoubleMatrix2D) (view().vRowFlip());
+ return (DoubleMatrix2D) view().vRowFlip();
}
/**
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/AbstractMatrix.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/AbstractMatrix.java?rev=1098706&r1=1098705&r2=1098706&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/AbstractMatrix.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/AbstractMatrix.java Mon May 2 18:14:18 2011
@@ -9,8 +9,10 @@ It is provided "as is" without expressed
package org.apache.mahout.math.matrix.impl;
/**
- Abstract base class for arbitrary-dimensional matrices holding objects or primitive data types such as <code>int</code>, <code>float</code>, etc.
- First see the <a href="package-summary.html">package summary</a> and javadoc <a href="package-tree.html">tree view</a> to get the broad picture.
+ Abstract base class for arbitrary-dimensional matrices holding objects or primitive data types such as
+ {@code int}, {@code float}, etc.
+ First see the <a href="package-summary.html">package summary</a> and javadoc
+ <a href="package-tree.html">tree view</a> to get the broad picture.
<p>
<b>Note that this implementation is not synchronized.</b>
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/AbstractMatrix1D.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/AbstractMatrix1D.java?rev=1098706&r1=1098705&r2=1098706&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/AbstractMatrix1D.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/AbstractMatrix1D.java Mon May 2 18:14:18 2011
@@ -10,7 +10,7 @@ package org.apache.mahout.math.matrix.im
/**
Abstract base class for 1-d matrices (aka <i>vectors</i>) holding objects or primitive data types such as
- <code>int</code>, <code>double</code>, etc.
+ {@code int}, {@code double}, etc.
First see the <a href="package-summary.html">package summary</a> and javadoc
<a href="package-tree.html">tree view</a> to get the broad picture.
<p>
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/AbstractMatrix2D.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/AbstractMatrix2D.java?rev=1098706&r1=1098705&r2=1098706&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/AbstractMatrix2D.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/AbstractMatrix2D.java Mon May 2 18:14:18 2011
@@ -10,7 +10,7 @@ package org.apache.mahout.math.matrix.im
/**
Abstract base class for 2-d matrices holding objects or primitive data types such as
- <code>int</code>, <code>double</code>, etc.
+ {@code int}, {@code double}, etc.
First see the <a href="package-summary.html">package summary</a> and javadoc
<a href="package-tree.html">tree view</a> to get the broad picture.
<p>
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/SparseDoubleMatrix2D.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/SparseDoubleMatrix2D.java?rev=1098706&r1=1098705&r2=1098706&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/SparseDoubleMatrix2D.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/SparseDoubleMatrix2D.java Mon May 2 18:14:18 2011
@@ -454,7 +454,7 @@ public final class SparseDoubleMatrix2D
@Override
public DoubleMatrix2D zMult(DoubleMatrix2D B, DoubleMatrix2D C, final double alpha, double beta,
final boolean transposeA, boolean transposeB) {
- if (!(this.isNoView)) {
+ if (!this.isNoView) {
return super.zMult(B, C, alpha, beta, transposeA, transposeB);
}
if (transposeB) {
@@ -467,7 +467,7 @@ public final class SparseDoubleMatrix2D
n = rows;
}
int p = B.columns;
- boolean ignore = (C == null);
+ boolean ignore = C == null;
if (C == null) {
C = new DenseDoubleMatrix2D(m, p);
}
Added: mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/package-info.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/package-info.java?rev=1098706&view=auto
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/package-info.java (added)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/package-info.java Mon May 2 18:14:18 2011
@@ -0,0 +1,5 @@
+/**
+ * Matrix <i>implementations</i>; You normally need not look at this package, because all concrete classes implement the
+ * abstract interfaces of {@code org.apache.mahout.math.matrix}, <i>without subsetting or supersetting</i>.
+ */
+package org.apache.mahout.math.matrix.impl;
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/EigenvalueDecomposition.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/EigenvalueDecomposition.java?rev=1098706&r1=1098705&r2=1098706&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/EigenvalueDecomposition.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/EigenvalueDecomposition.java Mon May 2 18:14:18 2011
@@ -396,7 +396,7 @@ public final class EigenvalueDecompositi
break;
}
if (Math.abs(H[m][m - 1]) * (Math.abs(q) + Math.abs(r))
- < eps * (Math.abs(p) * (Math.abs(H[m - 1][m - 1]) + Math.abs(z) + Math.abs(H[m + 1][m + 1])))) {
+ < eps * Math.abs(p) * (Math.abs(H[m - 1][m - 1]) + Math.abs(z) + Math.abs(H[m + 1][m + 1]))) {
break;
}
m--;
@@ -536,7 +536,7 @@ public final class EigenvalueDecompositi
// Overflow control
t = Math.abs(H[i][n]);
- if ((eps * t) * t > 1) {
+ if (eps * t * t > 1) {
for (int j = i; j <= n; j++) {
H[j][n] /= t;
}
@@ -594,7 +594,7 @@ public final class EigenvalueDecompositi
cdiv(x * r - z * ra + q * sa, x * s - z * sa - q * ra, vr, vi);
H[i][n - 1] = cdivr;
H[i][n] = cdivi;
- if (Math.abs(x) > (Math.abs(z) + Math.abs(q))) {
+ if (Math.abs(x) > Math.abs(z) + Math.abs(q)) {
H[i + 1][n - 1] = (-ra - w * H[i][n - 1] + q * H[i][n]) / x;
H[i + 1][n] = (-sa - w * H[i][n] - q * H[i][n - 1]) / x;
} else {
@@ -607,7 +607,7 @@ public final class EigenvalueDecompositi
// Overflow control
t = Math.max(Math.abs(H[i][n - 1]), Math.abs(H[i][n]));
- if ((eps * t) * t > 1) {
+ if (eps * t * t > 1) {
for (int j = i; j <= n; j++) {
H[j][n - 1] /= t;
H[j][n] /= t;
@@ -721,7 +721,7 @@ public final class EigenvalueDecompositi
g += ort[i] * V[i][j];
}
// Double division avoids possible underflow
- g = (g / ort[m]) / H[m][m - 1];
+ g = g / ort[m] / H[m][m - 1];
for (int i = m; i <= high; i++) {
V[i][j] += g * ort[i];
}