You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mahout.apache.org by ss...@apache.org on 2013/03/26 14:24:46 UTC
svn commit: r1461119 [3/4] - in /mahout/trunk: ./
buildtools/src/main/resources/
core/src/main/java/org/apache/mahout/cf/taste/hadoop/als/
core/src/main/java/org/apache/mahout/cf/taste/hadoop/item/
core/src/main/java/org/apache/mahout/cf/taste/hadoop/s...
Modified: mahout/trunk/integration/src/main/java/org/apache/mahout/text/SequenceFilesFromMailArchives.java
URL: http://svn.apache.org/viewvc/mahout/trunk/integration/src/main/java/org/apache/mahout/text/SequenceFilesFromMailArchives.java?rev=1461119&r1=1461118&r2=1461119&view=diff
==============================================================================
--- mahout/trunk/integration/src/main/java/org/apache/mahout/text/SequenceFilesFromMailArchives.java (original)
+++ mahout/trunk/integration/src/main/java/org/apache/mahout/text/SequenceFilesFromMailArchives.java Tue Mar 26 13:24:40 2013
@@ -165,8 +165,8 @@ public final class SequenceFilesFromMail
obuilder.withLongName("quotedRegex")
.withRequired(false).withArgument(abuilder.withName("regex")
.withMinimum(1).withMaximum(1).create()).withDescription(
- "Specify the regex that identifies quoted text. " +
- "Default is to look for > or | at the beginning of the line.")
+ "Specify the regex that identifies quoted text. "
+ + "Default is to look for > or | at the beginning of the line.")
.withShortName("q").create());
addOption(
obuilder.withLongName("separator")
@@ -179,8 +179,8 @@ public final class SequenceFilesFromMail
obuilder.withLongName("bodySeparator")
.withRequired(false).withArgument(abuilder.withName("bodySeparator")
.withMinimum(1).withMaximum(1).create()).withDescription(
- "The separator to use between lines in the body. Default is \\n. " +
- "Useful to change if you wish to have the message be on one line")
+ "The separator to use between lines in the body. Default is \\n. "
+ + "Useful to change if you wish to have the message be on one line")
.withShortName("bodySep").create());
addOption(DefaultOptionCreator.helpOption());
Map<String, List<String>> parsedArgs = parseArguments(args);
Modified: mahout/trunk/integration/src/main/java/org/apache/mahout/utils/Bump125.java
URL: http://svn.apache.org/viewvc/mahout/trunk/integration/src/main/java/org/apache/mahout/utils/Bump125.java?rev=1461119&r1=1461118&r2=1461119&view=diff
==============================================================================
--- mahout/trunk/integration/src/main/java/org/apache/mahout/utils/Bump125.java (original)
+++ mahout/trunk/integration/src/main/java/org/apache/mahout/utils/Bump125.java Tue Mar 26 13:24:40 2013
@@ -29,16 +29,16 @@ package org.apache.mahout.utils;
* and because early records all get messages, we get indications early.
*/
public class Bump125 {
- private static final int[] bumps = {1, 2, 5};
+ private static final int[] BUMPS = {1, 2, 5};
static int scale(double value, double base) {
double scale = value / base;
// scan for correct step
int i = 0;
- while (i < bumps.length - 1 && bumps[i + 1] <= scale) {
+ while (i < BUMPS.length - 1 && BUMPS[i + 1] <= scale) {
i++;
}
- return bumps[i];
+ return BUMPS[i];
}
static long base(double value) {
Modified: mahout/trunk/integration/src/main/java/org/apache/mahout/utils/SequenceFileDumper.java
URL: http://svn.apache.org/viewvc/mahout/trunk/integration/src/main/java/org/apache/mahout/utils/SequenceFileDumper.java?rev=1461119&r1=1461118&r2=1461119&view=diff
==============================================================================
--- mahout/trunk/integration/src/main/java/org/apache/mahout/utils/SequenceFileDumper.java (original)
+++ mahout/trunk/integration/src/main/java/org/apache/mahout/utils/SequenceFileDumper.java Tue Mar 26 13:24:40 2013
@@ -52,8 +52,8 @@ public final class SequenceFileDumper ex
addOption("substring", "b", "The number of chars to print out per value", false);
addOption(buildOption("count", "c", "Report the count only", false, false, null));
addOption("numItems", "n", "Output at most <n> key value pairs", false);
- addOption(buildOption("facets", "fa", "Output the counts per key. Note, if there are a lot of unique keys, " +
- "this can take up a fair amount of memory", false, false, null));
+ addOption(buildOption("facets", "fa", "Output the counts per key. Note, if there are a lot of unique keys, "
+ + "this can take up a fair amount of memory", false, false, null));
addOption(buildOption("quiet", "q", "Print only file contents.", false, false, null));
if (parseArguments(args, false, true) == null) {
Modified: mahout/trunk/integration/src/main/java/org/apache/mahout/utils/SplitInput.java
URL: http://svn.apache.org/viewvc/mahout/trunk/integration/src/main/java/org/apache/mahout/utils/SplitInput.java?rev=1461119&r1=1461118&r2=1461119&view=diff
==============================================================================
--- mahout/trunk/integration/src/main/java/org/apache/mahout/utils/SplitInput.java (original)
+++ mahout/trunk/integration/src/main/java/org/apache/mahout/utils/SplitInput.java Tue Mar 26 13:24:40 2013
@@ -156,20 +156,20 @@ public class SplitInput extends Abstract
addOption("testOutput", "te", "The test data output directory", false);
addOption("testSplitSize", "ss", "The number of documents held back as test data for each category", false);
addOption("testSplitPct", "sp", "The % of documents held back as test data for each category", false);
- addOption("splitLocation", "sl", "Location for start of test data expressed as a percentage of the input file " +
- "size (0=start, 50=middle, 100=end", false);
+ addOption("splitLocation", "sl", "Location for start of test data expressed as a percentage of the input file "
+ + "size (0=start, 50=middle, 100=end", false);
addOption("randomSelectionSize", "rs", "The number of items to be randomly selected as test data ", false);
- addOption("randomSelectionPct", "rp", "Percentage of items to be randomly selected as test data when using " +
- "mapreduce mode", false);
- addOption("charset", "c", "The name of the character encoding of the input files (not needed if using " +
- "SequenceFiles)", false);
+ addOption("randomSelectionPct", "rp", "Percentage of items to be randomly selected as test data when using "
+ + "mapreduce mode", false);
+ addOption("charset", "c", "The name of the character encoding of the input files (not needed if using "
+ + "SequenceFiles)", false);
addOption(buildOption("sequenceFiles", "seq", "Set if the input files are sequence files. Default is false",
false, false, "false"));
addOption(DefaultOptionCreator.methodOption().create());
addOption(DefaultOptionCreator.overwriteOption().create());
//TODO: extend this to sequential mode
- addOption("keepPct", "k", "The percentage of total data to keep in map-reduce mode, the rest will be ignored. " +
- "Default is 100%", false);
+ addOption("keepPct", "k", "The percentage of total data to keep in map-reduce mode, the rest will be ignored. "
+ + "Default is 100%", false);
addOption("mapRedOutputDir", "mro", "Output directory for map reduce jobs", false);
if (parseArguments(args) == null) {
@@ -227,8 +227,8 @@ public class SplitInput extends Abstract
}
if (hasOption("testSplitSize") && hasOption("testSplitPct")) {
- throw new OptionException(getCLIOption("testSplitPct"), "must have either split size or split percentage " +
- "option, not BOTH");
+ throw new OptionException(getCLIOption("testSplitPct"), "must have either split size or split percentage "
+ + "option, not BOTH");
}
if (hasOption("testSplitSize")) {
@@ -644,8 +644,8 @@ public class SplitInput extends Abstract
count++;
}
- Preconditions.checkArgument(count == 1, "Exactly one of testSplitSize, testSplitPct, testRandomSelectionSize, " +
- "testRandomSelectionPct should be set");
+ Preconditions.checkArgument(count == 1, "Exactly one of testSplitSize, testSplitPct, testRandomSelectionSize, "
+ + "testRandomSelectionPct should be set");
if (!useMapRed) {
Configuration conf = getConf();
Modified: mahout/trunk/integration/src/main/java/org/apache/mahout/utils/SplitInputJob.java
URL: http://svn.apache.org/viewvc/mahout/trunk/integration/src/main/java/org/apache/mahout/utils/SplitInputJob.java?rev=1461119&r1=1461118&r2=1461119&view=diff
==============================================================================
--- mahout/trunk/integration/src/main/java/org/apache/mahout/utils/SplitInputJob.java (original)
+++ mahout/trunk/integration/src/main/java/org/apache/mahout/utils/SplitInputJob.java Tue Mar 26 13:24:40 2013
@@ -82,7 +82,7 @@ public final class SplitInputJob {
@SuppressWarnings("rawtypes")
public static void run(Configuration initialConf, Path inputPath,
Path outputPath, int keepPct, float randomSelectionPercent)
- throws IOException, ClassNotFoundException, InterruptedException {
+ throws IOException, ClassNotFoundException, InterruptedException {
int downsamplingFactor = (int) (100.0 / keepPct);
initialConf.setInt(DOWNSAMPLING_FACTOR, downsamplingFactor);
Modified: mahout/trunk/integration/src/main/java/org/apache/mahout/utils/clustering/CSVClusterWriter.java
URL: http://svn.apache.org/viewvc/mahout/trunk/integration/src/main/java/org/apache/mahout/utils/clustering/CSVClusterWriter.java?rev=1461119&r1=1461118&r2=1461119&view=diff
==============================================================================
--- mahout/trunk/integration/src/main/java/org/apache/mahout/utils/clustering/CSVClusterWriter.java (original)
+++ mahout/trunk/integration/src/main/java/org/apache/mahout/utils/clustering/CSVClusterWriter.java Tue Mar 26 13:24:40 2013
@@ -48,7 +48,7 @@ public class CSVClusterWriter extends Ab
public void write(ClusterWritable clusterWritable) throws IOException {
StringBuilder line = new StringBuilder();
Cluster cluster = clusterWritable.getValue();
- line.append(cluster.getId());
+ line.append(cluster.getId());
List<WeightedVectorWritable> points = getClusterIdToPoints().get(cluster.getId());
if (points != null) {
for (WeightedVectorWritable point : points) {
Modified: mahout/trunk/integration/src/main/java/org/apache/mahout/utils/clustering/ClusterDumper.java
URL: http://svn.apache.org/viewvc/mahout/trunk/integration/src/main/java/org/apache/mahout/utils/clustering/ClusterDumper.java?rev=1461119&r1=1461118&r2=1461119&view=diff
==============================================================================
--- mahout/trunk/integration/src/main/java/org/apache/mahout/utils/clustering/ClusterDumper.java (original)
+++ mahout/trunk/integration/src/main/java/org/apache/mahout/utils/clustering/ClusterDumper.java Tue Mar 26 13:24:40 2013
@@ -111,12 +111,12 @@ public final class ClusterDumper extends
addOption(POINTS_DIR_OPTION, "p",
"The directory containing points sequence files mapping input vectors to their cluster. "
+ "If specified, then the program will output the points associated with a cluster");
- addOption(SAMPLE_POINTS, "sp", "Specifies the maximum number of points to include _per_ cluster. The default " +
- "is to include all points");
+ addOption(SAMPLE_POINTS, "sp", "Specifies the maximum number of points to include _per_ cluster. The default "
+ + "is to include all points");
addOption(DICTIONARY_OPTION, "d", "The dictionary file");
addOption(DICTIONARY_TYPE_OPTION, "dt", "The dictionary file type (text|sequencefile)", "text");
- addOption(buildOption(EVALUATE_CLUSTERS, "e", "Run ClusterEvaluator and CDbwEvaluator over the input. " +
- "The output will be appended to the rest of the output at the end.", false, false, null));
+ addOption(buildOption(EVALUATE_CLUSTERS, "e", "Run ClusterEvaluator and CDbwEvaluator over the input. "
+ + "The output will be appended to the rest of the output at the end.", false, false, null));
addOption(DefaultOptionCreator.distanceMeasureOption().create());
// output is optional, will print to System.out per default
@@ -182,7 +182,7 @@ public final class ClusterDumper extends
FileSystem fs = FileSystem.get(p.toUri(), conf);
writer = new OutputStreamWriter(fs.create(p), Charsets.UTF_8);
} else {
- Files.createParentDirs(outputFile);
+ Files.createParentDirs(outputFile);
writer = Files.newWriter(this.outputFile, Charsets.UTF_8);
}
}
@@ -196,11 +196,11 @@ public final class ClusterDumper extends
HadoopUtil.delete(conf, new Path("tmp/representative"));
int numIters = 5;
RepresentativePointsDriver.main(new String[]{
- "--input", seqFileDir.toString(),
- "--output", "tmp/representative",
- "--clusteredPoints", pointsDir.toString(),
- "--distanceMeasure", measure.getClass().getName(),
- "--maxIter", String.valueOf(numIters)//
+ "--input", seqFileDir.toString(),
+ "--output", "tmp/representative",
+ "--clusteredPoints", pointsDir.toString(),
+ "--distanceMeasure", measure.getClass().getName(),
+ "--maxIter", String.valueOf(numIters)
});
conf.set(RepresentativePointsDriver.DISTANCE_MEASURE_KEY, measure.getClass().getName());
conf.set(RepresentativePointsDriver.STATE_IN_KEY, "tmp/representative/representativePoints-" + numIters);
@@ -296,9 +296,9 @@ public final class ClusterDumper extends
public static Map<Integer, List<WeightedVectorWritable>> readPoints(Path pointsPathDir, long maxPointsPerCluster,
Configuration conf) {
Map<Integer, List<WeightedVectorWritable>> result = new TreeMap<Integer, List<WeightedVectorWritable>>();
- for (Pair<IntWritable, WeightedVectorWritable> record :
- new SequenceFileDirIterable<IntWritable, WeightedVectorWritable>(
- pointsPathDir, PathType.LIST, PathFilters.logsCRCFilter(), conf)) {
+ for (Pair<IntWritable, WeightedVectorWritable> record
+ : new SequenceFileDirIterable<IntWritable, WeightedVectorWritable>(pointsPathDir, PathType.LIST,
+ PathFilters.logsCRCFilter(), conf)) {
// value is the cluster id as an int, key is the name/id of the
// vector, but that doesn't matter because we only care about printing
// it
Modified: mahout/trunk/integration/src/main/java/org/apache/mahout/utils/clustering/GraphMLClusterWriter.java
URL: http://svn.apache.org/viewvc/mahout/trunk/integration/src/main/java/org/apache/mahout/utils/clustering/GraphMLClusterWriter.java?rev=1461119&r1=1461118&r2=1461119&view=diff
==============================================================================
--- mahout/trunk/integration/src/main/java/org/apache/mahout/utils/clustering/GraphMLClusterWriter.java (original)
+++ mahout/trunk/integration/src/main/java/org/apache/mahout/utils/clustering/GraphMLClusterWriter.java Tue Mar 26 13:24:40 2013
@@ -51,9 +51,8 @@ public class GraphMLClusterWriter extend
private final int subString;
public GraphMLClusterWriter(Writer writer, Map<Integer, List<WeightedVectorWritable>> clusterIdToPoints,
- DistanceMeasure measure,
- int numTopFeatures, String[] dictionary, int subString)
- throws IOException {
+ DistanceMeasure measure, int numTopFeatures, String[] dictionary, int subString)
+ throws IOException {
super(writer, clusterIdToPoints, measure);
this.dictionary = dictionary;
this.numTopFeatures = numTopFeatures;
@@ -63,18 +62,18 @@ public class GraphMLClusterWriter extend
private void init(Writer writer) throws IOException {
writer.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
- writer.append("<graphml xmlns=\"http://graphml.graphdrawing.org/xmlns\"\n" +
- "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" +
- "xsi:schemaLocation=\"http://graphml.graphdrawing.org/xmlns\n" +
- "http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd\">");
+ writer.append("<graphml xmlns=\"http://graphml.graphdrawing.org/xmlns\"\n"
+ + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
+ + "xsi:schemaLocation=\"http://graphml.graphdrawing.org/xmlns\n"
+ + "http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd\">");
//support rgb
- writer.append("<key attr.name=\"r\" attr.type=\"int\" for=\"node\" id=\"r\"/>\n" +
- "<key attr.name=\"g\" attr.type=\"int\" for=\"node\" id=\"g\"/>\n" +
- "<key attr.name=\"b\" attr.type=\"int\" for=\"node\" id=\"b\"/>" +
- "<key attr.name=\"size\" attr.type=\"int\" for=\"node\" id=\"size\"/>" +
- "<key attr.name=\"weight\" attr.type=\"float\" for=\"edge\" id=\"weight\"/>" +
- "<key attr.name=\"x\" attr.type=\"float\" for=\"node\" id=\"x\"/>" +
- "<key attr.name=\"y\" attr.type=\"float\" for=\"node\" id=\"y\"/>");
+ writer.append("<key attr.name=\"r\" attr.type=\"int\" for=\"node\" id=\"r\"/>\n"
+ + "<key attr.name=\"g\" attr.type=\"int\" for=\"node\" id=\"g\"/>\n"
+ + "<key attr.name=\"b\" attr.type=\"int\" for=\"node\" id=\"b\"/>"
+ + "<key attr.name=\"size\" attr.type=\"int\" for=\"node\" id=\"size\"/>"
+ + "<key attr.name=\"weight\" attr.type=\"float\" for=\"edge\" id=\"weight\"/>"
+ + "<key attr.name=\"x\" attr.type=\"float\" for=\"node\" id=\"x\"/>"
+ + "<key attr.name=\"y\" attr.type=\"float\" for=\"node\" id=\"y\"/>");
writer.append("<graph edgedefault=\"undirected\">");
lastClusterColor = new Color();
posStep = (int) (0.1 * clusterIdToPoints.size()) + 100;
@@ -99,7 +98,7 @@ public class GraphMLClusterWriter extend
public void write(ClusterWritable clusterWritable) throws IOException {
StringBuilder line = new StringBuilder();
Cluster cluster = clusterWritable.getValue();
- Color rgb = getColor(cluster.getId());
+ Color rgb = getColor(cluster.getId());
String topTerms = "";
if (dictionary != null) {
@@ -190,14 +189,14 @@ public class GraphMLClusterWriter extend
private static String createNode(String s, Color rgb, float x, float y) {
return "<node id=\"" + StringUtils.escapeXML(s) + "\"><data key=\"r\">" + rgb.r
- + "</data>" +
- "<data key=\"g\">" + rgb.g
- + "</data>" +
- "<data key=\"b\">" + rgb.b
- + "</data>" +
- "<data key=\"x\">" + x
- + "</data>" +
- "<data key=\"y\">" + y
+ + "</data>"
+ + "<data key=\"g\">" + rgb.g
+ + "</data>"
+ + "<data key=\"b\">" + rgb.b
+ + "</data>"
+ + "<data key=\"x\">" + x
+ + "</data>"
+ + "<data key=\"y\">" + y
+ "</data>"
+ "</node>";
}
Modified: mahout/trunk/integration/src/main/java/org/apache/mahout/utils/vectors/RowIdJob.java
URL: http://svn.apache.org/viewvc/mahout/trunk/integration/src/main/java/org/apache/mahout/utils/vectors/RowIdJob.java?rev=1461119&r1=1461118&r2=1461119&view=diff
==============================================================================
--- mahout/trunk/integration/src/main/java/org/apache/mahout/utils/vectors/RowIdJob.java (original)
+++ mahout/trunk/integration/src/main/java/org/apache/mahout/utils/vectors/RowIdJob.java Tue Mar 26 13:24:40 2013
@@ -71,13 +71,9 @@ public class RowIdJob extends AbstractJo
IntWritable docId = new IntWritable();
int i = 0;
int numCols = 0;
- for (Pair<Text,VectorWritable> record :
- new SequenceFileDirIterable<Text,VectorWritable>(getInputPath(),
- PathType.LIST,
- PathFilters.logsCRCFilter(),
- null,
- true,
- conf)) {
+ for (Pair<Text,VectorWritable> record
+ : new SequenceFileDirIterable<Text,VectorWritable>(getInputPath(), PathType.LIST, PathFilters.logsCRCFilter(),
+ null, true, conf)) {
VectorWritable value = record.getSecond();
docId.set(i);
indexWriter.append(docId, record.getFirst());
Modified: mahout/trunk/integration/src/main/java/org/apache/mahout/utils/vectors/VectorDumper.java
URL: http://svn.apache.org/viewvc/mahout/trunk/integration/src/main/java/org/apache/mahout/utils/vectors/VectorDumper.java?rev=1461119&r1=1461118&r2=1461119&view=diff
==============================================================================
--- mahout/trunk/integration/src/main/java/org/apache/mahout/utils/vectors/VectorDumper.java (original)
+++ mahout/trunk/integration/src/main/java/org/apache/mahout/utils/vectors/VectorDumper.java Tue Mar 26 13:24:40 2013
@@ -77,11 +77,11 @@ public final class VectorDumper extends
addOption("dictionaryType", "dt", "The dictionary file type (text|seqfile)", false);
addOption("csv", "c", "Output the Vector as CSV. Otherwise it substitutes in the terms for vector cell entries",
false);
- addOption("namesAsComments", "n", "If using CSV output, optionally add a comment line for each NamedVector " +
- "(if the vector is one) printing out the name", false);
+ addOption("namesAsComments", "n", "If using CSV output, optionally add a comment line for each NamedVector "
+ + "(if the vector is one) printing out the name", false);
addOption("nameOnly", "N", "Use the name as the value for each NamedVector (skip other vectors)", false);
- addOption("sortVectors", "sort", "Sort output key/value pairs of the vector entries in abs magnitude " +
- "descending order", false);
+ addOption("sortVectors", "sort", "Sort output key/value pairs of the vector entries in abs magnitude "
+ + "descending order", false);
addOption("quiet", "q", "Print only file contents", false);
addOption("sizeOnly", "sz", "Dump only the size of the vector", false);
addOption("numItems", "ni", "Output at most <n> vecors", false);
Modified: mahout/trunk/integration/src/main/java/org/apache/mahout/utils/vectors/VectorHelper.java
URL: http://svn.apache.org/viewvc/mahout/trunk/integration/src/main/java/org/apache/mahout/utils/vectors/VectorHelper.java?rev=1461119&r1=1461118&r2=1461119&view=diff
==============================================================================
--- mahout/trunk/integration/src/main/java/org/apache/mahout/utils/vectors/VectorHelper.java (original)
+++ mahout/trunk/integration/src/main/java/org/apache/mahout/utils/vectors/VectorHelper.java Tue Mar 26 13:24:40 2013
@@ -91,10 +91,10 @@ public final class VectorHelper {
}
}
Collections.sort(entries, new Comparator<Pair<Integer, Double>>() {
- @Override
- public int compare(Pair<Integer, Double> a, Pair<Integer, Double> b) {
- return b.getSecond().compareTo(a.getSecond());
- }
+ @Override
+ public int compare(Pair<Integer, Double> a, Pair<Integer, Double> b) {
+ return b.getSecond().compareTo(a.getSecond());
+ }
});
return entries;
}
@@ -114,20 +114,20 @@ public final class VectorHelper {
final String[] dictionary) {
if (dictionary != null) {
return Lists.newArrayList(Collections2.transform(entries,
- new Function<Pair<Integer, Double>, Pair<String, Double>>() {
- @Override
- public Pair<String, Double> apply(Pair<Integer, Double> p) {
- return Pair.of(dictionary[p.getFirst()], p.getSecond());
- }
- }));
+ new Function<Pair<Integer, Double>, Pair<String, Double>>() {
+ @Override
+ public Pair<String, Double> apply(Pair<Integer, Double> p) {
+ return Pair.of(dictionary[p.getFirst()], p.getSecond());
+ }
+ }));
} else {
return Lists.newArrayList(Collections2.transform(entries,
- new Function<Pair<Integer, Double>, Pair<String, Double>>() {
- @Override
- public Pair<String, Double> apply(Pair<Integer, Double> p) {
- return Pair.of(Integer.toString(p.getFirst()), p.getSecond());
- }
- }));
+ new Function<Pair<Integer, Double>, Pair<String, Double>>() {
+ @Override
+ public Pair<String, Double> apply(Pair<Integer, Double> p) {
+ return Pair.of(Integer.toString(p.getFirst()), p.getSecond());
+ }
+ }));
}
}
@@ -176,9 +176,9 @@ public final class VectorHelper {
*/
public static String[] loadTermDictionary(Configuration conf, String filePattern) {
OpenObjectIntHashMap<String> dict = new OpenObjectIntHashMap<String>();
- for (Pair<Text, IntWritable> record :
- new SequenceFileDirIterable<Text, IntWritable>(new Path(filePattern), PathType.GLOB,
- null, null, true, conf)) {
+ for (Pair<Text, IntWritable> record
+ : new SequenceFileDirIterable<Text, IntWritable>(new Path(filePattern), PathType.GLOB, null, null, true,
+ conf)) {
dict.put(record.getFirst().toString(), record.getSecond().get());
}
String[] dictionary = new String[dict.size()];
Modified: mahout/trunk/integration/src/main/java/org/apache/mahout/utils/vectors/arff/ARFFType.java
URL: http://svn.apache.org/viewvc/mahout/trunk/integration/src/main/java/org/apache/mahout/utils/vectors/arff/ARFFType.java?rev=1461119&r1=1461118&r2=1461119&view=diff
==============================================================================
--- mahout/trunk/integration/src/main/java/org/apache/mahout/utils/vectors/arff/ARFFType.java (original)
+++ mahout/trunk/integration/src/main/java/org/apache/mahout/utils/vectors/arff/ARFFType.java Tue Mar 26 13:24:40 2013
@@ -49,14 +49,14 @@ public enum ARFFType {
public static String removeQuotes(String str) {
String cleaned = str;
if (cleaned != null) {
- cleaned = cleaned.trim();
- boolean isQuoted = cleaned.length() > 1 &&
- (cleaned.startsWith("\"") && cleaned.endsWith("\"") ||
- cleaned.startsWith("'") && cleaned.endsWith("'"));
- if (isQuoted) {
- cleaned = cleaned.substring(1, cleaned.length() - 1);
- }
+ cleaned = cleaned.trim();
+ boolean isQuoted = cleaned.length() > 1
+ && (cleaned.startsWith("\"") && cleaned.endsWith("\"")
+ || cleaned.startsWith("'") && cleaned.endsWith("'"));
+ if (isQuoted) {
+ cleaned = cleaned.substring(1, cleaned.length() - 1);
}
+ }
return cleaned;
}
}
Modified: mahout/trunk/integration/src/main/java/org/apache/mahout/utils/vectors/lucene/AbstractLuceneIterator.java
URL: http://svn.apache.org/viewvc/mahout/trunk/integration/src/main/java/org/apache/mahout/utils/vectors/lucene/AbstractLuceneIterator.java?rev=1461119&r1=1461118&r2=1461119&view=diff
==============================================================================
--- mahout/trunk/integration/src/main/java/org/apache/mahout/utils/vectors/lucene/AbstractLuceneIterator.java (original)
+++ mahout/trunk/integration/src/main/java/org/apache/mahout/utils/vectors/lucene/AbstractLuceneIterator.java Tue Mar 26 13:24:40 2013
@@ -37,104 +37,104 @@ import java.io.IOException;
* Subclasses define how much information to retrieve from the Lucene index.
*/
public abstract class AbstractLuceneIterator extends AbstractIterator<Vector> {
- private static final Logger log = LoggerFactory.getLogger(LuceneIterator.class);
- protected final IndexReader indexReader;
- protected final String field;
- protected final TermInfo terminfo;
- protected final double normPower;
- protected final Weight weight;
- protected final Bump125 bump = new Bump125();
- protected int nextDocId;
- protected int maxErrorDocs;
- protected int numErrorDocs;
- protected long nextLogRecord = bump.increment();
- protected int skippedErrorMessages;
-
- public AbstractLuceneIterator(TermInfo terminfo, double normPower, IndexReader indexReader, Weight weight,
- double maxPercentErrorDocs, String field) {
- this.terminfo = terminfo;
- this.normPower = normPower;
- this.indexReader = indexReader;
-
- this.weight = weight;
- this.nextDocId = 0;
- this.maxErrorDocs = (int) (maxPercentErrorDocs * indexReader.numDocs());
- this.field = field;
- }
-
- /**
- * Given the document name, derive a name for the vector. This may involve
- * reading the document from Lucene and setting up any other state that the
- * subclass wants. This will be called once for each document that the
- * iterator processes.
- * @param documentIndex the lucene document index.
- * @return the name to store in the vector.
- */
- protected abstract String getVectorName(int documentIndex) throws IOException;
-
- @Override
- protected Vector computeNext() {
- try {
- int doc;
- Terms termFreqVector;
- String name;
-
- do {
- doc = this.nextDocId;
- nextDocId++;
+ private static final Logger log = LoggerFactory.getLogger(LuceneIterator.class);
+ protected final IndexReader indexReader;
+ protected final String field;
+ protected final TermInfo terminfo;
+ protected final double normPower;
+ protected final Weight weight;
+ protected final Bump125 bump = new Bump125();
+ protected int nextDocId;
+ protected int maxErrorDocs;
+ protected int numErrorDocs;
+ protected long nextLogRecord = bump.increment();
+ protected int skippedErrorMessages;
+
+ public AbstractLuceneIterator(TermInfo terminfo, double normPower, IndexReader indexReader, Weight weight,
+ double maxPercentErrorDocs, String field) {
+ this.terminfo = terminfo;
+ this.normPower = normPower;
+ this.indexReader = indexReader;
+
+ this.weight = weight;
+ this.nextDocId = 0;
+ this.maxErrorDocs = (int) (maxPercentErrorDocs * indexReader.numDocs());
+ this.field = field;
+ }
+
+ /**
+ * Given the document name, derive a name for the vector. This may involve
+ * reading the document from Lucene and setting up any other state that the
+ * subclass wants. This will be called once for each document that the
+ * iterator processes.
+ * @param documentIndex the lucene document index.
+ * @return the name to store in the vector.
+ */
+ protected abstract String getVectorName(int documentIndex) throws IOException;
+
+ @Override
+ protected Vector computeNext() {
+ try {
+ int doc;
+ Terms termFreqVector;
+ String name;
+
+ do {
+ doc = this.nextDocId;
+ nextDocId++;
- if (doc >= indexReader.maxDoc()) {
- return endOfData();
- }
+ if (doc >= indexReader.maxDoc()) {
+ return endOfData();
+ }
- termFreqVector = indexReader.getTermVector(doc, field);
- name = getVectorName(doc);
+ termFreqVector = indexReader.getTermVector(doc, field);
+ name = getVectorName(doc);
- if (termFreqVector == null) {
- numErrorDocs++;
- if (numErrorDocs >= maxErrorDocs) {
- log.error("There are too many documents that do not have a term vector for {}", field);
- throw new IllegalStateException("There are too many documents that do not have a term vector for " +
- field);
- }
- if (numErrorDocs >= nextLogRecord) {
- if (skippedErrorMessages == 0) {
- log.warn("{} does not have a term vector for {}", name, field);
- } else {
- log.warn("{} documents do not have a term vector for {}", numErrorDocs, field);
- }
- nextLogRecord = bump.increment();
- skippedErrorMessages = 0;
+ if (termFreqVector == null) {
+ numErrorDocs++;
+ if (numErrorDocs >= maxErrorDocs) {
+ log.error("There are too many documents that do not have a term vector for {}", field);
+ throw new IllegalStateException("There are too many documents that do not have a term vector for "
+ + field);
+ }
+ if (numErrorDocs >= nextLogRecord) {
+ if (skippedErrorMessages == 0) {
+ log.warn("{} does not have a term vector for {}", name, field);
} else {
- skippedErrorMessages++;
+ log.warn("{} documents do not have a term vector for {}", numErrorDocs, field);
}
+ nextLogRecord = bump.increment();
+ skippedErrorMessages = 0;
+ } else {
+ skippedErrorMessages++;
}
- } while (termFreqVector == null);
+ }
+ } while (termFreqVector == null);
- // The loop exits with termFreqVector and name set.
+ // The loop exits with termFreqVector and name set.
- TermsEnum te = termFreqVector.iterator(null);
- BytesRef term;
- TFDFMapper mapper = new TFDFMapper(indexReader.numDocs(), weight, this.terminfo);
- mapper.setExpectations(field, termFreqVector.size());
- while ((term = te.next()) != null) {
- mapper.map(term, (int) te.totalTermFreq());
- }
- Vector result = mapper.getVector();
- if (result == null) {
- // TODO is this right? last version would produce null in the iteration in this case, though it
- // seems like that may not be desirable
- return null;
- }
+ TermsEnum te = termFreqVector.iterator(null);
+ BytesRef term;
+ TFDFMapper mapper = new TFDFMapper(indexReader.numDocs(), weight, this.terminfo);
+ mapper.setExpectations(field, termFreqVector.size());
+ while ((term = te.next()) != null) {
+ mapper.map(term, (int) te.totalTermFreq());
+ }
+ Vector result = mapper.getVector();
+ if (result == null) {
+ // TODO is this right? last version would produce null in the iteration in this case, though it
+ // seems like that may not be desirable
+ return null;
+ }
- if (normPower == LuceneIterable.NO_NORMALIZING) {
- result = new NamedVector(result, name);
- } else {
- result = new NamedVector(result.normalize(normPower), name);
- }
- return result;
- } catch (IOException ioe) {
- throw new IllegalStateException(ioe);
+ if (normPower == LuceneIterable.NO_NORMALIZING) {
+ result = new NamedVector(result, name);
+ } else {
+ result = new NamedVector(result.normalize(normPower), name);
}
+ return result;
+ } catch (IOException ioe) {
+ throw new IllegalStateException(ioe);
}
+ }
}
Modified: mahout/trunk/integration/src/main/java/org/apache/mahout/utils/vectors/lucene/Driver.java
URL: http://svn.apache.org/viewvc/mahout/trunk/integration/src/main/java/org/apache/mahout/utils/vectors/lucene/Driver.java?rev=1461119&r1=1461118&r2=1461119&view=diff
==============================================================================
--- mahout/trunk/integration/src/main/java/org/apache/mahout/utils/vectors/lucene/Driver.java (original)
+++ mahout/trunk/integration/src/main/java/org/apache/mahout/utils/vectors/lucene/Driver.java Tue Mar 26 13:24:40 2013
@@ -182,8 +182,8 @@ public final class Driver {
Option maxPercentErrorDocsOpt = obuilder.withLongName("maxPercentErrorDocs").withRequired(false).withArgument(
abuilder.withName("maxPercentErrorDocs").withMinimum(1).withMaximum(1).create()).withDescription(
"The max percentage of docs that can have a null term vector. These are noise document and can occur if the "
- + "analyzer used strips out all terms in the target field. This percentage is expressed as a value " +
- "between 0 and 1. The default is 0.").withShortName("err").create();
+ + "analyzer used strips out all terms in the target field. This percentage is expressed as a value "
+ + "between 0 and 1. The default is 0.").withShortName("err").create();
Option helpOpt = obuilder.withLongName("help").withDescription("Print out help").withShortName("h")
.create();
Modified: mahout/trunk/integration/src/main/java/org/apache/mahout/utils/vectors/lucene/LuceneIterator.java
URL: http://svn.apache.org/viewvc/mahout/trunk/integration/src/main/java/org/apache/mahout/utils/vectors/lucene/LuceneIterator.java?rev=1461119&r1=1461118&r2=1461119&view=diff
==============================================================================
--- mahout/trunk/integration/src/main/java/org/apache/mahout/utils/vectors/lucene/LuceneIterator.java (original)
+++ mahout/trunk/integration/src/main/java/org/apache/mahout/utils/vectors/lucene/LuceneIterator.java Tue Mar 26 13:24:40 2013
@@ -32,8 +32,9 @@ import java.util.TreeSet;
* term vectors stored for it.
*/
public class LuceneIterator extends AbstractLuceneIterator {
- protected final Set<String> idFieldSelector;
- protected final String idField;
+
+ protected final Set<String> idFieldSelector;
+ protected final String idField;
/**
* Produce a LuceneIterable that can create the Vector plus normalize it.
@@ -45,11 +46,7 @@ public class LuceneIterator extends Abst
* @param weight weight
* @param normPower the normalization value. Must be nonnegative, or {@link LuceneIterable#NO_NORMALIZING}
*/
- public LuceneIterator(IndexReader indexReader,
- String idField,
- String field,
- TermInfo terminfo,
- Weight weight,
+ public LuceneIterator(IndexReader indexReader, String idField, String field, TermInfo terminfo, Weight weight,
double normPower) {
this(indexReader, idField, field, terminfo, weight, normPower, 0.0);
}
@@ -82,24 +79,20 @@ public class LuceneIterator extends Abst
idFieldSelector = new TreeSet<String>();
idFieldSelector.add(idField);
} else {
- idFieldSelector = null; /*The field in the index containing the index. If
- null, then the Lucene
- internal doc id is used
- which is prone to error
- if the underlying index
- changes*/
-
- }
+ /*The field in the index containing the index. If null, then the Lucene internal doc id is used
+ which is prone to error if the underlying index changes*/
+ idFieldSelector = null;
+ }
}
- @Override
- protected String getVectorName(int documentIndex) throws IOException {
- String name;
- if (idField != null) {
- name = indexReader.document(documentIndex, idFieldSelector).get(idField);
- } else {
- name = String.valueOf(documentIndex);
- }
- return name;
+ @Override
+ protected String getVectorName(int documentIndex) throws IOException {
+ String name;
+ if (idField != null) {
+ name = indexReader.document(documentIndex, idFieldSelector).get(idField);
+ } else {
+ name = String.valueOf(documentIndex);
}
+ return name;
+ }
}
Modified: mahout/trunk/integration/src/main/java/org/apache/mahout/utils/vectors/lucene/TFDFMapper.java
URL: http://svn.apache.org/viewvc/mahout/trunk/integration/src/main/java/org/apache/mahout/utils/vectors/lucene/TFDFMapper.java?rev=1461119&r1=1461118&r2=1461119&view=diff
==============================================================================
--- mahout/trunk/integration/src/main/java/org/apache/mahout/utils/vectors/lucene/TFDFMapper.java (original)
+++ mahout/trunk/integration/src/main/java/org/apache/mahout/utils/vectors/lucene/TFDFMapper.java Tue Mar 26 13:24:40 2013
@@ -51,14 +51,14 @@ public class TFDFMapper {
}
public void map(BytesRef term, int frequency) {
- TermEntry entry = termInfo.getTermEntry(field, term.utf8ToString() );
+ TermEntry entry = termInfo.getTermEntry(field, term.utf8ToString());
if (entry != null) {
vector.setQuick(entry.getTermIdx(), weight.calculate(frequency, entry.getDocFreq(), (int)numTerms, numDocs));
}
}
public Vector getVector() {
- return this.vector;
+ return this.vector;
}
}
Modified: mahout/trunk/math/src/main/java-templates/org/apache/mahout/math/map/OpenKeyTypeObjectHashMap.java.t
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java-templates/org/apache/mahout/math/map/OpenKeyTypeObjectHashMap.java.t?rev=1461119&r1=1461118&r2=1461119&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java-templates/org/apache/mahout/math/map/OpenKeyTypeObjectHashMap.java.t (original)
+++ mahout/trunk/math/src/main/java-templates/org/apache/mahout/math/map/OpenKeyTypeObjectHashMap.java.t Tue Mar 26 13:24:40 2013
@@ -54,7 +54,7 @@ public class Open${keyTypeCap}ObjectHash
/** Constructs an empty map with default capacity and default load factors. */
public Open${keyTypeCap}ObjectHashMap() {
- this(defaultCapacity);
+ this(DEFAULT_CAPACITY);
}
/**
@@ -64,7 +64,7 @@ public class Open${keyTypeCap}ObjectHash
* @throws IllegalArgumentException if the initial capacity is less than zero.
*/
public Open${keyTypeCap}ObjectHashMap(int initialCapacity) {
- this(initialCapacity, defaultMinLoadFactor, defaultMaxLoadFactor);
+ this(initialCapacity, DEFAULT_MIN_LOAD_FACTOR, DEFAULT_MAX_LOAD_FACTOR);
}
/**
@@ -482,7 +482,7 @@ public class Open${keyTypeCap}ObjectHash
// memory will be exhausted long before this pathological case happens, anyway.
this.minLoadFactor = minLoadFactor;
- if (capacity == PrimeFinder.largestPrime) {
+ if (capacity == PrimeFinder.LARGEST_PRIME) {
this.maxLoadFactor = 1.0;
} else {
this.maxLoadFactor = maxLoadFactor;
Modified: mahout/trunk/math/src/main/java-templates/org/apache/mahout/math/map/OpenKeyTypeValueTypeHashMap.java.t
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java-templates/org/apache/mahout/math/map/OpenKeyTypeValueTypeHashMap.java.t?rev=1461119&r1=1461118&r2=1461119&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java-templates/org/apache/mahout/math/map/OpenKeyTypeValueTypeHashMap.java.t (original)
+++ mahout/trunk/math/src/main/java-templates/org/apache/mahout/math/map/OpenKeyTypeValueTypeHashMap.java.t Tue Mar 26 13:24:40 2013
@@ -67,7 +67,7 @@ public class Open${keyTypeCap}${valueTyp
/** Constructs an empty map with default capacity and default load factors. */
public Open${keyTypeCap}${valueTypeCap}HashMap() {
- this(defaultCapacity);
+ this(DEFAULT_CAPACITY);
}
/**
@@ -77,7 +77,7 @@ public class Open${keyTypeCap}${valueTyp
* @throws IllegalArgumentException if the initial capacity is less than zero.
*/
public Open${keyTypeCap}${valueTypeCap}HashMap(int initialCapacity) {
- this(initialCapacity, defaultMinLoadFactor, defaultMaxLoadFactor);
+ this(initialCapacity, DEFAULT_MIN_LOAD_FACTOR, DEFAULT_MAX_LOAD_FACTOR);
}
/**
@@ -504,7 +504,7 @@ public class Open${keyTypeCap}${valueTyp
// memory will be exhausted long before this pathological case happens, anyway.
this.minLoadFactor = minLoadFactor;
- if (capacity == PrimeFinder.largestPrime) {
+ if (capacity == PrimeFinder.LARGEST_PRIME) {
this.maxLoadFactor = 1.0;
} else {
this.maxLoadFactor = maxLoadFactor;
Modified: mahout/trunk/math/src/main/java-templates/org/apache/mahout/math/map/OpenObjectValueTypeHashMap.java.t
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java-templates/org/apache/mahout/math/map/OpenObjectValueTypeHashMap.java.t?rev=1461119&r1=1461118&r2=1461119&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java-templates/org/apache/mahout/math/map/OpenObjectValueTypeHashMap.java.t (original)
+++ mahout/trunk/math/src/main/java-templates/org/apache/mahout/math/map/OpenObjectValueTypeHashMap.java.t Tue Mar 26 13:24:40 2013
@@ -58,7 +58,7 @@ public class OpenObject${valueTypeCap}Ha
/** Constructs an empty map with default capacity and default load factors. */
public OpenObject${valueTypeCap}HashMap() {
- this(defaultCapacity);
+ this(DEFAULT_CAPACITY);
}
/**
@@ -68,7 +68,7 @@ public class OpenObject${valueTypeCap}Ha
* @throws IllegalArgumentException if the initial capacity is less than zero.
*/
public OpenObject${valueTypeCap}HashMap(int initialCapacity) {
- this(initialCapacity, defaultMinLoadFactor, defaultMaxLoadFactor);
+ this(initialCapacity, DEFAULT_MIN_LOAD_FACTOR, DEFAULT_MAX_LOAD_FACTOR);
}
/**
@@ -497,7 +497,7 @@ public class OpenObject${valueTypeCap}Ha
// memory will be exhausted long before this pathological case happens, anyway.
this.minLoadFactor = minLoadFactor;
- if (capacity == PrimeFinder.largestPrime) {
+ if (capacity == PrimeFinder.LARGEST_PRIME) {
this.maxLoadFactor = 1.0;
} else {
this.maxLoadFactor = maxLoadFactor;
Modified: mahout/trunk/math/src/main/java-templates/org/apache/mahout/math/set/OpenKeyTypeHashSet.java.t
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java-templates/org/apache/mahout/math/set/OpenKeyTypeHashSet.java.t?rev=1461119&r1=1461118&r2=1461119&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java-templates/org/apache/mahout/math/set/OpenKeyTypeHashSet.java.t (original)
+++ mahout/trunk/math/src/main/java-templates/org/apache/mahout/math/set/OpenKeyTypeHashSet.java.t Tue Mar 26 13:24:40 2013
@@ -53,7 +53,7 @@ public class Open${keyTypeCap}HashSet ex
/** Constructs an empty map with default capacity and default load factors. */
public Open${keyTypeCap}HashSet() {
- this(defaultCapacity);
+ this(DEFAULT_CAPACITY);
}
/**
@@ -63,7 +63,7 @@ public class Open${keyTypeCap}HashSet ex
* @throws IllegalArgumentException if the initial capacity is less than zero.
*/
public Open${keyTypeCap}HashSet(int initialCapacity) {
- this(initialCapacity, defaultMinLoadFactor, defaultMaxLoadFactor);
+ this(initialCapacity, DEFAULT_MIN_LOAD_FACTOR, DEFAULT_MAX_LOAD_FACTOR);
}
/**
@@ -376,7 +376,7 @@ public class Open${keyTypeCap}HashSet ex
// memory will be exhausted long before this pathological case happens, anyway.
this.minLoadFactor = minLoadFactor;
- if (capacity == PrimeFinder.largestPrime) {
+ if (capacity == PrimeFinder.LARGEST_PRIME) {
this.maxLoadFactor = 1.0;
} else {
this.maxLoadFactor = maxLoadFactor;
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/collections/Arithmetic.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/collections/Arithmetic.java?rev=1461119&r1=1461118&r2=1461119&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/collections/Arithmetic.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/collections/Arithmetic.java Tue Mar 26 13:24:40 2013
@@ -30,8 +30,8 @@ package org.apache.mahout.collections;
* Arithmetic functions.
*/
public final class Arithmetic extends Constants {
- // for method stirlingCorrection(...)
- private static final double[] stirlingCorrection = {
+ // for method STIRLING_CORRECTION(...)
+ private static final double[] STIRLING_CORRECTION = {
0.0,
8.106146679532726e-02, 4.134069595540929e-02,
2.767792568499834e-02, 2.079067210376509e-02,
@@ -52,7 +52,7 @@ public final class Arithmetic extends Co
// for method logFactorial(...)
// log(k!) for k = 0, ..., 29
- private static final double[] logFactorials = {
+ private static final double[] LOG_FACTORIALS = {
0.00000000000000000, 0.00000000000000000, 0.69314718055994531,
1.79175946922805500, 3.17805383034794562, 4.78749174278204599,
6.57925121201010100, 8.52516136106541430, 10.60460290274525023,
@@ -66,7 +66,7 @@ public final class Arithmetic extends Co
};
// k! for k = 0, ..., 20
- private static final long[] longFactorials = {
+ private static final long[] LONG_FACTORIALS = {
1L,
1L,
2L,
@@ -91,7 +91,7 @@ public final class Arithmetic extends Co
};
// k! for k = 21, ..., 170
- private static final double[] doubleFactorials = {
+ private static final double[] DOUBLE_FACTORIALS = {
5.109094217170944E19,
1.1240007277776077E21,
2.585201673888498E22,
@@ -298,7 +298,7 @@ public final class Arithmetic extends Co
// try quick version and see whether we get numeric overflows.
// factorial(..) is O(1); requires no loop; only a table lookup.
if (n > k) {
- int max = longFactorials.length + doubleFactorials.length;
+ int max = LONG_FACTORIALS.length + DOUBLE_FACTORIALS.length;
if (n < max) { // if (n! < inf && k! < inf)
double n_fac = factorial((int) n);
double k_fac = factorial((int) k);
@@ -381,23 +381,23 @@ public final class Arithmetic extends Co
throw new IllegalArgumentException();
}
- int length1 = longFactorials.length;
+ int length1 = LONG_FACTORIALS.length;
if (k < length1) {
- return longFactorials[k];
+ return LONG_FACTORIALS[k];
}
- int length2 = doubleFactorials.length;
+ int length2 = DOUBLE_FACTORIALS.length;
if (k < length1 + length2) {
- return doubleFactorials[k - length1];
+ return DOUBLE_FACTORIALS[k - length1];
} else {
return Double.POSITIVE_INFINITY;
}
}
/**
- * Returns the largest <code>long <= value</code>. <dt>Examples: {@code 1.0 -> 1, 1.2 -> 1, 1.9 -> 1 <dt> 2.0 -> 2,}
- * 2.2 -> 2, 2.9 -> 2 </code><dt> This method is safer than using (long) Math.floor(value), because of possible
- * rounding error.
+ * Returns the largest <code>long <= value</code>.
+ * <dt>Examples: {@code 1.0 -> 1, 1.2 -> 1, 1.9 -> 1 <dt> 2.0 -> 2,} 2.2 -> 2, 2.9 -> 2 </code><dt>
+ * This method is safer than using (long) Math.floor(value), because of possible rounding error.
*/
public static long floor(double value) {
return Math.round(Math.floor(value));
@@ -438,7 +438,7 @@ public final class Arithmetic extends Co
double C0 = 9.18938533204672742e-01;
return (k + 0.5) * Math.log(k) - k + C0 + r * (C1 + rr * (C3 + rr * (C5 + rr * C7)));
} else {
- return logFactorials[k];
+ return LOG_FACTORIALS[k];
}
}
@@ -452,8 +452,8 @@ public final class Arithmetic extends Co
throw new IllegalArgumentException("Negative k");
}
- if (k < longFactorials.length) {
- return longFactorials[k];
+ if (k < LONG_FACTORIALS.length) {
+ return LONG_FACTORIALS[k];
}
throw new IllegalArgumentException("Overflow");
}
@@ -461,8 +461,8 @@ public final class Arithmetic extends Co
/**
* Returns the StirlingCorrection. <p> Correction term of the Stirling approximation for <tt>log(k!)</tt> (series in
* 1/k, or table values for small k) with int parameter k. <p> <tt> log k! = (k + 1/2)log(k + 1) - (k + 1) +
- * (1/2)log(2Pi) + stirlingCorrection(k + 1) <p> log k! = (k + 1/2)log(k) - k + (1/2)log(2Pi) +
- * stirlingCorrection(k) </tt>
+ * (1/2)log(2Pi) + STIRLING_CORRECTION(k + 1) <p> log k! = (k + 1/2)log(k) - k + (1/2)log(2Pi) +
+ * STIRLING_CORRECTION(k) </tt>
*/
public static double stirlingCorrection(int k) {
@@ -475,7 +475,7 @@ public final class Arithmetic extends Co
double C1 = 8.33333333333333333e-02; // +1/12
return r * (C1 + rr * (C3 + rr * (C5 + rr * C7)));
} else {
- return stirlingCorrection[k];
+ return STIRLING_CORRECTION[k];
}
}
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/collections/Constants.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/collections/Constants.java?rev=1461119&r1=1461118&r2=1461119&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/collections/Constants.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/collections/Constants.java Tue Mar 26 13:24:40 2013
@@ -42,8 +42,8 @@ public class Constants {
protected static final double SQRTH = 7.07106781186547524401E-1;
protected static final double LOGPI = 1.14472988584940017414;
- protected static final double big = 4.503599627370496e15;
- protected static final double biginv = 2.22044604925031308085e-16;
+ protected static final double BIG = 4.503599627370496e15;
+ protected static final double BIGINV = 2.22044604925031308085e-16;
/*
@@ -71,6 +71,5 @@ public class Constants {
* THPIO4 = 2.35619449019234492885 3*pi/4
* TWOOPI = 6.36619772367581343075535E-1 2/pi
*/
- protected Constants() {
- }
+ protected Constants() {}
}
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=1461119&r1=1461118&r2=1461119&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 Tue Mar 26 13:24:40 2013
@@ -356,7 +356,7 @@ public abstract class AbstractVector imp
* @param v2 The vector that we access via iterateNonZero and via Element.get()
* @return The squared difference between v1 and v2.
*/
- static double randomScanDiff(Vector v1, Vector v2) {
+ static double randomScanDiff(Vector v1, Vector v2) {
// keeps a list of elements we visited by iterating over v1. This should be
// almost all of the elements of v2 because we only call this method if the
// difference is small.
@@ -464,7 +464,7 @@ public abstract class AbstractVector imp
}
// one of i1 or i2 is exhausted here, but the other may not be
- while (e1 != null ) {
+ while (e1 != null) {
double x = e1.get();
r += x * x;
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/CholeskyDecomposition.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/CholeskyDecomposition.java?rev=1461119&r1=1461118&r2=1461119&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/CholeskyDecomposition.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/CholeskyDecomposition.java Tue Mar 26 13:24:40 2013
@@ -206,7 +206,8 @@ public class CholeskyDecomposition {
int i = L.rowUnpivot(internalI);
x.set(j, k, x.get(j, k) - x.get(j, i) * L.get(k, i));
if (Double.isInfinite(x.get(j, k)) || Double.isNaN(x.get(j, k))) {
- throw new IllegalStateException(String.format("Invalid value found at %d,%d (should not be possible)", j, k));
+ throw new IllegalStateException(
+ String.format("Invalid value found at %d,%d (should not be possible)", j, k));
}
}
if (L.get(k, k) != 0) {
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/DelegatingVector.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/DelegatingVector.java?rev=1461119&r1=1461118&r2=1461119&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/DelegatingVector.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/DelegatingVector.java Tue Mar 26 13:24:40 2013
@@ -293,4 +293,4 @@ public class DelegatingVector implements
public Iterator<Element> iterator() {
return delegate.iterator();
}
-}
\ No newline at end of file
+}
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/FileBasedMatrix.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/FileBasedMatrix.java?rev=1461119&r1=1461118&r2=1461119&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/FileBasedMatrix.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/FileBasedMatrix.java Tue Mar 26 13:24:40 2013
@@ -36,147 +36,148 @@ import java.util.List;
* that instead.
*/
public final class FileBasedMatrix extends AbstractMatrix {
- private final int rowsPerBlock;
- private final List<DoubleBuffer> content = Lists.newArrayList();
+ private final int rowsPerBlock;
+ private final List<DoubleBuffer> content = Lists.newArrayList();
- /**
- * Constructs an empty matrix of the given size.
- *
- * @param rows The number of rows in the result.
- * @param columns The number of columns in the result.
- */
- public FileBasedMatrix(int rows, int columns) {
- super(rows, columns);
- long maxRows = ((1L << 31) - 1) / (columns * 8);
- if (rows > maxRows) {
- rowsPerBlock = (int) maxRows;
- } else {
- rowsPerBlock = rows;
- }
- }
-
- private void addData(DoubleBuffer content) {
- this.content.add(content);
- }
-
- public void setData(File f, boolean loadNow) throws IOException {
- Preconditions.checkArgument(f.length() == (long) rows * columns * 8L, "File " + f + " is wrong length");
-
- for (int i = 0; i < (rows + rowsPerBlock - 1) / rowsPerBlock; i++) {
- long start = (long) i * rowsPerBlock * columns * 8L;
- long size = rowsPerBlock * columns * 8L;
- MappedByteBuffer buf = new FileInputStream(f).getChannel().map(FileChannel.MapMode.READ_ONLY, start, Math.min(f.length() - start, size));
- if (loadNow) {
- buf.load();
- }
- addData(buf.asDoubleBuffer());
- }
- }
-
- public static void writeMatrix(File f, Matrix m) throws IOException {
- Preconditions.checkArgument(f.canWrite(), "Can't write to output file");
- FileOutputStream fos = new FileOutputStream(f);
-
- ByteBuffer buf = ByteBuffer.allocate(m.columnSize() * 8);
- for (MatrixSlice row : m) {
- buf.clear();
- for (Vector.Element element : row.vector()) {
- buf.putDouble(element.get());
- }
- buf.flip();
- fos.write(buf.array());
- }
- fos.close();
- }
-
- /**
- * Assign the other vector values to the column of the receiver
- *
- * @param column the int row to assign
- * @param other a Vector
- * @return the modified receiver
- * @throws org.apache.mahout.math.CardinalityException
- * if the cardinalities differ
- */
- @Override
- public Matrix assignColumn(int column, Vector other) {
- throw new UnsupportedOperationException("Default operation");
- }
-
- /**
- * Assign the other vector values to the row of the receiver
- *
- * @param row the int row to assign
- * @param other a Vector
- * @return the modified receiver
- * @throws org.apache.mahout.math.CardinalityException
- * if the cardinalities differ
- */
- @Override
- public Matrix assignRow(int row, Vector other) {
- throw new UnsupportedOperationException("Default operation");
- }
-
- /**
- * Return the value at the given indexes, without checking bounds
- *
- * @param row an int row index
- * @param column an int column index
- * @return the double at the index
- */
- @Override
- public double getQuick(int row, int column) {
- int block = row / rowsPerBlock;
- return content.get(block).get((row % rowsPerBlock) * columns + column);
- }
-
- /**
- * Return an empty matrix of the same underlying class as the receiver
- *
- * @return a Matrix
- */
- @Override
- public Matrix like() {
- throw new UnsupportedOperationException("Default operation");
- }
-
- /**
- * Returns an empty matrix of the same underlying class as the receiver and of the specified size.
- *
- * @param rows the int number of rows
- * @param columns the int number of columns
- */
- @Override
- public Matrix like(int rows, int columns) {
- return new DenseMatrix(rows, columns);
- }
-
- /**
- * Set the value at the given index, without checking bounds
- *
- * @param row an int row index into the receiver
- * @param column an int column index into the receiver
- * @param value a double value to set
- */
- @Override
- public void setQuick(int row, int column, double value) {
- throw new UnsupportedOperationException("Default operation");
- }
-
- /**
- * Return a view into part of a matrix. Changes to the view will change the
- * original matrix.
- *
- * @param offset an int[2] offset into the receiver
- * @param size the int[2] size of the desired result
- * @return a matrix that shares storage with part of the original matrix.
- * @throws org.apache.mahout.math.CardinalityException
- * if the length is greater than the cardinality of the receiver
- * @throws org.apache.mahout.math.IndexException
- * if the offset is negative or the offset+length is outside of the receiver
- */
- @Override
- public Matrix viewPart(int[] offset, int[] size) {
- throw new UnsupportedOperationException("Default operation");
- }
+ /**
+ * Constructs an empty matrix of the given size.
+ *
+ * @param rows The number of rows in the result.
+ * @param columns The number of columns in the result.
+ */
+ public FileBasedMatrix(int rows, int columns) {
+ super(rows, columns);
+ long maxRows = ((1L << 31) - 1) / (columns * 8);
+ if (rows > maxRows) {
+ rowsPerBlock = (int) maxRows;
+ } else {
+ rowsPerBlock = rows;
+ }
+ }
+
+ private void addData(DoubleBuffer content) {
+ this.content.add(content);
+ }
+
+ public void setData(File f, boolean loadNow) throws IOException {
+ Preconditions.checkArgument(f.length() == (long) rows * columns * 8L, "File " + f + " is wrong length");
+
+ for (int i = 0; i < (rows + rowsPerBlock - 1) / rowsPerBlock; i++) {
+ long start = (long) i * rowsPerBlock * columns * 8L;
+ long size = rowsPerBlock * columns * 8L;
+ MappedByteBuffer buf = new FileInputStream(f).getChannel().map(FileChannel.MapMode.READ_ONLY, start,
+ Math.min(f.length() - start, size));
+ if (loadNow) {
+ buf.load();
+ }
+ addData(buf.asDoubleBuffer());
+ }
+ }
+
+ public static void writeMatrix(File f, Matrix m) throws IOException {
+ Preconditions.checkArgument(f.canWrite(), "Can't write to output file");
+ FileOutputStream fos = new FileOutputStream(f);
+
+ ByteBuffer buf = ByteBuffer.allocate(m.columnSize() * 8);
+ for (MatrixSlice row : m) {
+ buf.clear();
+ for (Vector.Element element : row.vector()) {
+ buf.putDouble(element.get());
+ }
+ buf.flip();
+ fos.write(buf.array());
+ }
+ fos.close();
+ }
+
+ /**
+ * Assign the other vector values to the column of the receiver
+ *
+ * @param column the int row to assign
+ * @param other a Vector
+ * @return the modified receiver
+ * @throws org.apache.mahout.math.CardinalityException
+ * if the cardinalities differ
+ */
+ @Override
+ public Matrix assignColumn(int column, Vector other) {
+ throw new UnsupportedOperationException("Default operation");
+ }
+
+ /**
+ * Assign the other vector values to the row of the receiver
+ *
+ * @param row the int row to assign
+ * @param other a Vector
+ * @return the modified receiver
+ * @throws org.apache.mahout.math.CardinalityException
+ * if the cardinalities differ
+ */
+ @Override
+ public Matrix assignRow(int row, Vector other) {
+ throw new UnsupportedOperationException("Default operation");
+ }
+
+ /**
+ * Return the value at the given indexes, without checking bounds
+ *
+ * @param row an int row index
+ * @param column an int column index
+ * @return the double at the index
+ */
+ @Override
+ public double getQuick(int row, int column) {
+ int block = row / rowsPerBlock;
+ return content.get(block).get((row % rowsPerBlock) * columns + column);
+ }
+
+ /**
+ * Return an empty matrix of the same underlying class as the receiver
+ *
+ * @return a Matrix
+ */
+ @Override
+ public Matrix like() {
+ throw new UnsupportedOperationException("Default operation");
+ }
+
+ /**
+ * Returns an empty matrix of the same underlying class as the receiver and of the specified size.
+ *
+ * @param rows the int number of rows
+ * @param columns the int number of columns
+ */
+ @Override
+ public Matrix like(int rows, int columns) {
+ return new DenseMatrix(rows, columns);
+ }
+
+ /**
+ * Set the value at the given index, without checking bounds
+ *
+ * @param row an int row index into the receiver
+ * @param column an int column index into the receiver
+ * @param value a double value to set
+ */
+ @Override
+ public void setQuick(int row, int column, double value) {
+ throw new UnsupportedOperationException("Default operation");
+ }
+
+ /**
+ * Return a view into part of a matrix. Changes to the view will change the
+ * original matrix.
+ *
+ * @param offset an int[2] offset into the receiver
+ * @param size the int[2] size of the desired result
+ * @return a matrix that shares storage with part of the original matrix.
+ * @throws org.apache.mahout.math.CardinalityException
+ * if the length is greater than the cardinality of the receiver
+ * @throws org.apache.mahout.math.IndexException
+ * if the offset is negative or the offset+length is outside of the receiver
+ */
+ @Override
+ public Matrix viewPart(int[] offset, int[] size) {
+ throw new UnsupportedOperationException("Default operation");
+ }
}
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/FileBasedSparseBinaryMatrix.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/FileBasedSparseBinaryMatrix.java?rev=1461119&r1=1461118&r2=1461119&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/FileBasedSparseBinaryMatrix.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/FileBasedSparseBinaryMatrix.java Tue Mar 26 13:24:40 2013
@@ -208,8 +208,7 @@ public final class FileBasedSparseBinary
}
if (low >= row.limit()) {
return 0;
- }
- else if (high == low && row.get(low) == columnIndex) {
+ } else if (high == low && row.get(low) == columnIndex) {
return 1;
} else {
return 0;
@@ -397,13 +396,13 @@ public final class FileBasedSparseBinary
@Override
protected Element computeNext() {
if (i < buffer.limit()) {
- return new BinaryReadOnlyElement(buffer.get(i++));
- } else {
- return endOfData();
+ return new BinaryReadOnlyElement(buffer.get(i++));
+ } else {
+ return endOfData();
+ }
}
- }
- };
- }
+ };
+ }
/**
* Return the value at the given index, without checking bounds
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/MurmurHash3.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/MurmurHash3.java?rev=1461119&r1=1461118&r2=1461119&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/MurmurHash3.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/MurmurHash3.java Tue Mar 26 13:24:40 2013
@@ -1,10 +1,12 @@
/*
* This code is public domain.
*
- * The MurmurHash3 algorithm was created by Austin Appleby and put into the public domain. See http://code.google.com/p/smhasher/
+ * The MurmurHash3 algorithm was created by Austin Appleby and put into the public domain.
+ * See http://code.google.com/p/smhasher/
*
* This java port was authored by
- * Yonik Seeley and was placed into the public domain per https://github.com/yonik/java_util/blob/master/src/util/hash/MurmurHash3.java.
+ * Yonik Seeley and was placed into the public domain per
+ * https://github.com/yonik/java_util/blob/master/src/util/hash/MurmurHash3.java.
*/
package org.apache.mahout.math;
@@ -24,11 +26,10 @@ package org.apache.mahout.math;
*/
public final class MurmurHash3 {
- private MurmurHash3() {
- }
+ private MurmurHash3() {}
/** Returns the MurmurHash3_x86_32 hash. */
- public static int murmurhash3_x86_32(byte[] data, int offset, int len, int seed) {
+ public static int murmurhash3x8632(byte[] data, int offset, int len, int seed) {
int c1 = 0xcc9e2d51;
int c2 = 0x1b873593;
@@ -36,16 +37,16 @@ public final class MurmurHash3 {
int h1 = seed;
int roundedEnd = offset + (len & 0xfffffffc); // round down to 4 byte block
- for (int i=offset; i<roundedEnd; i+=4) {
+ for (int i = offset; i < roundedEnd; i += 4) {
// little endian load order
- int k1 = (data[i] & 0xff) | ((data[i+1] & 0xff) << 8) | ((data[i+2] & 0xff) << 16) | (data[i+3] << 24);
+ int k1 = (data[i] & 0xff) | ((data[i + 1] & 0xff) << 8) | ((data[i + 2] & 0xff) << 16) | (data[i + 3] << 24);
k1 *= c1;
k1 = (k1 << 15) | (k1 >>> 17); // ROTL32(k1,15);
k1 *= c2;
h1 ^= k1;
h1 = (h1 << 13) | (h1 >>> 19); // ROTL32(h1,13);
- h1 = h1*5+0xe6546b64;
+ h1 = h1 * 5 + 0xe6546b64;
}
// tail
@@ -64,6 +65,7 @@ public final class MurmurHash3 {
k1 = (k1 << 15) | (k1 >>> 17); // ROTL32(k1,15);
k1 *= c2;
h1 ^= k1;
+ default:
}
// finalization
@@ -79,4 +81,4 @@ public final class MurmurHash3 {
return h1;
}
-}
\ No newline at end of file
+}
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/OrderedIntDoubleMapping.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/OrderedIntDoubleMapping.java?rev=1461119&r1=1461118&r2=1461119&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/OrderedIntDoubleMapping.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/OrderedIntDoubleMapping.java Tue Mar 26 13:24:40 2013
@@ -48,10 +48,23 @@ final class OrderedIntDoubleMapping impl
return indices;
}
+ int indexAt(int offset) {
+ return indices[offset];
+ }
+
+ void setIndexAt(int offset, int index) {
+ indices[offset] = index;
+ }
+
double[] getValues() {
return values;
}
+ void setValueAt(int offset, double value) {
+ values[offset] = value;
+ }
+
+
int getNumMappings() {
return numMappings;
}
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/RandomTrinaryMatrix.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/RandomTrinaryMatrix.java?rev=1461119&r1=1461118&r2=1461119&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/RandomTrinaryMatrix.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/RandomTrinaryMatrix.java Tue Mar 26 13:24:40 2013
@@ -30,7 +30,7 @@ import java.util.concurrent.atomic.Atomi
* which uses a murmur hash of the coordinates.
*/
public class RandomTrinaryMatrix extends AbstractMatrix {
- private static final AtomicInteger id = new AtomicInteger();
+ private static final AtomicInteger ID = new AtomicInteger();
private static final int PRIME1 = 104047;
private static final int PRIME2 = 101377;
private static final int PRIME3 = 64661;
@@ -49,7 +49,7 @@ public class RandomTrinaryMatrix extends
}
public RandomTrinaryMatrix(int rows, int columns) {
- this(id.incrementAndGet(), rows, columns, false);
+ this(ID.incrementAndGet(), rows, columns, false);
}
@Override
@@ -78,8 +78,8 @@ public class RandomTrinaryMatrix extends
buf.flip();
return (MurmurHash.hash64A(buf, seed) & (SCALE - 1)) / (double) SCALE;
} else {
- // this isn't a fantastic random number generator, but it is just fine for random projections
- return ((((row * PRIME1) + column * PRIME2 + row * column * PRIME3) & 8) * 0.25) - 1;
+ // this isn't a fantastic random number generator, but it is just fine for random projections
+ return ((((row * PRIME1) + column * PRIME2 + row * column * PRIME3) & 8) * 0.25) - 1;
}
}
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/SequentialAccessSparseVector.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/SequentialAccessSparseVector.java?rev=1461119&r1=1461118&r2=1461119&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/SequentialAccessSparseVector.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/SequentialAccessSparseVector.java Tue Mar 26 13:24:40 2013
@@ -94,8 +94,8 @@ public class SequentialAccessSparseVecto
}
Arrays.sort(sortableElements);
for (int i = 0; i < sortableElements.length; i++) {
- values.getIndices()[i] = sortableElements[i].index;
- values.getValues()[i] = sortableElements[i].value;
+ values.setIndexAt(i, sortableElements[i].index);
+ values.setValueAt(i, sortableElements[i].value);
}
values = new OrderedIntDoubleMapping(values.getIndices(), values.getValues(), elementCount);
return elementCount;
@@ -292,7 +292,7 @@ public class SequentialAccessSparseVecto
@Override
public void set(double value) {
invalidateCachedLength();
- values.getValues()[offset] = value;
+ values.setValueAt(offset, value);
}
}
@@ -329,8 +329,8 @@ public class SequentialAccessSparseVecto
@Override
public void set(double value) {
invalidateCachedLength();
- if (nextOffset < values.getNumMappings() && index == values.getIndices()[nextOffset]) {
- values.getValues()[nextOffset] = value;
+ if (nextOffset < values.getNumMappings() && index == values.indexAt(nextOffset)) {
+ values.setValueAt(nextOffset, value);
} else {
// Yes, this works; the offset into indices of the new value's index will still be nextOffset
values.set(index, value);
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=1461119&r1=1461118&r2=1461119&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 Tue Mar 26 13:24:40 2013
@@ -347,7 +347,7 @@ public class SingularValueDecomposition
}
}
}
- break;
+ break;
// Split at negligible s(k).
@@ -370,7 +370,7 @@ public class SingularValueDecomposition
}
}
}
- break;
+ break;
// Perform one qr step.
@@ -438,7 +438,7 @@ public class SingularValueDecomposition
e[p - 2] = f;
//iter += 1;
}
- break;
+ break;
// Convergence.
@@ -483,7 +483,7 @@ public class SingularValueDecomposition
//iter = 0;
p--;
}
- break;
+ break;
default:
throw new IllegalStateException();
}
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/Sorting.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/Sorting.java?rev=1461119&r1=1461118&r2=1461119&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/Sorting.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/Sorting.java Tue Mar 26 13:24:40 2013
@@ -503,9 +503,9 @@ public final class Sorting {
int comparisonab = comp.compare(a, b);
int comparisonac = comp.compare(a, c);
int comparisonbc = comp.compare(b, c);
- return comparisonab < 0 ?
- (comparisonbc < 0 ? b : (comparisonac < 0 ? c : a)) :
- (comparisonbc > 0 ? b : (comparisonac > 0 ? c : a));
+ return comparisonab < 0
+ ? (comparisonbc < 0 ? b : (comparisonac < 0 ? c : a))
+ : (comparisonbc > 0 ? b : (comparisonac > 0 ? c : a));
}
private static int med3(long[] array, int a, int b, int c, LongComparator comp) {
@@ -669,7 +669,7 @@ public final class Sorting {
* if {@code start < 0} or {@code end > array.length}.
*/
public static void quickSort(int start, int end, IntComparator comp, Swapper swap) {
- checkBounds(end+1, start, end);
+ checkBounds(end + 1, start, end);
quickSort0(start, end, comp, swap);
}
@@ -708,8 +708,7 @@ public final class Sorting {
if (comparison == 0) {
if (a == partitionIndex) {
partitionIndex = b;
- }
- else if (b == partitionIndex) {
+ } else if (b == partitionIndex) {
partitionIndex = a;
}
swap.swap(a, b);
@@ -770,7 +769,7 @@ public final class Sorting {
length = Math.min(d - c, end - 1 - d);
l = b;
h = end - length;
- while (length-- > 0) {
+ while (length-- > 0) {
swap.swap(l, h);
l++;
h++;
@@ -1712,11 +1711,12 @@ public final class Sorting {
return l - 1;
}
- private static final ByteComparator naturalByteComparison = new ByteComparator() {
+ private static final ByteComparator NATURAL_BYTE_COMPARISON = new ByteComparator() {
@Override
public int compare(byte o1, byte o2) {
return o1 - o2;
- }};
+ }
+ };
/**
* Perform a merge sort on a range of a byte array, using numerical order.
@@ -1725,7 +1725,7 @@ public final class Sorting {
* @param end the last index (exclusive).
*/
public static void mergeSort(byte[] array, int start, int end) {
- mergeSort(array, start, end, naturalByteComparison);
+ mergeSort(array, start, end, NATURAL_BYTE_COMPARISON);
}
/**
@@ -1829,11 +1829,12 @@ public final class Sorting {
return l - 1;
}
- private static final CharComparator naturalCharComparison = new CharComparator() {
+ private static final CharComparator NATURAL_CHAR_COMPARISON = new CharComparator() {
@Override
public int compare(char o1, char o2) {
return o1 - o2;
- }};
+ }
+ };
/**
* Perform a merge sort on a range of a char array, using numerical order.
@@ -1842,7 +1843,7 @@ public final class Sorting {
* @param end the last index (exclusive).
*/
public static void mergeSort(char[] array, int start, int end) {
- mergeSort(array, start, end, naturalCharComparison);
+ mergeSort(array, start, end, NATURAL_CHAR_COMPARISON);
}
/**
@@ -1946,11 +1947,12 @@ public final class Sorting {
return l - 1;
}
- private static final ShortComparator naturalShortComparison = new ShortComparator() {
+ private static final ShortComparator NATURAL_SHORT_COMPARISON = new ShortComparator() {
@Override
public int compare(short o1, short o2) {
return o1 - o2;
- }};
+ }
+ };
/**
* Perform a merge sort on a range of a short array, using numerical order.
@@ -1959,7 +1961,7 @@ public final class Sorting {
* @param end the last index (exclusive).
*/
public static void mergeSort(short[] array, int start, int end) {
- mergeSort(array, start, end, naturalShortComparison);
+ mergeSort(array, start, end, NATURAL_SHORT_COMPARISON);
}
public static void mergeSort(short[] array, int start, int end, ShortComparator comp) {
@@ -2064,14 +2066,15 @@ public final class Sorting {
return l - 1;
}
- private static final IntComparator naturalIntComparison = new IntComparator() {
+ private static final IntComparator NATURAL_INT_COMPARISON = new IntComparator() {
@Override
public int compare(int o1, int o2) {
return o1 < o2 ? -1 : o1 > o2 ? 1 : 0;
- }};
+ }
+ };
public static void mergeSort(int[] array, int start, int end) {
- mergeSort(array, start, end, naturalIntComparison);
+ mergeSort(array, start, end, NATURAL_INT_COMPARISON);
}
/**
@@ -2183,11 +2186,12 @@ public final class Sorting {
}
- private static final LongComparator naturalLongComparison = new LongComparator() {
+ private static final LongComparator NATURAL_LONG_COMPARISON = new LongComparator() {
@Override
public int compare(long o1, long o2) {
return o1 < o2 ? -1 : o1 > o2 ? 1 : 0;
- }};
+ }
+ };
/**
* Perform a merge sort on a range of a long array using numerical order.
@@ -2196,7 +2200,7 @@ public final class Sorting {
* @param end the last index (exclusive).
*/
public static void mergeSort(long[] array, int start, int end) {
- mergeSort(array, start, end, naturalLongComparison);
+ mergeSort(array, start, end, NATURAL_LONG_COMPARISON);
}
/**
@@ -2300,11 +2304,12 @@ public final class Sorting {
return l - 1;
}
- private static final FloatComparator naturalFloatComparison = new FloatComparator() {
+ private static final FloatComparator NATURAL_FLOAT_COMPARISON = new FloatComparator() {
@Override
public int compare(float o1, float o2) {
return Float.compare(o1, o2);
- }};
+ }
+ };
/**
* Perform a merge sort on a range of a float array using Float.compare for an ordering.
@@ -2313,7 +2318,7 @@ public final class Sorting {
* @param end the last index (exclusive).
*/
public static void mergeSort(float[] array, int start, int end) {
- mergeSort(array, start, end, naturalFloatComparison);
+ mergeSort(array, start, end, NATURAL_FLOAT_COMPARISON);
}
/**
@@ -2417,11 +2422,12 @@ public final class Sorting {
return l - 1;
}
- private static final DoubleComparator naturalDoubleComparison = new DoubleComparator() {
+ private static final DoubleComparator NATURAL_DOUBLE_COMPARISON = new DoubleComparator() {
@Override
public int compare(double o1, double o2) {
return Double.compare(o1, o2);
- }};
+ }
+ };
/**
@@ -2431,7 +2437,7 @@ public final class Sorting {
* @param end the last index (exclusive).
*/
public static void mergeSort(double[] array, int start, int end) {
- mergeSort(array, start, end, naturalDoubleComparison);
+ mergeSort(array, start, end, NATURAL_DOUBLE_COMPARISON);
}
/**
@@ -2561,7 +2567,8 @@ public final class Sorting {
}
// rotate(firstCut, middle, secondCut, swapper);
- // is manually inlined for speed (jitter inlining seems to work only for small call depths, even if methods are "static private")
+ // is manually inlined for speed (jitter inlining seems to work only for small call depths, even if methods
+ // are "static private")
// speedup = 1.7
// begin inline
int first2 = firstCut;
@@ -2599,8 +2606,8 @@ public final class Sorting {
* @param last One past the end of the range.
* @param x Element to be searched for.
* @param comp Comparison function.
- * @return The largest index i such that, for every j in the range <code>[first, i)</code>, {@code comp.apply(array[j],}
- * x)</code> is {@code true}.
+ * @return The largest index i such that, for every j in the range <code>[first, i)</code>,
+ * <code></code></codeA>{@code comp.apply(array[j], x)</code> is {@code true}.
* @see Sorting#upperBound
*/
static int lowerBound(int first, int last, int x, IntComparator comp) {
@@ -2640,7 +2647,8 @@ public final class Sorting {
/*
We retain the same method signature as quickSort.
Given only a comparator and swapper we do not know how to copy and move elements from/to temporary arrays.
- Hence, in contrast to the JDK mergesorts this is an "in-place" mergesort, i.e. does not allocate any temporary arrays.
+ Hence, in contrast to the JDK mergesorts this is an "in-place" mergesort, i.e. does not allocate any temporary
+ arrays.
A non-inplace mergesort would perhaps be faster in most cases, but would require non-intuitive delegate objects...
*/
int length = toIndex - fromIndex;
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=1461119&r1=1461118&r2=1461119&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 Tue Mar 26 13:24:40 2013
@@ -78,7 +78,8 @@ public interface Vector extends Cloneabl
Vector assign(Vector other, DoubleDoubleFunction function);
/**
- * Apply the function to each element of the receiver, using the y value as the second argument of the DoubleDoubleFunction
+ * Apply the function to each element of the receiver, using the y value as the second argument of the
+ * DoubleDoubleFunction
*
* @param f a DoubleDoubleFunction to be applied
* @param y a double value to be argument to the function
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/als/AlternatingLeastSquaresSolver.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/als/AlternatingLeastSquaresSolver.java?rev=1461119&r1=1461118&r2=1461119&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/als/AlternatingLeastSquaresSolver.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/als/AlternatingLeastSquaresSolver.java Tue Mar 26 13:24:40 2013
@@ -28,7 +28,8 @@ import org.apache.mahout.math.Vector;
import java.util.Iterator;
/**
- * See <a href="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 final class AlternatingLeastSquaresSolver {
@@ -50,7 +51,7 @@ public final class AlternatingLeastSquar
Matrix RiIiMaybeTransposed = createRiIiMaybeTransposed(ratingVector);
/* compute Ai = MiIi * t(MiIi) + lambda * nui * E */
- Matrix Ai = MiTimesMiTransposePlusLambdaTimesNuiTimesE(MiIi, lambda, nui);
+ Matrix Ai = miTimesMiTransposePlusLambdaTimesNuiTimesE(MiIi, lambda, nui);
/* compute Vi = MiIi * t(R(i,Ii)) */
Matrix Vi = MiIi.times(RiIiMaybeTransposed);
/* compute Ai * ui = Vi */
@@ -71,7 +72,7 @@ public final class AlternatingLeastSquar
return matrix;
}
- private static Matrix MiTimesMiTransposePlusLambdaTimesNuiTimesE(Matrix MiIi, double lambda, int nui) {
+ private static Matrix miTimesMiTransposePlusLambdaTimesNuiTimesE(Matrix MiIi, double lambda, int nui) {
double lambdaTimesNui = lambda * nui;
int rows = MiIi.numRows();