Package org.grouplens.lenskit.vectors

Examples of org.grouplens.lenskit.vectors.MutableSparseVector


        scorer.score(user, scores);
        LongSet fallbackKeys = LongSets.EMPTY_SET;

        if (baselineScorer != null) {
            fallbackKeys = scores.unsetKeySet();
            MutableSparseVector unpred = MutableSparseVector.create(fallbackKeys);
            baselineScorer.score(user, unpred);
            scores.set(unpred);
        }

        // FIXME Make this faster
View Full Code Here


    @Test
    public void testSimpleTruncate() {
        long[] keys = {1, 2, 3, 4, 5};
        double[] values = {1.0, 2.0, 3.0, 4.0, 5.0};
        MutableSparseVector v = MutableSparseVector.wrap(keys, values);

        VectorTruncator truncator = new TopNTruncator(3, null);
        truncator.truncate(v);

        long i = 3;
        for (VectorEntry e : v.view(VectorEntry.State.SET)) {
            assertThat(e.getKey(), equalTo(i));
            assertThat(e.getValue(), closeTo(i, EPSILON));
            i++;
        }
        assertThat(i, equalTo(6L));
View Full Code Here

    @Test
    public void testTruncate() {
        long[] keys = {1, 2, 3, 4};
        double[] values = {1.0, 2.0, 3.0, 4.0};
        MutableSparseVector v = MutableSparseVector.wrap(keys, values);

        VectorTruncator truncator = new ThresholdTruncator(new RealThreshold(3.5));
        truncator.truncate(v);

        int numSeen = 0;
        for (VectorEntry e : v.view(VectorEntry.State.SET)) {
            assertThat(e.getKey(), equalTo(4L));
            assertThat(e.getValue(), closeTo(4.0, EPSILON));
            numSeen++;
        }
        assertThat(numSeen, equalTo(1));
View Full Code Here

    @Test
    public void testSimpleTruncate() {
        long[] keys = {1, 2, 3, 4};
        double[] values = {1.0, 2.0, 3.0, 4.0};
        MutableSparseVector v = MutableSparseVector.wrap(keys, values);

        VectorTruncator truncator = new NoOpTruncator();
        truncator.truncate(v);

        long i = 1;
        for (VectorEntry e : v.view(VectorEntry.State.SET)) {
            assertThat(e.getKey(), equalTo(i));
            assertThat(e.getValue(), closeTo(i, EPSILON));
            i++;
        }
        assertThat(i, equalTo(5L));
View Full Code Here

    @Override
    @Nonnull
    public MutableSparseVector globalScore(@Nonnull Collection<Long> queryItems,
                                           @Nonnull Collection<Long> items) {
        MutableSparseVector v = MutableSparseVector.create(items);
        globalScore(queryItems, v);
        return v;
    }
View Full Code Here

        LongList keys = new LongArrayList();
        keys.add(1);
        keys.add(2);
        keys.add(3);
        keys.add(4);
        MutableSparseVector v = MutableSparseVector.create(keys);
        pred.predict(40, v);
        assertThat(v.get(1),
                   closeTo(4.0, EPSILON));
        assertThat(v.get(2),
                   closeTo(5.0, EPSILON));
        assertThat(v.get(3),
                   closeTo(1.0, EPSILON));
        assertThat(v.get(4, 0.0), closeTo(0.0, EPSILON));
        assertThat(v.getChannel(SimpleRatingPredictor.PREDICTION_SOURCE_SYMBOL).get(1),
                   equalTo(ScoreSource.PRIMARY));
    }
View Full Code Here

    }

    @Test
    public void testEmptyURV() {
        List<Rating> ratings = Collections.emptyList();
        MutableSparseVector urv = Ratings.userRatingVector(ratings);
        assertThat(urv.isEmpty(), equalTo(true));
        assertThat(urv.size(), equalTo(0));
    }
View Full Code Here

                                         .addScore(42, 2, 3.0)
                                         .addScore(42, 3, 3.0)
                                         .build();
        ItemScorer scorer = new FallbackItemScorer(primary, base1);
        RatingPredictor pred = new SimpleRatingPredictor(scorer, base2, null);
        MutableSparseVector vec = MutableSparseVector.create(1, 2, 3);
        pred.predict(42, vec);
        assertThat(vec.size(), equalTo(3));
        assertThat(vec.get(1), equalTo(3.5));
        assertThat(vec.get(2), equalTo(2.5));
        assertThat(vec.get(3), equalTo(3.0));
        assertThat(vec.getChannel(FallbackItemScorer.SCORE_SOURCE_SYMBOL).get(1),
                   equalTo(ScoreSource.PRIMARY));
        assertThat(vec.getChannel(FallbackItemScorer.SCORE_SOURCE_SYMBOL).get(2),
                   equalTo(ScoreSource.BASELINE));
        assertThat(vec.getChannel(FallbackItemScorer.SCORE_SOURCE_SYMBOL).get(3),
                   nullValue());
        assertThat(vec.getChannel(SimpleRatingPredictor.PREDICTION_SOURCE_SYMBOL).get(1),
                   equalTo(ScoreSource.PRIMARY));
        assertThat(vec.getChannel(SimpleRatingPredictor.PREDICTION_SOURCE_SYMBOL).get(2),
                   equalTo(ScoreSource.PRIMARY));
        assertThat(vec.getChannel(SimpleRatingPredictor.PREDICTION_SOURCE_SYMBOL).get(3),
                   equalTo(ScoreSource.BASELINE));
    }
View Full Code Here

    public void testURVRatingsInOrder() {
        List<Rating> ratings = new ArrayList<Rating>();
        ratings.add(new SimpleRating(1, 2, 3.0, 3));
        ratings.add(new SimpleRating(1, 3, 4.5, 7));
        ratings.add(new SimpleRating(1, 5, 2.3, 10));
        MutableSparseVector urv = Ratings.userRatingVector(ratings);
        assertThat(urv.isEmpty(), equalTo(false));
        assertThat(urv.size(), equalTo(3));
        assertThat(urv.get(2), closeTo(3.0, 1.0e-6));
        assertThat(urv.get(3), closeTo(4.5, 1.0e-6));
        assertThat(urv.get(5), closeTo(2.3, 1.0e-6));
        assertThat(urv.containsKey(1), equalTo(false));
    }
View Full Code Here

    public void testURVRatingsOutOfOrder() {
        List<Rating> ratings = new ArrayList<Rating>();
        ratings.add(new SimpleRating(1, 2, 3.0, 3));
        ratings.add(new SimpleRating(1, 5, 2.3, 7));
        ratings.add(new SimpleRating(1, 3, 4.5, 10));
        MutableSparseVector urv = Ratings.userRatingVector(ratings);
        assertThat(urv.isEmpty(), equalTo(false));
        assertThat(urv.size(), equalTo(3));
        assertThat(urv.get(2), closeTo(3.0, 1.0e-6));
        assertThat(urv.get(3), closeTo(4.5, 1.0e-6));
        assertThat(urv.get(5), closeTo(2.3, 1.0e-6));
        assertThat(urv.containsKey(1), equalTo(false));
    }
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.