Package org.grouplens.lenskit.vectors

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


            ImmutableList.Builder<ImmutableSparseVector> nvecs = ImmutableList.builder();
            for (LongIterator uiter = domain.activeSetView().iterator(); uiter.hasNext();) {
                final long user = uiter.nextLong();
                MutableSparseVector vec = vectors.get(user);
                // save user's original vector
                ImmutableSparseVector userVector = vec.immutable();
                vecs.add(userVector);
                // normalize user vector
                normalizer.normalize(user, userVector, vec);
                // and save normalized vector
                nvecs.add(vec.immutable());
View Full Code Here


                ImmutableSparseVector userVector = vec.immutable();
                vecs.add(userVector);
                // normalize user vector
                normalizer.normalize(user, userVector, vec);
                // and save normalized vector
                nvecs.add(vec.immutable());
                for (LongIterator iiter = userVector.keySet().iterator(); iiter.hasNext();) {
                    final long item = iiter.nextLong();
                    LongList itemUsers = itemUserLists.get(item);
                    if (itemUsers == null) {
                        itemUsers = new LongArrayList();
View Full Code Here

        protected Neighbor computeNext() {
            while (neighborIter.hasNext()) {
                final long neighbor = neighborIter.nextLong();
                MutableSparseVector nbrRatings = getUserRatingVector(neighbor);
                if (nbrRatings != null) {
                    ImmutableSparseVector rawRatings = nbrRatings.immutable();
                    normalizer.normalize(neighbor, rawRatings, nbrRatings);
                    final double sim = similarity.similarity(user, userVector, neighbor, nbrRatings);
                    if (acceptSimilarity(sim)) {
                        // we have found a neighbor
                        return new Neighbor(neighbor, rawRatings, sim);
View Full Code Here

    @Test
    public void testScale() {
        MutableSparseVector v = MutableSparseVector.create(keySet);
        v.set(1, 1);
        v.set(4, 1);
        assertThat(norm.normalize(v.immutable(), v), sameInstance(v));
        assertThat(v.norm(), closeTo(1, 1.0e-6));
        assertThat(v.size(), equalTo(2));
        assertThat(v.get(1), closeTo(1 / sqrt(2), 1.0e-6));
        assertThat(v.get(4), closeTo(1 / sqrt(2), 1.0e-6));
    }
View Full Code Here

        MutableSparseVector ref = MutableSparseVector.create(keySet);
        ref.set(1, 1);
        ref.set(6, 1);
        ref.set(3, 2);

        VectorTransformation tx = norm.makeTransformation(ref.immutable());
        assertThat(tx.apply(v), sameInstance(v));
        assertThat(v.norm(), closeTo(sqrt(2.0 / 6), 1.0e-6));
        assertThat(v.size(), equalTo(2));
        assertThat(v.get(1), closeTo(1 / sqrt(6), 1.0e-6));
        assertThat(v.get(4), closeTo(1 / sqrt(6), 1.0e-6));
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.