@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)); }
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; }