Package org.grouplens.lenskit.vectors

Examples of org.grouplens.lenskit.vectors.MutableSparseVector


    }

    @Test
    public void testUnknownItem() {
        final long user = 2;
        MutableSparseVector output = MutableSparseVector.create(14, 15, 16);

        predictor.score(user, output);

        assertEquals(3.07, output.get(14), EPSILON);
        assertEquals(3.07, output.get(15), EPSILON);
        assertEquals(3.07, output.get(16), EPSILON);
    }
View Full Code Here


    }

    @Test
    public void testUnknownUser() {
        final long user = 11;
        MutableSparseVector output = MutableSparseVector.create(4, 5, 6);

        predictor.score(user, output);

        assertEquals(3.05, output.get(4), EPSILON);
        assertEquals(3.20, output.get(5), EPSILON);
        assertEquals(3.13, output.get(6), EPSILON);
    }
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

     * @return Baseline predictions for all items either in the target set or the set of
     *         rated items.
     */
    private MutableSparseVector initialEstimates(long user, SparseVector ratings, LongSortedSet items) {
        LongSet allItems = LongUtils.setUnion(items, ratings.keySet());
        MutableSparseVector estimates = MutableSparseVector.create(allItems);
        baselineScorer.score(user, estimates);
        return estimates;
    }
View Full Code Here

                return;
            }
            uprefs = model.getAverageUserVector();
        }

        MutableSparseVector estimates = initialEstimates(user, ratings, scores.keyDomain());
        // propagate estimates to the output scores
        scores.set(estimates);

        if (!ratings.isEmpty() && rule != null) {
            AVector updated = Vector.create(uprefs);
View Full Code Here

        assert feature >= 0 && feature < featureCount;

        int tailStart = feature + 1;
        int tailSize = featureCount - feature - 1;
        AVector utail = uprefs.subVector(tailStart, tailSize);
        MutableSparseVector tails = MutableSparseVector.create(ratings.keySet());
        for (VectorEntry e: tails.view(VectorEntry.State.EITHER)) {
            AVector ivec = model.getItemVector(e.getKey());
            if (ivec == null) {
                // FIXME Do this properly
                tails.set(e, 0);
            } else {
                ivec = ivec.subVector(tailStart, tailSize);
                tails.set(e, utail.dotProduct(ivec));
            }
        }

        double rmse = Double.MAX_VALUE;
        TrainingLoopController controller = rule.getTrainingLoopController();
View Full Code Here

        TopNScoredItemAccumulator accumulator = new TopNScoredItemAccumulator(n);
        for (VectorEntry e : v.view(VectorEntry.State.SET)) {
            accumulator.put(e.getKey(), e.getValue());
        }
        MutableSparseVector truncated = accumulator.finishVector();

        // retain only the truncated keys
        v.keySet().retainAll(truncated.keySet());
    }
View Full Code Here

TOP

Related Classes of org.grouplens.lenskit.vectors.MutableSparseVector

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.