Package net.myrrix.common.collection

Examples of net.myrrix.common.collection.FastIDSet$KeyIterator


    Arrays.sort(keysArray);
    return keysArray;
  }

  private static long[] unionColumnKeysInOrder(FastByIDMap<FastByIDFloatMap> M) {
    FastIDSet keys = new FastIDSet(1000);
    for (FastByIDMap.MapEntry<FastByIDFloatMap> entry : M.entrySet()) {
      LongPrimitiveIterator it = entry.getValue().keySetIterator();
      while (it.hasNext()) {
        keys.add(it.nextLong());
      }
    }
    long[] keysArray = keys.toArray();
    Arrays.sort(keysArray);
    return keysArray;
  }
View Full Code Here


  private static double[] doTestRandomVecs(FastByIDMap<float[]> Y, float[] userVec) {

    CandidateFilter lsh = new LocationSensitiveHash(Y);

    FastIDSet candidates = new FastIDSet();
    float[][] userVecs = { userVec };
    for (Iterator<FastByIDMap.MapEntry<float[]>> candidatesIterator : lsh.getCandidateIterator(userVecs)) {
      while (candidatesIterator.hasNext()) {
        candidates.add(candidatesIterator.next().getKey());
      }
    }

    List<Long> topIDs = findTopRecommendations(Y, userVec);

    double score = 0.0;
    double maxScore = 0.0;
    int intersectionSize = 0;
    for (int i = 0; i < topIDs.size(); i++) {
      double value = LN2 / Math.log(2.0 + i);
      long id = topIDs.get(i);
      if (candidates.contains(id)) {
        intersectionSize++;
        score += value;
      }
      maxScore += value;
    }

    double percentTopRecsConsidered = (double) intersectionSize / topIDs.size();
    double ndcg = maxScore == 0.0 ? 0.0 : score / maxScore;
    double percentAllItemsConsidered = (double) candidates.size() / Y.size();

    return new double[] {percentTopRecsConsidered, ndcg, percentAllItemsConsidered};
  }
View Full Code Here

    return true;
  }

  @Override
  public FastIDSet getAllUserIDs() throws TasteException {
    FastIDSet result = new FastIDSet();
    int numPartitions = partitions.size();
    for (int i = 0; i < numPartitions; i++) {
      getAllIDsFromPartition(i, true, result);
    }
    return result;
View Full Code Here

  @Override
  public FastIDSet getAllItemIDs() throws TasteException {
    // Yes, loop over all partitions. Most item IDs will be returned from all partitions but it's
    // possible for some to exist only on a few.
    FastIDSet result = new FastIDSet();
    int numPartitions = partitions.size();
    for (int i = 0; i < numPartitions; i++) {
      getAllIDsFromPartition(i, false, result);
    }
    return result;
View Full Code Here

      HttpURLConnection connection = null;
      try {
        connection = buildConnectionToReplica(replica, urlPath, "GET");
        switch (connection.getResponseCode()) {
          case HttpURLConnection.HTTP_OK:
            FastIDSet members = new FastIDSet();
            consumeIDs(connection, members);
            return members;          case HttpURLConnection.HTTP_NOT_IMPLEMENTED:
            throw new UnsupportedOperationException();
          case HttpURLConnection.HTTP_UNAVAILABLE:
            throw new NotReadyException();
View Full Code Here

    if (pathInfo == null) {
      response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No path");
      return;
    }
    Iterator<String> pathComponents = SLASH.split(pathInfo).iterator();
    FastIDSet userIDSet = new FastIDSet();
    try {
      while (pathComponents.hasNext()) {
        userIDSet.add(Long.parseLong(pathComponents.next()));
      }
    } catch (NoSuchElementException nsee) {
      response.sendError(HttpServletResponse.SC_BAD_REQUEST, nsee.toString());
      return;
    } catch (NumberFormatException nfe) {
      response.sendError(HttpServletResponse.SC_BAD_REQUEST, nfe.toString());
      return;
    }

    long[] userIDs = userIDSet.toArray();

    MyrrixRecommender recommender = getRecommender();
    RescorerProvider rescorerProvider = getRescorerProvider();
    try {
      IDRescorer rescorer = rescorerProvider == null ? null :
View Full Code Here

        } catch (NumberFormatException nfe) {
          response.sendError(HttpServletResponse.SC_BAD_REQUEST, nfe.toString());
          return;
        }
        try {
          FastIDSet ids = isUser() ? recommender.getUserCluster(n) : recommender.getItemCluster(n);
          outputIDs(request, response, ids);
        } catch (IndexOutOfBoundsException ioobe) {
          response.sendError(HttpServletResponse.SC_BAD_REQUEST, ioobe.toString());
        }
      }
View Full Code Here

  @Override
  protected final void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
    MyrrixRecommender recommender = getRecommender();
    try {
      FastIDSet ids = isUserIDs() ? recommender.getAllUserIDs() : recommender.getAllItemIDs();
      outputIDs(request, response, ids);
    } catch (NotReadyException nre) {
      response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, nre.toString());
    } catch (TasteException te) {
      response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, te.toString());
View Full Code Here

    if (pathInfo == null) {
      response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No path");
      return;
    }
    Iterator<String> pathComponents = SLASH.split(pathInfo).iterator();
    FastIDSet itemIDSet = new FastIDSet();
    try {
      while (pathComponents.hasNext()) {
        itemIDSet.add(Long.parseLong(pathComponents.next()));
      }
    } catch (NoSuchElementException nsee) {
      response.sendError(HttpServletResponse.SC_BAD_REQUEST, nsee.toString());
      return;
    } catch (NumberFormatException nfe) {
      response.sendError(HttpServletResponse.SC_BAD_REQUEST, nfe.toString());
      return;
    }

    if (itemIDSet.isEmpty()) {
      response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No items");
      return;
    }

    MyrrixRecommender recommender = getRecommender();
    RescorerProvider rescorerProvider = getRescorerProvider();
    try {
      int howMany = getHowMany(request);
      Iterable<RecommendedItem> similar;
      if (rescorerProvider == null) {
        similar = recommender.mostSimilarItems(itemIDSet.toArray(), howMany);
      } else {
        Rescorer<LongPair> rescorer =
            rescorerProvider.getMostSimilarItemsRescorer(recommender, getRescorerParams(request));
        similar = recommender.mostSimilarItems(itemIDSet.toArray(),
                                               howMany,
                                               rescorer);
      }
      output(request, response, similar);
    } catch (NoSuchItemException nsie) {
View Full Code Here

TOP

Related Classes of net.myrrix.common.collection.FastIDSet$KeyIterator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.