Package org.apache.mahout.cf.taste.model

Examples of org.apache.mahout.cf.taste.model.DataModel


    assertEquals(0.06666666666666668, average.getAverage(), EPSILON);
    assertEquals(3, average.getCount());
  }

  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


    assertEquals(2, firstRecommended.getItemID());
    assertEquals(0.3f, firstRecommended.getValue());
  }

  public void testHowMany() throws Exception {
    DataModel dataModel = getDataModel(
            new long[] {1, 2, 3, 4, 5},
            new Double[][] {
                    {0.1, 0.2},
                    {0.2, 0.3, 0.3, 0.6},
                    {0.4, 0.4, 0.5, 0.9},
View Full Code Here

      assertEquals(fewRecommended.get(i).getItemID(), moreRecommended.get(i).getItemID());
    }
  }

  public void testRescorer() throws Exception {
    DataModel dataModel = getDataModel(
            new long[] {1, 2, 3},
            new Double[][] {
                    {0.1, 0.2},
                    {0.2, 0.3, 0.3, 0.6},
                    {0.4, 0.4, 0.5, 0.9},
View Full Code Here

    assertEquals(2, similar[0]);
    assertEquals(4, similar[1]);
  }

  public void testIsolatedUser() throws Exception {
    DataModel dataModel = getDataModel(
            new long[] {1, 2, 3, 4},
            new Double[][] {
                    {0.1, 0.2},
                    {0.2, 0.3, 0.3, 0.6},
                    {0.4, 0.4, 0.5, 0.9},
View Full Code Here

    }
    return totalSimilarity == 0.0 ? Float.NaN : (float) (preference / totalSimilarity);
  }
 
  protected FastIDSet getAllOtherItems(long[] theNeighborhood, long theUserID) throws TasteException {
    DataModel dataModel = getDataModel();
    FastIDSet possibleItemIDs = new FastIDSet();
    for (long userID : theNeighborhood) {
      possibleItemIDs.addAll(dataModel.getItemIDsFromUser(userID));
    }
    possibleItemIDs.removeAll(dataModel.getItemIDsFromUser(theUserID));
    return possibleItemIDs;
  }
View Full Code Here

    // do nothing
  }
 
  public static void main(String... args) throws IOException, TasteException, OptionException {
    RecommenderEvaluator evaluator = new AverageAbsoluteDifferenceRecommenderEvaluator();
    DataModel model;
    File ratingsFile = TasteOptionParser.getRatings(args);
    if (ratingsFile != null) {
      model = new JesterDataModel(ratingsFile);
    } else {
      model = new JesterDataModel();
View Full Code Here

    // do nothing
  }
 
  public static void main(String... args) throws IOException, TasteException, OptionException {
    RecommenderEvaluator evaluator = new AverageAbsoluteDifferenceRecommenderEvaluator();
    DataModel model;
    File ratingsFile = TasteOptionParser.getRatings(args);
    if (ratingsFile != null) {
      model = new GroupLensDataModel(ratingsFile);
    } else {
      model = new GroupLensDataModel();
View Full Code Here

    // do nothing
  }
 
  public static void main(String... args) throws IOException, TasteException, OptionException {
    RecommenderEvaluator evaluator = new AverageAbsoluteDifferenceRecommenderEvaluator();
    DataModel model;
    File ratingsFile = TasteOptionParser.getRatings(args);
    if (ratingsFile != null) {
      model = new BookCrossingDataModel(ratingsFile, false);
    } else {
      model = new BookCrossingDataModel(false);
View Full Code Here

    int k = itemNeighborhood.length;
    double[][] A = new double[k][k];
    double[] b = new double[k];
    int i = 0;
   
    DataModel dataModel = getDataModel();
   
    int numUsers = getDataModel().getNumUsers();
    for (long iitem : itemNeighborhood) {
      PreferenceArray iPrefs = getDataModel().getPreferencesForItem(iitem);
      int iSize = iPrefs.length();
      int j = 0;
      for (long jitem : itemNeighborhood) {
        double value = 0.0;
        for (int pi = 0; pi < iSize; pi++) {
          long v = iPrefs.getUserID(pi);
          if (v == userID) {
            continue;
          }
          Float pj = dataModel.getPreferenceValue(userID, jitem);
          if (pj != null) {
            value += iPrefs.getValue(pi) * pj;
          }
        }
        A[i][j] = value / numUsers;
        j++;
      }
      i++;
    }
   
    PreferenceArray iPrefs = getDataModel().getPreferencesForItem(itemID);
    int iSize = iPrefs.length();
    i = 0;
    for (long jitem : itemNeighborhood) {
      double value = 0.0;
      for (int pi = 0; pi < iSize; pi++) {
        long v = iPrefs.getUserID(pi);
        if (v == userID) {
          continue;
        }
        Float pj = dataModel.getPreferenceValue(userID, jitem);
        if (pj != null) {
          value += iPrefs.getValue(pi) * pj;
        }
      }
      b[i] = value / numUsers;
View Full Code Here

  }
 
  @Override
  protected float doEstimatePreference(long theUserID, long itemID) throws TasteException {
   
    DataModel dataModel = getDataModel();
    PreferenceArray prefs = dataModel.getPreferencesFromUser(theUserID);
    int size = prefs.length();
    FastIDSet possibleItemIDs = new FastIDSet(size);
    for (int i = 0; i < size; i++) {
      possibleItemIDs.add(prefs.getItemID(i));
    }
    possibleItemIDs.remove(itemID);
   
    List<RecommendedItem> mostSimilar = mostSimilarItems(itemID, possibleItemIDs.iterator(),
      neighborhoodSize, null);
    long[] theNeighborhood = new long[mostSimilar.size()];
    int nOffset = 0;
    for (RecommendedItem rec : mostSimilar) {
      theNeighborhood[nOffset++] = rec.getItemID();
    }
   
    double[] weights = getInterpolations(itemID, theUserID, theNeighborhood);
   
    int i = 0;
    double preference = 0.0;
    double totalSimilarity = 0.0;
    for (long jitem : theNeighborhood) {
     
      Float pref = dataModel.getPreferenceValue(theUserID, jitem);
     
      if (pref != null) {
        preference += pref * weights[i];
        totalSimilarity += weights[i];
      }
View Full Code Here

TOP

Related Classes of org.apache.mahout.cf.taste.model.DataModel

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.