Пример #1
0
 @Test
 public void testDampedEqualKeys() {
   long[] keys = {2, 5, 6};
   double[] val1 = {1, 2, 1};
   double[] val2 = {1, 2, 5};
   SparseVector v1 = MutableSparseVector.wrap(keys, val1).freeze();
   SparseVector v2 = MutableSparseVector.wrap(keys, val2).freeze();
   assertEquals(0.375, dampedSimilarity.similarity(v1, v1), EPSILON);
   assertEquals(0.42705098, dampedSimilarity.similarity(v1, v2), EPSILON);
 }
Пример #2
0
 @Test
 public void testEqualKeys() {
   long[] keys = {2, 5, 6};
   double[] val1 = {1, 2, 1};
   double[] val2 = {1, 2, 5};
   SparseVector v1 = MutableSparseVector.wrap(keys, val1).freeze();
   SparseVector v2 = MutableSparseVector.wrap(keys, val2).freeze();
   assertEquals(1, similarity.similarity(v1, v1), EPSILON);
   assertEquals(0.745355993, similarity.similarity(v1, v2), EPSILON);
 }
Пример #3
0
 @Test
 public void testOverlap() {
   long[] k1 = {1, 2, 5, 6};
   double[] val1 = {3, 1, 2, 1};
   long[] k2 = {2, 3, 5, 6, 7};
   double[] val2 = {1, 7, 2, 5, 0};
   SparseVector v1 = MutableSparseVector.wrap(k1, val1).freeze();
   SparseVector v2 = MutableSparseVector.wrap(k2, val2).freeze();
   assertEquals(1, similarity.similarity(v1, v1), EPSILON);
   assertEquals(1, similarity.similarity(v2, v2), EPSILON);
   assertEquals(0.29049645, similarity.similarity(v1, v2), EPSILON);
 }
Пример #4
0
 @Test
 public void testDisjoint() {
   long[] k1 = {2, 5, 6};
   double[] val1 = {1, 3, 2};
   long[] k2 = {3, 4, 7};
   double[] val2 = {1, 3, 2};
   SparseVector v1, v2;
   v1 = MutableSparseVector.wrap(k1, val1).freeze();
   v2 = MutableSparseVector.wrap(k2, val2).freeze();
   assertEquals(0, similarity.similarity(v1, v2), EPSILON);
   assertEquals(0, dampedSimilarity.similarity(v1, v2), EPSILON);
 }
Пример #5
0
 @Test
 public void testEmptyDamped() {
   assertEquals(0, dampedSimilarity.similarity(emptyVector(), emptyVector()), EPSILON);
 }