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

Examples of org.apache.mahout.cf.taste.impl.model.GenericPreference


   * @param item preferred {@link Item}
   * @param value preference value
   * @return {@link GenericPreference} by default
   */
  protected Preference buildPreference(User user, Item item, double value) {
    return new GenericPreference(user, item, value);
  }
View Full Code Here


  protected Item buildItem(String id) {
    return new GenericItem<String>(id);
  }

  protected Preference buildPreference(User user, Item item, double value) {
    return new GenericPreference(user, item, value);
  }
View Full Code Here

    double correlation = new EuclideanDistanceSimilarity(dataModel, Weighting.WEIGHTED).userSimilarity(user1, user2);
    assertCorrelationEquals(0.8081551272944483, correlation);
  }

  public void testNoCorrelation2() throws Exception {
    Preference pref1 = new GenericPreference(null, new GenericItem<String>("1"), 1.0);
    GenericUser<String> user1 = new GenericUser<String>("test1", Collections.singletonList(pref1));
    Preference pref2 = new GenericPreference(null, new GenericItem<String>("2"), 1.0);
    GenericUser<String> user2 = new GenericUser<String>("test2", Collections.singletonList(pref2));
    DataModel dataModel = getDataModel(user1, user2);
    double correlation = new EuclideanDistanceSimilarity(dataModel).userSimilarity(user1, user2);
    assertTrue(Double.isNaN(correlation));
  }
View Full Code Here

            new EuclideanDistanceSimilarity(dataModel).itemSimilarity(dataModel.getItem("0"), dataModel.getItem("1"));
    assertCorrelationEquals(0.424465381883345, correlation);
  }

  public void testNoItemCorrelation2() throws Exception {
    Preference pref1 = new GenericPreference(null, new GenericItem<String>("1"), 1.0);
    GenericUser<String> user1 = new GenericUser<String>("test1", Collections.singletonList(pref1));
    Preference pref2 = new GenericPreference(null, new GenericItem<String>("2"), 1.0);
    GenericUser<String> user2 = new GenericUser<String>("test2", Collections.singletonList(pref2));
    DataModel dataModel = getDataModel(user1, user2);
    double correlation =
            new EuclideanDistanceSimilarity(dataModel).itemSimilarity(dataModel.getItem("1"), dataModel.getItem("2"));
    assertTrue(Double.isNaN(correlation));
View Full Code Here

    double correlation = new PearsonCorrelationSimilarity(dataModel, Weighting.WEIGHTED).userSimilarity(user1, user2);
    assertCorrelationEquals(-1.0, correlation);
  }

  public void testNoCorrelation2() throws Exception {
    Preference pref1 = new GenericPreference(null, new GenericItem<String>("1"), 1.0);
    GenericUser<String> user1 = new GenericUser<String>("test1", Collections.singletonList(pref1));
    Preference pref2 = new GenericPreference(null, new GenericItem<String>("2"), 1.0);
    GenericUser<String> user2 = new GenericUser<String>("test2", Collections.singletonList(pref2));
    DataModel dataModel = getDataModel(user1, user2);
    double correlation = new PearsonCorrelationSimilarity(dataModel).userSimilarity(user1, user2);
    assertTrue(Double.isNaN(correlation));
  }
View Full Code Here

            new PearsonCorrelationSimilarity(dataModel).itemSimilarity(dataModel.getItem("0"), dataModel.getItem("1"));
    assertCorrelationEquals(-1.0, correlation);
  }

  public void testNoItemCorrelation2() throws Exception {
    Preference pref1 = new GenericPreference(null, new GenericItem<String>("1"), 1.0);
    GenericUser<String> user1 = new GenericUser<String>("test1", Collections.singletonList(pref1));
    Preference pref2 = new GenericPreference(null, new GenericItem<String>("2"), 1.0);
    GenericUser<String> user2 = new GenericUser<String>("test2", Collections.singletonList(pref2));
    DataModel dataModel = getDataModel(user1, user2);
    double correlation =
            new PearsonCorrelationSimilarity(dataModel).itemSimilarity(dataModel.getItem("1"), dataModel.getItem("2"));
    assertTrue(Double.isNaN(correlation));
View Full Code Here

  public static User getUser(String userID, Double... values) {
    List<Preference> prefs = new ArrayList<Preference>(values.length);
    int i = 0;
    for (Double value : values) {
      if (value != null) {
        prefs.add(new GenericPreference(null, new GenericItem<String>(String.valueOf(i)), value));
      }
      i++;
    }
    return new GenericUser<String>(userID, prefs);
  }
View Full Code Here

    List<User> users = new ArrayList<User>(NUM_USERS);
    for (int i = 0; i < NUM_USERS; i++) {
      int numPrefs = random.nextInt(NUM_PREFS) + 1;
      List<Preference> prefs = new ArrayList<Preference>(numPrefs);
      for (int j = 0; j < numPrefs; j++) {
        prefs.add(new GenericPreference(null, items.get(random.nextInt(NUM_ITEMS)), random.nextDouble()));
      }
      GenericUser<String> user = new GenericUser<String>(String.valueOf(i), prefs);
      users.add(user);
    }
View Full Code Here

  }

  // Some overrideable methods to customize the class behavior:

  protected Preference buildPreference(ResultSet rs) throws SQLException {
    return new GenericPreference(getLongColumn(rs, 1), getLongColumn(rs, 2), rs.getFloat(3));
  }
View Full Code Here

        if (!exists) {
          if (prefs == null) {
            prefs = Lists.newArrayListWithCapacity(2);
            ((FastByIDMap<Collection<Preference>>) data).put(userID, prefs);
          }
          prefs.add(new GenericPreference(userID, itemID, preferenceValue));
        }

        addTimestamp(userID, itemID, timestampString, timestamps);

      }
View Full Code Here

TOP

Related Classes of org.apache.mahout.cf.taste.impl.model.GenericPreference

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.