Package org.apache.mahout.cf.taste.similarity

Examples of org.apache.mahout.cf.taste.similarity.ItemSimilarity.itemSimilarity()


    ItemSimilarity similarity = new MySQLJDBCInMemoryItemSimilarity(dataSource);

    assertEquals(0.5, similarity.itemSimilarity(1L, 2L), EPSILON);
    assertEquals(0.4, similarity.itemSimilarity(1L, 3L), EPSILON);
    assertEquals(0.1, similarity.itemSimilarity(3L, 4L), EPSILON);
    assertTrue(Double.isNaN(similarity.itemSimilarity(1L, 4L)));

    EasyMock.verify(dataSource, connection, statement, resultSet);
  }
}
View Full Code Here


    ItemSimilarity similarity = new MySQLJDBCInMemoryItemSimilarity(dataSource);

    assertEquals(0.5, similarity.itemSimilarity(1L, 2L), EPSILON);
    assertEquals(0.4, similarity.itemSimilarity(1L, 3L), EPSILON);
    assertEquals(0.1, similarity.itemSimilarity(3L, 4L), EPSILON);
    assertTrue(Double.isNaN(similarity.itemSimilarity(1L, 4L)));

    EasyMock.verify(dataSource, connection, statement, resultSet);
  }
}
View Full Code Here

  @Test
  public void testLoadFromFile() throws Exception {
    ItemSimilarity similarity = new FileItemSimilarity(testFile);

    assertEquals(0.125, similarity.itemSimilarity(1L, 5L), EPSILON);
    assertEquals(0.125, similarity.itemSimilarity(5L, 1L), EPSILON);
    assertEquals(0.5, similarity.itemSimilarity(1L, 7L), EPSILON);
    assertEquals(0.5, similarity.itemSimilarity(7L, 1L), EPSILON);

    assertTrue(Double.isNaN(similarity.itemSimilarity(7L, 8L)));
View Full Code Here

  @Test
  public void testLoadFromFile() throws Exception {
    ItemSimilarity similarity = new FileItemSimilarity(testFile);

    assertEquals(0.125, similarity.itemSimilarity(1L, 5L), EPSILON);
    assertEquals(0.125, similarity.itemSimilarity(5L, 1L), EPSILON);
    assertEquals(0.5, similarity.itemSimilarity(1L, 7L), EPSILON);
    assertEquals(0.5, similarity.itemSimilarity(7L, 1L), EPSILON);

    assertTrue(Double.isNaN(similarity.itemSimilarity(7L, 8L)));
View Full Code Here

  public void testLoadFromFile() throws Exception {
    ItemSimilarity similarity = new FileItemSimilarity(testFile);

    assertEquals(0.125, similarity.itemSimilarity(1L, 5L), EPSILON);
    assertEquals(0.125, similarity.itemSimilarity(5L, 1L), EPSILON);
    assertEquals(0.5, similarity.itemSimilarity(1L, 7L), EPSILON);
    assertEquals(0.5, similarity.itemSimilarity(7L, 1L), EPSILON);

    assertTrue(Double.isNaN(similarity.itemSimilarity(7L, 8L)));

    double[] valuesForOne = similarity.itemSimilarities(1L, new long[] { 5L, 7L });
View Full Code Here

    ItemSimilarity similarity = new FileItemSimilarity(testFile);

    assertEquals(0.125, similarity.itemSimilarity(1L, 5L), EPSILON);
    assertEquals(0.125, similarity.itemSimilarity(5L, 1L), EPSILON);
    assertEquals(0.5, similarity.itemSimilarity(1L, 7L), EPSILON);
    assertEquals(0.5, similarity.itemSimilarity(7L, 1L), EPSILON);

    assertTrue(Double.isNaN(similarity.itemSimilarity(7L, 8L)));

    double[] valuesForOne = similarity.itemSimilarities(1L, new long[] { 5L, 7L });
    assertNotNull(valuesForOne);
View Full Code Here

    assertEquals(0.125, similarity.itemSimilarity(1L, 5L), EPSILON);
    assertEquals(0.125, similarity.itemSimilarity(5L, 1L), EPSILON);
    assertEquals(0.5, similarity.itemSimilarity(1L, 7L), EPSILON);
    assertEquals(0.5, similarity.itemSimilarity(7L, 1L), EPSILON);

    assertTrue(Double.isNaN(similarity.itemSimilarity(7L, 8L)));

    double[] valuesForOne = similarity.itemSimilarities(1L, new long[] { 5L, 7L });
    assertNotNull(valuesForOne);
    assertEquals(2, valuesForOne.length);
    assertEquals(0.125, valuesForOne[0], EPSILON);
View Full Code Here

  @Test
  public void testNoRefreshAfterFileUpdate() throws Exception {
    ItemSimilarity similarity = new FileItemSimilarity(testFile, 0L);

    /* call a method to make sure the original file is loaded*/
    similarity.itemSimilarity(1L, 5L);

    /* change the underlying file,
     * we have to wait at least a second to see the change in the file's lastModified timestamp */
    Thread.sleep(2000L);
    writeLines(testFile, changedData);
View Full Code Here

     * we have to wait at least a second to see the change in the file's lastModified timestamp */
    Thread.sleep(2000L);
    writeLines(testFile, changedData);

    /* we shouldn't see any changes in the data as we have not yet refreshed */
    assertEquals(0.5, similarity.itemSimilarity(1L, 7L), EPSILON);
    assertEquals(0.5, similarity.itemSimilarity(7L, 1L), EPSILON);
    assertTrue(Double.isNaN(similarity.itemSimilarity(7L, 8L)));
  }

  @Test
View Full Code Here

    Thread.sleep(2000L);
    writeLines(testFile, changedData);

    /* we shouldn't see any changes in the data as we have not yet refreshed */
    assertEquals(0.5, similarity.itemSimilarity(1L, 7L), EPSILON);
    assertEquals(0.5, similarity.itemSimilarity(7L, 1L), EPSILON);
    assertTrue(Double.isNaN(similarity.itemSimilarity(7L, 8L)));
  }

  @Test
  public void testRefreshAfterFileUpdate() throws Exception {
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.