void setup(LongSet universe, Recommender rec, TestUser user) { allItems = LongUtils.packedSet(universe); testUser = user; recommender = rec; }
/** * Construct a new least-squares scorer. * * @param ubs the user biases * @param ibs the item biases * @param mean the global mean rating */ public LeastSquaresItemScorer(Long2DoubleMap ubs, Long2DoubleMap ibs, double mean) { this.userBiases = LongUtils.frozenMap(ubs); this.itemBiases = LongUtils.frozenMap(ibs); this.globalMean = mean; }
/** * Return a list that repeats a single object multiple times. * * @param obj The object. * @param n The size of the list. * @param <T> The type of list elements. * @return A list containing <var>obj</var> <var>n</var> times. */ public static <T> List<T> repeat(T obj, int n) { return new RepeatedList<>(obj, n); }
@Nonnull private Long2DoubleAccumulator newAccumulator() { Long2DoubleAccumulator accum; if (modelSize <= 0) { accum = new UnlimitedLong2DoubleAccumulator(); } else { accum = new TopNLong2DoubleAccumulator(modelSize); } return accum; }
/** * Pick a random subset of a set of items. * @param items The set of items to pick from. * @param n the number of items to select. * @return A random subset of `items` of size at most `n`. */ public LongSet pickRandom(Set<Long> items, int n) { return LongUtils.randomSubset(LongUtils.asLongSet(items), n, random); }
/** * Create a new sorted list accumulator. * @param n The number of results desired; negative for unlimited. * @return An accumulator accumulator. */ public static <T extends Comparable<? super T>> SortedListAccumulator<T> decreasing(int n) { if (n < 0) { return new Unlimited<T>(Ordering.<T>natural()); } else { return new TopN<T>(n, Ordering.<T>natural()); } }
private Object readResolve() throws ObjectStreamException { return new CompactableLongArrayList(storage); } }
private Object writeReplace() throws ObjectStreamException { if (fullImpl != null) { // just serialize the non-compact list return fullImpl; } else { // serialize the compact list in a proxy wrapper return new SerialProxy(compactImpl); } }
@Override public int getInt(int index) { checkIndex(index, startIndex, endIndex); return startIndex + index; }
private void ensureCanInsert(long val) { if (fullImpl == null && (val < Integer.MIN_VALUE || val > Integer.MAX_VALUE)) { decompact(); } }
public static LongList asLongList(List<Long> longs) { if (longs instanceof LongList) { return (LongList) longs; } else { return new LongListWrapper(longs); } }
/** * Compute the size of the intersection of two sets. * @param a The first set. * @param b The second set. * @return The size of the intersection of the two sets. */ public static int intersectSize(LongSortedSet a, LongSortedSet b) { return countCommonItems(a, b, -1); }
/** * Create a flyweight vector with a key set and value function. * @param keys The key set. * @param valueFunc Function to compute keys from values. * @return The flyweight map. */ public static Long2DoubleMap flyweightMap(LongSet keys, LongToDoubleFunction valueFunc) { return new FlyweightLong2DoubleMap(keys, valueFunc); }
/** * Wrap or cast a long-to-double map into Fastutil. * @param map The map. * @return A function backed by {@code map}, or {@code map} if it is a Fastutil map. */ public static Long2DoubleMap asLong2DoubleMap(final Map<Long,Double> map) { if (map instanceof Long2DoubleMap) { return (Long2DoubleMap) map; } else { return new Long2DoubleMapWrapper(map); } }
@Override public long[] toArray(long[] a) { return toLongArray(a); }
@Override public ObjectSet<Entry> long2DoubleEntrySet() { return new EntrySet(); }
@Override public Double getValue() { return getDoubleValue(); }
@Override public boolean remove(long k) { return super.rem(k); }
@Override public long[] toArray(long[] a) { return toLongArray(a); }
@Override public Long2DoubleMap truncate(Long2DoubleMap v) { return LongUtils.frozenMap(v); } }