Examples of GenericPreference


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

                              User user) {
    List<Preference> trainingPrefs = new ArrayList<Preference>();
    List<Preference> testPrefs = new ArrayList<Preference>();
    Preference[] prefs = user.getPreferencesAsArray();
    for (Preference pref : prefs) {
      Preference newPref = new GenericPreference(null, pref.getItem(), pref.getValue());
      if (random.nextDouble() < trainingPercentage) {
        trainingPrefs.add(newPref);
      } else {
        testPrefs.add(newPref);
      }
View Full Code Here

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

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

  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

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

    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

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

            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

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

    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

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

            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

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

  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

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

    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

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

  }

  // 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
TOP
Copyright © 2018 www.massapi.com. 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.