Package it.unimi.dsi.fastutil.longs

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


     * @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);

        return users;
    }
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

    }

    private class ItemScanner implements Supplier<LongSet> {
        @Override
        public LongSet get() {
            LongSet items = new LongOpenHashSet();
            Cursor<Event> events = eventDAO.streamEvents();
            try {
                for (Event e: events) {
                    items.add(e.getItemId());
                }
            } finally {
                events.close();
            }
            return items;
View Full Code Here

    @Override
    public LongSet finishSet() {
        assert size == heap.size();

        LongSet longs = new LongOpenHashSet(size);
        while (!heap.isEmpty()) {
            longs.add(items.get(heap.dequeue()));
        }
        clear();

        return longs;
    }
View Full Code Here

    }

    private class UserScanner implements Supplier<LongSet> {
        @Override
        public LongSet get() {
            LongSet us = new LongOpenHashSet();
            Cursor<Event> events = eventDAO.streamEvents();
            try {
                for (Event e: events) {
                    us.add(e.getUserId());
                }
            } finally {
                events.close();
            }
            return us;
View Full Code Here

    public void testItemItemRecommender4() {
        List<ScoredId> recs = recommender.recommend(5, -1, null, null);
        assertThat(Lists.transform(recs, ScoredIds.idFunction()),
                   containsInAnyOrder(6L, 7L, 9L));

        LongOpenHashSet candidates = new LongOpenHashSet();
        candidates.add(6);
        candidates.add(7);
        candidates.add(8);
        candidates.add(9);
        recs = recommender.recommend(5, -1, candidates, null);
        assertThat(Lists.transform(recs, ScoredIds.idFunction()),
                   containsInAnyOrder(6L, 7L, 9L));

        candidates.remove(6);
        recs = recommender.recommend(5, -1, candidates, null);
        assertThat(Lists.transform(recs, ScoredIds.idFunction()),
                   containsInAnyOrder(7L, 9L));

        candidates.remove(7);
        recs = recommender.recommend(5, -1, candidates, null);
        assertThat(Lists.transform(recs, ScoredIds.idFunction()),
                   containsInAnyOrder(9L));

        candidates.remove(9);
        recs = recommender.recommend(5, -1, candidates, null);
        assertThat(recs, hasSize(0));

        candidates.add(9);
        candidates.add(7);
        recs = recommender.recommend(5, 1, candidates, null);
        assertThat(Lists.transform(recs, ScoredIds.idFunction()),
                   anyOf(contains(9L), contains(7L)));

        LongOpenHashSet exclude = new LongOpenHashSet();
        exclude.add(7);
        recs = recommender.recommend(5, 2, candidates, exclude);
        assertThat(Lists.transform(recs, ScoredIds.idFunction()),
                   containsInAnyOrder(9L));

        recs = recommender.recommend(5, 0, candidates, null);
        assertThat(recs, hasSize(0));

        candidates.clear();
        candidates.add(7);
        candidates.add(9);
        recs = recommender.recommend(5, -1, candidates, null);
        assertThat(Lists.transform(recs, ScoredIds.idFunction()),
                   containsInAnyOrder(7L, 9L));

        candidates.add(6);
        exclude.clear();
        exclude.add(9);
        recs = recommender.recommend(5, -1, candidates, exclude);
        assertThat(Lists.transform(recs, ScoredIds.idFunction()),
                   containsInAnyOrder(6L, 7L));

        exclude.add(7);
        recs = recommender.recommend(5, -1, candidates, exclude);
        assertThat(Lists.transform(recs, ScoredIds.idFunction()),
                   containsInAnyOrder(6L));

        exclude.add(6);
        recs = recommender.recommend(5, -1, candidates, exclude);
        assertThat(recs, hasSize(0));
    }
View Full Code Here

     */
    private Vectors() {}

    @SuppressWarnings({"rawtypes", "unchecked"})
    public static MutableSparseVector fromScoredIds(List<ScoredId> scores) {
        LongSet ids = new LongOpenHashSet();
        for (ScoredId sid: scores) {
            ids.add(sid.getId());
        }
        MutableSparseVector vec = MutableSparseVector.create(ids);
        for (ScoredId sid: scores) {
            long id = sid.getId();
            if (!vec.containsKey(id)) {
View Full Code Here

        List<Rating> ratings = getEventsForItem(item, Rating.class);
        if (ratings == null) {
            return null;
        }

        LongSet users = new LongOpenHashSet(ratings.size());
        for (Rating rating: ratings) {
            users.add(rating.getUserId());
        }
        return users;
    }
View Full Code Here

        List<Event> events = getEventsForItem(item);
        if (events == null) {
            return null;
        }

        LongSet users = new LongOpenHashSet();
        for (Event evt: events) {
            users.add(evt.getUserId());
        }
        return users;
    }
View Full Code Here

TOP

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

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.