Package org.apache.mahout.cf.taste.impl.common

Examples of org.apache.mahout.cf.taste.impl.common.LongPrimitiveIterator


  public void testTopItems() throws Exception {
    long[] ids = new long[100];
    for (int i = 0; i < 100; i++) {
      ids[i] = i;
    }
    LongPrimitiveIterator possibleItemIds = new LongPrimitiveArrayIterator(ids);
    TopItems.Estimator<Long> estimator = new TopItems.Estimator<Long>() {
      @Override
      public double estimate(Long thing) {
        return thing;
      }
View Full Code Here


  public void testTopItemsRandom() throws Exception {
    long[] ids = new long[100];
    for (int i = 0; i < 100; i++) {
      ids[i] = i;
    }
    LongPrimitiveIterator possibleItemIds = new LongPrimitiveArrayIterator(ids);
    final Random random = RandomUtils.getRandom();
    TopItems.Estimator<Long> estimator = new TopItems.Estimator<Long>() {
      @Override
      public double estimate(Long thing) {
        return random.nextDouble();
View Full Code Here

  public void testTopUsers() throws Exception {
    long[] ids = new long[100];
    for (int i = 0; i < 100; i++) {
      ids[i] = i;
    }
    LongPrimitiveIterator possibleItemIds = new LongPrimitiveArrayIterator(ids);
    TopItems.Estimator<Long> estimator = new TopItems.Estimator<Long>() {
      @Override
      public double estimate(Long thing) {
        return thing;
      }
View Full Code Here

    assertEquals("pref Size: " + pref.length() + " is not: " + 3, 3, pref.length());
  }

  @Test 
  public void testGetItems() throws Exception {
    LongPrimitiveIterator it = model.getItemIDs();
    assertNotNull(it);
    assertTrue(it.hasNext());
    assertEquals(123, it.nextLong());
    assertTrue(it.hasNext());
    assertEquals(234, it.nextLong());
    assertTrue(it.hasNext());
    assertEquals(456, it.nextLong());
    assertTrue(it.hasNext());
    assertEquals(654, it.nextLong());
    assertTrue(it.hasNext());
    assertEquals(789, it.nextLong());
    assertTrue(it.hasNext());
    assertEquals(999, it.nextLong());
    assertFalse(it.hasNext());
    try {
      it.next();
      fail("Should throw NoSuchElementException");
    } catch (NoSuchElementException nsee) {
      // good
    }
  }
View Full Code Here

  @Override
  public FastIDSet getCandidateItems(long userID, DataModel dataModel) throws TasteException {
    FastIDSet possibleItemsIDs = new FastIDSet();
    FastIDSet itemIDs = dataModel.getItemIDsFromUser(userID);
    LongPrimitiveIterator itemIDIterator = itemIDs.iterator();
    while (itemIDIterator.hasNext()) {
      long itemID = itemIDIterator.next();
      PreferenceArray prefs2 = dataModel.getPreferencesForItem(itemID);
      int size2 = prefs2.length();
      for (int j = 0; j < size2; j++) {
        possibleItemsIDs.addAll(dataModel.getItemIDsFromUser(prefs2.getUserID(j)));
      }
View Full Code Here

    } else {

      List<FastIDSet> clusters = new ArrayList<FastIDSet>();
      // Begin with a cluster for each user:
      LongPrimitiveIterator it = model.getUserIDs();
      while (it.hasNext()) {
        FastIDSet newCluster = new FastIDSet();
        newCluster.add(it.nextLong());
        clusters.add(newCluster);
      }

      boolean done = false;
      while (!done) {
View Full Code Here

  private FastByIDMap<List<RecommendedItem>> computeTopRecsPerUserID(Iterable<FastIDSet> clusters)
    throws TasteException {
    FastByIDMap<List<RecommendedItem>> recsPerUser = new FastByIDMap<List<RecommendedItem>>();
    for (FastIDSet cluster : clusters) {
      List<RecommendedItem> recs = computeTopRecsForCluster(cluster);
      LongPrimitiveIterator it = cluster.iterator();
      while (it.hasNext()) {
        recsPerUser.put(it.next(), recs);
      }
    }
    return recsPerUser;
  }
View Full Code Here

 
  private List<RecommendedItem> computeTopRecsForCluster(FastIDSet cluster) throws TasteException {
   
    DataModel dataModel = getDataModel();
    FastIDSet possibleItemIDs = new FastIDSet();
    LongPrimitiveIterator it = cluster.iterator();
    while (it.hasNext()) {
      possibleItemIDs.addAll(dataModel.getItemIDsFromUser(it.next()));
    }
   
    TopItems.Estimator<Long> estimator = new Estimator(cluster);
   
    List<RecommendedItem> topItems = TopItems.getTopItems(NUM_CLUSTER_RECS,
View Full Code Here

  }
 
  private static FastByIDMap<FastIDSet> computeClustersPerUserID(Collection<FastIDSet> clusters) {
    FastByIDMap<FastIDSet> clustersPerUser = new FastByIDMap<FastIDSet>(clusters.size());
    for (FastIDSet cluster : clusters) {
      LongPrimitiveIterator it = cluster.iterator();
      while (it.hasNext()) {
        clustersPerUser.put(it.next(), cluster);
      }
    }
    return clustersPerUser;
  }
View Full Code Here

   
    @Override
    public double estimate(Long itemID) throws TasteException {
      DataModel dataModel = getDataModel();
      RunningAverage average = new FullRunningAverage();
      LongPrimitiveIterator it = cluster.iterator();
      while (it.hasNext()) {
        Float pref = dataModel.getPreferenceValue(it.next(), itemID);
        if (pref != null) {
          average.addDatum(pref);
        }
      }
      return average.getAverage();
View Full Code Here

TOP

Related Classes of org.apache.mahout.cf.taste.impl.common.LongPrimitiveIterator

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.