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

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


  @Test
  public void testRemove() throws Exception {
    DataModel model = getDataModel();
    MemoryDiffStorage storage = new MemoryDiffStorage(model, Weighting.UNWEIGHTED, false, Long.MAX_VALUE);
    storage.updateItemPref(1, 0.5f, true);
    RunningAverage average = storage.getDiff(1, 2);
    assertEquals(0.1, average.getAverage(), EPSILON);
    assertEquals(2, average.getCount());
  }
View Full Code Here


      this.rescorer = rescorer;
    }
   
    @Override
    public double estimate(Long itemID) throws TasteException {
      RunningAverage average = new FullRunningAverage();
      double[] similarities = similarity.itemSimilarities(itemID, toItemIDs);
      for (int i = 0; i < toItemIDs.length; i++) {
        long toItemID = toItemIDs[i];
        LongPair pair = new LongPair(toItemID, itemID);
        if ((rescorer != null) && rescorer.isFiltered(pair)) {
          continue;
        }
        double estimate = similarities[i];
        if (rescorer != null) {
          estimate = rescorer.rescore(pair, estimate);
        }
        average.addDatum(estimate);
      }
      return average.getAverage();
    }
View Full Code Here

 
  private final class PrefRetriever implements Retriever<Long,Float> {
   
    @Override
    public Float get(Long key) throws TasteException {
      RunningAverage average = new FullRunningAverage();
      PreferenceArray prefs = dataModel.getPreferencesFromUser(key);
      int size = prefs.length();
      if (size == 0) {
        return ZERO;
      }
      for (int i = 0; i < size; i++) {
        average.addDatum(prefs.getValue(i));
      }
      return (float) average.getAverage();
    }
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

      }
    }
  }
 
  private double getAveragePreference() throws TasteException {
    RunningAverage average = new FullRunningAverage();
    DataModel dataModel = getDataModel();
    LongPrimitiveIterator it = dataModel.getUserIDs();
    while (it.hasNext()) {
      for (Preference pref : dataModel.getPreferencesFromUser(it.nextLong())) {
        average.addDatum(pref.getValue());
      }
    }
    return average.getAverage();
  }
View Full Code Here

      this.cluster = cluster;
    }

    @Override
    public double estimate(Item item) {
      RunningAverage average = new FullRunningAverage();
      for (User user : cluster) {
        Preference pref = user.getPreferenceFor(item.getID());
        if (pref != null) {
          average.addDatum(pref.getValue());
        }
      }
      return average.getAverage();
    }
View Full Code Here

  }

  private double doEstimatePreference(Object itemID) {
    buildAveragesLock.readLock().lock();
    try {
      RunningAverage average = itemAverages.get(itemID);
      return average == null ? Double.NaN : average.getAverage();
    } finally {
      buildAveragesLock.readLock().unlock();
    }
  }
View Full Code Here

      DataModel dataModel = getDataModel();
      for (User user : dataModel.getUsers()) {
        Preference[] prefs = user.getPreferencesAsArray();
        for (Preference pref : prefs) {
          Object itemID = pref.getItem().getID();
          RunningAverage average = itemAverages.get(itemID);
          if (average == null) {
            average = new FullRunningAverage();
            itemAverages.put(itemID, average);
          }
          average.addDatum(pref.getValue());
        }
      }
      averagesBuilt = true;
    } finally {
      buildAveragesLock.writeLock().unlock();
View Full Code Here

      prefDelta = value;
    }
    super.setPreference(userID, itemID, value);
    try {
      buildAveragesLock.writeLock().lock();
      RunningAverage average = itemAverages.get(itemID);
      if (average == null) {
        RunningAverage newAverage = new FullRunningAverage();
        newAverage.addDatum(prefDelta);
        itemAverages.put(itemID, newAverage);
      } else {
        average.changeDatum(prefDelta);
      }
    } finally {
View Full Code Here

    Preference oldPref = theUser.getPreferenceFor(itemID);
    super.removePreference(userID, itemID);
    if (oldPref != null) {
      try {
        buildAveragesLock.writeLock().lock();
        RunningAverage average = itemAverages.get(itemID);
        if (average == null) {
          throw new IllegalStateException("No preferences exist for item ID: " + itemID);
        } else {
          average.removeDatum(oldPref.getValue());
        }
      } finally {
        buildAveragesLock.writeLock().unlock();
      }
    }
View Full Code Here

TOP

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

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.