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 2009/08/21 00:57:27 UTC
svn commit: r806392 - in
/lucene/mahout/trunk/core/src/main/java/org/apache/mahout:
clustering/dirichlet/ clustering/lda/ matrix/ utils/
Author: srowen
Date: Thu Aug 20 22:57:27 2009
New Revision: 806392
URL: http://svn.apache.org/viewvc?rev=806392&view=rev
Log:
MAHOUT-164
Modified:
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/dirichlet/UncommonDistributions.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/lda/IntPairWritable.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/lda/LDADriver.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/lda/LDAInference.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/lda/LDAMapper.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/lda/LDAPrintTopics.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/lda/LDAReducer.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/AbstractVector.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/DenseVector.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/SparseVector.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/VectorView.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/utils/EuclideanDistanceMeasure.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/utils/ManhattanDistanceMeasure.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/utils/SquaredEuclideanDistanceMeasure.java
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/dirichlet/UncommonDistributions.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/dirichlet/UncommonDistributions.java?rev=806392&r1=806391&r2=806392&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/dirichlet/UncommonDistributions.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/dirichlet/UncommonDistributions.java Thu Aug 20 22:57:27 2009
@@ -226,9 +226,7 @@
x += 1;
}
if (x == 0) {
- {
- return 0;
- }
+ return 0;
}
return x - 1;
}
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/lda/IntPairWritable.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/lda/IntPairWritable.java?rev=806392&r1=806391&r2=806392&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/lda/IntPairWritable.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/lda/IntPairWritable.java Thu Aug 20 22:57:27 2009
@@ -69,9 +69,15 @@
y = dataInput.readInt();
}
+ @Override
public int compareTo(IntPairWritable that) {
- int xdiff = this.x - that.x;
- return (xdiff != 0) ? xdiff : this.y - that.y;
+ if (this.x < that.x) {
+ return -1;
+ } else if (this.x > that.x) {
+ return 1;
+ } else {
+ return this.y < that.y ? -1 : this.y > that.y ? 1 : 0;
+ }
}
public boolean equals(Object o) {
@@ -93,7 +99,7 @@
@Override
public String toString() {
- return "(" + x + ", " + y + ")";
+ return "(" + x + ", " + y + ')';
}
static {
@@ -105,6 +111,7 @@
super(IntPairWritable.class);
}
+ @Override
public int compare(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2) {
assert l1 == 8;
int int11 = readInt(b1, s1);
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/lda/LDADriver.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/lda/LDADriver.java?rev=806392&r1=806391&r2=806392&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/lda/LDADriver.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/lda/LDADriver.java Thu Aug 20 22:57:27 2009
@@ -63,15 +63,14 @@
static final int LOG_LIKELIHOOD_KEY = -2;
static final int TOPIC_SUM_KEY = -1;
- static final double OVERALL_CONVERGENCE = 1E-5;
+ static final double OVERALL_CONVERGENCE = 1.0E-5;
private static final Logger log = LoggerFactory.getLogger(LDADriver.class);
private LDADriver() {
}
- public static void main(String[] args) throws InstantiationException,
- IllegalAccessException, ClassNotFoundException,
+ public static void main(String[] args) throws ClassNotFoundException,
IOException, InterruptedException {
DefaultOptionBuilder obuilder = new DefaultOptionBuilder();
@@ -155,7 +154,7 @@
topicSmoothing = Double.parseDouble(cmdLine.getValue(maxIterOpt).toString());
}
if(topicSmoothing < 1) {
- topicSmoothing = 50. / numTopics;
+ topicSmoothing = 50.0 / numTopics;
}
runJob(input, output, numTopics, numWords, topicSmoothing, maxIterations,
@@ -223,13 +222,12 @@
SequenceFile.Writer writer = new SequenceFile.Writer(fs, job, path,
IntPairWritable.class, DoubleWritable.class);
- double total = 0.0; // total number of pseudo counts we made
-
kw.setX(k);
+ double total = 0.0; // total number of pseudo counts we made
for (int w = 0; w < numWords; ++w) {
kw.setY(w);
// A small amount of random noise, minimized by having a floor.
- double pseudocount = random.nextDouble() + 1E-8;
+ double pseudocount = random.nextDouble() + 1.0E-8;
total += pseudocount;
v.set(Math.log(pseudocount));
writer.append(kw, v);
@@ -272,9 +270,7 @@
* @param input the directory pathname for input points
* @param stateIn the directory pathname for input state
* @param stateOut the directory pathname for output state
- * @param modelFactory the class name of the model factory class
* @param numTopics the number of clusters
- * @param alpha_0 alpha_0
* @param numReducers the number of Reducers desired
*/
public static double runIteration(String input, String stateIn,
@@ -307,10 +303,10 @@
}
static LDAState createState(Configuration job) throws IOException {
- String statePath = job.get(LDADriver.STATE_IN_KEY);
- int numTopics = Integer.parseInt(job.get(LDADriver.NUM_TOPICS_KEY));
- int numWords = Integer.parseInt(job.get(LDADriver.NUM_WORDS_KEY));
- double topicSmoothing = Double.parseDouble(job.get(LDADriver.TOPIC_SMOOTHING_KEY));
+ String statePath = job.get(STATE_IN_KEY);
+ int numTopics = Integer.parseInt(job.get(NUM_TOPICS_KEY));
+ int numWords = Integer.parseInt(job.get(NUM_WORDS_KEY));
+ double topicSmoothing = Double.parseDouble(job.get(TOPIC_SMOOTHING_KEY));
Path dir = new Path(statePath);
FileSystem fs = dir.getFileSystem(job);
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/lda/LDAInference.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/lda/LDAInference.java?rev=806392&r1=806391&r2=806392&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/lda/LDAInference.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/lda/LDAInference.java Thu Aug 20 22:57:27 2009
@@ -45,7 +45,7 @@
* the document, phi(k,w) is the probability of
* topic k generating w in this document.
*/
- public class InferredDocument {
+ public static class InferredDocument {
public final Vector wordCounts;
public final Vector gamma; // p(topic)
@@ -83,8 +83,6 @@
DenseMatrix phi = new DenseMatrix(state.numTopics, docLength);
- boolean converged = false;
- double oldLL = 1;
// digamma is expensive, precompute
Vector digammaGamma = digamma(gamma);
// and log normalize:
@@ -96,6 +94,8 @@
int iteration = 0;
final int MAX_ITER = 20;
+ boolean converged = false;
+ double oldLL = 1;
while (!converged && iteration < MAX_ITER) {
nextGamma.assign(state.topicSmoothing); // nG := alpha, for all topics
@@ -139,7 +139,7 @@
return new InferredDocument(wordCounts, gamma, columnMap, phi, oldLL);
}
- private LDAState state;
+ private final LDAState state;
private double computeLikelihood(Vector wordCounts, Map<Integer, Integer> columnMap,
Matrix phi, Vector gamma, Vector digammaGamma) {
@@ -206,6 +206,7 @@
private static Vector digamma(Vector v) {
Vector digammaGamma = new DenseVector(v.size());
digammaGamma.assign(v, new BinaryFunction() {
+ @Override
public double apply(double unused, double g) {
return digamma(g);
}
@@ -241,7 +242,7 @@
x += 1;
}
- double f = 1. / (x * x);
+ double f = 1.0 / (x * x);
double t = f * (-1 / 12.0
+ f * (1 / 120.0
+ f * (-1 / 252.0
@@ -253,5 +254,5 @@
return r + Math.log(x) - 0.5 / x + t;
}
- private static final double E_STEP_CONVERGENCE = 1E-6;
+ private static final double E_STEP_CONVERGENCE = 1.0E-6;
}
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/lda/LDAMapper.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/lda/LDAMapper.java?rev=806392&r1=806391&r2=806392&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/lda/LDAMapper.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/lda/LDAMapper.java Thu Aug 20 22:57:27 2009
@@ -23,11 +23,8 @@
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.io.DoubleWritable;
-import org.apache.hadoop.io.Text;
import org.apache.hadoop.io.WritableComparable;
import org.apache.hadoop.mapreduce.Mapper;
-import org.apache.hadoop.mapreduce.MapContext;
-import org.apache.mahout.matrix.AbstractVector;
import org.apache.mahout.matrix.Vector;
/**
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/lda/LDAPrintTopics.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/lda/LDAPrintTopics.java?rev=806392&r1=806391&r2=806392&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/lda/LDAPrintTopics.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/lda/LDAPrintTopics.java Thu Aug 20 22:57:27 2009
@@ -27,6 +27,7 @@
import java.util.LinkedList;
import java.util.List;
import java.util.PriorityQueue;
+import java.util.Queue;
import org.apache.commons.cli2.CommandLine;
import org.apache.commons.cli2.Group;
@@ -52,17 +53,33 @@
}
private static class StringDoublePair implements Comparable<StringDoublePair> {
+ private final double score;
+ private final String word;
+
StringDoublePair(double score, String word) {
this.score = score;
this.word = word;
}
+ @Override
public int compareTo(StringDoublePair other) {
return Double.compare(score,other.score);
}
- double score;
- String word;
+ @Override
+ public boolean equals(Object o) {
+ if (!(o instanceof String)) {
+ return false;
+ }
+ StringDoublePair other = (StringDoublePair) o;
+ return score == other.score && word.equals(other.word);
+ }
+
+ @Override
+ public int hashCode() {
+ return (int) Double.doubleToLongBits(score) ^ word.hashCode();
+ }
+
}
public static List<List<String>> topWordsForTopics(String dir, Configuration job,
@@ -109,7 +126,7 @@
}
// Adds the word if the queue is below capacity, or the score is high enough
- private static void maybeEnqueue(PriorityQueue<StringDoublePair> q, String word,
+ private static void maybeEnqueue(Queue<StringDoublePair> q, String word,
double score, int numWordsToPrint) {
if (q.size() >= numWordsToPrint && score > q.peek().score) {
q.poll();
@@ -141,7 +158,7 @@
return result;
}
- public static void main(String[] args) {
+ public static void main(String[] args) throws Exception {
DefaultOptionBuilder obuilder = new DefaultOptionBuilder();
ArgumentBuilder abuilder = new ArgumentBuilder();
GroupBuilder gbuilder = new GroupBuilder();
@@ -208,11 +225,9 @@
}
} catch (OptionException e) {
- System.err.println("Exception: " + e);
CommandLineUtil.printHelp(group);
} catch (IOException e) {
- System.err.println("Exception:" + e);
- e.printStackTrace();
+ throw e;
}
}
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/lda/LDAReducer.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/lda/LDAReducer.java?rev=806392&r1=806391&r2=806392&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/lda/LDAReducer.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/lda/LDAReducer.java Thu Aug 20 22:57:27 2009
@@ -16,7 +16,6 @@
*/
package org.apache.mahout.clustering.lda;
-import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.io.DoubleWritable;
import org.apache.hadoop.mapreduce.Reducer;
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/AbstractVector.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/AbstractVector.java?rev=806392&r1=806391&r2=806392&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/AbstractVector.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/AbstractVector.java Thu Aug 20 22:57:27 2009
@@ -59,10 +59,6 @@
@Override
- public abstract Vector.Element getElement(int index);
-
-
- @Override
public Vector clone() {
AbstractVector clone;
try {
@@ -120,9 +116,9 @@
throw new CardinalityException();
}
Vector result = clone();
- Iterator<Vector.Element> iter = x.iterateNonZero();
+ Iterator<Element> iter = x.iterateNonZero();
while (iter.hasNext()) {
- Vector.Element e = iter.next();
+ Element e = iter.next();
result.setQuick(e.index(), getQuick(e.index()) - e.get());
}
return result;
@@ -208,9 +204,9 @@
}
//TODO: get smarter about this, if we are adding a dense to a sparse, then we should return a dense
Vector result = clone();
- Iterator<Vector.Element> iter = x.iterateNonZero();
+ Iterator<Element> iter = x.iterateNonZero();
while (iter.hasNext()) {
- Vector.Element e = iter.next();
+ Element e = iter.next();
result.setQuick(e.index(), getQuick(e.index()) + e.get());
}
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/DenseVector.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/DenseVector.java?rev=806392&r1=806391&r2=806392&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/DenseVector.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/DenseVector.java Thu Aug 20 22:57:27 2009
@@ -22,6 +22,7 @@
import java.io.IOException;
import java.util.Arrays;
import java.util.Iterator;
+import java.util.NoSuchElementException;
/** Implements vector as an array of doubles */
public class DenseVector extends AbstractVector {
@@ -143,26 +144,29 @@
private final Element element = new Element(0);
private int offset;
- @Override
- public boolean hasNext() {
+ private NonZeroIterator() {
+ goToNext();
+ }
+
+ private void goToNext() {
while (offset < values.length && values[offset] == 0) {
offset++;
}
- boolean next = true;
- if (offset >= values.length) {
- next = false;
- } else {
- element.ind = offset;
- offset++;
- }
- return next;
+ }
+
+ @Override
+ public boolean hasNext() {
+ return offset < values.length;
}
@Override
public Vector.Element next() {
- /*if (!hasNext()) {
+ if (offset >= values.length) {
throw new NoSuchElementException();
- }*/
+ }
+ element.ind = offset;
+ offset++;
+ goToNext();
return element;
}
@@ -183,9 +187,9 @@
@Override
public Vector.Element next() {
- /*if (!hasNext()) {
+ if (!hasNext()) {
throw new NoSuchElementException();
- }*/
+ }
element.ind++;
return element;
}
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/SparseVector.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/SparseVector.java?rev=806392&r1=806391&r2=806392&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/SparseVector.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/SparseVector.java Thu Aug 20 22:57:27 2009
@@ -130,7 +130,7 @@
* NOTE: this implementation reuses the Vector.Element instance for each call of next(). If you need to preserve the
* instance, you need to make a copy of it
*
- * @return an {@link org.apache.mahout.matrix.SparseVector.NonZeroIterator} over the Elements.
+ * @return an {@link NonZeroIterator} over the Elements.
* @see #getElement(int)
*/
@Override
@@ -194,6 +194,9 @@
@Override
public Vector.Element next() {
+ if (offset >= cardinality) {
+ throw new NoSuchElementException();
+ }
element.ind = offset++;
return element;
}
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/VectorView.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/VectorView.java?rev=806392&r1=806391&r2=806392&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/VectorView.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/VectorView.java Thu Aug 20 22:57:27 2009
@@ -89,14 +89,10 @@
@Override
public Vector viewPart(int offset, int length) {
if (length > cardinality) {
- {
- throw new CardinalityException();
- }
+ throw new CardinalityException();
}
if (offset < 0 || offset + length > cardinality) {
- {
- throw new IndexException();
- }
+ throw new IndexException();
}
return new VectorView(vector, offset + this.offset, length);
}
@@ -104,13 +100,9 @@
@Override
public boolean haveSharedCells(Vector other) {
if (other instanceof VectorView) {
- {
- return other == this || vector.haveSharedCells(other);
- }
+ return other == this || vector.haveSharedCells(other);
} else {
- {
- return other.haveSharedCells(vector);
- }
+ return other.haveSharedCells(vector);
}
}
@@ -251,15 +243,11 @@
@Override
public double dot(Vector x) {
if (size() != x.size()) {
- {
- throw new CardinalityException();
- }
+ throw new CardinalityException();
}
double result = 0;
for (int i = 0; i < size(); i++) {
- {
- result += getQuick(i) * x.getQuick(i);
- }
+ result += getQuick(i) * x.getQuick(i);
}
return result;
}
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/utils/EuclideanDistanceMeasure.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/utils/EuclideanDistanceMeasure.java?rev=806392&r1=806391&r2=806392&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/utils/EuclideanDistanceMeasure.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/utils/EuclideanDistanceMeasure.java Thu Aug 20 22:57:27 2009
@@ -20,12 +20,13 @@
import org.apache.mahout.matrix.Vector;
/**
- * This class implements a Euclidian distance metric by summing the square root of the squared differences between each
+ * This class implements a Euclidean distance metric by summing the square root of the squared differences between each
* coordinate. <p/> If you don't care about the true distance and only need the values for comparison, then the base
* class, {@link SquaredEuclideanDistanceMeasure}, will be faster since it doesn't do the actual square root of the
* squared differences.
*/
public class EuclideanDistanceMeasure extends SquaredEuclideanDistanceMeasure {
+
@Override
public double distance(Vector v1, Vector v2) {
return Math.sqrt(super.distance(v1, v2));
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/utils/ManhattanDistanceMeasure.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/utils/ManhattanDistanceMeasure.java?rev=806392&r1=806391&r2=806392&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/utils/ManhattanDistanceMeasure.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/utils/ManhattanDistanceMeasure.java Thu Aug 20 22:57:27 2009
@@ -32,7 +32,7 @@
*/
public class ManhattanDistanceMeasure implements DistanceMeasure {
- public static double distance(double[] p1, double[] p2) {
+ public double distance(double[] p1, double[] p2) {
double result = 0.0;
for (int i = 0; i < p1.length; i++) {
result += Math.abs(p2[i] - p1[i]);
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/utils/SquaredEuclideanDistanceMeasure.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/utils/SquaredEuclideanDistanceMeasure.java?rev=806392&r1=806391&r2=806392&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/utils/SquaredEuclideanDistanceMeasure.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/utils/SquaredEuclideanDistanceMeasure.java Thu Aug 20 22:57:27 2009
@@ -25,7 +25,6 @@
import java.util.Collections;
import java.util.Iterator;
-
/**
* Like {@link org.apache.mahout.utils.EuclideanDistanceMeasure} but it does not take the square root. <p/> Thus, it is
* not actually the Euclidean Distance, but it is saves on computation when you only need the distance for comparison
@@ -48,16 +47,6 @@
// nothing to do
}
- public static double distance(double[] p1, double[] p2) {
- double result = 0.0;
- for (int i = 0; i < p1.length; i++) {
- double delta = p2[i] - p1[i];
- result += delta * delta;
- }
-
- return result;
- }
-
@Override
public double distance(Vector v1, Vector v2) {
if (v1.size() != v2.size()) {