Package org.grouplens.lenskit.collections

Examples of org.grouplens.lenskit.collections.LongKeyDomain


        String[] values = {a,b,a};
        return new TypedSideChannel<String>(keys,values);
    }
   
    protected TypedSideChannel<String> singletonSideChannel() {
        LongKeyDomain keys = LongKeyDomain.create(1);
        String[] values = {a};
        return new TypedSideChannel<String>(keys,values);
    }
View Full Code Here


        return new TypedSideChannel<String>(keys,values);
    }
   
    @Test
    public void testConstructors() {
        LongKeyDomain keys = LongKeyDomain.create(1, 2);
        TypedSideChannel<String> channel = new TypedSideChannel<String>(keys.clone());
        assertTrue(channel.isEmpty());
       
        channel = new TypedSideChannel<String>(keys ,new String[]{a,b});
        assertFalse(channel.isEmpty());
        assertEquals(a, channel.get(1));
        assertEquals(b, channel.get(2));

        keys.setActive(0, false);
        channel = new TypedSideChannel<String>(keys, new String[]{null,b});
        assertFalse(channel.isEmpty());
        assertEquals(b,channel.get(2));
        assertNull(channel.get(1));
    }
View Full Code Here

    /**
     * Test ItemItemBuildContext when all items have rating data.
     */
    @Test
    public void testAllItemsData() {
        LongKeyDomain items = LongKeyDomain.create(1,2,3,4);

        long[] userIds = {101, 102, 103, 104};
        double[] ratings1 = {4.0, 3.0, 2.5, 2.0};
        double[] ratings2 = {3.0, 2.5, 4.0, 1.0};
        double[] ratings3 = {5.0, 3.5, 0.5, 1.0};
View Full Code Here

    /**
     * Test ItemItemBuildContext when some items have rating data.
     */
    @Test
    public void testSomeItemsData() {
        LongKeyDomain items = LongKeyDomain.create(1,2,3,4);

        long[] userIds = {101, 102, 103, 104};
        double[] ratings1 = {4.0, 3.0, 2.5, 2.0};
        double[] ratings4 = {4.5, 3.0, 3.5, 1.5};
        SparseVector v1 = MutableSparseVector.wrap(userIds, ratings1);
View Full Code Here

    /**
     * Test ItemItemBuildContext when no items have rating data.
     */
    @Test
    public void testNoItemsData() {
        LongKeyDomain items = LongKeyDomain.create(1,2,3,4);

        SparseVector[] ratingMap = {
                MutableSparseVector.create(),
                MutableSparseVector.create(),
                MutableSparseVector.create(),
View Full Code Here

    /**
     * Test ItemItemBuildContext when there is no rating data.
     */
    @Test
    public void testEmpty() {
        LongKeyDomain items = LongKeyDomain.create();
        SparseVector[] ratingMap = new SparseVector[] {};
        ItemItemBuildContext context = new ItemItemBuildContext(items, ratingMap,
                                                                new Long2ObjectOpenHashMap<LongSortedSet>());

        testRatingIntegrity(items, ratingMap, context);
View Full Code Here

        }
        int end = buffer.position() + nextExpectedOffset * 4;
        ByteBuffer dup = buffer.duplicate();
        dup.limit(end);
        buffer.position(end);
        LongKeyDomain dom = LongKeyDomain.wrap(keys, keys.length, true);
        return new BinaryIndexTable(dom, offsets, sizes, dup.asIntBuffer());
    }
View Full Code Here

            } finally {
                users.close();
            }

            Long2ObjectMap<LongList> itemUserLists = new Long2ObjectOpenHashMap<LongList>();
            LongKeyDomain domain = LongKeyDomain.fromCollection(vectors.keySet()).compactCopy(true);
            assert domain.size() == domain.domainSize();
            ImmutableList.Builder<ImmutableSparseVector> vecs = ImmutableList.builder();
            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());
                for (LongIterator iiter = userVector.keySet().iterator(); iiter.hasNext();) {
                    final long item = iiter.nextLong();
                    LongList itemUsers = itemUserLists.get(item);
                    if (itemUsers == null) {
                        itemUsers = new LongArrayList();
                        itemUserLists.put(item, itemUsers);
                    }
                    itemUsers.add(user);
                }
            }

            Long2ObjectMap<LongSortedSet> itemUserSets = new Long2ObjectOpenHashMap<LongSortedSet>();
            for (Long2ObjectMap.Entry<LongList> entry: itemUserLists.long2ObjectEntrySet()) {
                itemUserSets.put(entry.getLongKey(), LongUtils.packedSet(entry.getValue()));
            }
            return new UserSnapshot(domain.unowned(), vecs.build(), nvecs.build(), itemUserSets);
        }
View Full Code Here

TOP

Related Classes of org.grouplens.lenskit.collections.LongKeyDomain

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.