You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mahout.apache.org by sr...@apache.org on 2011/10/15 16:08:39 UTC
svn commit: r1183642 [3/3] - in /mahout/trunk:
core/src/main/java/org/apache/mahout/cf/taste/hadoop/
core/src/main/java/org/apache/mahout/cf/taste/impl/model/file/
core/src/main/java/org/apache/mahout/classifier/
core/src/main/java/org/apache/mahout/cl...
Modified: mahout/trunk/integration/src/main/java/org/apache/mahout/utils/vectors/io/AbstractClusterWriter.java
URL: http://svn.apache.org/viewvc/mahout/trunk/integration/src/main/java/org/apache/mahout/utils/vectors/io/AbstractClusterWriter.java?rev=1183642&r1=1183641&r2=1183642&view=diff
==============================================================================
--- mahout/trunk/integration/src/main/java/org/apache/mahout/utils/vectors/io/AbstractClusterWriter.java (original)
+++ mahout/trunk/integration/src/main/java/org/apache/mahout/utils/vectors/io/AbstractClusterWriter.java Sat Oct 15 14:08:33 2011
@@ -1,4 +1,3 @@
-package org.apache.mahout.utils.vectors.io;
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
@@ -16,9 +15,10 @@ package org.apache.mahout.utils.vectors.
* limitations under the License.
*/
+package org.apache.mahout.utils.vectors.io;
+
import com.google.common.collect.Lists;
import org.apache.commons.lang.StringUtils;
-import org.apache.mahout.cf.taste.impl.common.SamplingLongPrimitiveIterator;
import org.apache.mahout.clustering.Cluster;
import org.apache.mahout.clustering.WeightedVectorWritable;
import org.apache.mahout.common.Pair;
@@ -40,15 +40,24 @@ import java.util.Map;
* Base class for implementing ClusterWriter
*/
public abstract class AbstractClusterWriter implements ClusterWriter {
- private transient static Logger log = LoggerFactory.getLogger(AbstractClusterWriter.class);
- protected Writer writer;
- protected Map<Integer, List<WeightedVectorWritable>> clusterIdToPoints;
+ private static final Logger log = LoggerFactory.getLogger(AbstractClusterWriter.class);
+
+ private final Writer writer;
+ private final Map<Integer, List<WeightedVectorWritable>> clusterIdToPoints;
- public AbstractClusterWriter(Writer writer, Map<Integer, List<WeightedVectorWritable>> clusterIdToPoints) {
+ protected AbstractClusterWriter(Writer writer, Map<Integer, List<WeightedVectorWritable>> clusterIdToPoints) {
this.writer = writer;
this.clusterIdToPoints = clusterIdToPoints;
}
+
+ protected Writer getWriter() {
+ return writer;
+ }
+
+ protected Map<Integer, List<WeightedVectorWritable>> getClusterIdToPoints() {
+ return clusterIdToPoints;
+ }
public static String getTopFeatures(Vector vector, String[] dictionary, int numTerms) {
Modified: mahout/trunk/integration/src/main/java/org/apache/mahout/utils/vectors/io/CSVClusterWriter.java
URL: http://svn.apache.org/viewvc/mahout/trunk/integration/src/main/java/org/apache/mahout/utils/vectors/io/CSVClusterWriter.java?rev=1183642&r1=1183641&r2=1183642&view=diff
==============================================================================
--- mahout/trunk/integration/src/main/java/org/apache/mahout/utils/vectors/io/CSVClusterWriter.java (original)
+++ mahout/trunk/integration/src/main/java/org/apache/mahout/utils/vectors/io/CSVClusterWriter.java Sat Oct 15 14:08:33 2011
@@ -1,4 +1,3 @@
-package org.apache.mahout.utils.vectors.io;
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
@@ -16,6 +15,7 @@ package org.apache.mahout.utils.vectors.
* limitations under the License.
*/
+package org.apache.mahout.utils.vectors.io;
import org.apache.mahout.clustering.Cluster;
import org.apache.mahout.clustering.WeightedVectorWritable;
@@ -26,13 +26,16 @@ import java.io.IOException;
import java.io.Writer;
import java.util.List;
import java.util.Map;
+import java.util.regex.Pattern;
/**
* Format is adjacency style as put forth at http://gephi.org/users/supported-graph-formats/csv-format/, the centroid
* is the first element and all the rest of the row are the points in that cluster
*
**/
-public class CSVClusterWriter extends AbstractClusterWriter implements ClusterWriter {
+public class CSVClusterWriter extends AbstractClusterWriter {
+
+ private static final Pattern VEC_PATTERN = Pattern.compile("\\{|\\:|\\,|\\}");
public CSVClusterWriter(Writer writer, Map<Integer, List<WeightedVectorWritable>> clusterIdToPoints) {
super(writer, clusterIdToPoints);
@@ -42,21 +45,21 @@ public class CSVClusterWriter extends Ab
public void write(Cluster cluster) throws IOException {
StringBuilder line = new StringBuilder();
line.append(cluster.getId());
- List<WeightedVectorWritable> points = clusterIdToPoints.get(cluster.getId());
+ List<WeightedVectorWritable> points = getClusterIdToPoints().get(cluster.getId());
if (points != null) {
for (WeightedVectorWritable point : points) {
Vector theVec = point.getVector();
- line.append(",");
+ line.append(',');
if (theVec instanceof NamedVector){
line.append(((NamedVector)theVec).getName());
} else {
String vecStr = theVec.asFormatString();
//do some basic manipulations for display
- vecStr = vecStr.replaceAll("\\{|\\:|\\,|\\}", "_");
+ vecStr = VEC_PATTERN.matcher(vecStr).replaceAll("_");
line.append(vecStr);
}
}
- writer.append(line).append("\n");
+ getWriter().append(line).append("\n");
}
}
}
Modified: mahout/trunk/integration/src/main/java/org/apache/mahout/utils/vectors/io/ClusterDumperWriter.java
URL: http://svn.apache.org/viewvc/mahout/trunk/integration/src/main/java/org/apache/mahout/utils/vectors/io/ClusterDumperWriter.java?rev=1183642&r1=1183641&r2=1183642&view=diff
==============================================================================
--- mahout/trunk/integration/src/main/java/org/apache/mahout/utils/vectors/io/ClusterDumperWriter.java (original)
+++ mahout/trunk/integration/src/main/java/org/apache/mahout/utils/vectors/io/ClusterDumperWriter.java Sat Oct 15 14:08:33 2011
@@ -1,4 +1,3 @@
-package org.apache.mahout.utils.vectors.io;
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
@@ -16,40 +15,34 @@ package org.apache.mahout.utils.vectors.
* limitations under the License.
*/
+package org.apache.mahout.utils.vectors.io;
-import com.google.common.collect.Lists;
-import org.apache.commons.lang.StringUtils;
import org.apache.hadoop.io.Text;
import org.apache.mahout.clustering.AbstractCluster;
import org.apache.mahout.clustering.Cluster;
import org.apache.mahout.clustering.WeightedPropertyVectorWritable;
import org.apache.mahout.clustering.WeightedVectorWritable;
-import org.apache.mahout.common.Pair;
-import org.apache.mahout.math.Vector;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.io.Writer;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Comparator;
import java.util.Iterator;
-import java.util.LinkedList;
import java.util.List;
import java.util.Map;
/**
- * Implements a {@link org.apache.mahout.utils.vectors.io.ClusterWriter} that outputs in the format
- * used by ClusterDumper in Mahout 0.5
+ * Implements a {@link ClusterWriter} that outputs in the format used by ClusterDumper in Mahout 0.5
*/
-public class ClusterDumperWriter extends AbstractClusterWriter implements ClusterWriter {
- private transient static Logger log = LoggerFactory.getLogger(ClusterDumperWriter.class);
- protected int subString;
- protected String[] dictionary;
- protected int numTopFeatures;
+public class ClusterDumperWriter extends AbstractClusterWriter {
- public ClusterDumperWriter(Writer writer, Map<Integer, List<WeightedVectorWritable>> clusterIdToPoints, int numTopFeatures, String[] dictionary, int subString) {
+ private final int subString;
+ private final String[] dictionary;
+ private final int numTopFeatures;
+
+ public ClusterDumperWriter(Writer writer,
+ Map<Integer, List<WeightedVectorWritable>> clusterIdToPoints,
+ int numTopFeatures,
+ String[] dictionary,
+ int subString) {
super(writer, clusterIdToPoints);
this.numTopFeatures = numTopFeatures;
this.dictionary = dictionary;
@@ -59,6 +52,7 @@ public class ClusterDumperWriter extends
@Override
public void write(Cluster value) throws IOException {
String fmtStr = value.asFormatString(dictionary);
+ Writer writer = getWriter();
if (subString > 0 && fmtStr.length() > subString) {
writer.write(':');
writer.write(fmtStr, 0, Math.min(subString, fmtStr.length()));
@@ -75,6 +69,7 @@ public class ClusterDumperWriter extends
writer.write('\n');
}
+ Map<Integer, List<WeightedVectorWritable>> clusterIdToPoints = getClusterIdToPoints();
List<WeightedVectorWritable> points = clusterIdToPoints.get(value.getId());
if (points != null) {
writer.write("\tWeight : [props - optional]: Point:\n\t");
Modified: mahout/trunk/integration/src/test/java/org/apache/mahout/utils/email/MailProcessorTest.java
URL: http://svn.apache.org/viewvc/mahout/trunk/integration/src/test/java/org/apache/mahout/utils/email/MailProcessorTest.java?rev=1183642&r1=1183641&r2=1183642&view=diff
==============================================================================
--- mahout/trunk/integration/src/test/java/org/apache/mahout/utils/email/MailProcessorTest.java (original)
+++ mahout/trunk/integration/src/test/java/org/apache/mahout/utils/email/MailProcessorTest.java Sat Oct 15 14:08:33 2011
@@ -1,39 +1,47 @@
-package org.apache.mahout.utils.email;
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.mahout.utils.email;
+import com.google.common.base.Charsets;
import org.apache.mahout.common.MahoutTestCase;
import org.junit.Test;
import java.io.File;
import java.io.StringWriter;
import java.net.URL;
-import java.nio.charset.Charset;
import java.util.regex.Pattern;
-/**
- *
- *
- **/
-public class MailProcessorTest extends MahoutTestCase {
+public final class MailProcessorTest extends MahoutTestCase {
+
@Test
public void testLabel() throws Exception {
StringWriter writer = new StringWriter();
MailOptions options = new MailOptions();
- options.separator = ":::";
- options.charset = Charset.forName("UTF-8");
- options.patternsToMatch = new Pattern[]{MailProcessor.FROM_PREFIX, MailProcessor.SUBJECT_PREFIX, MailProcessor.TO_PREFIX};
- options.input = new File(System.getProperty("user.dir"));
+ options.setSeparator(":::");
+ options.setCharset(Charsets.UTF_8);
+ options.setPatternsToMatch(new Pattern[]{
+ MailProcessor.FROM_PREFIX, MailProcessor.SUBJECT_PREFIX, MailProcessor.TO_PREFIX});
+ options.setInput(new File(System.getProperty("user.dir")));
MailProcessor proc = new MailProcessor(options, "", writer);
URL url = MailProcessorTest.class.getClassLoader().getResource("test.mbox");
File file = new File(url.toURI());
- //System.out.println(file);
long count = proc.parseMboxLineByLine(file);
assertEquals(7, count);
- System.out.println(writer.getBuffer());
- //TODO
-
}
-
-
}
Modified: mahout/trunk/integration/src/test/java/org/apache/mahout/utils/vectors/lucene/LuceneIterableTest.java
URL: http://svn.apache.org/viewvc/mahout/trunk/integration/src/test/java/org/apache/mahout/utils/vectors/lucene/LuceneIterableTest.java?rev=1183642&r1=1183641&r2=1183642&view=diff
==============================================================================
--- mahout/trunk/integration/src/test/java/org/apache/mahout/utils/vectors/lucene/LuceneIterableTest.java (original)
+++ mahout/trunk/integration/src/test/java/org/apache/mahout/utils/vectors/lucene/LuceneIterableTest.java Sat Oct 15 14:08:33 2011
@@ -170,7 +170,7 @@ public final class LuceneIterableTest ex
createNew,
IndexWriter.MaxFieldLength.UNLIMITED);
try {
- for (int i = 0; i < LuceneIterableTest.DOCS.length; i++) {
+ for (int i = 0; i < DOCS.length; i++) {
Document doc = new Document();
Fieldable id = new Field("id", "doc_" + (i + startingId), Field.Store.YES,
Field.Index.NOT_ANALYZED_NO_NORMS);
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/ConstantVector.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/ConstantVector.java?rev=1183642&r1=1183641&r2=1183642&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/ConstantVector.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/ConstantVector.java Sat Oct 15 14:08:33 2011
@@ -73,8 +73,8 @@ public class ConstantVector extends Abst
@Override
public Iterator<Element> iterator() {
return new AbstractIterator<Element>() {
- int i = 0;
- final int n = size();
+ private int i = 0;
+ private final int n = size();
@Override
protected Element computeNext() {
if (i < n) {
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/PermutedVectorView.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/PermutedVectorView.java?rev=1183642&r1=1183641&r2=1183642&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/PermutedVectorView.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/PermutedVectorView.java Sat Oct 15 14:08:33 2011
@@ -93,14 +93,14 @@ public class PermutedVectorView extends
@Override
public Iterator<Element> iterator() {
return new AbstractIterator<Element>() {
- final Iterator<Element> i = vector.iterator();
+ private final Iterator<Element> i = vector.iterator();
@Override
protected Vector.Element computeNext() {
if (i.hasNext()) {
final Element x = i.next();
return new Element() {
- final int index = unpivot[x.index()];
+ private final int index = unpivot[x.index()];
@Override
public double get() {
@@ -134,14 +134,14 @@ public class PermutedVectorView extends
@Override
public Iterator<Element> iterateNonZero() {
return new AbstractIterator<Element>() {
- final Iterator<Element> i = vector.iterateNonZero();
+ private final Iterator<Element> i = vector.iterateNonZero();
@Override
protected Vector.Element computeNext() {
if (i.hasNext()) {
final Element x = i.next();
return new Element() {
- final int index = unpivot[x.index()];
+ private final int index = unpivot[x.index()];
@Override
public double get() {
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/RandomAccessSparseVector.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/RandomAccessSparseVector.java?rev=1183642&r1=1183641&r2=1183642&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/RandomAccessSparseVector.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/RandomAccessSparseVector.java Sat Oct 15 14:08:33 2011
@@ -20,7 +20,6 @@ package org.apache.mahout.math;
import java.util.Iterator;
import com.google.common.collect.AbstractIterator;
-import org.apache.mahout.math.function.IntDoubleProcedure;
import org.apache.mahout.math.list.IntArrayList;
import org.apache.mahout.math.map.OpenIntDoubleHashMap;
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/decomposer/hebbian/HebbianSolver.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/decomposer/hebbian/HebbianSolver.java?rev=1183642&r1=1183641&r2=1183642&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/decomposer/hebbian/HebbianSolver.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/decomposer/hebbian/HebbianSolver.java Sat Oct 15 14:08:33 2011
@@ -172,8 +172,8 @@ public class HebbianSolver {
int cols = corpus.numCols();
Matrix eigens = new DenseMatrix(desiredRank, cols);
List<Double> eigenValues = Lists.newArrayList();
- log.info("Finding " + desiredRank + " singular vectors of matrix with " + corpus.numRows() + " rows, via Hebbian");
- /**
+ log.info("Finding {} singular vectors of matrix with {} rows, via Hebbian", desiredRank, corpus.numRows());
+ /*
* The corpusProjections matrix is a running cache of the residual projection of each corpus vector against all
* of the previously found singular vectors. Without this, if multiple passes over the data is made (per
* singular vector), recalculating these projections eventually dominates the computational complexity of the
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/AbstractDistribution.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/AbstractDistribution.java?rev=1183642&r1=1183641&r2=1183642&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/AbstractDistribution.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/AbstractDistribution.java Sat Oct 15 14:08:33 2011
@@ -31,11 +31,20 @@ import org.apache.mahout.math.function.I
import java.util.Random;
public abstract class AbstractDistribution implements DoubleFunction, IntFunction {
- protected Random randomGenerator;
+
+ private Random randomGenerator;
/** Makes this class non instantiable, but still let's others inherit from it. */
protected AbstractDistribution() {
}
+
+ protected Random getRandomGenerator() {
+ return randomGenerator;
+ }
+
+ protected double randomDouble() {
+ return randomGenerator.nextDouble();
+ }
/**
* Equivalent to <tt>nextDouble()</tt>. This has the effect that distributions can now be used as function objects,
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Exponential.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Exponential.java?rev=1183642&r1=1183641&r2=1183642&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Exponential.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Exponential.java Sat Oct 15 14:08:33 2011
@@ -46,7 +46,7 @@ public class Exponential extends Abstrac
*/
@Override
public double nextDouble() {
- return -Math.log1p(-randomGenerator.nextDouble()) / lambda;
+ return -Math.log1p(-randomDouble()) / lambda;
}
/**
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Gamma.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Gamma.java?rev=1183642&r1=1183641&r2=1183642&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Gamma.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Gamma.java Sat Oct 15 14:08:33 2011
@@ -103,15 +103,15 @@ public class Gamma extends AbstractConti
if (alpha < 1.0) { // CASE A: Acceptance rejection algorithm gs
b = 1.0 + 0.36788794412 * alpha; // Step 1
while (true) {
- double p = b * randomGenerator.nextDouble();
+ double p = b * randomDouble();
if (p <= 1.0) { // Step 2. Case gds <= 1
gds = Math.exp(Math.log(p) / alpha);
- if (Math.log(randomGenerator.nextDouble()) <= -gds) {
+ if (Math.log(randomDouble()) <= -gds) {
return gds / rate;
}
} else { // Step 3. Case gds > 1
gds = -Math.log((b - p) / alpha);
- if (Math.log(randomGenerator.nextDouble()) <= (alpha - 1.0) * Math.log(gds)) {
+ if (Math.log(randomDouble()) <= (alpha - 1.0) * Math.log(gds)) {
return gds / rate;
}
}
@@ -129,8 +129,8 @@ public class Gamma extends AbstractConti
double v12;
double v1;
do {
- v1 = 2.0 * randomGenerator.nextDouble() - 1.0;
- double v2 = 2.0 * randomGenerator.nextDouble() - 1.0;
+ v1 = 2.0 * randomDouble() - 1.0;
+ double v2 = 2.0 * randomDouble() - 1.0;
v12 = v1 * v1 + v2 * v2;
} while (v12 > 1.0);
double t = v1 * Math.sqrt(-2.0 * Math.log(v12) / v12);
@@ -140,7 +140,7 @@ public class Gamma extends AbstractConti
return gds / rate;
} // Immediate acceptance
- double u = randomGenerator.nextDouble();
+ double u = randomDouble();
if (d * u <= t * t * t) {
return gds / rate;
} // Squeeze acceptance
@@ -211,8 +211,8 @@ public class Gamma extends AbstractConti
double sign_u;
double e;
do {
- e = -Math.log(randomGenerator.nextDouble());
- u = randomGenerator.nextDouble();
+ e = -Math.log(randomDouble());
+ u = randomDouble();
u = u + u - 1.0;
sign_u = u > 0 ? 1.0 : -1.0;
t = b + e * si * sign_u;
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Normal.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Normal.java?rev=1183642&r1=1183641&r2=1183642&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Normal.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Normal.java Sat Oct 15 14:08:33 2011
@@ -68,8 +68,8 @@ public class Normal extends AbstractCont
double y;
double r;
do {
- x = 2.0 * randomGenerator.nextDouble() - 1.0;
- y = 2.0 * randomGenerator.nextDouble() - 1.0;
+ x = 2.0 * randomDouble() - 1.0;
+ y = 2.0 * randomDouble() - 1.0;
r = x * x + y * y;
} while (r >= 1.0);
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Poisson.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Poisson.java?rev=1183642&r1=1183641&r2=1183642&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Poisson.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Poisson.java Sat Oct 15 14:08:33 2011
@@ -78,23 +78,23 @@ public final class Poisson extends Abstr
/** Returns a random number from the distribution; bypasses the internal state. */
public int nextInt(double theMean) {
-/******************************************************************
- * *
- * Poisson Distribution - Patchwork Rejection/Inversion *
- * *
- ******************************************************************
- * *
- * For parameter my < 10 Tabulated Inversion is applied. *
- * For my >= 10 Patchwork Rejection is employed: *
- * The area below the histogram function f(x) is rearranged in *
- * its body by certain point reflections. Within a large center *
- * interval variates are sampled efficiently by rejection from *
- * uniform hats. Rectangular immediate acceptance regions speed *
- * up the generation. The remaining tails are covered by *
- * exponential functions. *
- * *
- *****************************************************************/
- Random gen = this.randomGenerator;
+ /******************************************************************
+ * *
+ * Poisson Distribution - Patchwork Rejection/Inversion *
+ * *
+ ******************************************************************
+ * *
+ * For parameter my < 10 Tabulated Inversion is applied. *
+ * For my >= 10 Patchwork Rejection is employed: *
+ * The area below the histogram function f(x) is rearranged in *
+ * its body by certain point reflections. Within a large center *
+ * interval variates are sampled efficiently by rejection from *
+ * uniform hats. Rectangular immediate acceptance regions speed *
+ * up the generation. The remaining tails are covered by *
+ * exponential functions. *
+ * *
+ *****************************************************************/
+ Random gen = getRandomGenerator();
//double t, g, my_k;
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Uniform.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Uniform.java?rev=1183642&r1=1183641&r2=1183642&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Uniform.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Uniform.java Sat Oct 15 14:08:33 2011
@@ -50,7 +50,7 @@ public class Uniform extends AbstractCon
/** Returns a uniformly distributed random <tt>boolean</tt>. */
public boolean nextBoolean() {
- return randomGenerator.nextDouble() > 0.5;
+ return randomDouble() > 0.5;
}
/**
@@ -59,7 +59,7 @@ public class Uniform extends AbstractCon
*/
@Override
public double nextDouble() {
- return min + (max - min) * randomGenerator.nextDouble();
+ return min + (max - min) * randomDouble();
}
/**
@@ -67,7 +67,7 @@ public class Uniform extends AbstractCon
* <tt>to</tt>). Pre conditions: <tt>from <= to</tt>.
*/
public double nextDoubleFromTo(double from, double to) {
- return from + (to - from) * randomGenerator.nextDouble();
+ return from + (to - from) * randomDouble();
}
/**
@@ -84,7 +84,7 @@ public class Uniform extends AbstractCon
* and <tt>to</tt>). Pre conditions: <tt>from <= to</tt>.
*/
public int nextIntFromTo(int from, int to) {
- return (int) ((long) from + (long) ((1L + (long) to - (long) from) * randomGenerator.nextDouble()));
+ return (int) ((long) from + (long) ((1L + (long) to - (long) from) * randomDouble()));
}
/**
@@ -123,9 +123,9 @@ public class Uniform extends AbstractCon
int i2 = nextIntFromTo(Integer.MIN_VALUE, Integer.MAX_VALUE);
return ((i1 & 0xFFFFFFFFL) << 32) | (i2 & 0xFFFFFFFFL);
}
- random = Math.round(nextDoubleFromTo(from, to + 1));
+ random = Math.round(nextDoubleFromTo(Long.MIN_VALUE, to + 1));
if (random > to) {
- random = from;
+ random = Long.MIN_VALUE;
}
} else {
random = Math.round(nextDoubleFromTo(from - 1, to));
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/stat/Gamma.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/stat/Gamma.java?rev=1183642&r1=1183641&r2=1183642&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/stat/Gamma.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/stat/Gamma.java Sat Oct 15 14:08:33 2011
@@ -135,7 +135,8 @@ public final class Gamma {
while (x < 0.0) {
if (x == 0.0) {
throw new ArithmeticException("gamma: singular");
- } else if (x > -1.0e-9) {
+ }
+ if (x > -1.0e-9) {
return z / ((1.0 + 0.5772156649015329 * x) * x);
}
z /= x;
@@ -145,7 +146,8 @@ public final class Gamma {
while (x < 2.0) {
if (x == 0.0) {
throw new ArithmeticException("gamma: singular");
- } else if (x < 1.0e-9) {
+ }
+ if (x < 1.0e-9) {
return z / ((1.0 + 0.5772156649015329 * x) * x);
}
z /= x;
@@ -640,7 +642,7 @@ public final class Gamma {
u = a * Math.log(x);
if ((a + b) < Constants.MAXGAM && Math.abs(u) < Constants.MAXLOG) {
t = gamma(a + b) / (gamma(a) * gamma(b));
- s = s * t * Math.pow(x, a);
+ s *= t * Math.pow(x, a);
} else {
t = logGamma(a + b) - logGamma(a) - logGamma(b) + u + Math.log(s);
s = t < Constants.MINLOG ? 0.0 : Math.exp(t);
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/DenseDoubleMatrix1D.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/DenseDoubleMatrix1D.java?rev=1183642&r1=1183641&r2=1183642&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/DenseDoubleMatrix1D.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/DenseDoubleMatrix1D.java Sat Oct 15 14:08:33 2011
@@ -322,7 +322,8 @@ public class DenseDoubleMatrix1D extends
if (other instanceof SelectedDenseDoubleMatrix1D) {
SelectedDenseDoubleMatrix1D otherMatrix = (SelectedDenseDoubleMatrix1D) other;
return this.elements == otherMatrix.elements;
- } else if (other instanceof DenseDoubleMatrix1D) {
+ }
+ if (other instanceof DenseDoubleMatrix1D) {
DenseDoubleMatrix1D otherMatrix = (DenseDoubleMatrix1D) other;
return this.elements == otherMatrix.elements;
}
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/DenseDoubleMatrix2D.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/DenseDoubleMatrix2D.java?rev=1183642&r1=1183641&r2=1183642&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/DenseDoubleMatrix2D.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/DenseDoubleMatrix2D.java Sat Oct 15 14:08:33 2011
@@ -380,7 +380,8 @@ public final class DenseDoubleMatrix2D e
if (other instanceof SelectedDenseDoubleMatrix2D) {
SelectedDenseDoubleMatrix2D otherMatrix = (SelectedDenseDoubleMatrix2D) other;
return this.elements == otherMatrix.elements;
- } else if (other instanceof DenseDoubleMatrix2D) {
+ }
+ if (other instanceof DenseDoubleMatrix2D) {
DenseDoubleMatrix2D otherMatrix = (DenseDoubleMatrix2D) other;
return this.elements == otherMatrix.elements;
}
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/SelectedDenseDoubleMatrix1D.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/SelectedDenseDoubleMatrix1D.java?rev=1183642&r1=1183641&r2=1183642&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/SelectedDenseDoubleMatrix1D.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/SelectedDenseDoubleMatrix1D.java Sat Oct 15 14:08:33 2011
@@ -105,7 +105,8 @@ final class SelectedDenseDoubleMatrix1D
if (other instanceof SelectedDenseDoubleMatrix1D) {
SelectedDenseDoubleMatrix1D otherMatrix = (SelectedDenseDoubleMatrix1D) other;
return this.elements == otherMatrix.elements;
- } else if (other instanceof DenseDoubleMatrix1D) {
+ }
+ if (other instanceof DenseDoubleMatrix1D) {
DenseDoubleMatrix1D otherMatrix = (DenseDoubleMatrix1D) other;
return this.elements == otherMatrix.elements;
}
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/SelectedDenseDoubleMatrix2D.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/SelectedDenseDoubleMatrix2D.java?rev=1183642&r1=1183641&r2=1183642&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/SelectedDenseDoubleMatrix2D.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/SelectedDenseDoubleMatrix2D.java Sat Oct 15 14:08:33 2011
@@ -134,7 +134,8 @@ final class SelectedDenseDoubleMatrix2D
if (other instanceof SelectedDenseDoubleMatrix2D) {
SelectedDenseDoubleMatrix2D otherMatrix = (SelectedDenseDoubleMatrix2D) other;
return this.elements == otherMatrix.elements;
- } else if (other instanceof DenseDoubleMatrix2D) {
+ }
+ if (other instanceof DenseDoubleMatrix2D) {
DenseDoubleMatrix2D otherMatrix = (DenseDoubleMatrix2D) other;
return this.elements == otherMatrix.elements;
}
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/SelectedSparseDoubleMatrix1D.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/SelectedSparseDoubleMatrix1D.java?rev=1183642&r1=1183641&r2=1183642&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/SelectedSparseDoubleMatrix1D.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/SelectedSparseDoubleMatrix1D.java Sat Oct 15 14:08:33 2011
@@ -108,7 +108,8 @@ final class SelectedSparseDoubleMatrix1D
if (other instanceof SelectedSparseDoubleMatrix1D) {
SelectedSparseDoubleMatrix1D otherMatrix = (SelectedSparseDoubleMatrix1D) other;
return this.elements == otherMatrix.elements;
- } else if (other instanceof SparseDoubleMatrix1D) {
+ }
+ if (other instanceof SparseDoubleMatrix1D) {
SparseDoubleMatrix1D otherMatrix = (SparseDoubleMatrix1D) other;
return this.elements == otherMatrix.elements;
}
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/SelectedSparseDoubleMatrix2D.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/SelectedSparseDoubleMatrix2D.java?rev=1183642&r1=1183641&r2=1183642&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/SelectedSparseDoubleMatrix2D.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/SelectedSparseDoubleMatrix2D.java Sat Oct 15 14:08:33 2011
@@ -138,7 +138,8 @@ final class SelectedSparseDoubleMatrix2D
if (other instanceof SelectedSparseDoubleMatrix2D) {
SelectedSparseDoubleMatrix2D otherMatrix = (SelectedSparseDoubleMatrix2D) other;
return this.elements == otherMatrix.elements;
- } else if (other instanceof SparseDoubleMatrix2D) {
+ }
+ if (other instanceof SparseDoubleMatrix2D) {
SparseDoubleMatrix2D otherMatrix = (SparseDoubleMatrix2D) other;
return this.elements == otherMatrix.elements;
}
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/SparseDoubleMatrix1D.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/SparseDoubleMatrix1D.java?rev=1183642&r1=1183641&r2=1183642&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/SparseDoubleMatrix1D.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/SparseDoubleMatrix1D.java Sat Oct 15 14:08:33 2011
@@ -153,7 +153,8 @@ public final class SparseDoubleMatrix1D
if (other instanceof SelectedSparseDoubleMatrix1D) {
SelectedSparseDoubleMatrix1D otherMatrix = (SelectedSparseDoubleMatrix1D) other;
return this.elements == otherMatrix.elements;
- } else if (other instanceof SparseDoubleMatrix1D) {
+ }
+ if (other instanceof SparseDoubleMatrix1D) {
SparseDoubleMatrix1D otherMatrix = (SparseDoubleMatrix1D) other;
return this.elements == otherMatrix.elements;
}
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/SparseDoubleMatrix2D.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/SparseDoubleMatrix2D.java?rev=1183642&r1=1183641&r2=1183642&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/SparseDoubleMatrix2D.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/SparseDoubleMatrix2D.java Sat Oct 15 14:08:33 2011
@@ -283,7 +283,8 @@ public final class SparseDoubleMatrix2D
if (other instanceof SelectedSparseDoubleMatrix2D) {
SelectedSparseDoubleMatrix2D otherMatrix = (SelectedSparseDoubleMatrix2D) other;
return this.elements == otherMatrix.elements;
- } else if (other instanceof SparseDoubleMatrix2D) {
+ }
+ if (other instanceof SparseDoubleMatrix2D) {
SparseDoubleMatrix2D otherMatrix = (SparseDoubleMatrix2D) other;
return this.elements == otherMatrix.elements;
}
Modified: mahout/trunk/math/src/test/java/org/apache/mahout/math/MatrixTest.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/test/java/org/apache/mahout/math/MatrixTest.java?rev=1183642&r1=1183641&r2=1183642&view=diff
==============================================================================
--- mahout/trunk/math/src/test/java/org/apache/mahout/math/MatrixTest.java (original)
+++ mahout/trunk/math/src/test/java/org/apache/mahout/math/MatrixTest.java Sat Oct 15 14:08:33 2011
@@ -34,14 +34,10 @@ public abstract class MatrixTest extends
protected static final int COL = AbstractMatrix.COL;
- private final double[][] values = {{1.1, 2.2}, {3.3, 4.4},
- {5.5, 6.6}};
+ private final double[][] values = {{1.1, 2.2}, {3.3, 4.4}, {5.5, 6.6}};
private final double[] vectorAValues = {1.0 / 1.1, 2.0 / 1.1};
-
- //protected final double[] vectorBValues = {5.0, 10.0, 100.0};
-
- protected Matrix test;
+ private Matrix test;
@Override
@Before
Modified: mahout/trunk/math/src/test/java/org/apache/mahout/math/PermutedVectorViewTest.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/test/java/org/apache/mahout/math/PermutedVectorViewTest.java?rev=1183642&r1=1183641&r2=1183642&view=diff
==============================================================================
--- mahout/trunk/math/src/test/java/org/apache/mahout/math/PermutedVectorViewTest.java (original)
+++ mahout/trunk/math/src/test/java/org/apache/mahout/math/PermutedVectorViewTest.java Sat Oct 15 14:08:33 2011
@@ -93,7 +93,7 @@ public class PermutedVectorViewTest exte
private static Vector randomVector() {
Vector v = new DenseVector(20);
v.assign(new DoubleFunction() {
- final Random gen = RandomUtils.getRandom();
+ private final Random gen = RandomUtils.getRandom();
@Override
public double apply(double arg1) {
Modified: mahout/trunk/math/src/test/java/org/apache/mahout/math/TestVectorView.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/test/java/org/apache/mahout/math/TestVectorView.java?rev=1183642&r1=1183641&r2=1183642&view=diff
==============================================================================
--- mahout/trunk/math/src/test/java/org/apache/mahout/math/TestVectorView.java (original)
+++ mahout/trunk/math/src/test/java/org/apache/mahout/math/TestVectorView.java Sat Oct 15 14:08:33 2011
@@ -97,11 +97,7 @@ public final class TestVectorView extend
public void testSet() throws Exception {
test.set(2, 4.5);
for (int i = 0; i < test.size(); i++) {
- if (i == 2) {
- assertEquals("set [" + i + ']', 4.5, test.get(i), EPSILON);
- } else {
- assertEquals("set [" + i + ']', values[OFFSET + i], test.get(i), EPSILON);
- }
+ assertEquals("set [" + i + ']', i == 2 ? 4.5 : values[OFFSET + i], test.get(i), EPSILON);
}
}
Modified: mahout/trunk/math/src/test/java/org/apache/mahout/math/als/AlternateLeastSquaresSolverTest.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/test/java/org/apache/mahout/math/als/AlternateLeastSquaresSolverTest.java?rev=1183642&r1=1183641&r2=1183642&view=diff
==============================================================================
--- mahout/trunk/math/src/test/java/org/apache/mahout/math/als/AlternateLeastSquaresSolverTest.java (original)
+++ mahout/trunk/math/src/test/java/org/apache/mahout/math/als/AlternateLeastSquaresSolverTest.java Sat Oct 15 14:08:33 2011
@@ -31,10 +31,12 @@ import java.util.Arrays;
public class AlternateLeastSquaresSolverTest extends MahoutTestCase {
- AlternateLeastSquaresSolver solver;
+ private AlternateLeastSquaresSolver solver;
+ @Override
@Before
- public void setup() {
+ public void setUp() throws Exception {
+ super.setUp();
solver = new AlternateLeastSquaresSolver();
}
Modified: mahout/trunk/math/src/test/java/org/apache/mahout/math/decomposer/SolverTest.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/test/java/org/apache/mahout/math/decomposer/SolverTest.java?rev=1183642&r1=1183641&r2=1183642&view=diff
==============================================================================
--- mahout/trunk/math/src/test/java/org/apache/mahout/math/decomposer/SolverTest.java (original)
+++ mahout/trunk/math/src/test/java/org/apache/mahout/math/decomposer/SolverTest.java Sat Oct 15 14:08:33 2011
@@ -55,12 +55,12 @@ public abstract class SolverTest extends
assertTrue("not norm 1 : " + dot + " (eigen #" + i + ')', Math.abs(1.0 - dot) < errorMargin);
} else {
if(Math.abs(dot) > errorMargin) {
- log.info("not orthogonal : " + dot + " (eigens " + i + ", " + j + ')', Math.abs(dot) < errorMargin);
+ log.info("not orthogonal : {} (eigens {}, {})", new Object[] {dot, i, j});
nonOrthogonals.add("(" + i + ',' + j + ')');
}
}
}
- log.info(nonOrthogonals.size() + ": " + nonOrthogonals.toString());
+ log.info("{}:{}", nonOrthogonals.size(), nonOrthogonals);
}
}
@@ -79,13 +79,13 @@ public abstract class SolverTest extends
assertTrue("not norm 1 : " + dot + " (eigen #" + i + ')', Math.abs(1.0 - dot) < errorMargin);
} else {
if(Math.abs(dot) > errorMargin) {
- log.info("not orthogonal : " + dot + " (eigens " + i + ", " + j + ')', Math.abs(dot) < errorMargin);
+ log.info("not orthogonal : {} (eigens {}, {})", new Object[] {dot, i, j});
nonOrthogonals.add("(" + i + ',' + j + ')');
}
}
}
if (!nonOrthogonals.isEmpty()) {
- log.info(nonOrthogonals.size() + ": " + nonOrthogonals.toString());
+ log.info("{}:{}", nonOrthogonals.size(), nonOrthogonals);
}
}
}
Modified: mahout/trunk/math/src/test/java/org/apache/mahout/math/decomposer/lanczos/TestLanczosSolver.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/test/java/org/apache/mahout/math/decomposer/lanczos/TestLanczosSolver.java?rev=1183642&r1=1183641&r2=1183642&view=diff
==============================================================================
--- mahout/trunk/math/src/test/java/org/apache/mahout/math/decomposer/lanczos/TestLanczosSolver.java (original)
+++ mahout/trunk/math/src/test/java/org/apache/mahout/math/decomposer/lanczos/TestLanczosSolver.java Sat Oct 15 14:08:33 2011
@@ -52,7 +52,7 @@ public final class TestLanczosSolver ext
for(int i = 0; i < fractionOfEigensExpectedGood * desiredRank; i++) {
double s = state.getSingularValue(desiredRank - i - 1);
double e = eigenvalues.get(eigenvalues.size() - i - 1);
- log.info(i + " : L = {}, E = {}", s, e);
+ log.info("{} : L = {}, E = {}", new Object[] {i, s, e});
assertTrue("Singular value differs from eigenvalue", Math.abs((s-e)/e) < ERROR_TOLERANCE);
Vector v = state.getRightSingularVector(i);
Vector v2 = decomposition.getV().viewColumn(eigenvalues.size() - i - 1).toVector();