Java Code Examples for it.unimi.dsi.fastutil.longs.LongArrayList#getLong()

The following examples show how to use it.unimi.dsi.fastutil.longs.LongArrayList#getLong() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RecentlyClickedPostFiltering.java    From StreamingRec with Apache License 2.0 6 votes vote down vote up
@Override
public LongArrayList recommendInternal(ClickData clickData) {
	//filter out items that have not received at last one click in the last time frame
	//first, retrieve the recommendation results of the underlying algorithm
	LongArrayList rec = mainStrategy.recommendInternal(clickData);
	
	//create lists of filtered items and retained items
	LongArrayList filteredRec = new LongArrayList();
	LongArrayList filteredRecNotMatch = new LongArrayList();
	//iterate over the recommendation list of the underlying strategy
	for (int j = 0; j < rec.size(); j++) {
		long i = rec.getLong(j);
		//filter items whose last-clicked timestamp is too old
		if ((itemClickTime.containsKey(i)) && ((clickData.click.timestamp.getTime()-itemClickTime.get(i))<filterTime)) {
			filteredRec.add(i);
		} else if (fallback) {
			//if we have a fallback, add the filtered item to the fallback list
			filteredRecNotMatch.add(i);
		}
	}
	//merge the filtered list with the fallback list (empty in case fallback==false)
	filteredRec.addAll(filteredRecNotMatch);
	//return the filtered list
	return filteredRec;
}
 
Example 2
Source File: PopularityPostFiltering.java    From StreamingRec with Apache License 2.0 6 votes vote down vote up
@Override
public LongArrayList recommendInternal(ClickData clickData) {
	//filter out items with low overall click counts
	//first, retrieve the recommendation results of the underlying algorithm
	LongArrayList rec = mainStrategy.recommendInternal(clickData);
	
	//create lists of filtered items and retained items
	LongArrayList filteredRec = new LongArrayList();
	LongArrayList filteredRecNotMatch = new LongArrayList();
	//iterate over the recommendation list of the underlying strategy
	for (int j = 0; j < rec.size(); j++) {
		long i = rec.getLong(j);
		//filter items if they do not have enough clicks
		if ((itemClickCount.containsKey(i)) && (itemClickCount.get(i) >= minClickCount)) {
			filteredRec.add(i);
		} else if (fallback) {
			//if we have a fallback, add the filtered item to the fallback list
			filteredRecNotMatch.add(i);
		}
	}
	//merge the filtered list with the fallback list (empty in case fallback==false)
	filteredRec.addAll(filteredRecNotMatch);
	//return the filtered list
	return filteredRec;
}
 
Example 3
Source File: MRR.java    From StreamingRec with Apache License 2.0 5 votes vote down vote up
@Override
public void evaluate(Transaction transaction, LongArrayList recommendations,
		LongOpenHashSet userTransactions) {
	//if there is no ground truth, there is nothing to evaluate
	if (userTransactions == null || userTransactions.isEmpty()) {
		return;
	}
	
	// if the algorithm does not return any recommendations, count it as 0
	if (recommendations.isEmpty()) {
		results.add(0);
		return;
	}

	// calculate the MRR
	// if the algorithm retrieves less than k recommendations, we calculate
	// the real k value for this case
	int realK = Math.min(k, recommendations.size());
	// iterate over relevant items and calculate recall rank
	for (Long itemID : userTransactions) {
		for (int i = 0; i < realK; i++) {
			if (itemID == recommendations.getLong(i)) {
				results.add(1d/(i+1));
				return;
			}
		}
	}
	//nothing found -> count as zero
	results.add(0);
}
 
Example 4
Source File: RecencyPostFiltering.java    From StreamingRec with Apache License 2.0 5 votes vote down vote up
@Override
public LongArrayList recommendInternal(ClickData clickData) {
	//filter out items that have been release too long ago
	//first, retrieve the recommendation results of the underlying algorithm
	LongArrayList rec = mainStrategy.recommendInternal(clickData);
	
	//create lists of filtered items and retained items
	LongArrayList filteredRec = new LongArrayList();
	LongArrayList filteredRecNotMatch = new LongArrayList();
	//iterate over the recommendation list of the underlying strategy
	for (int j = 0; j < rec.size(); j++) {
		long i = rec.getLong(j);
		// filter item based on the difference between the current (simulation) time and
		// the time of publication
		if ((clickData.click.timestamp.getTime() - timestampMap.get(i)) <= filterTime
				&& (clickData.click.timestamp.getTime() - timestampMap.get(i)) > 0) {
			filteredRec.add(i);
		} else if (fallback) {
			//if we have a fallback, add the filtered item to the fallback list
			filteredRecNotMatch.add(i);
		}
	}
	//merge the filtered list with the fallback list (empty in case fallback==false)
	filteredRec.addAll(filteredRecNotMatch);
	//return the filtered list
	return filteredRec;

}
 
Example 5
Source File: PagesSpatialIndexSupplier.java    From presto with Apache License 2.0 4 votes vote down vote up
private static STRtree buildRTree(LongArrayList addresses, List<List<Block>> channels, int geometryChannel, Optional<Integer> radiusChannel, Optional<Integer> partitionChannel)
{
    STRtree rtree = new STRtree();
    Operator relateOperator = OperatorFactoryLocal.getInstance().getOperator(Operator.Type.Relate);

    for (int position = 0; position < addresses.size(); position++) {
        long pageAddress = addresses.getLong(position);
        int blockIndex = decodeSliceIndex(pageAddress);
        int blockPosition = decodePosition(pageAddress);

        Block block = channels.get(geometryChannel).get(blockIndex);
        // TODO Consider pushing is-null and is-empty checks into a filter below the join
        if (block.isNull(blockPosition)) {
            continue;
        }

        Slice slice = block.getSlice(blockPosition, 0, block.getSliceLength(blockPosition));
        OGCGeometry ogcGeometry = deserialize(slice);
        verifyNotNull(ogcGeometry);
        if (ogcGeometry.isEmpty()) {
            continue;
        }

        double radius = radiusChannel.map(channel -> DOUBLE.getDouble(channels.get(channel).get(blockIndex), blockPosition)).orElse(0.0);
        if (radius < 0) {
            continue;
        }

        if (radiusChannel.isEmpty()) {
            // If radiusChannel is supplied, this is a distance query, for which our acceleration won't help.
            accelerateGeometry(ogcGeometry, relateOperator);
        }

        int partition = -1;
        if (partitionChannel.isPresent()) {
            Block partitionBlock = channels.get(partitionChannel.get()).get(blockIndex);
            partition = toIntExact(INTEGER.getLong(partitionBlock, blockPosition));
        }

        rtree.insert(getEnvelope(ogcGeometry, radius), new GeometryWithPosition(ogcGeometry, partition, position));
    }

    rtree.build();
    return rtree;
}
 
Example 6
Source File: PrecisionOrRecall.java    From StreamingRec with Apache License 2.0 4 votes vote down vote up
public void evaluate(Transaction transaction, LongArrayList recommendations, LongOpenHashSet userTransactions) {
	//if there is no ground truth, there is nothing to evaluate
	if (userTransactions == null || userTransactions.isEmpty()) {
		return;
	}
	// if the algorithm does not return any recommendations, count it as 0
	if (recommendations.isEmpty()) {
		results.add(0);
		return;
	}

	// if the algorithm retrieves less than k recommendations, we calculate
	// the real k value for this case
	int realK = Math.min(k, recommendations.size());

	// check duplicates
	LongOpenHashSet uniqueRecs = new LongOpenHashSet();
	for (int i = 0; i < realK; i++) {
		if (!uniqueRecs.add(recommendations.getLong(i))) {
			throw new RuntimeException("Duplicate recommendation.");
		}
	}

	// calculate the precision
	double result = 0;
	// iterate over relevant items and recommendations to calculate the
	// intersection
	for (LongIterator iterator = userTransactions.iterator(); iterator.hasNext();) {
		long itemID = iterator.nextLong();
		for (int i = 0; i < realK; i++) {
			if (itemID == recommendations.getLong(i)) {
				result++;
			}
		}
	}

	//determine the divider of the fraction (different for precision and recall)
	double divider;
	if(type == Type.Precision){
		divider = realK;
	}else if(type == Type.Recall){
		divider = userTransactions.size();
	}else{
		throw new RuntimeException("Neither precision nor recall defined.");
	}
	// store the precision/Recall
	results.add(result / divider);
}
 
Example 7
Source File: TransactionManager.java    From phoenix-tephra with Apache License 2.0 4 votes vote down vote up
private void doCommit(long transactionId, long writePointer, ChangeSet changes, long commitPointer,
                      boolean addToCommitted) {
  // In case this method is called when loading a previous WAL, we need to remove the tx from these sets
  committingChangeSets.remove(transactionId);
  if (addToCommitted && !changes.getChangeIds().isEmpty()) {
    // No need to add empty changes to the committed change sets, they will never trigger any conflict

    // Record the committed change set with the next writePointer as the commit time.
    // NOTE: we use current next writePointer as key for the map, hence we may have multiple txs changesets to be
    //       stored under one key
    ChangeSet committed = committedChangeSets.get(commitPointer);
    if (committed != null) {
      // NOTE: we modify the new set to prevent concurrent modification exception, as other threads (e.g. in
      // canCommit) use it unguarded
      changes.getChangeIds().addAll(committed.getChangeIds());
    }
    committedChangeSets.put(commitPointer, changes);
  }
  // remove from in-progress set, so that it does not get excluded in the future
  InProgressTx previous = inProgress.remove(transactionId);
  if (previous == null) {
    // tx was not in progress! perhaps it timed out and is invalid? try to remove it there.
    if (invalidTxList.remove(transactionId)) {
      LOG.info("Tx invalid list: removed committed tx {}", transactionId);
    }
  } else {
    LongArrayList checkpointPointers = previous.getCheckpointWritePointers();
    if (!checkpointPointers.isEmpty()) {
      // adjust the write pointer to be the last checkpoint of the tx and remove all checkpoints from inProgress
      writePointer = checkpointPointers.getLong(checkpointPointers.size() - 1);
      inProgress.keySet().removeAll(previous.getCheckpointWritePointers());
    }
  }
  // moving read pointer
  moveReadPointerIfNeeded(writePointer);

  // All committed change sets that are smaller than the earliest started transaction can be removed.
  // here we ignore transactions that have no timeout, they are long-running and don't participate in
  // conflict detection.
  // TODO: for efficiency, can we do this once per-log in replayLogs instead of once per edit?
  committedChangeSets.headMap(TxUtils.getFirstShortInProgress(inProgress)).clear();
}