Пример #1
0
  private static double[] doTestRandomVecs(LongObjectMap<float[]> Y, float[] userVec) {

    LocationSensitiveHash lsh = new LocationSensitiveHash(Y, 0.1, 20);

    LongSet candidates = new LongSet();
    float[][] userVecs = {userVec};
    for (Iterator<LongObjectMap.MapEntry<float[]>> candidatesIterator :
        lsh.getCandidateIterator(userVecs)) {
      while (candidatesIterator.hasNext()) {
        candidates.add(candidatesIterator.next().getKey());
      }
    }

    List<Long> topIDs = findTopRecommendations(Y, userVec);

    double score = 0.0;
    double maxScore = 0.0;
    int intersectionSize = 0;
    for (int i = 0; i < topIDs.size(); i++) {
      double value = LN2 / Math.log(2.0 + i);
      long id = topIDs.get(i);
      if (candidates.contains(id)) {
        intersectionSize++;
        score += value;
      }
      maxScore += value;
    }

    double percentTopRecsConsidered = (double) intersectionSize / topIDs.size();
    double ndcg = maxScore == 0.0 ? 0.0 : score / maxScore;
    double percentAllItemsConsidered = (double) candidates.size() / Y.size();

    return new double[] {percentTopRecsConsidered, ndcg, percentAllItemsConsidered};
  }
Пример #2
0
 public int size() {
   return reverseMapping.size();
 }