Package org.grouplens.lenskit.vectors

Examples of org.grouplens.lenskit.vectors.MutableSparseVector


        List<Rating> ratings = new ArrayList<Rating>();
        ratings.add(new SimpleRating(1, 2, 3.0, 3));
        ratings.add(new SimpleRating(1, 5, 2.3, 4));
        ratings.add(new SimpleRating(1, 3, 4.5, 5));
        ratings.add(new SimpleRating(1, 5, 3.7, 6));
        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(3.7, 1.0e-6));
        assertThat(urv.containsKey(1), equalTo(false));
    }
View Full Code Here


        List<Rating> ratings = new ArrayList<Rating>();
        ratings.add(new SimpleRating(1, 2, 3.0, 3));
        ratings.add(new SimpleRating(1, 5, 2.3, 5));
        ratings.add(new SimpleNullRating(1, 2, 7));
        ratings.add(new SimpleRating(1, 3, 4.5, 8));
        MutableSparseVector urv = Ratings.userRatingVector(ratings);
        assertThat(urv.isEmpty(), equalTo(false));
        assertThat(urv.size(), equalTo(2));
        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));
        assertThat(urv.containsKey(2), equalTo(false));
    }
View Full Code Here

    @Test
    public void testVectorScore() {
        ItemScorer scorer = PrecomputedItemScorer.newBuilder()
                                          .addScore(42, 1, 4)
                                          .build();
        MutableSparseVector msv = MutableSparseVector.create(1, 3);
        scorer.score(42, msv);
        assertThat(msv.containsKey(1), equalTo(true));
        assertThat(msv.containsKey(3), equalTo(false));
        assertThat(msv.get(1), closeTo(4, 1.0e-5));
    }
View Full Code Here

        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, 5));
        ratings.add(new SimpleRating(1, 5, 3.7, 6));
        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

    }

    @Test
    public void testScoreVector() {
        ItemScorer pred = new ConstantItemScorer(5);
        MutableSparseVector v = MutableSparseVector.create(1, 2, 3, 5, 7);
        pred.score(42, v);
        assertThat(v.keySet(), contains(1L, 2L, 3L, 5L, 7L));
        assertThat(v.values(), everyItem(equalTo(5.0)));
    }
View Full Code Here

    public void testAddMultipleScores() {
        ItemScorer scorer = PrecomputedItemScorer.newBuilder()
                                          .addScore(42, 3, 4)
                                          .addScore(42, 7, 2)
                                          .build();
        MutableSparseVector msv = MutableSparseVector.create(1, 3, 5, 7, 8);
        scorer.score(42, msv);
        assertThat(msv.keySet().size(), equalTo(2));
        assertThat(msv.containsKey(1), equalTo(false));
        assertThat(msv.containsKey(3), equalTo(true));
        assertThat(msv.containsKey(5), equalTo(false));
        assertThat(msv.containsKey(7), equalTo(true));
        assertThat(msv.containsKey(8), equalTo(false));
        assertThat(msv.get(3), closeTo(4, 1.0e-5));
        assertThat(msv.get(7), closeTo(2, 1.0e-5));

        scorer.score(5, msv);
        assertThat(msv.keySet().isEmpty(), equalTo(true));
    }
View Full Code Here

    }

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

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

        assertThat(msv.keySet().isEmpty(), equalTo(true));
    }

    @Test
    public void testAddScoreVector() {
        MutableSparseVector uv = MutableSparseVector.create(2, 3, 5);
        uv.set(2, 3);
        uv.set(3, 4);
        uv.set(5, 2);
        ItemScorer scorer = PrecomputedItemScorer.newBuilder()
                                          .addUser(3, uv)
                                          .build();
        MutableSparseVector output = MutableSparseVector.create(2, 3, 4, 5);
        scorer.score(3, output);
        assertThat(output, equalTo(uv));
    }
View Full Code Here

    }

    @Test
    public void testKnownUserItem() {
        final long user = 1;
        MutableSparseVector output = MutableSparseVector.create(1, 2, 3);

        predictor.score(user, output);

        assertEquals(3.18, output.get(1), EPSILON);
        assertEquals(3.04, output.get(2), EPSILON);
        assertEquals(3.07, output.get(3), EPSILON);
    }
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.