[ https://issues.apache.org/jira/browse/MAHOUT-66?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12611742#action_12611742 ]
Karl Wettin commented on MAHOUT-66: ----------------------------------- What is it that actually does not work when using SparseVector? I just added this to the trunk test and it passes for all distance measure classes: {code} Index: core/src/test/java/org/apache/mahout/utils/DefaultDistanceMeasureTest.java =================================================================== --- core/src/test/java/org/apache/mahout/utils/DefaultDistanceMeasureTest.java (revision 674908) +++ core/src/test/java/org/apache/mahout/utils/DefaultDistanceMeasureTest.java (working copy) @@ -20,6 +20,7 @@ import junit.framework.TestCase; import org.apache.mahout.matrix.DenseVector; import org.apache.mahout.matrix.Vector; +import org.apache.mahout.matrix.SparseVector; public abstract class DefaultDistanceMeasureTest extends TestCase { @@ -59,4 +60,51 @@ } + public void testMeasureSparse() throws Exception { + + DistanceMeasure distanceMeasure = distanceMeasureFactory(); + + Vector[] vectors = new Vector[]{ + new SparseVector(6), + new SparseVector(6), + new SparseVector(6) + }; + + for (int i=0; i<6; i++) { + vectors[0].set(i, 1); + } + + for (int i=0; i<6; i++) { + vectors[1].set(i, 2); + } + for (int i=0; i<6; i++) { + vectors[2].set(i, 6); + } + + + + + double[][] distanceMatrix = new double[3][3]; + + for (int a = 0; a < 3; a++) { + for (int b = 0; b < 3; b++) { + distanceMatrix[a][b] = distanceMeasure.distance(vectors[a], vectors[b]); + } + } + + assertEquals(0d, distanceMatrix[0][0]); + assertTrue(distanceMatrix[0][0] < distanceMatrix[0][1]); + assertTrue(distanceMatrix[0][1] < distanceMatrix[0][2]); + + assertEquals(0d, distanceMatrix[1][1]); + assertTrue(distanceMatrix[1][0] > distanceMatrix[1][1]); + assertTrue(distanceMatrix[1][2] > distanceMatrix[1][0]); + + assertEquals(0d, distanceMatrix[2][2]); + assertTrue(distanceMatrix[2][0] > distanceMatrix[2][1]); + assertTrue(distanceMatrix[2][1] > distanceMatrix[2][2]); + + + } + } {code} > EuclideanDistanceMeasure and ManhattanDistanceMeasure classes does not > compute distance for Sparse Vectors > ---------------------------------------------------------------------------------------------------------- > > Key: MAHOUT-66 > URL: https://issues.apache.org/jira/browse/MAHOUT-66 > Project: Mahout > Issue Type: Bug > Components: Clustering > Reporter: Pallavi Palleti > Priority: Minor > Attachments: MAHOUT-66.patch, MAHOUT-66.patch > > -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.