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 2008/08/14 04:29:49 UTC
svn commit: r685750 - in /lucene/mahout/trunk/core/src/main:
examples/org/apache/mahout/clustering/syntheticcontrol/canopy/
examples/org/apache/mahout/clustering/syntheticcontrol/kmeans/
examples/org/apache/mahout/clustering/syntheticcontrol/meanshift/...
Author: srowen
Date: Wed Aug 13 19:29:48 2008
New Revision: 685750
URL: http://svn.apache.org/viewvc?rev=685750&view=rev
Log:
More tweaks noted by IntelliJ, mostly to avoid unneeded unnecessary boxing/unboxing, or simplify exception handling
Modified:
lucene/mahout/trunk/core/src/main/examples/org/apache/mahout/clustering/syntheticcontrol/canopy/InputDriver.java
lucene/mahout/trunk/core/src/main/examples/org/apache/mahout/clustering/syntheticcontrol/canopy/Job.java
lucene/mahout/trunk/core/src/main/examples/org/apache/mahout/clustering/syntheticcontrol/canopy/OutputDriver.java
lucene/mahout/trunk/core/src/main/examples/org/apache/mahout/clustering/syntheticcontrol/kmeans/Job.java
lucene/mahout/trunk/core/src/main/examples/org/apache/mahout/clustering/syntheticcontrol/kmeans/OutputDriver.java
lucene/mahout/trunk/core/src/main/examples/org/apache/mahout/clustering/syntheticcontrol/meanshift/InputDriver.java
lucene/mahout/trunk/core/src/main/examples/org/apache/mahout/clustering/syntheticcontrol/meanshift/Job.java
lucene/mahout/trunk/core/src/main/examples/org/apache/mahout/clustering/syntheticcontrol/meanshift/OutputDriver.java
lucene/mahout/trunk/core/src/main/examples/org/apache/mahout/ga/watchmaker/cd/CDGA.java
lucene/mahout/trunk/core/src/main/examples/org/apache/mahout/ga/watchmaker/cd/DataLine.java
lucene/mahout/trunk/core/src/main/examples/org/apache/mahout/ga/watchmaker/cd/FileInfoParser.java
lucene/mahout/trunk/core/src/main/examples/org/apache/mahout/ga/watchmaker/cd/hadoop/DatasetSplit.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/correlation/AveragingPreferenceInferrer.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/canopy/Canopy.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/canopy/CanopyClusteringJob.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/canopy/CanopyDriver.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/canopy/ClusterDriver.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/kmeans/Cluster.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/kmeans/KMeansDriver.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/kmeans/KMeansJob.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/kmeans/KMeansReducer.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/meanshift/MeanShiftCanopy.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/meanshift/MeanShiftCanopyCombiner.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/meanshift/MeanShiftCanopyDriver.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/meanshift/MeanShiftCanopyJob.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/DenseVector.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/SparseMatrix.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/SparseVector.java
Modified: lucene/mahout/trunk/core/src/main/examples/org/apache/mahout/clustering/syntheticcontrol/canopy/InputDriver.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/examples/org/apache/mahout/clustering/syntheticcontrol/canopy/InputDriver.java?rev=685750&r1=685749&r2=685750&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/examples/org/apache/mahout/clustering/syntheticcontrol/canopy/InputDriver.java (original)
+++ lucene/mahout/trunk/core/src/main/examples/org/apache/mahout/clustering/syntheticcontrol/canopy/InputDriver.java Wed Aug 13 19:29:48 2008
@@ -25,13 +25,15 @@
import org.apache.hadoop.mapred.Reducer;
import org.apache.mahout.matrix.Vector;
+import java.io.IOException;
+
public class InputDriver {
- public static void main(String[] args) {
+ public static void main(String[] args) throws Exception {
runJob(args[0], args[1]);
}
- public static void runJob(String input, String output) {
+ public static void runJob(String input, String output) throws IOException {
JobClient client = new JobClient();
JobConf conf = new JobConf(InputDriver.class);
@@ -47,11 +49,7 @@
conf.setNumReduceTasks(0);
client.setConf(conf);
- try {
- JobClient.runJob(conf);
- } catch (Exception e) {
- e.printStackTrace();
- }
+ JobClient.runJob(conf);
}
}
Modified: lucene/mahout/trunk/core/src/main/examples/org/apache/mahout/clustering/syntheticcontrol/canopy/Job.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/examples/org/apache/mahout/clustering/syntheticcontrol/canopy/Job.java?rev=685750&r1=685749&r2=685750&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/examples/org/apache/mahout/clustering/syntheticcontrol/canopy/Job.java (original)
+++ lucene/mahout/trunk/core/src/main/examples/org/apache/mahout/clustering/syntheticcontrol/canopy/Job.java Wed Aug 13 19:29:48 2008
@@ -23,15 +23,17 @@
import org.apache.hadoop.mapred.JobConf;
import org.apache.mahout.clustering.canopy.CanopyClusteringJob;
+import java.io.IOException;
+
public class Job {
- public static void main(String[] args) {
+ public static void main(String[] args) throws Exception {
if (args.length == 5) {
String input = args[0];
String output = args[1];
String measureClassName = args[2];
- double t1 = new Double(args[3]);
- double t2 = new Double(args[4]);
+ double t1 = Double.parseDouble(args[3]);
+ double t2 = Double.parseDouble(args[4]);
runJob(input, output, measureClassName, t1, t2);
} else
runJob("testdata", "output",
@@ -56,23 +58,20 @@
* @param t2 the canopy T2 threshold
*/
private static void runJob(String input, String output,
- String measureClassName, double t1, double t2) {
+ String measureClassName, double t1, double t2) throws IOException {
JobClient client = new JobClient();
JobConf conf = new JobConf(Job.class);
Path outPath = new Path(output);
client.setConf(conf);
- try {
- FileSystem dfs = FileSystem.get(conf);
- if (dfs.exists(outPath))
- dfs.delete(outPath, true);
- InputDriver.runJob(input, output + "/data");
- CanopyClusteringJob.runJob(output + "/data", output, measureClassName,
- t1, t2);
- OutputDriver.runJob(output + "/clusters", output + "/clustered-points");
- } catch (Exception e) {
- e.printStackTrace();
- }
+ FileSystem dfs = FileSystem.get(conf);
+ if (dfs.exists(outPath))
+ dfs.delete(outPath, true);
+ InputDriver.runJob(input, output + "/data");
+ CanopyClusteringJob.runJob(output + "/data", output, measureClassName,
+ t1, t2);
+ OutputDriver.runJob(output + "/clusters", output + "/clustered-points");
+
}
}
Modified: lucene/mahout/trunk/core/src/main/examples/org/apache/mahout/clustering/syntheticcontrol/canopy/OutputDriver.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/examples/org/apache/mahout/clustering/syntheticcontrol/canopy/OutputDriver.java?rev=685750&r1=685749&r2=685750&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/examples/org/apache/mahout/clustering/syntheticcontrol/canopy/OutputDriver.java (original)
+++ lucene/mahout/trunk/core/src/main/examples/org/apache/mahout/clustering/syntheticcontrol/canopy/OutputDriver.java Wed Aug 13 19:29:48 2008
@@ -26,13 +26,15 @@
import org.apache.hadoop.mapred.JobConf;
import org.apache.hadoop.mapred.Reducer;
+import java.io.IOException;
+
public class OutputDriver {
- public static void main(String[] args) {
+ public static void main(String[] args) throws Exception {
runJob(args[0], args[1]);
}
- public static void runJob(String input, String output) {
+ public static void runJob(String input, String output) throws IOException {
JobClient client = new JobClient();
JobConf conf = new JobConf(OutputDriver.class);
@@ -48,11 +50,7 @@
conf.setNumReduceTasks(0);
client.setConf(conf);
- try {
- JobClient.runJob(conf);
- } catch (Exception e) {
- e.printStackTrace();
- }
+ JobClient.runJob(conf);
}
}
Modified: lucene/mahout/trunk/core/src/main/examples/org/apache/mahout/clustering/syntheticcontrol/kmeans/Job.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/examples/org/apache/mahout/clustering/syntheticcontrol/kmeans/Job.java?rev=685750&r1=685749&r2=685750&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/examples/org/apache/mahout/clustering/syntheticcontrol/kmeans/Job.java (original)
+++ lucene/mahout/trunk/core/src/main/examples/org/apache/mahout/clustering/syntheticcontrol/kmeans/Job.java Wed Aug 13 19:29:48 2008
@@ -25,17 +25,19 @@
import org.apache.mahout.clustering.kmeans.KMeansDriver;
import org.apache.mahout.clustering.syntheticcontrol.canopy.InputDriver;
+import java.io.IOException;
+
public class Job {
- public static void main(String[] args) {
+ public static void main(String[] args) throws Exception {
if (args.length == 6) {
String input = args[0];
String output = args[1];
String measureClass = args[2];
- double t1 = new Double(args[3]);
- double t2 = new Double(args[4]);
- double convergenceDelta = new Double(args[5]);
- int maxIterations = new Integer(args[6]);
+ double t1 = Double.parseDouble(args[3]);
+ double t2 = Double.parseDouble(args[4]);
+ double convergenceDelta = Double.parseDouble(args[5]);
+ int maxIterations = Integer.parseInt(args[6]);
runJob(input, output, measureClass, convergenceDelta, t1, t2,
maxIterations);
} else
@@ -63,24 +65,20 @@
* @param maxIterations the int maximum number of iterations
*/
private static void runJob(String input, String output, String measureClass,
- double t1, double t2, double convergenceDelta, int maxIterations) {
+ double t1, double t2, double convergenceDelta, int maxIterations) throws IOException {
JobClient client = new JobClient();
JobConf conf = new JobConf(Job.class);
Path outPath = new Path(output);
client.setConf(conf);
- try {
- FileSystem dfs = FileSystem.get(conf);
- if (dfs.exists(outPath))
- dfs.delete(outPath, true);
- InputDriver.runJob(input, output + "/data");
- CanopyClusteringJob
- .runJob(output + "/data", output, measureClass, t1, t2);
- KMeansDriver.runJob(output + "/data", output + "/canopies", output,
- measureClass, convergenceDelta, maxIterations);
- OutputDriver.runJob(output + "/points", output + "/clustered-points");
- } catch (Exception e) {
- e.printStackTrace();
- }
+ FileSystem dfs = FileSystem.get(conf);
+ if (dfs.exists(outPath))
+ dfs.delete(outPath, true);
+ InputDriver.runJob(input, output + "/data");
+ CanopyClusteringJob
+ .runJob(output + "/data", output, measureClass, t1, t2);
+ KMeansDriver.runJob(output + "/data", output + "/canopies", output,
+ measureClass, convergenceDelta, maxIterations);
+ OutputDriver.runJob(output + "/points", output + "/clustered-points");
}
}
Modified: lucene/mahout/trunk/core/src/main/examples/org/apache/mahout/clustering/syntheticcontrol/kmeans/OutputDriver.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/examples/org/apache/mahout/clustering/syntheticcontrol/kmeans/OutputDriver.java?rev=685750&r1=685749&r2=685750&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/examples/org/apache/mahout/clustering/syntheticcontrol/kmeans/OutputDriver.java (original)
+++ lucene/mahout/trunk/core/src/main/examples/org/apache/mahout/clustering/syntheticcontrol/kmeans/OutputDriver.java Wed Aug 13 19:29:48 2008
@@ -26,13 +26,15 @@
import org.apache.hadoop.mapred.JobConf;
import org.apache.hadoop.mapred.Reducer;
+import java.io.IOException;
+
public class OutputDriver {
- public static void main(String[] args) {
+ public static void main(String[] args) throws Exception {
runJob(args[0], args[1]);
}
- public static void runJob(String input, String output) {
+ public static void runJob(String input, String output) throws IOException {
JobClient client = new JobClient();
JobConf conf = new JobConf(OutputDriver.class);
@@ -48,11 +50,7 @@
conf.setNumReduceTasks(0);
client.setConf(conf);
- try {
- JobClient.runJob(conf);
- } catch (Exception e) {
- e.printStackTrace();
- }
+ JobClient.runJob(conf);
}
}
Modified: lucene/mahout/trunk/core/src/main/examples/org/apache/mahout/clustering/syntheticcontrol/meanshift/InputDriver.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/examples/org/apache/mahout/clustering/syntheticcontrol/meanshift/InputDriver.java?rev=685750&r1=685749&r2=685750&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/examples/org/apache/mahout/clustering/syntheticcontrol/meanshift/InputDriver.java (original)
+++ lucene/mahout/trunk/core/src/main/examples/org/apache/mahout/clustering/syntheticcontrol/meanshift/InputDriver.java Wed Aug 13 19:29:48 2008
@@ -25,13 +25,15 @@
import org.apache.hadoop.mapred.Reducer;
import org.apache.mahout.matrix.Vector;
+import java.io.IOException;
+
public class InputDriver {
- public static void main(String[] args) {
+ public static void main(String[] args) throws Exception {
runJob(args[0], args[1]);
}
- public static void runJob(String input, String output) {
+ public static void runJob(String input, String output) throws IOException {
JobClient client = new JobClient();
JobConf conf = new JobConf(
org.apache.mahout.clustering.syntheticcontrol.meanshift.InputDriver.class);
@@ -49,11 +51,7 @@
conf.setNumReduceTasks(0);
client.setConf(conf);
- try {
- JobClient.runJob(conf);
- } catch (Exception e) {
- e.printStackTrace();
- }
+ JobClient.runJob(conf);
}
}
Modified: lucene/mahout/trunk/core/src/main/examples/org/apache/mahout/clustering/syntheticcontrol/meanshift/Job.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/examples/org/apache/mahout/clustering/syntheticcontrol/meanshift/Job.java?rev=685750&r1=685749&r2=685750&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/examples/org/apache/mahout/clustering/syntheticcontrol/meanshift/Job.java (original)
+++ lucene/mahout/trunk/core/src/main/examples/org/apache/mahout/clustering/syntheticcontrol/meanshift/Job.java Wed Aug 13 19:29:48 2008
@@ -24,17 +24,19 @@
import org.apache.mahout.clustering.meanshift.MeanShiftCanopyJob;
import org.apache.mahout.clustering.syntheticcontrol.meanshift.InputDriver;
+import java.io.IOException;
+
public class Job {
- public static void main(String[] args) {
+ public static void main(String[] args) throws Exception {
if (args.length == 7) {
String input = args[0];
String output = args[1];
String measureClassName = args[2];
- double t1 = new Double(args[3]);
- double t2 = new Double(args[4]);
- double convergenceDelta = new Double(args[5]);
- int maxIterations = new Integer(args[6]);
+ double t1 = Double.parseDouble(args[3]);
+ double t2 = Double.parseDouble(args[4]);
+ double convergenceDelta = Double.parseDouble(args[5]);
+ int maxIterations = Integer.parseInt(args[6]);
runJob(input, output, measureClassName, t1, t2, convergenceDelta,
maxIterations);
} else
@@ -63,25 +65,21 @@
*/
private static void runJob(String input, String output,
String measureClassName, double t1, double t2, double convergenceDelta,
- int maxIterations) {
+ int maxIterations) throws IOException {
JobClient client = new JobClient();
JobConf conf = new JobConf(Job.class);
Path outPath = new Path(output);
client.setConf(conf);
- try {
- FileSystem dfs = FileSystem.get(conf);
- if (dfs.exists(outPath))
- dfs.delete(outPath, true);
- InputDriver.runJob(input, output + "/data");
- MeanShiftCanopyJob.runJob(output + "/data", output + "/meanshift",
- measureClassName, t1, t2, convergenceDelta, maxIterations);
- FileStatus[] status = dfs.listStatus(new Path(output + "/meanshift"));
- OutputDriver.runJob(status[status.length - 1].getPath().toString(),
- output + "/clustered-points");
- } catch (Exception e) {
- e.printStackTrace();
- }
+ FileSystem dfs = FileSystem.get(conf);
+ if (dfs.exists(outPath))
+ dfs.delete(outPath, true);
+ InputDriver.runJob(input, output + "/data");
+ MeanShiftCanopyJob.runJob(output + "/data", output + "/meanshift",
+ measureClassName, t1, t2, convergenceDelta, maxIterations);
+ FileStatus[] status = dfs.listStatus(new Path(output + "/meanshift"));
+ OutputDriver.runJob(status[status.length - 1].getPath().toString(),
+ output + "/clustered-points");
}
}
Modified: lucene/mahout/trunk/core/src/main/examples/org/apache/mahout/clustering/syntheticcontrol/meanshift/OutputDriver.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/examples/org/apache/mahout/clustering/syntheticcontrol/meanshift/OutputDriver.java?rev=685750&r1=685749&r2=685750&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/examples/org/apache/mahout/clustering/syntheticcontrol/meanshift/OutputDriver.java (original)
+++ lucene/mahout/trunk/core/src/main/examples/org/apache/mahout/clustering/syntheticcontrol/meanshift/OutputDriver.java Wed Aug 13 19:29:48 2008
@@ -27,13 +27,15 @@
import org.apache.hadoop.mapred.Reducer;
import org.apache.hadoop.mapred.SequenceFileInputFormat;
+import java.io.IOException;
+
public class OutputDriver {
- public static void main(String[] args) {
+ public static void main(String[] args) throws Exception {
runJob(args[0], args[1]);
}
- public static void runJob(String input, String output) {
+ public static void runJob(String input, String output) throws IOException {
JobClient client = new JobClient();
JobConf conf = new JobConf(
org.apache.mahout.clustering.syntheticcontrol.meanshift.OutputDriver.class);
@@ -51,11 +53,7 @@
conf.setNumReduceTasks(0);
client.setConf(conf);
- try {
- JobClient.runJob(conf);
- } catch (Exception e) {
- e.printStackTrace();
- }
+ JobClient.runJob(conf);
}
}
Modified: lucene/mahout/trunk/core/src/main/examples/org/apache/mahout/ga/watchmaker/cd/CDGA.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/examples/org/apache/mahout/ga/watchmaker/cd/CDGA.java?rev=685750&r1=685749&r2=685750&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/examples/org/apache/mahout/ga/watchmaker/cd/CDGA.java (original)
+++ lucene/mahout/trunk/core/src/main/examples/org/apache/mahout/ga/watchmaker/cd/CDGA.java Wed Aug 13 19:29:48 2008
@@ -79,13 +79,13 @@
if (args.length == 8) {
dataset = args[0];
- threshold = new Double(args[1]);
- crosspnts = new Integer(args[2]);
- mutrate = new Double(args[3]);
- mutrange = new Double(args[4]);
- mutprec = new Integer(args[5]);
- popSize = new Integer(args[6]);
- genCount = new Integer(args[7]);
+ threshold = Double.parseDouble(args[1]);
+ crosspnts = Integer.parseInt(args[2]);
+ mutrate = Double.parseDouble(args[3]);
+ mutrange = Double.parseDouble(args[4]);
+ mutprec = Integer.parseInt(args[5]);
+ popSize = Integer.parseInt(args[6]);
+ genCount = Integer.parseInt(args[7]);
}
runJob(dataset, threshold, crosspnts, mutrate, mutrange, mutprec, popSize,
Modified: lucene/mahout/trunk/core/src/main/examples/org/apache/mahout/ga/watchmaker/cd/DataLine.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/examples/org/apache/mahout/ga/watchmaker/cd/DataLine.java?rev=685750&r1=685749&r2=685750&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/examples/org/apache/mahout/ga/watchmaker/cd/DataLine.java (original)
+++ lucene/mahout/trunk/core/src/main/examples/org/apache/mahout/ga/watchmaker/cd/DataLine.java Wed Aug 13 19:29:48 2008
@@ -65,7 +65,7 @@
// load attributes
for (int index = 0; index < dataset.getNbAttributes(); index++) {
if (dataset.isNumerical(index)) {
- attributes[index] = Double.valueOf(tokens.get(index));
+ attributes[index] = Double.parseDouble(tokens.get(index));
} else {
attributes[index] = dataset.valueIndex(index, tokens.get(index));
}
Modified: lucene/mahout/trunk/core/src/main/examples/org/apache/mahout/ga/watchmaker/cd/FileInfoParser.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/examples/org/apache/mahout/ga/watchmaker/cd/FileInfoParser.java?rev=685750&r1=685749&r2=685750&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/examples/org/apache/mahout/ga/watchmaker/cd/FileInfoParser.java (original)
+++ lucene/mahout/trunk/core/src/main/examples/org/apache/mahout/ga/watchmaker/cd/FileInfoParser.java Wed Aug 13 19:29:48 2008
@@ -165,7 +165,7 @@
double value;
try {
- value = Double.valueOf(token);
+ value = Double.parseDouble(token);
} catch (NumberFormatException e) {
throw new RuntimeException("Exception while parsing info file", e);
}
Modified: lucene/mahout/trunk/core/src/main/examples/org/apache/mahout/ga/watchmaker/cd/hadoop/DatasetSplit.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/examples/org/apache/mahout/ga/watchmaker/cd/hadoop/DatasetSplit.java?rev=685750&r1=685749&r2=685750&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/examples/org/apache/mahout/ga/watchmaker/cd/hadoop/DatasetSplit.java (original)
+++ lucene/mahout/trunk/core/src/main/examples/org/apache/mahout/ga/watchmaker/cd/hadoop/DatasetSplit.java Wed Aug 13 19:29:48 2008
@@ -106,7 +106,7 @@
if (thrstr == null)
throw new RuntimeException("THRESHOLD job parameter not found");
- return Double.valueOf(thrstr);
+ return Double.parseDouble(thrstr);
}
static boolean isTraining(JobConf conf) {
@@ -171,8 +171,9 @@
public boolean next(LongWritable key, Text value) throws IOException {
boolean read;
- while ((read = reader.next(k, v)) && !selected())
- ;
+ do {
+ read = reader.next(k, v);
+ } while (read && !selected());
if (!read)
return false;
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/correlation/AveragingPreferenceInferrer.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/correlation/AveragingPreferenceInferrer.java?rev=685750&r1=685749&r2=685750&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/correlation/AveragingPreferenceInferrer.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/correlation/AveragingPreferenceInferrer.java Wed Aug 13 19:29:48 2008
@@ -39,6 +39,7 @@
public final class AveragingPreferenceInferrer implements PreferenceInferrer {
private static final Retriever<User, Double> RETRIEVER = new PrefRetriever();
+ private static final Double ZERO = new Double(0.0);
private final Cache<User, Double> averagePreferenceValue;
@@ -64,7 +65,7 @@
RunningAverage average = new FullRunningAverage();
Preference[] prefs = key.getPreferencesAsArray();
if (prefs.length == 0) {
- return 0.0;
+ return ZERO;
}
for (int i = 0; i < prefs.length; i++) {
average.addDatum(prefs[i].getValue());
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/canopy/Canopy.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/canopy/Canopy.java?rev=685750&r1=685749&r2=685750&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/canopy/Canopy.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/canopy/Canopy.java Wed Aug 13 19:29:48 2008
@@ -114,8 +114,8 @@
throw new RuntimeException(e);
}
nextCanopyId = 0;
- t1 = new Double(job.get(T1_KEY));
- t2 = new Double(job.get(T2_KEY));
+ t1 = Double.parseDouble(job.get(T1_KEY));
+ t2 = Double.parseDouble(job.get(T2_KEY));
}
/**
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/canopy/CanopyClusteringJob.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/canopy/CanopyClusteringJob.java?rev=685750&r1=685749&r2=685750&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/canopy/CanopyClusteringJob.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/canopy/CanopyClusteringJob.java Wed Aug 13 19:29:48 2008
@@ -30,8 +30,8 @@
String input = args[0];
String output = args[1];
String measureClassName = args[2];
- double t1 = new Double(args[3]);
- double t2 = new Double(args[4]);
+ double t1 = Double.parseDouble(args[3]);
+ double t2 = Double.parseDouble(args[4]);
runJob(input, output, measureClassName, t1, t2);
}
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/canopy/CanopyDriver.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/canopy/CanopyDriver.java?rev=685750&r1=685749&r2=685750&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/canopy/CanopyDriver.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/canopy/CanopyDriver.java Wed Aug 13 19:29:48 2008
@@ -34,8 +34,8 @@
String input = args[0];
String output = args[1];
String measureClassName = args[2];
- double t1 = new Double(args[3]);
- double t2 = new Double(args[4]);
+ double t1 = Double.parseDouble(args[3]);
+ double t2 = Double.parseDouble(args[4]);
runJob(input, output, measureClassName, t1, t2);
}
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/canopy/ClusterDriver.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/canopy/ClusterDriver.java?rev=685750&r1=685749&r2=685750&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/canopy/ClusterDriver.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/canopy/ClusterDriver.java Wed Aug 13 19:29:48 2008
@@ -35,8 +35,8 @@
String canopies = args[1];
String output = args[2];
String measureClassName = args[3];
- double t1 = new Double(args[4]);
- double t2 = new Double(args[5]);
+ double t1 = Double.parseDouble(args[4]);
+ double t2 = Double.parseDouble(args[5]);
runJob(points, canopies, output, measureClassName, t1, t2);
}
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/kmeans/Cluster.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/kmeans/Cluster.java?rev=685750&r1=685749&r2=685750&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/kmeans/Cluster.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/kmeans/Cluster.java Wed Aug 13 19:29:48 2008
@@ -83,7 +83,7 @@
String id = formattedString.substring(0, beginIndex);
String center = formattedString.substring(beginIndex);
if (id.startsWith("C") || id.startsWith("V")) {
- int clusterId = new Integer(formattedString.substring(1, beginIndex - 2));
+ int clusterId = Integer.parseInt(formattedString.substring(1, beginIndex - 2));
Vector clusterCenter = AbstractVector.decodeVector(center);
Cluster cluster = new Cluster(clusterCenter, clusterId);
cluster.converged = id.startsWith("V");
@@ -104,7 +104,7 @@
Class<?> cl = ccl.loadClass(job.get(DISTANCE_MEASURE_KEY));
measure = (DistanceMeasure) cl.newInstance();
measure.configure(job);
- convergenceDelta = new Double(job.get(CLUSTER_CONVERGENCE_KEY));
+ convergenceDelta = Double.parseDouble(job.get(CLUSTER_CONVERGENCE_KEY));
nextClusterId = 0;
} catch (Exception e) {
throw new RuntimeException(e);
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/kmeans/KMeansDriver.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/kmeans/KMeansDriver.java?rev=685750&r1=685749&r2=685750&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/kmeans/KMeansDriver.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/kmeans/KMeansDriver.java Wed Aug 13 19:29:48 2008
@@ -42,8 +42,8 @@
String clusters = args[1];
String output = args[2];
String measureClass = args[3];
- double convergenceDelta = new Double(args[4]);
- int maxIterations = new Integer(args[5]);
+ double convergenceDelta = Double.parseDouble(args[4]);
+ int maxIterations = Integer.parseInt(args[5]);
runJob(input, clusters, output, measureClass, convergenceDelta, maxIterations);
}
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/kmeans/KMeansJob.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/kmeans/KMeansJob.java?rev=685750&r1=685749&r2=685750&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/kmeans/KMeansJob.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/kmeans/KMeansJob.java Wed Aug 13 19:29:48 2008
@@ -30,8 +30,8 @@
String clusters = args[1];
String output = args[2];
String measureClass = args[3];
- double convergenceDelta = new Double(args[4]);
- int maxIterations = new Integer(args[5]);
+ double convergenceDelta = Double.parseDouble(args[4]);
+ int maxIterations = Integer.parseInt(args[5]);
runJob(input, clusters, output, measureClass, convergenceDelta,
maxIterations);
}
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/kmeans/KMeansReducer.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/kmeans/KMeansReducer.java?rev=685750&r1=685749&r2=685750&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/kmeans/KMeansReducer.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/kmeans/KMeansReducer.java Wed Aug 13 19:29:48 2008
@@ -39,7 +39,7 @@
while (values.hasNext()) {
String value = values.next().toString();
int ix = value.indexOf(',');
- int count = new Integer(value.substring(0, ix));
+ int count = Integer.parseInt(value.substring(0, ix));
Vector total = AbstractVector.decodeVector(value.substring(ix + 2));
cluster.addPoints(count, total);
}
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/meanshift/MeanShiftCanopy.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/meanshift/MeanShiftCanopy.java?rev=685750&r1=685749&r2=685750&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/meanshift/MeanShiftCanopy.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/meanshift/MeanShiftCanopy.java Wed Aug 13 19:29:48 2008
@@ -94,9 +94,9 @@
throw new RuntimeException(e);
}
nextCanopyId = 0;
- t1 = new Double(job.get(T1_KEY));
- t2 = new Double(job.get(T2_KEY));
- convergenceDelta = new Double(job.get(CLUSTER_CONVERGENCE_KEY));
+ t1 = Double.parseDouble(job.get(T1_KEY));
+ t2 = Double.parseDouble(job.get(T2_KEY));
+ convergenceDelta = Double.parseDouble(job.get(CLUSTER_CONVERGENCE_KEY));
}
/**
@@ -207,7 +207,7 @@
String boundPoints = formattedString.substring(endIndex + 1).trim();
boolean startsWithV = id.startsWith("V");
if (id.startsWith("C") || startsWithV) {
- int canopyId = new Integer(formattedString.substring(1, beginIndex - 3));
+ int canopyId = Integer.parseInt(formattedString.substring(1, beginIndex - 3));
Vector canopyCentroid = DenseVector.decodeFormat(new Text(centroid));
List<Vector> canopyBoundPoints = new ArrayList<Vector>();
while (boundPoints.length() > 0) {
@@ -230,7 +230,7 @@
*/
public MeanShiftCanopy(String id) {
super();
- this.canopyId = new Integer(id.substring(1));
+ this.canopyId = Integer.parseInt(id.substring(1));
this.center = null;
this.pointTotal = null;
this.numPoints = 0;
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/meanshift/MeanShiftCanopyCombiner.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/meanshift/MeanShiftCanopyCombiner.java?rev=685750&r1=685749&r2=685750&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/meanshift/MeanShiftCanopyCombiner.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/meanshift/MeanShiftCanopyCombiner.java Wed Aug 13 19:29:48 2008
@@ -55,8 +55,7 @@
canopy.merge(MeanShiftCanopy.decodeCanopy(valueStr.substring(6)));
else {
Vector formatString = DenseVector.decodeFormat(new Text(valueStr));
- int number = new Integer(valueStr
- .substring(valueStr.indexOf(']') + 2));
+ int number = Integer.parseInt(valueStr.substring(valueStr.indexOf(']') + 2));
canopy.addPoints(formatString, number);
}
}
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/meanshift/MeanShiftCanopyDriver.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/meanshift/MeanShiftCanopyDriver.java?rev=685750&r1=685749&r2=685750&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/meanshift/MeanShiftCanopyDriver.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/meanshift/MeanShiftCanopyDriver.java Wed Aug 13 19:29:48 2008
@@ -35,9 +35,9 @@
String input = args[0];
String output = args[1];
String measureClassName = args[2];
- double t1 = new Double(args[3]);
- double t2 = new Double(args[4]);
- double convergenceDelta = new Double(args[5]);
+ double t1 = Double.parseDouble(args[3]);
+ double t2 = Double.parseDouble(args[4]);
+ double convergenceDelta = Double.parseDouble(args[5]);
runJob(input, output, measureClassName, t1, t2, convergenceDelta, false);
}
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/meanshift/MeanShiftCanopyJob.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/meanshift/MeanShiftCanopyJob.java?rev=685750&r1=685749&r2=685750&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/meanshift/MeanShiftCanopyJob.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/meanshift/MeanShiftCanopyJob.java Wed Aug 13 19:29:48 2008
@@ -34,10 +34,10 @@
String input = args[0];
String output = args[1];
String measureClassName = args[2];
- double t1 = new Double(args[3]);
- double t2 = new Double(args[4]);
- double convergenceDelta = new Double(args[5]);
- int maxIterations = new Integer(args[6]);
+ double t1 = Double.parseDouble(args[3]);
+ double t2 = Double.parseDouble(args[4]);
+ double convergenceDelta = Double.parseDouble(args[5]);
+ int maxIterations = Integer.parseInt(args[6]);
runJob(input, output, measureClassName, t1, t2, convergenceDelta,
maxIterations);
}
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/DenseVector.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/DenseVector.java?rev=685750&r1=685749&r2=685750&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/DenseVector.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/DenseVector.java Wed Aug 13 19:29:48 2008
@@ -56,7 +56,7 @@
String[] pts = formattedString.split(",");
double[] point = new double[pts.length - 2];
for (int i = 1; i < pts.length - 1; i++)
- point[i - 1] = new Double(pts[i]);
+ point[i - 1] = Double.parseDouble(pts[i]);
return new DenseVector(point);
}
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/SparseMatrix.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/SparseMatrix.java?rev=685750&r1=685749&r2=685750&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/SparseMatrix.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/SparseMatrix.java Wed Aug 13 19:29:48 2008
@@ -154,10 +154,7 @@
*/
@Override
public Matrix like(int rows, int columns) {
- int[] c = new int[2];
- c[ROW] = rows;
- c[COL] = columns;
- return new SparseMatrix(c);
+ return new SparseMatrix(new int[] { rows, columns });
}
/*
@@ -167,9 +164,13 @@
*/
@Override
public void setQuick(int row, int column, double value) {
- if (rows.get(row) == null)
- rows.put(row, new SparseVector(cardinality[COL]));
- rows.get(row).setQuick(column, value);
+ Integer rowKey = Integer.valueOf(row);
+ Vector r = rows.get(rowKey);
+ if (r == null) {
+ r = new SparseVector(cardinality[COL]);
+ rows.put(rowKey, r);
+ }
+ r.setQuick(column, value);
}
/*
@@ -230,10 +231,11 @@
for (int row = 0; row < cardinality[ROW]; row++) {
double val = other.getQuick(row);
if (val != 0.0) {
- Vector r = rows.get(row);
+ Integer rowKey = Integer.valueOf(row);
+ Vector r = rows.get(rowKey);
if (r == null) {
r = new SparseVector(cardinality[ROW]);
- rows.put(row, r);
+ rows.put(rowKey, r);
}
r.setQuick(column, val);
}
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/SparseVector.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/SparseVector.java?rev=685750&r1=685749&r2=685750&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/SparseVector.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/SparseVector.java Wed Aug 13 19:29:48 2008
@@ -67,8 +67,8 @@
result = new SparseVector(c);
} else if (!pt.startsWith("]")) {
int ix = pt.indexOf(':');
- Integer index = new Integer(pt.substring(0, ix).trim());
- Double value = new Double(pt.substring(ix + 1));
+ int index = Integer.parseInt(pt.substring(0, ix).trim());
+ double value = Double.parseDouble(pt.substring(ix + 1));
result.setQuick(index, value);
}
}
@@ -97,8 +97,9 @@
public String asFormatString() {
StringBuilder out = new StringBuilder();
out.append("[s").append(cardinality).append(", ");
- for (Integer index : values.keySet())
- out.append(index).append(':').append(values.get(index)).append(", ");
+ for (Map.Entry<Integer, Double> entry : values.entrySet()) {
+ out.append(entry.getKey()).append(':').append(entry.getValue()).append(", ");
+ }
out.append("] ");
return out.toString();
}
@@ -111,8 +112,9 @@
@Override
public SparseVector copy() {
SparseVector result = like();
- for (Integer index : values.keySet())
- result.setQuick(index, values.get(index));
+ for (Map.Entry<Integer, Double> entry : values.entrySet()) {
+ result.setQuick(entry.getKey(), entry.getValue());
+ }
return result;
}
@@ -120,14 +122,14 @@
public double getQuick(int index) {
Double value = values.get(index);
if (value == null)
- return 0;
+ return 0.0;
else
return value;
}
@Override
public void setQuick(int index, double value) {
- if (value == 0)
+ if (value == 0.0)
values.remove(index);
else
values.put(index, value);
@@ -141,8 +143,9 @@
@Override
public double[] toArray() {
double[] result = new double[cardinality];
- for (int i = 0; i < cardinality; i++)
- result[i] = getQuick(i);
+ for (Map.Entry<Integer, Double> entry : values.entrySet()) {
+ result[entry.getKey()] = entry.getValue();
+ }
return result;
}
@@ -218,10 +221,10 @@
@Override
public double zSum() {
- java.util.Iterator<Double> iter = values.values().iterator();
- double result = 0;
- while (iter.hasNext())
- result += iter.next();
+ double result = 0.0;
+ for (Double value : values.values()) {
+ result += value;
+ }
return result;
}
@@ -229,11 +232,9 @@
public double dot(Vector x) throws CardinalityException {
if (cardinality() != x.cardinality())
throw new CardinalityException();
- java.util.Iterator<Integer> iter = values.keySet().iterator();
- double result = 0;
- while (iter.hasNext()) {
- int nextIndex = iter.next();
- result += getQuick(nextIndex) * x.getQuick(nextIndex);
+ double result = 0.0;
+ for (Map.Entry<Integer, Double> entry : values.entrySet()) {
+ result += entry.getValue() * x.getQuick(entry.getKey());
}
return result;
}
@@ -251,8 +252,8 @@
public void readFields(DataInput dataInput) throws IOException {
int cardinality = dataInput.readInt();
- Map<Integer, Double> values = new HashMap<Integer, Double>();
int size = dataInput.readInt();
+ Map<Integer, Double> values = new HashMap<Integer, Double>(size);
for (int i = 0; i < size; i++) {
values.put(dataInput.readInt(), dataInput.readDouble());
}