Package it.unimi.dsi.fastutil.longs

Examples of it.unimi.dsi.fastutil.longs.LongList


     * Read a list of long IDs from a file, one per line.
     * @param file The file to read.
     * @return A list of longs.
     */
    public static LongList readIdList(File file) throws IOException {
        LongList items = new LongArrayList();
        Closer closer = Closer.create();
        try {
            FileReader fread = closer.register(new FileReader(file));
            BufferedReader buf = closer.register(new BufferedReader(fread));
            String line;
            int lno = 0;
            while ((line = buf.readLine()) != null) {
                lno += 1;
                if (line.trim().isEmpty()) {
                    continue; // skip blank lines
                }
                long item;
                try {
                    item = Long.parseLong(line.trim());
                } catch (IllegalArgumentException ex) {
                    throw new IOException("invalid ID on " + file + " line " + lno + ": " + line);
                }
                items.add(item);
            }
        } catch (Throwable th) {
            throw closer.rethrow(th);
        } finally {
            closer.close();
View Full Code Here


        if (predictions == null) {
            return null;
        }

        SparseVector ratings = user.getTestRatings();
        LongList ideal = ratings.keysByValue(true);
        LongList actual = predictions.keysByValue(true);
        double idealGain = computeDCG(ideal, ratings);
        double gain = computeDCG(actual, ratings);
        double score = gain / idealGain;
        context.add(score);
        return new Result(score);
View Full Code Here

    private List<ScoredId> rescore(long user, List<ScoredId> recs) {
        if (recs.isEmpty()) {
            return Collections.emptyList();
        }

        LongList items = new LongArrayList(recs.size());
        for (ScoredId sid: recs) {
            items.add(sid.getId());
        }

        SparseVector scores = scorer.score(user, items);
        ScoredIdListBuilder builder = ScoredIds.newListBuilder(recs.size());
        builder.addChannel(ORIGINAL_SCORE_SYMBOL);
View Full Code Here

        if (predictions == null) {
            return null;
        }

        SparseVector ratings = user.getTestRatings();
        LongList ideal = ratings.keysByValue(true);
        LongList actual = predictions.keysByValue(true);
        double idealUtility = computeHLU(ideal, ratings);
        double actualUtility = computeHLU(actual, ratings);
        double u = actualUtility / idealUtility;

        context.add(u);
View Full Code Here

        if (recommendations == null) {
            return null;
        }

        SparseVector ratings = user.getTestRatings();
        LongList ideal = ratings.keysByValue(true);
        if (ideal.size() > listSize) {
            ideal = ideal.subList(0, listSize);
        }
        double idealGain = computeDCG(ideal, ratings);

        LongList actual = new LongArrayList(recommendations.size());
        for (ScoredId id: recommendations) {
            actual.add(id.getId());
        }
        double gain = computeDCG(actual, ratings);

        double score = gain / idealGain;
View Full Code Here

    for (int i = 0; i < valueCount; i++) {
      compositeActivityValues.update(UID_BASE + i, String.format("%08d", valueCount + i), toMap(new JSONObject().put("likes", "+1")));
   
    compositeActivityValues.flush();
    compositeActivityValues.syncWithPersistentVersion(String.format("%08d",  valueCount - 1));
    LongList uidsToDelete = new LongArrayList();
    for (int i = 0; i < valueCount; i++) {
      if (i == 2) {
        continue;
      }
      uidsToDelete.add(UID_BASE + i);
      if (i %1000 == 0) {
        compositeActivityValues.delete(uidsToDelete.toLongArray());
        uidsToDelete.clear();
      }
    }
    compositeActivityValues.flush();
    compositeActivityValues.delete(uidsToDelete.toLongArray());
    compositeActivityValues.flush();
    int notDeletedIndex = compositeActivityValues.uidToArrayIndex.get(UID_BASE + 2);
    final CompositeActivityValues testActivityData = compositeActivityValues;   
    Wait.until(10000L, "", new Wait.Condition() {     
      public boolean evaluate() {
View Full Code Here

  }

  @Override
  public Long2ObjectMap<ValueSpecification> getValueSpecifications(LongCollection identifiers) {
    final Long2ObjectMap<ValueSpecification> specifications = new Long2ObjectOpenHashMap<ValueSpecification>();
    LongList cacheMisses = null;
    for (long identifier : identifiers) {
      final Long key = identifier;
      final ValueSpecification specification = _identifierToSpecification.get(key);
      if (specification != null) {
        specifications.put(identifier, specification);
      } else {
        if (cacheMisses == null) {
          cacheMisses = new LongArrayList(identifiers.size());
        }
        cacheMisses.add(identifier);
      }
    }
    if (cacheMisses != null) {
      if (cacheMisses.size() == 1) {
        final long identifier = cacheMisses.getLong(0);
        final ValueSpecification specification = getUnderlying().getValueSpecification(identifier);
        final Long key = identifier;
        _specificationToIdentifier.put(specification, key);
        _identifierToSpecification.put(key, specification);
        specifications.put(identifier, specification);
View Full Code Here

    return response;
  }

  @Override
  protected SpecificationLookupResponse visitSpecificationLookupRequest(final SpecificationLookupRequest request) {
    final LongList identifiers = new AbstractLongList() {

      private List<Long> _raw = request.getIdentifier();

      @Override
      public long getLong(int index) {
        return _raw.get(index);
      }

      @Override
      public int size() {
        return _raw.size();
      }

    };
    final Collection<ValueSpecification> specifications;
    if (identifiers.size() == 1) {
      specifications = Collections.singleton(getUnderlying().getValueSpecification(identifiers.getLong(0)));
    } else {
      final Long2ObjectMap<ValueSpecification> specificationMap = getUnderlying().getValueSpecifications(identifiers);
      specifications = new ArrayList<ValueSpecification>(specificationMap.size());
      for (Long identifier : identifiers) {
        specifications.add(specificationMap.get(identifier));
View Full Code Here

TOP

Related Classes of it.unimi.dsi.fastutil.longs.LongList

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.