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

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


    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 {
    ItemSimilarity similarity = new FileItemSimilarity(testFile, 0L);
View Full Code Here


  @Test
  public void testRefreshAfterFileUpdate() 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

    writeLines(testFile, changedData);

    similarity.refresh(null);

    /* we should now see the changes in the data */
    assertEquals(0.9, similarity.itemSimilarity(1L, 7L), EPSILON);
    assertEquals(0.9, similarity.itemSimilarity(7L, 1L), EPSILON);
    assertEquals(0.125, similarity.itemSimilarity(1L, 5L), EPSILON);
    assertEquals(0.125, similarity.itemSimilarity(5L, 1L), EPSILON);

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

    similarity.refresh(null);

    /* we should now see the changes in the data */
    assertEquals(0.9, similarity.itemSimilarity(1L, 7L), EPSILON);
    assertEquals(0.9, similarity.itemSimilarity(7L, 1L), EPSILON);
    assertEquals(0.125, similarity.itemSimilarity(1L, 5L), EPSILON);
    assertEquals(0.125, similarity.itemSimilarity(5L, 1L), EPSILON);

    assertFalse(Double.isNaN(similarity.itemSimilarity(7L, 8L)));
    assertEquals(0.112, similarity.itemSimilarity(7L, 8L), EPSILON);
View Full Code Here

    similarity.refresh(null);

    /* we should now see the changes in the data */
    assertEquals(0.9, similarity.itemSimilarity(1L, 7L), EPSILON);
    assertEquals(0.9, similarity.itemSimilarity(7L, 1L), EPSILON);
    assertEquals(0.125, similarity.itemSimilarity(1L, 5L), EPSILON);
    assertEquals(0.125, similarity.itemSimilarity(5L, 1L), EPSILON);

    assertFalse(Double.isNaN(similarity.itemSimilarity(7L, 8L)));
    assertEquals(0.112, similarity.itemSimilarity(7L, 8L), EPSILON);
    assertEquals(0.112, similarity.itemSimilarity(8L, 7L), EPSILON);
View Full Code Here

    /* we should now see the changes in the data */
    assertEquals(0.9, similarity.itemSimilarity(1L, 7L), EPSILON);
    assertEquals(0.9, similarity.itemSimilarity(7L, 1L), EPSILON);
    assertEquals(0.125, similarity.itemSimilarity(1L, 5L), EPSILON);
    assertEquals(0.125, similarity.itemSimilarity(5L, 1L), EPSILON);

    assertFalse(Double.isNaN(similarity.itemSimilarity(7L, 8L)));
    assertEquals(0.112, similarity.itemSimilarity(7L, 8L), EPSILON);
    assertEquals(0.112, similarity.itemSimilarity(8L, 7L), EPSILON);
  }
View Full Code Here

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

    assertFalse(Double.isNaN(similarity.itemSimilarity(7L, 8L)));
    assertEquals(0.112, similarity.itemSimilarity(7L, 8L), EPSILON);
    assertEquals(0.112, similarity.itemSimilarity(8L, 7L), EPSILON);
  }

  @Test(expected = IllegalArgumentException.class)
View Full Code Here

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

    assertFalse(Double.isNaN(similarity.itemSimilarity(7L, 8L)));
    assertEquals(0.112, similarity.itemSimilarity(7L, 8L), EPSILON);
    assertEquals(0.112, similarity.itemSimilarity(8L, 7L), EPSILON);
  }

  @Test(expected = IllegalArgumentException.class)
  public void testFileNotFoundExceptionForNonExistingFile() throws Exception {
View Full Code Here

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

    assertFalse(Double.isNaN(similarity.itemSimilarity(7L, 8L)));
    assertEquals(0.112, similarity.itemSimilarity(7L, 8L), EPSILON);
    assertEquals(0.112, similarity.itemSimilarity(8L, 7L), EPSILON);
  }

  @Test(expected = IllegalArgumentException.class)
  public void testFileNotFoundExceptionForNonExistingFile() throws Exception {
    new FileItemSimilarity(new File("xKsdfksdfsdf"));
View Full Code Here

                    {1.0, 2.0},
                    {2.0, 5.0},
                    {3.0, 6.0},
            });
    ItemSimilarity itemSimilarity = new PearsonCorrelationSimilarity(dataModel, Weighting.WEIGHTED);
    double correlation = itemSimilarity.itemSimilarity(0, 1);
    assertCorrelationEquals(0.9901922307076306, correlation);
  }

  @Test
  public void testRefresh() 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.