Package org.grouplens.lenskit.vectors

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


        if (history == null) {
            baseline.score(user, items);
        } else {
            MutableSparseVector vec = summarizer.summarize(history).mutableCopy();
            // score everything, both rated and not, for offsets
            LongSet allItems = LongUtils.setUnion(vec.keySet(), items.keyDomain());
            MutableSparseVector baseScores = MutableSparseVector.create(allItems);
            baseline.score(user, baseScores);
            // subtract scores from ratings, yielding offsets
            vec.subtract(baseScores);
            double meanOffset = vec.sum() / (vec.size() + damping);
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

                                          .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));
View Full Code Here

        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));
    }

    @Test
    public void testAddScoreVector() {
        MutableSparseVector uv = MutableSparseVector.create(2, 3, 5);
View Full Code Here

            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
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.