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

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


 
  private static Collection<Callable<Void>> wrapWithStatsCallables(Collection<Callable<Void>> callables) {
    int size = callables.size();
    Collection<Callable<Void>> wrapped = new ArrayList<Callable<Void>>(size);
    int count = 0;
    RunningAverageAndStdDev timing = new FullRunningAverageAndStdDev();
    for (Callable<Void> callable : callables) {
      boolean logStats = count++ % 1000 == 0; // log every 100 or so iterations
      wrapped.add(new StatsCallable(callable, logStats, timing));
    }
    return wrapped;
View Full Code Here


  private static double computeThreshold(PreferenceArray prefs) {
    if (prefs.length() < 2) {
      // Not enough data points -- return a threshold that allows everything
      return Double.NEGATIVE_INFINITY;
    }
    RunningAverageAndStdDev stdDev = new FullRunningAverageAndStdDev();
    int size = prefs.length();
    for (int i = 0; i < size; i++) {
      stdDev.addDatum(prefs.getValue(i));
    }
    return stdDev.getAverage() + stdDev.getStandardDeviation();
  }
View Full Code Here

    refresh(null);
  }
 
  @Override
  public float getTransformedValue(Preference pref) throws TasteException {
    RunningAverageAndStdDev meanAndStdev = meanAndStdevs.get(pref.getUserID());
    if (meanAndStdev.getCount() > 1) {
      double stdev = meanAndStdev.getStandardDeviation();
      if (stdev > 0.0) {
        return (float) ((pref.getValue() - meanAndStdev.getAverage()) / stdev);
      }
    }
    return 0.0f;
  }
View Full Code Here

 
  private class MeanStdevRetriever implements Retriever<Long,RunningAverageAndStdDev> {
   
    @Override
    public RunningAverageAndStdDev get(Long userID) throws TasteException {
      RunningAverageAndStdDev running = new FullRunningAverageAndStdDev();
      PreferenceArray prefs = dataModel.getPreferencesFromUser(userID);
      int size = prefs.length();
      for (int i = 0; i < size; i++) {
        running.addDatum(prefs.getValue(i));
      }
      return running;
    }
View Full Code Here

  private static double computeThreshold(PreferenceArray prefs) {
    if (prefs.length() < 2) {
      // Not enough data points -- return a threshold that allows everything
      return Double.NEGATIVE_INFINITY;
    }
    RunningAverageAndStdDev stdDev = new FullRunningAverageAndStdDev();
    int size = prefs.length();
    for (int i = 0; i < size; i++) {
      stdDev.addDatum(prefs.getValue(i));
    }
    return stdDev.getAverage() + stdDev.getStandardDeviation();
  }
View Full Code Here

  private static Collection<Callable<Void>> wrapWithStatsCallables(Collection<Callable<Void>> callables,
                                                                   AtomicInteger noEstimateCounter) {
    int size = callables.size();
    Collection<Callable<Void>> wrapped = new ArrayList<Callable<Void>>(size);
    int count = 0;
    RunningAverageAndStdDev timing = new FullRunningAverageAndStdDev();
    for (Callable<Void> callable : callables) {
      boolean logStats = count++ % 1000 == 0; // log every 100 or so iterations
      wrapped.add(new StatsCallable(callable, logStats, timing, noEstimateCounter));
    }
    return wrapped;
View Full Code Here

    refresh(null);
  }

  @Override
  public double getTransformedValue(Preference pref) throws TasteException {
    RunningAverageAndStdDev meanAndStdev = meanAndStdevs.get(pref.getUser());
    if (meanAndStdev.getCount() > 1) {
      double stdev = meanAndStdev.getStandardDeviation();
      if (stdev > 0.0) {
        return (pref.getValue() - meanAndStdev.getAverage()) / stdev;
      }
    }
    return 0.0;
  }
View Full Code Here

  private static class MeanStdevRetriever implements Retriever<User, RunningAverageAndStdDev> {

    @Override
    public RunningAverageAndStdDev get(User user) throws TasteException {
      RunningAverageAndStdDev running = new FullRunningAverageAndStdDev();
      Preference[] prefs = user.getPreferencesAsArray();
      for (Preference pref : prefs) {
        running.addDatum(pref.getValue());
      }
      return running;
    }
View Full Code Here

  private static double computeThreshold(Preference[] prefs) {
    if (prefs.length < 2) {
      // Not enough data points -- return a threshold that allows everything
      return Double.NEGATIVE_INFINITY;
    }
    RunningAverageAndStdDev stdDev = new FullRunningAverageAndStdDev();
    for (Preference pref : prefs) {
      stdDev.addDatum(pref.getValue());
    }
    return stdDev.getAverage() + stdDev.getStandardDeviation();
  }
View Full Code Here

  public void testRemovePref() throws Exception {
    double eps = 0.0001;
    DataModel model = getDataModelPocked();
    MemoryDiffStorage storage = new MemoryDiffStorage(model, Weighting.WEIGHTED, Long.MAX_VALUE);
   
    RunningAverageAndStdDev average = (RunningAverageAndStdDev) storage.getDiff(0, 1);
    assertEquals(-0.033333, average.getAverage(), eps);
    assertEquals(0.32145, average.getStandardDeviation(), eps);
    assertEquals(3, average.getCount());

    storage.removeItemPref(2, 1, 0.1f);
    average = (RunningAverageAndStdDev) storage.getDiff(0, 1);
    assertEquals(0.00000001, average.getAverage(), eps);
    assertEquals(0.44721, average.getStandardDeviation(), eps);
    assertEquals(2, average.getCount());
  }
View Full Code Here

TOP

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

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.