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

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


    return recommendations;
  }

  public static void main(String[] args) throws Exception {
    PreferenceArray anonymousPrefs =
        new GenericUserPreferenceArray(3);
    anonymousPrefs.setUserID(0,
        PlusAnonymousUserDataModel.TEMP_USER_ID);
    anonymousPrefs.setItemID(0, 123L);
    anonymousPrefs.setValue(0, 1.0f);
    anonymousPrefs.setItemID(1, 123L);
    anonymousPrefs.setValue(1, 3.0f);
    anonymousPrefs.setItemID(2, 123L);
    anonymousPrefs.setValue(2, 2.0f);
    LibimsetiWithAnonymousRecommender recommender =
        new LibimsetiWithAnonymousRecommender();
    List<RecommendedItem> recommendations =
        recommender.recommend(anonymousPrefs, 10);
    System.out.println(recommendations);
View Full Code Here


  }

  public static void main(String[] args) {
    FastByIDMap<PreferenceArray> preferences =
      new FastByIDMap<PreferenceArray>();
    PreferenceArray prefsForUser1 = new GenericUserPreferenceArray(10);
    prefsForUser1.setUserID(0, 1L);
    prefsForUser1.setItemID(0, 101L);
    prefsForUser1.setValue(0, 3.0f);
    prefsForUser1.setItemID(1, 102L);
    prefsForUser1.setValue(1, 4.5f);

    preferences.put(1L, prefsForUser1);

    DataModel model = new GenericDataModel(preferences);
    System.out.println(model);
View Full Code Here

  private CreatePreferenceArray() {
  }

  public static void main(String[] args) {
    PreferenceArray user1Prefs = new GenericUserPreferenceArray(2);
    user1Prefs.setUserID(0, 1L);
    user1Prefs.setItemID(0, 101L);
    user1Prefs.setValue(0, 2.0f);
    user1Prefs.setItemID(1, 102L);
    user1Prefs.setValue(1, 3.0f);
    Preference pref = user1Prefs.get(1);
    System.out.println(pref);
  }
View Full Code Here

        }
        testPrefs.add(newPref);
      }
    }
    if (trainingPrefs != null) {
      trainingUsers.put(userID, new GenericUserPreferenceArray(trainingPrefs));
      if (testPrefs != null) {
        testUserPrefs.put(userID, new GenericUserPreferenceArray(testPrefs));
      }
    }
  }
View Full Code Here

        if (relevantItemIDs.contains(pref.getItemID())) {
          iterator.remove();
        }
      }
      if (!prefs2.isEmpty()) {
        trainingUsers.put(userID2, new GenericUserPreferenceArray(prefs2));
      }
    } else {
      trainingUsers.put(userID2, prefs2Array);
    }
  }
View Full Code Here

        if (prefValues[i][j] != null) {
          prefsList.add(new GenericPreference(userIDs[i], j, prefValues[i][j].floatValue()));
        }
      }
      if (!prefsList.isEmpty()) {
        result.put(userIDs[i], new GenericUserPreferenceArray(prefsList));
      }
    }
    return new GenericDataModel(result);
  }
View Full Code Here

  private DataModel createModel() {
    FastByIDMap<PreferenceArray> data = new FastByIDMap<PreferenceArray>(NUM_USERS);
    for (int i = 0; i < NUM_USERS; i++) {
      int numPrefs = random.nextInt(NUM_PREFS) + 1;
      PreferenceArray prefs = new GenericUserPreferenceArray(numPrefs);
      for (int j = 0; j < numPrefs; j++) {
        prefs.set(j, new GenericPreference(i, random.nextInt(NUM_ITEMS), random.nextFloat()));
      }
      data.put(i, prefs);
    }
    return new GenericDataModel(data);
  }
View Full Code Here

          }
          if (exists) {
            if (length == 1) {
              data.remove(userID);
            } else {
              PreferenceArray newPrefs = new GenericUserPreferenceArray(length - 1);
              for (int i = 0, j = 0; i < length; i++, j++) {
                if (prefs.getItemID(i) == itemID) {
                  j--;
                } else {
                  newPrefs.set(j, prefs.get(i));
                }
              }
            }
          }
        }
       
      } else {
       
        float preferenceValue = Float.parseFloat(preferenceValueString);
       
        boolean exists = false;
        if (prefs != null) {
          for (int i = 0; i < prefs.length(); i++) {
            if (prefs.getItemID(i) == itemID) {
              exists = true;
              prefs.setValue(i, preferenceValue);
              break;
            }
          }
        }
       
        if (!exists) {
          if (prefs == null) {
            prefs = new GenericUserPreferenceArray(1);
            ((FastByIDMap<PreferenceArray>) data).put(userID, prefs);
          } else {
            PreferenceArray newPrefs = new GenericUserPreferenceArray(prefs.length() + 1);
            for (int i = 0, j = 1; i < prefs.length(); i++, j++) {
              newPrefs.set(j, prefs.get(i));
            }
          }
          prefs.setUserID(0, userID);
          prefs.setItemID(0, itemID);
          prefs.setValue(0, preferenceValue);
View Full Code Here

     
      if (prefs.isEmpty()) {
        throw new NoSuchUserException();
      }
     
      return new GenericUserPreferenceArray(prefs);
     
    } catch (SQLException sqle) {
      log.warn("Exception while retrieving user", sqle);
      throw new TasteException(sqle);
    } finally {
View Full Code Here

      List<Preference> currentPrefs = new ArrayList<Preference>();
      while (rs.next()) {
        long nextUserID = getLongColumn(rs, 1);
        if ((currentUserID != null) && !currentUserID.equals(nextUserID)) {
          if (!currentPrefs.isEmpty()) {
            result.put(currentUserID, new GenericUserPreferenceArray(currentPrefs));
            currentPrefs.clear();
          }
        } else {
          currentPrefs.add(buildPreference(rs));
        }
        currentUserID = nextUserID;
      }
      if (!currentPrefs.isEmpty()) {
        result.put(currentUserID, new GenericUserPreferenceArray(currentPrefs));
      }
     
      return result;
     
    } catch (SQLException sqle) {
View Full Code Here

TOP

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

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.