Refine search
LongRawValueBasedNotInPredicateEvaluator(NotInPredicate notInPredicate) { String[] values = notInPredicate.getValues(); _nonMatchingValues = new LongOpenHashSet(values.length); for (String value : values) { _nonMatchingValues.add(Long.parseLong(value)); } }
@Test public void testLongPredicateEvaluators() { List<String> stringValues = new ArrayList<>(NUM_PREDICATE_VALUES); LongSet valueSet = new LongOpenHashSet(); valueSet.add(value); Assert.assertEquals(inPredicateEvaluator.applySV(value), valueSet.contains(value)); Assert.assertEquals(notInPredicateEvaluator.applySV(value), !valueSet.contains(value));
@Override public DateTimeColumn unique() { LongSet ints = new LongOpenHashSet(data.size()); for (long i : data) { ints.add(i); } DateTimeColumn column = emptyCopy(ints.size()); column.setName(name() + " Unique values"); column.data = LongArrayList.wrap(ints.toLongArray()); return column; }
@Override public void seal() { sealed = true; sortedLongList = new long[rawLongSet.size()]; rawLongSet.toArray(sortedLongList); Arrays.sort(sortedLongList); if (sortedLongList.length == 0) { min = null; max = null; return; } // Update min/max based on raw docs. min = sortedLongList[0]; max = sortedLongList[sortedLongList.length - 1]; // Merge the raw and aggregated docs, so stats for dictionary creation are collected correctly. int numAggregated = aggregatedLongSet.size(); if (numAggregated > 0) { rawLongSet.addAll(aggregatedLongSet); sortedLongList = new long[rawLongSet.size()]; rawLongSet.toArray(sortedLongList); Arrays.sort(sortedLongList); } } }
@Override public int countUnique() { LongSet ints = new LongOpenHashSet(data.size()); for (long i : data) { ints.add(i); } return ints.size(); }
/** * 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(LongSet a, LongSet b) { if (a instanceof LongSortedSet && b instanceof LongSortedSet) { return intersectSize((LongSortedSet) a, (LongSortedSet) b); } else { int n = 0; LongIterator iter = a.iterator(); while (iter.hasNext()) { long x = iter.nextLong(); if (b.contains(x)) { n += 1; } } return n; } }
ratings = Long2DoubleMaps.EMPTY_MAP; LongSet allItems = new LongOpenHashSet(ratings.keySet()); allItems.addAll(items); while (iter.hasNext()) { final long item = iter.nextLong(); Double score = scores.get(item); if (score == null) {
/** * Get the IDs of the candidate neighbors for a user. * @param user The user. * @param userItems The user's rated items. * @param targetItems The set of target items. * @return The set of IDs of candidate neighbors. */ private LongSet findCandidateNeighbors(long user, LongSet userItems, LongCollection targetItems) { LongSet users = new LongOpenHashSet(100); LongIterator items; if (userItems.size() < targetItems.size()) { items = userItems.iterator(); } else { items = targetItems.iterator(); } while (items.hasNext()) { LongSet iusers = dao.query(CommonTypes.RATING) .withAttribute(CommonAttributes.ITEM_ID, items.nextLong()) .valueSet(CommonAttributes.USER_ID); if (iusers != null) { users.addAll(iusers); } } users.remove(user); return users; }
@Override public String get() { String name = fileName; logger.info("writing {}", name); File file = new File(workingDir, name); try (PrintWriter writer = new PrintWriter(file, CHARSET_UTF_8)) { LongIterator iter = identifiers.iterator(); while (iter.hasNext()) { writer.println(iter.nextLong()); } } catch (IOException e) { throw new ExternalProcessException("Error creating ratings file", e); } return name; } }
this.tempHashes[0].clear(); this.tempHashes[1].clear(); LongIterator chunkIterator = player.getConnection().getPlayerChunks().iterator(); while ( chunkIterator.hasNext() ) { this.tempHashes[0].add( chunkIterator.nextLong() ); chunkIterator = player.getConnection().getLoadingChunks().iterator(); while ( chunkIterator.hasNext() ) { this.tempHashes[0].add( chunkIterator.nextLong() ); if ( this.tempHashes[0].contains( entry.getLongKey() ) ) { continue; this.tempHashes[1].add( entry.getLongKey() ); if ( !this.tempHashes[1].isEmpty() ) { LongIterator toRemoveCursor = this.tempHashes[1].iterator(); while ( toRemoveCursor.hasNext() ) { this.cachedChunks.remove( toRemoveCursor.nextLong() );
/** * The set of items this user has *seen* in either training or test. * @return The set of all seen items (training and test). */ public LongSet getSeenItems() { if (seenItems == null) { LongSet items = new LongOpenHashSet(getTrainItems()); items.addAll(getTestItems()); seenItems = items; } return seenItems; }
int nexcl = 0; for (LongSet xs: exclude) { nexcl += xs.size(); mergedExclude = new LongOpenHashSet(); for (LongSet xs: exclude) { mergedExclude.addAll(xs); nexcl = mergedExclude.size(); long k = keys.getKey(nj >= 0 ? nj : j); if (mergedExclude != null) { good = !mergedExclude.contains(k); } else { good = true; for (LongSet xs: exclude) { good &= !xs.contains(k);
@Override public DateTimeColumn unique() { LongSet ints = new LongOpenHashSet(data.size()); for (long i : data) { ints.add(i); } return DateTimeColumn.create(name() + " Unique values", LongArrayList.wrap(ints.toLongArray())); }
LongSet candidates = new LongOpenHashSet(); LongSet excludes = new LongOpenHashSet(); candidates.add(rating.getItemId()); excludes.add(rating.getItemId()); excludes.addAll(dao.query(Rating.class) .withAttribute(CommonAttributes.USER_ID, rating.getUserId()) .valueSet(CommonAttributes.ITEM_ID)); candidates.addAll(LongUtils.randomSubset(dao.getEntityIds(CommonTypes.ITEM), listSize - 1, excludes, rng));
@Test public void testDotVectors() { for (Map<Long,Double> map: someMaps(longs(), doubles(-1000, 1000))) { Long2DoubleMap m = new Long2DoubleOpenHashMap(map); assertThat(Vectors.dotProduct(m, m), equalTo(Vectors.sumOfSquares(m))); if (!m.isEmpty()) { long k1 = m.keySet().iterator().nextLong(); double v1 = m.get(k1); Long2DoubleMap m2 = new Long2DoubleOpenHashMap(m); m2.remove(k1); long k2 = k1; // find a key we haven't seen yet while (m2.containsKey(k2) || k2 == k1) { k2++; } m2.put(k2, v1); // and test that it is missing from the dot product assertThat(Vectors.dotProduct(m, m2), closeTo(Vectors.sumOfSquares(m) - v1 * v1, 1.0e-6)); } } }
@Nonnull @Override public MetricResult measureUserRecList(Recommender rec, TestUser user, int targetLength, List<Long> recommendations, Context context) { LongSet good = goodItems.selectItems(context.universe, rec, user); if (good.isEmpty()) { logger.warn("no good items for user {}", user.getUserId()); } Integer rank = null; int i = 0; for (long item: recommendations) { i++; if (good.contains(item)) { rank = i; break; } } UserResult result = new UserResult(rank); context.addUser(result); return result.withSuffix(suffix); }
/** * Collect statistics for the given entry. * - Add it to the passed in set (which could be raw or aggregated) * - Update maximum number of values for Multi-valued entries * - Update Total number of entries * - Check if entry is sorted. * @param entry * @param set */ private void collectEntry(Object entry, LongSet set) { if (entry instanceof Object[]) { for (final Object e : (Object[]) entry) { set.add(((Number) e).longValue()); } if (maxNumberOfMultiValues < ((Object[]) entry).length) { maxNumberOfMultiValues = ((Object[]) entry).length; } updateTotalNumberOfEntries((Object[]) entry); } else { long value = ((Number) entry).longValue(); addressSorted(value); updatePartition(value); set.add(value); totalNumberOfEntries++; } }
public AdaptiveSparseItemIterator(ItemItemBuildContext context, LongSet users, long lowerBound) { this.context = context; this.users = users; this.lowerBound = lowerBound; if (lowerBound == Long.MIN_VALUE) { universeSize = context.getItems().size(); } else { // since universe size is only used for sparsity estimation, it is // fine to have an off-by-1 discrepancy between this & iterator behavior universeSize = context.getItems().tailSet(lowerBound).size(); } seen = new LongOpenHashSet(context.getItems().size()); userIter = users.iterator(); }
@Override public boolean applySV(long value) { return _matchingValues.contains(value); } }
@Override public Long2IntMap splitEntities(LongSet entities, int np, Random rng) { Long2IntMap emap = new Long2IntOpenHashMap(entities.size()); logger.info("Splitting {} entities into {} partitions", entities.size(), np); long[] array = entities.toLongArray(); LongArrays.shuffle(array, rng); for (int i = 0; i < array.length; i++) { final long user = array[i]; emap.put(user, i % np); } return emap; }