Package org.grouplens.lenskit.vectors

Examples of org.grouplens.lenskit.vectors.SparseVector.keySet()


    @Override
    public void predict(long uid, @Nonnull MutableSparseVector predictions) {
        logger.debug("predicting {} items for {}", predictions.keyDomain().size(), uid);
        OrdRecModel params = new OrdRecModel(quantizer);
        SparseVector ratings = makeUserVector(uid, userEventDao);
        LongSet keySet = LongUtils.setUnion(ratings.keySet(), predictions.keyDomain());
        MutableSparseVector scores = MutableSparseVector.create(keySet);
        itemScorer.score(uid, scores);
        params.train(ratings, scores);
        logger.debug("trained parameters for {}: {}", uid, params);
View Full Code Here


                    }
                    ivect.add(uid, rating.getValue());
                }

                // get the item's candidate set
                userItems.put(uid, LongUtils.packedSet(summary.keySet()));
            }
        } finally {
            users.close();
        }
    }
View Full Code Here

        if (predictions == null) {
            predictions = MutableSparseVector.create();
        }

        LongSortedSet items = ratings.keySet();
        if (!items.containsAll(predictions.keySet())) {
            items = LongUtils.setUnion(items, predictions.keySet());
        }

        logger.debug("outputting {} predictions for user {}", predictions.size(), user.getUserId());
        for (LongIterator iter = items.iterator(); iter.hasNext(); /* no increment */) {
View Full Code Here

            predictions = MutableSparseVector.create();
        }

        LongSortedSet items = ratings.keySet();
        if (!items.containsAll(predictions.keySet())) {
            items = LongUtils.setUnion(items, predictions.keySet());
        }

        logger.debug("outputting {} predictions for user {}", predictions.size(), user.getUserId());
        for (LongIterator iter = items.iterator(); iter.hasNext(); /* no increment */) {
            long item = iter.nextLong();
View Full Code Here

        for (VectorEntry e : scores.view(VectorEntry.State.EITHER)) {
            final long predicteeItem = e.getKey();
            if (!user.containsKey(predicteeItem)) {
                double total = 0;
                int nitems = 0;
                LongIterator ratingIter = user.keySet().iterator();
                while (ratingIter.hasNext()) {
                    long currentItem = ratingIter.nextLong();
                    int nusers = model.getCoratings(predicteeItem, currentItem);
                    if (nusers != 0) {
                        double currentDev = model.getDeviation(predicteeItem, currentItem);
View Full Code Here

        for (VectorEntry e : scores.view(VectorEntry.State.EITHER)) {
            final long predicteeItem = e.getKey();
            if (!ratings.containsKey(predicteeItem)) {
                double total = 0;
                int nusers = 0;
                LongIterator ratingIter = ratings.keySet().iterator();
                while (ratingIter.hasNext()) {
                    long currentItem = ratingIter.nextLong();
                    double currentDev = model.getDeviation(predicteeItem, currentItem);
                    if (!Double.isNaN(currentDev)) {
                        int weight = model.getCoratings(predicteeItem, currentItem);
View Full Code Here

    @Test
    public void testScoreSet() {
        ItemScorer pred = new ConstantItemScorer(5);
        SparseVector v = pred.score(42, LongUtils.packedSet(1, 2, 3, 5, 7));
        assertThat(v.keySet(), contains(1L, 2L, 3L, 5L, 7L));
        assertThat(v.values(), everyItem(equalTo(5.0)));
    }

    @Test
    public void testScoreVector() {
View Full Code Here

        final LongCollection userIds = snap.getUserIds();
        LongIterator userIter = userIds.iterator();
        while (userIter.hasNext()) {
            long uid = userIter.nextLong();
            SparseVector rvector = snap.userRatingVector(uid);
            MutableSparseVector blpreds = MutableSparseVector.create(rvector.keySet());
            baseline.score(uid, blpreds);

            for (IndexedPreference r : snap.getUserRatings(uid)) {
                estimates[r.getIndex()] = blpreds.get(r.getItemId());
            }
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.