public static HashKeyIndex create() { return new HashKeyIndex(); }
PackedRatingDataBuilder() { itemIndex = new HashKeyIndex(); userIndex = new HashKeyIndex(); freeList = new IntHeapPriorityQueue(); allocate(INITIAL_CHUNK_COUNT); }
/** * Create a new key index. * * @param keys The keys. * @return A key index containing the elements of {@code keys}. */ public static FrozenHashKeyIndex create(LongCollection keys) { if (keys instanceof LongList) { return create((LongList) keys); } else { HashKeyIndex index = new HashKeyIndex(); LongIterator iter = keys.iterator(); while (iter.hasNext()) { index.internId(iter.nextLong()); } return index.frozenCopy(); } }
@Test public void testReinternId() { HashKeyIndex idx = new HashKeyIndex(); assertThat(idx.internId(42), equalTo(0)); assertThat(idx.internId(39), equalTo(1)); assertThat(idx.internId(42), equalTo(0)); }
@Test public void testImmutableCopy() { HashKeyIndex idx = new HashKeyIndex(); assertThat(idx.internId(42), equalTo(0)); assertThat(idx.internId(39), equalTo(1)); KeyIndex imm = idx.frozenCopy(); assertThat(imm.getKey(0), equalTo(42L)); assertThat(imm.getKey(1), equalTo(39L)); assertThat(imm.getIndex(42), equalTo(0)); } }
public static HashKeyIndex create() { return new HashKeyIndex(); }
@Test public void testInternId() { HashKeyIndex idx = new HashKeyIndex(); assertThat(idx.size(), equalTo(0)); assertThat(idx.tryGetIndex(42), lessThan(0)); assertThat(idx.internId(42), equalTo(0)); assertThat(idx.getKey(0), equalTo(42L)); assertThat(idx.tryGetIndex(42), equalTo(0)); }
@Test public void testFromArray() { HashKeyIndex map = new HashKeyIndex(); map.internId(42); map.internId(37); map.internId(62); double[] values = { 3.5, 4.9, 1.8 }; Long2DoubleMap res = Long2DoubleSortedArrayMap.fromArray(map, values); assertThat(res.size(), equalTo(3)); assertThat(res.keySet(), contains(37L, 42L, 62L)); assertThat(res, hasEntry(37L, 4.9)); assertThat(res, hasEntry(42L, 3.5)); assertThat(res, hasEntry(62L, 1.8)); }
PackedRatingDataBuilder() { itemIndex = new HashKeyIndex(); userIndex = new HashKeyIndex(); freeList = new IntHeapPriorityQueue(); allocate(INITIAL_CHUNK_COUNT); }
@Override public RatingSummary get() { HashKeyIndex index = new HashKeyIndex(); DoubleArrayList sums = new DoubleArrayList(); IntArrayList counts = new IntArrayList();
@Before public void createModel() { baseline = PrecomputedItemScorer.newBuilder() .addScore(1, 42, 3.0) .addScore(1, 39, 2.5) .addScore(1, 25, 4.2) .addScore(5, 42, 3.7) .addScore(5, 39, 2.8) .addScore(3, 42, 2.2) .addScore(3, 39, 3.2) .addScore(17, 42, 2.5) .build(); RealMatrix umat = MatrixUtils.createRealMatrix(3, 2); umat.setRow(0, new double[]{0.1, 0.3}); umat.setRow(1, new double[]{-0.2, 0.2}); umat.setRow(2, new double[]{0.0, 0.15}); HashKeyIndex uidx = new HashKeyIndex(); uidx.internId(1); uidx.internId(5); uidx.internId(3); RealMatrix imat = MatrixUtils.createRealMatrix(2, 2); imat.setRow(0, new double[]{0.52, 0.29}); imat.setRow(1, new double[]{0.3, -1.2}); HashKeyIndex iidx = new HashKeyIndex(); iidx.internId(42); iidx.internId(39); model = new MFModel(umat, imat, uidx, iidx); // scorer = new BiasedMFItemScorer(model, baseline); }
/** * Create a new key index. * * @param keys The keys. * @return A key index containing the elements of {@code keys}. */ public static FrozenHashKeyIndex create(LongCollection keys) { if (keys instanceof LongList) { return create((LongList) keys); } else { HashKeyIndex index = new HashKeyIndex(); LongIterator iter = keys.iterator(); while (iter.hasNext()) { index.internId(iter.nextLong()); } return index.frozenCopy(); } }
@Override public RatingSummary get() { HashKeyIndex index = new HashKeyIndex(); DoubleArrayList sums = new DoubleArrayList(); IntArrayList counts = new IntArrayList();