it.unimi.dsi.fastutil.bytes.Byte2ObjectMap Java Examples
The following examples show how to use
it.unimi.dsi.fastutil.bytes.Byte2ObjectMap.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NodeMetadataSocialProofResult.java From GraphJet with Apache License 2.0 | 5 votes |
public NodeMetadataSocialProofResult( int nodeMetadataId, Byte2ObjectMap<Long2ObjectMap<LongSet>> socialProof, double weight, RecommendationType recommendationType ) { this.nodeMetadataId = nodeMetadataId; this.socialProof = socialProof; this.weight = weight; this.recommendationType = recommendationType; }
Example #2
Source File: SocialProofResult.java From GraphJet with Apache License 2.0 | 5 votes |
public SocialProofResult( Long node, Byte2ObjectMap<LongSet> socialProof, double weight, RecommendationType recommendationType ) { this.node = node; this.socialProof = socialProof; this.weight = weight; this.recommendationType = recommendationType; }
Example #3
Source File: ByteDictionaryMap.java From tablesaw with Apache License 2.0 | 4 votes |
ObjectSet<Byte2ObjectMap.Entry<String>> getKeyValueEntries() { return keyToValue.byte2ObjectEntrySet(); }
Example #4
Source File: ByteDictionaryMap.java From tablesaw with Apache License 2.0 | 4 votes |
private Byte2ObjectMap<String> keyToValueMap() { return keyToValue; }
Example #5
Source File: NodeMetadataSocialProofResult.java From GraphJet with Apache License 2.0 | 4 votes |
public Byte2ObjectMap<Long2ObjectMap<LongSet>> getSocialProof() { return this.socialProof; }
Example #6
Source File: NodeMetadataSocialProofRequest.java From GraphJet with Apache License 2.0 | 4 votes |
public Byte2ObjectMap<IntSet> getNodeMetadataTypeToIdsMap() { return this.nodeMetadataTypeToIdsMap; }
Example #7
Source File: SocialProofResult.java From GraphJet with Apache License 2.0 | 4 votes |
public Byte2ObjectMap<LongSet> getSocialProof() { return this.socialProof; }
Example #8
Source File: NodeMetadataSocialProofTest.java From GraphJet with Apache License 2.0 | 4 votes |
@Test public void testComputeRecommendations() throws Exception { NodeMetadataLeftIndexedPowerLawMultiSegmentBipartiteGraph graph = BipartiteGraphTestHelper. buildSmallTestNodeMetadataLeftIndexedPowerLawMultiSegmentBipartiteGraphWithEdgeTypes(); Long2DoubleMap seedsMap = new Long2DoubleArrayMap(new long[]{2, 3}, new double[]{1.0, 0.5}); IntSet urlIds = new IntOpenHashSet(new int[]{200, 300}); IntSet hashtagIds = new IntOpenHashSet(new int[]{100, 101, 102}); Byte2ObjectMap<IntSet> nodeMetadataTypeToIdsMap = new Byte2ObjectArrayMap<>(); nodeMetadataTypeToIdsMap.put((byte) RecommendationType.HASHTAG.getValue(), hashtagIds); nodeMetadataTypeToIdsMap.put((byte) RecommendationType.URL.getValue(), urlIds); byte[] validSocialProofs = new byte[]{1, 2, 3, 4}; long randomSeed = 918324701982347L; Random random = new Random(randomSeed); NodeMetadataSocialProofRequest request = new NodeMetadataSocialProofRequest( nodeMetadataTypeToIdsMap, seedsMap, validSocialProofs ); SocialProofResponse socialProofResponse = new NodeMetadataSocialProofGenerator( graph ).computeRecommendations(request, random); List<RecommendationInfo> socialProofResults = Lists.newArrayList(socialProofResponse.getRankedRecommendations()); for (RecommendationInfo recommendationInfo: socialProofResults) { NodeMetadataSocialProofResult socialProofResult = (NodeMetadataSocialProofResult) recommendationInfo; int nodeMetadataId = socialProofResult.getNodeMetadataId(); Byte2ObjectMap<Long2ObjectMap<LongSet>> socialProofs = socialProofResult.getSocialProof(); if (nodeMetadataId == 100) { assertEquals(socialProofResult.getSocialProofSize(), 1); assertEquals(socialProofs.get((byte) 1).get(2).contains(3), true); } else if (nodeMetadataId == 101) { assertEquals(socialProofs.isEmpty(), true); } else if (nodeMetadataId == 102) { assertEquals(socialProofs.isEmpty(), true); } else if (nodeMetadataId == 300) { assertEquals(socialProofs.isEmpty(), true); } else if (nodeMetadataId == 200) { assertEquals(socialProofResult.getSocialProofSize(), 3); assertEquals(socialProofs.get((byte) 1).get(2).contains(4), true); assertEquals(socialProofs.get((byte) 1).get(2).contains(6), true); assertEquals(socialProofs.get((byte) 4).get(3).contains(4), true); } } }
Example #9
Source File: MomentSocialProofTest.java From GraphJet with Apache License 2.0 | 4 votes |
@Test public void testComputeRecommendations() throws Exception { LeftIndexedMultiSegmentBipartiteGraph bipartiteGraph = BipartiteGraphTestHelper. buildSmallTestLeftIndexedPowerLawMultiSegmentBipartiteGraphWithEdgeTypes(); Long2DoubleMap seedsMap = new Long2DoubleArrayMap(new long[]{2, 3}, new double[]{1.0, 0.5}); LongSet moments = new LongArraySet(new long[]{2, 3, 4, 5}); byte[] validSocialProofs = new byte[]{0, 1, 2}; long randomSeed = 918324701982347L; Random random = new Random(randomSeed); SocialProofRequest socialProofRequest = new SocialProofRequest( moments, seedsMap, validSocialProofs ); SocialProofResponse socialProofResponse = new MomentSocialProofGenerator( bipartiteGraph ).computeRecommendations(socialProofRequest, random); List<RecommendationInfo> socialProofResults = Lists.newArrayList(socialProofResponse.getRankedRecommendations()); for (RecommendationInfo recommendationInfo: socialProofResults) { SocialProofResult socialProofResult = (SocialProofResult) recommendationInfo; Long momentId = socialProofResult.getNode(); Byte2ObjectMap<LongSet> socialProofs = socialProofResult.getSocialProof(); if (momentId == 2 || momentId == 4) { assertEquals(socialProofs.isEmpty(), true); } else if (momentId == 3) { assertEquals(socialProofs.get((byte) 1).size(), 2); assertEquals(socialProofs.get((byte) 1).contains(2), true); assertEquals(socialProofs.get((byte) 1).contains(3), true); } else if (momentId == 5) { assertEquals(socialProofs.get((byte) 0).size(), 1); assertEquals(socialProofs.get((byte) 0).contains(2), true); } } }
Example #10
Source File: TweetSocialProofTest.java From GraphJet with Apache License 2.0 | 4 votes |
@Test public void testTweetSocialProofs() { NodeMetadataLeftIndexedMultiSegmentBipartiteGraph bipartiteGraph = BipartiteGraphTestHelper.buildSmallTestNodeMetadataLeftIndexedMultiSegmentBipartiteGraph(); Long2DoubleMap seedsMap = new Long2DoubleArrayMap( new long[] {user2, user3}, new double[] {1.0, 0.5}); LongSet tweets = new LongArraySet(new long[] {tweet2, tweet3, tweet4, tweet5}); byte[] validSocialProofTypes = new byte[] { CLICK_SOCIAL_PROOF_TYPE, FAVORITE_SOCIAL_PROOF_TYPE, RETWEET_SOCIAL_PROOF_TYPE, REPLY_SOCIAL_PROOF_TYPE, AUTHOR_SOCIAL_PROOF_TYPE, }; SocialProofRequest socialProofRequest = new SocialProofRequest( tweets, seedsMap, validSocialProofTypes ); HashMap<Long, SocialProofResult> results = new HashMap<>(); new TweetSocialProofGenerator(bipartiteGraph) .computeRecommendations(socialProofRequest, new Random(0)) .getRankedRecommendations().forEach( recInfo -> results.put(((SocialProofResult)recInfo).getNode(), (SocialProofResult)recInfo)); assertEquals(results.size(), 2); Byte2ObjectMap<LongSet> expectedProofs; SocialProofResult expected; // Test social proofs for tweet 2 expectedProofs = new Byte2ObjectArrayMap<>(); expectedProofs.put(CLICK_SOCIAL_PROOF_TYPE, new LongArraySet(new long[] {user3})); expected = new SocialProofResult(tweet2, expectedProofs, 0.5, RecommendationType.TWEET); assertEqualSocialProofResults(expected, results.get(tweet2)); // Test social proofs for tweet 5 expectedProofs = new Byte2ObjectArrayMap<>(); expectedProofs.put(CLICK_SOCIAL_PROOF_TYPE, new LongArraySet(new long[] {user2, user3})); expected = new SocialProofResult(tweet5, expectedProofs, 1.5, RecommendationType.TWEET); assertEqualSocialProofResults(expected, results.get(tweet5)); }
Example #11
Source File: TweetSocialProofTest.java From GraphJet with Apache License 2.0 | 4 votes |
@Test public void testTweetSocialProofs2() { // Run on another test graph LeftIndexedPowerLawMultiSegmentBipartiteGraph bipartiteGraph = BipartiteGraphTestHelper.buildSmallTestLeftIndexedPowerLawMultiSegmentBipartiteGraphWithEdgeTypes(); Long2DoubleMap seedsMap = new Long2DoubleArrayMap( new long[] {user1, user2}, new double[] {1.0, 0.5}); LongSet tweets = new LongArraySet(new long[] {tweet2, tweet3, tweet4, tweet5, tweet6, tweet7, tweet8}); byte[] validSocialProofTypes = new byte[] { FAVORITE_SOCIAL_PROOF_TYPE, RETWEET_SOCIAL_PROOF_TYPE }; SocialProofRequest socialProofRequest = new SocialProofRequest( tweets, seedsMap, validSocialProofTypes ); HashMap<Long, SocialProofResult> results = new HashMap<>(); new TweetSocialProofGenerator(bipartiteGraph) .computeRecommendations(socialProofRequest, new Random(0)) .getRankedRecommendations().forEach( recInfo -> results.put(((SocialProofResult)recInfo).getNode(), (SocialProofResult)recInfo)); assertEquals(5, results.size()); Byte2ObjectMap<LongSet> expectedProofs; SocialProofResult expected; // Test social proofs for tweet 3 expectedProofs = new Byte2ObjectArrayMap<>(); expectedProofs.put(FAVORITE_SOCIAL_PROOF_TYPE, new LongArraySet(new long[] {user1, user2})); expected = new SocialProofResult(tweet3, expectedProofs, 1.5, RecommendationType.TWEET); assertEqualSocialProofResults(expected, results.get(tweet3)); // Test social proofs for tweet 4 expectedProofs = new Byte2ObjectArrayMap<>(); expectedProofs.put(RETWEET_SOCIAL_PROOF_TYPE, new LongArraySet(new long[] {user1})); expected = new SocialProofResult(tweet4, expectedProofs, 1, RecommendationType.TWEET); assertEqualSocialProofResults(expected, results.get(tweet4)); // Test social proofs for tweet 6 expectedProofs = new Byte2ObjectArrayMap<>(); expectedProofs.put(FAVORITE_SOCIAL_PROOF_TYPE, new LongArraySet(new long[] {user2})); expected = new SocialProofResult(tweet6, expectedProofs, 0.5, RecommendationType.TWEET); assertEqualSocialProofResults(expected, results.get(tweet6)); // Test social proofs for tweet 7 expectedProofs = new Byte2ObjectArrayMap<>(); expectedProofs.put(FAVORITE_SOCIAL_PROOF_TYPE, new LongArraySet(new long[] {user2})); expected = new SocialProofResult(tweet7, expectedProofs, 0.5, RecommendationType.TWEET); assertEqualSocialProofResults(expected, results.get(tweet7)); // Test social proofs for tweet 8 expectedProofs = new Byte2ObjectArrayMap<>(); expectedProofs.put(FAVORITE_SOCIAL_PROOF_TYPE, new LongArraySet(new long[] {user1})); expectedProofs.put(RETWEET_SOCIAL_PROOF_TYPE, new LongArraySet(new long[] {user2})); expected = new SocialProofResult(tweet8, expectedProofs, 1.5, RecommendationType.TWEET); assertEqualSocialProofResults(expected, results.get(tweet8)); }
Example #12
Source File: TweetSocialProofTest.java From GraphJet with Apache License 2.0 | 4 votes |
@Test public void testTweetSocialProofsWithUnfavorites() { // Test graph with favorite edges that are potentially unfavorited later NodeMetadataLeftIndexedMultiSegmentBipartiteGraph graph = BipartiteGraphTestHelper.buildTestNodeMetadataLeftIndexedMultiSegmentBipartiteGraphWithUnfavorite(); Long2DoubleMap seedsMap = new Long2DoubleArrayMap( new long[] {user1, user2, user3, user4, user5, user6, user7, user8, user9, user10, user11, user12, user13, user14}, new double[] {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}); LongSet tweets = new LongArraySet( new long[] {tweet1, tweet2, tweet3, tweet4, tweet5, tweet6, tweet7, tweet8, tweet9, tweet10, tweet11, tweet12, tweet13}); byte[] validSocialProofTypes = new byte[] {FAVORITE_SOCIAL_PROOF_TYPE}; SocialProofRequest socialProofRequest = new SocialProofRequest( tweets, seedsMap, validSocialProofTypes); HashMap<Long, SocialProofResult> results = new HashMap<>(); new TweetSocialProofGenerator(graph) .computeRecommendations(socialProofRequest, new Random(0)) .getRankedRecommendations().forEach( recInfo -> results.put(((SocialProofResult)recInfo).getNode(), (SocialProofResult)recInfo)); assertEquals(7, results.size()); Byte2ObjectMap<LongSet> expectedProofs; SocialProofResult expected; // Test social proofs for tweet 1 expectedProofs = new Byte2ObjectArrayMap<>(); expectedProofs.put(FAVORITE_SOCIAL_PROOF_TYPE, new LongArraySet(new long[] {user1})); expected = new SocialProofResult(tweet1, expectedProofs, 1, RecommendationType.TWEET); assertEqualSocialProofResults(expected, results.get(tweet1)); // Test social proofs for tweet 5 expectedProofs = new Byte2ObjectArrayMap<>(); expectedProofs.put(FAVORITE_SOCIAL_PROOF_TYPE, new LongArraySet(new long[] {user5})); expected = new SocialProofResult(tweet5, expectedProofs, 1, RecommendationType.TWEET); assertEqualSocialProofResults(expected, results.get(tweet5)); // Test social proofs for tweet 7 expectedProofs = new Byte2ObjectArrayMap<>(); expectedProofs.put(FAVORITE_SOCIAL_PROOF_TYPE, new LongArraySet(new long[] {user7})); expected = new SocialProofResult(tweet7, expectedProofs, 1, RecommendationType.TWEET); assertEqualSocialProofResults(expected, results.get(tweet7)); // Test social proofs for tweet 8 expectedProofs = new Byte2ObjectArrayMap<>(); expectedProofs.put(FAVORITE_SOCIAL_PROOF_TYPE, new LongArraySet(new long[] {user8, user9})); expected = new SocialProofResult(tweet8, expectedProofs, 2, RecommendationType.TWEET); assertEqualSocialProofResults(expected, results.get(tweet8)); // Test social proofs for tweet 9 expectedProofs = new Byte2ObjectArrayMap<>(); expectedProofs.put(FAVORITE_SOCIAL_PROOF_TYPE, new LongArraySet(new long[] {user9, user10})); expected = new SocialProofResult(tweet9, expectedProofs, 2, RecommendationType.TWEET); assertEqualSocialProofResults(expected, results.get(tweet9)); // Test social proofs for tweet 10 expectedProofs = new Byte2ObjectArrayMap<>(); expectedProofs.put(FAVORITE_SOCIAL_PROOF_TYPE, new LongArraySet(new long[] {user10})); expected = new SocialProofResult(tweet10, expectedProofs, 1, RecommendationType.TWEET); assertEqualSocialProofResults(expected, results.get(tweet10)); // Test social proofs for tweet 13 expectedProofs = new Byte2ObjectArrayMap<>(); expectedProofs.put(FAVORITE_SOCIAL_PROOF_TYPE, new LongArraySet(new long[] {user13})); expected = new SocialProofResult(tweet13, expectedProofs, 1, RecommendationType.TWEET); assertEqualSocialProofResults(expected, results.get(tweet13)); }
Example #13
Source File: TweetSocialProofTest.java From GraphJet with Apache License 2.0 | 4 votes |
@Test public void testTweetSocialProofWithRetweetAndUnfavorites() { // Test cases where unfavorite tweets are also retweeted NodeMetadataLeftIndexedMultiSegmentBipartiteGraph graph = BipartiteGraphTestHelper.buildTestNodeMetadataLeftIndexedMultiSegmentBipartiteGraphWithUnfavorite(); Long2DoubleMap seedsMap = new Long2DoubleArrayMap( new long[] {user1, user2, user3, user4, user5, user6, user7, user8, user9, user10, user11, user12, user13, user14}, new double[] {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}); LongSet tweets = new LongArraySet( new long[] {tweet1, tweet2, tweet3, tweet4, tweet5, tweet6, tweet7, tweet8, tweet9, tweet10, tweet11, tweet12, tweet13}); byte[] validSocialProofTypes = new byte[] {FAVORITE_SOCIAL_PROOF_TYPE, RETWEET_SOCIAL_PROOF_TYPE}; SocialProofRequest socialProofRequest = new SocialProofRequest( tweets, seedsMap, validSocialProofTypes); HashMap<Long, SocialProofResult> results = new HashMap<>(); new TweetSocialProofGenerator(graph) .computeRecommendations(socialProofRequest, new Random(0)) .getRankedRecommendations().forEach( recInfo -> results.put(((SocialProofResult)recInfo).getNode(), (SocialProofResult)recInfo)); assertEquals(10, results.size()); Byte2ObjectMap<LongSet> expectedProofs; SocialProofResult expected; // Test social proofs for tweet 1 expectedProofs = new Byte2ObjectArrayMap<>(); expectedProofs.put(FAVORITE_SOCIAL_PROOF_TYPE, new LongArraySet(new long[] {user1})); expected = new SocialProofResult(tweet1, expectedProofs, 1, RecommendationType.TWEET); assertEqualSocialProofResults(expected, results.get(tweet1)); // Test social proofs for tweet 2 expectedProofs = new Byte2ObjectArrayMap<>(); expectedProofs.put(RETWEET_SOCIAL_PROOF_TYPE, new LongArraySet(new long[] {user2})); expected = new SocialProofResult(tweet2, expectedProofs, 1, RecommendationType.TWEET); assertEqualSocialProofResults(expected, results.get(tweet2)); // Test social proofs for tweet 5 expectedProofs = new Byte2ObjectArrayMap<>(); expectedProofs.put(FAVORITE_SOCIAL_PROOF_TYPE, new LongArraySet(new long[] {user5})); expected = new SocialProofResult(tweet5, expectedProofs, 1, RecommendationType.TWEET); assertEqualSocialProofResults(expected, results.get(tweet5)); // Test social proofs for tweet 7 expectedProofs = new Byte2ObjectArrayMap<>(); expectedProofs.put(FAVORITE_SOCIAL_PROOF_TYPE, new LongArraySet(new long[] {user7})); expected = new SocialProofResult(tweet7, expectedProofs, 1, RecommendationType.TWEET); assertEqualSocialProofResults(expected, results.get(tweet7)); // Test social proofs for tweet 8 expectedProofs = new Byte2ObjectArrayMap<>(); expectedProofs.put(FAVORITE_SOCIAL_PROOF_TYPE, new LongArraySet(new long[] {user8, user9})); expected = new SocialProofResult(tweet8, expectedProofs, 2, RecommendationType.TWEET); assertEqualSocialProofResults(expected, results.get(tweet8)); // Test social proofs for tweet 9 expectedProofs = new Byte2ObjectArrayMap<>(); expectedProofs.put(FAVORITE_SOCIAL_PROOF_TYPE, new LongArraySet(new long[] {user9, user10})); expected = new SocialProofResult(tweet9, expectedProofs, 2, RecommendationType.TWEET); assertEqualSocialProofResults(expected, results.get(tweet9)); // Test social proofs for tweet 10 expectedProofs = new Byte2ObjectArrayMap<>(); expectedProofs.put(FAVORITE_SOCIAL_PROOF_TYPE, new LongArraySet(new long[] {user10})); expectedProofs.put(RETWEET_SOCIAL_PROOF_TYPE, new LongArraySet(new long[] {user11})); expected = new SocialProofResult(tweet10, expectedProofs, 2, RecommendationType.TWEET); assertEqualSocialProofResults(expected, results.get(tweet10)); // Test social proofs for tweet 11 expectedProofs = new Byte2ObjectArrayMap<>(); expectedProofs.put(RETWEET_SOCIAL_PROOF_TYPE, new LongArraySet(new long[] {user11})); expected = new SocialProofResult(tweet11, expectedProofs, 1, RecommendationType.TWEET); assertEqualSocialProofResults(expected, results.get(tweet11)); // Test social proofs for tweet 12 expectedProofs = new Byte2ObjectArrayMap<>(); expectedProofs.put(RETWEET_SOCIAL_PROOF_TYPE, new LongArraySet(new long[] {user12})); expected = new SocialProofResult(tweet12, expectedProofs, 1, RecommendationType.TWEET); assertEqualSocialProofResults(expected, results.get(tweet12)); // Test social proofs for tweet 13 expectedProofs = new Byte2ObjectArrayMap<>(); expectedProofs.put(FAVORITE_SOCIAL_PROOF_TYPE, new LongArraySet(new long[] {user13})); expectedProofs.put(RETWEET_SOCIAL_PROOF_TYPE, new LongArraySet(new long[] {user14})); expected = new SocialProofResult(tweet13, expectedProofs, 2, RecommendationType.TWEET); assertEqualSocialProofResults(expected, results.get(tweet13)); }
Example #14
Source File: ByteDictionaryMap.java From tablesaw with Apache License 2.0 | 4 votes |
ObjectSet<Byte2ObjectMap.Entry<String>> getKeyValueEntries() { return keyToValue.byte2ObjectEntrySet(); }
Example #15
Source File: ByteDictionaryMap.java From tablesaw with Apache License 2.0 | 4 votes |
private Byte2ObjectMap<String> keyToValueMap() { return keyToValue; }
Example #16
Source File: NodeMetadataSocialProofRequest.java From GraphJet with Apache License 2.0 | 3 votes |
/** * Create a social proof request for a right node's metadata. * * @param nodeMetadataTypeToIdsMap The map of node metadata type to ids map. Used to specify * which node metadata types to retrieve social proof for, and * for which ids. These metadata types are derived from * the RecommendationType enum. * @param weightedSeedNodes The set of left nodes to be used as social proofs. * @param socialProofTypes The social proof types to return. */ public NodeMetadataSocialProofRequest( Byte2ObjectMap<IntSet> nodeMetadataTypeToIdsMap, Long2DoubleMap weightedSeedNodes, byte[] socialProofTypes ) { super(0, EMPTY_SET, socialProofTypes); this.leftSeedNodesWithWeight = weightedSeedNodes; this.nodeMetadataTypeToIdsMap = nodeMetadataTypeToIdsMap; }