Package org.grouplens.lenskit.vectors

Examples of org.grouplens.lenskit.vectors.SparseVector


    }

    @Test
    public void testEmpty() {
        List<ScoredId> nbrs = Collections.emptyList();
        SparseVector scores = MutableSparseVector.create();
        assertThat(scorer.score(42, nbrs, scores), nullValue());
    }
View Full Code Here


    }

    @Test
    public void testEmptyNbrs() {
        List<ScoredId> nbrs = Collections.emptyList();
        SparseVector scores = MutableSparseVector.wrap(new long[]{5}, new double[]{3.7}).freeze();
        assertThat(scorer.score(42, nbrs, scores), nullValue());
    }
View Full Code Here

    public void testOneNbr() {
        List<ScoredId> nbrs = Lists.newArrayList(ScoredIds.newBuilder()
                                                          .setId(5)
                                                          .setScore(1.0)
                                                          .build());
        SparseVector scores = MutableSparseVector.wrap(new long[]{5}, new double[]{3.7}).freeze();
        assertThat(scorer.score(42, nbrs, scores).getScore(), closeTo(1.0));
    }
View Full Code Here

                                       .add(5, 1.0)
                                       .add(7, 0.92)
                                       .build();
        long[] scoreKeys = {2, 3, 5, 7};
        double[] scoreValues = {3.7, 4.2, 1.2, 7.8};
        SparseVector scores = MutableSparseVector.wrap(scoreKeys, scoreValues).freeze();
        assertThat(scorer.score(42, nbrs, scores).getScore(), closeTo(2.42));
    }
View Full Code Here

        }

        logger.info("predicting {} items", items.size());
        Symbol pchan = getPrintChannel();
        Stopwatch timer = Stopwatch.createStarted();
        SparseVector preds = pred.predict(user, items);
        Long2ObjectMap channel = null;
        if (pchan != null) {
            for (TypedSymbol sym: preds.getChannelSymbols()) {
                if (sym.getRawSymbol().equals(pchan)) {
                    channel = preds.getChannel(sym);
                }
            }
        }
        for (VectorEntry e: preds) {
            System.out.format("  %d: %.3f", e.getKey(), e.getValue());
View Full Code Here

    public void testGlobalItemScorerNoRating() {
        long[] queryItems = {1, 10};
        long[] items = {5, 10};
        ItemItemGlobalScorer scorer = session.get(ItemItemGlobalScorer.class);
        assertThat(scorer, notNullValue());
        SparseVector scores = scorer.globalScore(LongArrayList.wrap(queryItems), LongArrayList.wrap(items));
        assertThat(scores, notNullValue());
        assertThat(scores.size(), equalTo(2));
        assertThat(scores.get(5), not(notANumber()));
        // assertThat(scores.get(10), equalTo(0.0));

    }
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

    public void score(long user, @Nonnull MutableSparseVector scores) {
        UserHistory<Rating> history = dao.getEventsForUser(user, Rating.class);
        if (history == null) {
            history = History.forUser(user);
        }
        SparseVector ratings = Ratings.userRatingVector(history);
       
        AVector uprefs = model.getUserVector(user);
        if (uprefs == null) {
            if (ratings.isEmpty()) {
                // no real work to do.
                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);
            for (int f = 0; f < featureCount; f++) {
                trainUserFeature(user, updated, ratings, estimates, f);
            }
            uprefs = updated;
View Full Code Here

TOP

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

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.