Package it.unimi.dsi.fastutil.longs

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


        return new Context(ds.getTestData().getItemDAO().getItemIds());
    }

    @Override
    public UserResult doMeasureUser(TestUser user, Context context) {
        LongSet good = goodItems.select(user);
        if (good.isEmpty()) {
            logger.warn("no good items for user {}", user.getUserId());
        }

        List<ScoredId> recs = user.getRecommendations(listSize, candidates, exclude);
        Integer rank = null;
        int i = 0;
        for(ScoredId s : recs) {
            i++;
            if(good.contains(s.getId())) {
                rank = i;
                break;
            }
        }
View Full Code Here


    @Override
    public Result doMeasureUser(TestUser user, Context context) {
        double score = 0;

        LongSet items = queryItems.select(user);
        LongIterator it = items.iterator();
        while (it.hasNext()) {
            final long l = it.nextLong();
            ItemSelector finalCandidates = ItemSelectors.union(ItemSelectors.fixed(l), candidates);

            List<ScoredId> recs = user.getRecommendations(listSize, finalCandidates, exclude);
            for (ScoredId s : recs) {
                if (s.getId() == l) {
                    score +=1;
                }
            }
        }

        int n = items.size();
        if (n>0) {
            score /= n;
            context.mean.add(score);
            return new Result(score);
        } else {
View Full Code Here

    public Iterable<Neighbor> getCandidateNeighbors(UserHistory<? extends Event> user, LongSet items) {
        final long uid = user.getUserId();
        SparseVector urs = RatingVectorUserHistorySummarizer.makeRatingVector(user);
        final ImmutableSparseVector nratings = normalizer.normalize(user.getUserId(), urs, null)
                                                   .freeze();
        final LongSet candidates = findCandidateNeighbors(uid, nratings, items);
        logger.debug("found {} candidate neighbors for {}", candidates.size(), uid);
        return new Iterable<Neighbor>() {
            @Override
            public Iterator<Neighbor> iterator() {
                return new NeighborIterator(uid, nratings, candidates);
            }
View Full Code Here

     * @param uvec The user's normalized preference vector.
     * @param itemSet The set of target items.
     * @return The set of IDs of candidate neighbors.
     */
    private LongSet findCandidateNeighbors(long user, SparseVector uvec, LongCollection itemSet) {
        LongSet users = new LongOpenHashSet(100);
        LongSet userItems = uvec.keySet();

        LongIterator items;
        if (userItems.size() < itemSet.size()) {
            items = userItems.iterator();
        } else {
            items = itemSet.iterator();
        }
        while (items.hasNext()) {
            LongSet iusers = itemDAO.getUsersForItem(items.nextLong());
            if (iusers != null) {
                users.addAll(iusers);
            }
        }
        users.remove(user);
View Full Code Here

            }
            ItemRecommender irec = recommender.getItemRecommender();
            if (irec == null) {
                return Optional.absent();
            }
            LongSet candidates = key.candidates.select(LenskitTestUser.this);
            LongSet excludes = key.exclude.select(LenskitTestUser.this);
            return Optional.of(irec.recommend(getUserId(), key.listSize, candidates, excludes));
        }
View Full Code Here

    }

    @Override
    public void score(long user, @Nonnull MutableSparseVector output) {
        primaryScorer.score(user, output);
        LongSet fallbackKeys = LongSets.EMPTY_SET;
        if (output.size() != output.keyDomain().size()) {
            fallbackKeys = output.unsetKeySet();
            MutableSparseVector blpreds = MutableSparseVector.create(fallbackKeys);
            baselineScorer.score(user, blpreds);
            output.set(blpreds);
        }

        // FIXME Make this faster
        Long2ObjectMap<ScoreSource> chan = output.getOrAddChannel(SCORE_SOURCE_SYMBOL);
        for (VectorEntry e: output) {
            long key = e.getKey();
            ScoreSource source = ScoreSource.PRIMARY;
            if (fallbackKeys.contains(key)) {
                source = ScoreSource.BASELINE;
            }
            chan.put(key, source);
        }
    }
View Full Code Here

        // One of the vector is empty
        if (vec1.norm() == 0 || vec2.norm() == 0){
            return Double.NaN;
        }

        LongSet ts = LongUtils.setUnion(vec1.keySet(),vec2.keySet());

        MutableSparseVector v1 = MutableSparseVector.create(ts);
        v1.fill(0);
        v1.set(vec1);
        v1.multiply(1.0 / v1.norm());
View Full Code Here

        if (history == null) {
            baseline.score(user, items);
        } else {
            MutableSparseVector vec = summarizer.summarize(history).mutableCopy();
            // score everything, both rated and not, for offsets
            LongSet allItems = LongUtils.setUnion(vec.keySet(), items.keyDomain());
            MutableSparseVector baseScores = MutableSparseVector.create(allItems);
            baseline.score(user, baseScores);
            // subtract scores from ratings, yielding offsets
            vec.subtract(baseScores);
            double meanOffset = vec.sum() / (vec.size() + damping);
View Full Code Here

    }

    protected LongSet getIdSet(PreparedStatement s) throws SQLException {
        ResultSet results = s.executeQuery();
        try {
            LongSet ids = new LongOpenHashSet();
            while (results.next()) {
                ids.add(results.getLong(1));
            }
            return ids;
        } finally {
            results.close();
        }
View Full Code Here

    public LongSet finishSet() {
        if (scores == null) {
            return LongSets.EMPTY_SET;
        }

        LongSet set = new LongOpenHashSet(scores.size());
        for (ScoredId id: finish()) {
            set.add(id.getId());
        }
        return set;
    }
View Full Code Here

TOP

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

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.