Package org.apache.mahout.cf.taste.recommender

Examples of org.apache.mahout.cf.taste.recommender.IDRescorer


/** <p>Tests {@link NullRescorer}.</p> */
public final class NullRescorerTest extends TasteTestCase {

  @Test
  public void testItemRescorer() throws Exception {
    IDRescorer rescorer = NullRescorer.getItemInstance();
    assertNotNull(rescorer);
    assertEquals(1.0, rescorer.rescore(1L, 1.0), EPSILON);
    assertEquals(1.0, rescorer.rescore(0L, 1.0), EPSILON);
    assertEquals(0.0, rescorer.rescore(1L, 0.0), EPSILON);
    assertTrue(Double.isNaN(rescorer.rescore(1L, Double.NaN)));
  }
View Full Code Here


    assertTrue(Double.isNaN(rescorer.rescore(1L, Double.NaN)));
  }

  @Test
  public void testUserRescorer() throws Exception {
    IDRescorer rescorer = NullRescorer.getUserInstance();
    assertNotNull(rescorer);
    assertEquals(1.0, rescorer.rescore(1L, 1.0), EPSILON);
    assertEquals(1.0, rescorer.rescore(0L, 1.0), EPSILON);
    assertEquals(0.0, rescorer.rescore(1L, 0.0), EPSILON);
    assertTrue(Double.isNaN(rescorer.rescore(1L, Double.NaN)));
  }
View Full Code Here

  @Test
  public void testMultiRecommendRescorer() {
    RescorerProvider multi =
        new MultiRescorerProvider(new SimpleModRescorerProvider(2), new SimpleModRescorerProvider(3));
   
    IDRescorer provider = multi.getRecommendRescorer(new long[]{5}, (MyrrixRecommender) null);
    assertNull(provider);
   
    provider = multi.getRecommendRescorer(new long[]{2}, (MyrrixRecommender) null);
    assertNotNull(provider);
    assertFalse(provider instanceof MultiRescorer);
    assertTrue(provider.isFiltered(3));
    assertFalse(provider.isFiltered(2));

    provider = multi.getRecommendRescorer(new long[]{6}, (MyrrixRecommender) null);
    assertNotNull(provider);
    assertTrue(provider instanceof MultiRescorer);
    assertTrue(provider.isFiltered(3));
    assertTrue(provider.isFiltered(2));
    assertFalse(provider.isFiltered(12));
  }
View Full Code Here

  @Test
  public void testMultiRecommendToAnonymousRescorer() {
    RescorerProvider multi =
        new MultiRescorerProvider(new SimpleModRescorerProvider(2), new SimpleModRescorerProvider(3));
   
    IDRescorer provider = multi.getRecommendToAnonymousRescorer(new long[]{5}, (MyrrixRecommender) null);
    assertNull(provider);
   
    provider = multi.getRecommendToAnonymousRescorer(new long[]{2}, (MyrrixRecommender) null);
    assertNotNull(provider);
    assertFalse(provider instanceof MultiRescorer);
    assertTrue(provider.isFiltered(3));
    assertFalse(provider.isFiltered(2));

    provider = multi.getRecommendToAnonymousRescorer(new long[]{6}, (MyrrixRecommender) null);
    assertNotNull(provider);
    assertTrue(provider instanceof MultiRescorer);
    assertTrue(provider.isFiltered(3));
    assertTrue(provider.isFiltered(2));
    assertFalse(provider.isFiltered(12));
  }
View Full Code Here

 
  @Test
  public void testMultiMostPopularItemsRescorer() {
    RescorerProvider multi =
        new MultiRescorerProvider(new SimpleModRescorerProvider(2), new SimpleModRescorerProvider(3));
    IDRescorer provider = multi.getMostPopularItemsRescorer(null);
    assertNotNull(provider);
    assertTrue(provider instanceof MultiRescorer);
    assertTrue(provider.isFiltered(3));
    assertTrue(provider.isFiltered(2));
    assertFalse(provider.isFiltered(6));   
  }
View Full Code Here

          return null;
        }
      }
    }

    IDRescorer rescorer = this.rescorer;
    if (rescorer != null && rescorer.isFiltered(itemID)) {
      return null;
    }

    float[] itemFeatures = entry.getValue();
    double sum = 0.0;
    int count = 0;
    for (float[] oneUserFeatures : features) {
      sum += SimpleVectorMath.dot(itemFeatures, oneUserFeatures);
      count++;
    }
   
    if (rescorer != null) {
      sum = rescorer.rescore(itemID, sum);
      if (!LangUtils.isFinite(sum)) {
        return null;
      }
    }
View Full Code Here

 
  @Override
  public IDRescorer getRecommendRescorer(long[] userIDs, MyrrixRecommender recommender, String... args) {
    List<IDRescorer> rescorers = Lists.newArrayListWithCapacity(providers.length);
    for (RescorerProvider provider : providers) {
      IDRescorer rescorer = provider.getRecommendRescorer(userIDs, recommender, args);
      if (rescorer != null) {
        rescorers.add(rescorer);
      }
    }
    return buildRescorer(rescorers);
View Full Code Here

  @Override
  public IDRescorer getRecommendToAnonymousRescorer(long[] itemIDs, MyrrixRecommender recommender, String... args) {
    List<IDRescorer> rescorers = Lists.newArrayListWithCapacity(providers.length);
    for (RescorerProvider provider : providers) {
      IDRescorer rescorer = provider.getRecommendToAnonymousRescorer(itemIDs, recommender, args);
      if (rescorer != null) {
        rescorers.add(rescorer);
      }
    }
    return buildRescorer(rescorers)
View Full Code Here

  @Override
  public IDRescorer getMostPopularItemsRescorer(MyrrixRecommender recommender, String... args) {
    List<IDRescorer> rescorers = Lists.newArrayListWithCapacity(providers.length);
    for (RescorerProvider provider : providers) {
      IDRescorer rescorer = provider.getMostPopularItemsRescorer(recommender, args);
      if (rescorer != null) {
        rescorers.add(rescorer);
      }
    }
    return buildRescorer(rescorers);
View Full Code Here

  @Override
  public RecommendedItem next() {
    FastByIDFloatMap.MapEntry entry = countsIterator.next();
    long id = entry.getKey();
    float value = entry.getValue();
    IDRescorer theRescorer = rescorer;
    if (theRescorer != null) {
      if (theRescorer.isFiltered(id)) {
        return null;
      }
      value = (float) theRescorer.rescore(id, value);
      if (!LangUtils.isFinite(value)) {
        return null;
      }
    }
    delegate.set(id, value);
View Full Code Here

TOP

Related Classes of org.apache.mahout.cf.taste.recommender.IDRescorer

Copyright © 2018 www.massapicom. 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.