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

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


    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

    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

    Iterable<? extends Preference> prefs = model.getPreferencesForItem("456");
    assertNotNull(prefs);
    Iterator<? extends Preference> it = prefs.iterator();
    assertNotNull(it);
    assertTrue(it.hasNext());
    Preference pref1 = it.next();
    assertEquals("A123", pref1.getUser().getID());
    assertEquals("456", pref1.getItem().getID());
    assertTrue(it.hasNext());
    Preference pref2 = it.next();
    assertEquals("D456", pref2.getUser().getID());
    assertEquals("456", pref2.getItem().getID());
    assertFalse(it.hasNext());
    try {
      it.next();
      fail("Should throw NoSuchElementException");
    } catch (NoSuchElementException nsee) {
View Full Code Here

    GenericDataModel dummy = new GenericDataModel(users);
    InverseUserFrequency iuf = new InverseUserFrequency(dummy, 10.0);

    User user = dummy.getUser("test5");
    for (int i = 0; i < 5; i++) {
      Preference pref = user.getPreferenceFor(String.valueOf(i));
      assertNotNull(pref);
      assertEquals(Math.log(5.0 / (double) (5 - i)) / Math.log(iuf.getLogBase()),
                   iuf.getTransformedValue(pref),
                   EPSILON);
    }
View Full Code Here

        // Then line is of form "userID,itemID,", meaning remove
        if (prefs != null) {
          // remove pref
          Iterator<Preference> prefsIterator = prefs.iterator();
          while (prefsIterator.hasNext()) {
            Preference pref = prefsIterator.next();
            if (pref.getItemID() == itemID) {
              prefsIterator.remove();
              break;
            }
          }
        }

        removeTimestamp(userID, itemID, timestamps);
       
      } else {

        float preferenceValue = Float.parseFloat(preferenceValueString);

        boolean exists = false;
        if (prefs != null) {
          for (Preference pref : prefs) {
            if (pref.getItemID() == itemID) {
              exists = true;
              pref.setValue(preferenceValue);
              break;
            }
          }
        }
View Full Code Here

      }
    }

    //merge this part into shuffle() will make compiler-optimizer do some real absurd stuff, test on OpenJDK7
    private void swapCachedPreferences(int x, int y) {
      Preference p = unstagedPreferences[x];

      unstagedPreferences[x] = unstagedPreferences[y];
      unstagedPreferences[y] = p;
    }
View Full Code Here

      List<Preference> prefs2 = Lists.newArrayListWithCapacity(prefs2Array.length());
      for (Preference pref : prefs2Array) {
        prefs2.add(pref);
      }
      for (Iterator<Preference> iterator = prefs2.iterator(); iterator.hasNext();) {
        Preference pref = iterator.next();
        if (relevantItemIDs.contains(pref.getItemID())) {
          iterator.remove();
        }
      }
      if (!prefs2.isEmpty()) {
        trainingUsers.put(otherUserID, new GenericUserPreferenceArray(prefs2));
View Full Code Here

  @Test
  public void testPreferencesForItem() throws Exception {
    PreferenceArray prefs = model.getPreferencesForItem(456);
    assertNotNull(prefs);
    Preference pref1 = prefs.get(0);
    assertEquals(123, pref1.getUserID());
    assertEquals(456, pref1.getItemID());
    Preference pref2 = prefs.get(1);
    assertEquals(456, pref2.getUserID());
    assertEquals(456, pref2.getItemID());
    assertEquals(2, prefs.length());
  }
View Full Code Here

TOP

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

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.