コード例 #1
0
  @Test
  public void itShouldDecompressLists() throws IOException {
    final Input input =
        getInput(
            "1 1 01101 00101 0101 01100 1"
                + "0100 1 1 1 01101 00001 1 1 00100011"
                + "0101 1 1 1 1"
                + "1 0100 00001 001000111"
                + "0101 1 1 1 1"
                + "01101 0101 0 0101 01100 1 1");
    final PebbleOffsetsStore offsetsStore =
        new LongListPebbleOffsetsStore(new long[] {0L, 22L, 49L, 57L, 76L, 84L});
    final PebbleBytesStore bytesStore = new BytesArrayPebbleBytesStore(input.buffer, offsetsStore);
    final int valueBitSize = 5;
    final LongList[] expectedLists =
        new LongList[] {
          new LongArrayList(new long[] {5L, 8L, 12L, 13L}),
          new LongArrayList(new long[] {1L, 2L, 3L, 5L, 8L, 12L, 13L, 14L}),
          new LongArrayList(new long[] {5L, 8L, 12L, 13L}),
          new LongArrayList(
              new long[] {1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L}),
          new LongArrayList(new long[] {5L, 8L, 12L, 13L}),
          new LongArrayList(new long[] {5L, 8L, 12L, 13L})
        };
    final LongList[] lists = new LongList[expectedLists.length];
    LongList list;
    LongIterator iterator;

    for (int i = 0; i < lists.length; i++) {
      iterator = StrictlyIncrementalListIterator.build(i, valueBitSize, bytesStore);
      lists[i] = list = new LongArrayList();
      while (iterator.hasNext()) {
        list.add(iterator.nextLong());
      }
    }

    assertEquals(
        Helper.<Long, LongList>translateToUtilsCollection(expectedLists),
        Helper.<Long, LongList>translateToUtilsCollection(lists));
  }
コード例 #2
0
  public double measureUser(
      TestUser user, MeanAccumulator context, List<ScoredId> recommendations, int listSize) {
    if (recommendations.size() > listSize) {
      recommendations = new ArrayList<ScoredId>(recommendations.subList(0, listSize));
    }
    SparseVector ratings = user.getTestRatings();
    LongList ideal = ratings.keysByValue(true);
    if (ideal.size() > listSize) {
      ideal = ideal.subList(0, listSize);
    }
    double idealGain = computeDCG(ideal, ratings);

    LongList actual = new LongArrayList(recommendations.size());
    for (ScoredId id : recommendations) {
      actual.add(id.getId());
    }
    double gain = computeDCG(actual, ratings);

    double score = gain / idealGain;

    context.add(score);
    return score;
  }
コード例 #3
0
  /** Compute the DCG of a list of items with respect to a value vector. */
  static double computeDCG(LongList items, SparseVector values) {
    final double lg2 = log(2);

    double gain = 0;
    int rank = 0;

    LongIterator iit = items.iterator();
    while (iit.hasNext()) {
      final long item = iit.nextLong();
      final double v = values.get(item, 0);
      rank++;
      if (rank < 2) {
        gain += v;
      } else {
        gain += v * lg2 / log(rank);
      }
    }

    return gain;
  }
コード例 #4
0
 private static void doSwap(LongList longs, int i, int j) {
   longs.set(i, longs.set(j, longs.get(i)));
 }