Java Code Examples for it.unimi.dsi.fastutil.bytes.Byte2ObjectMap#put()

The following examples show how to use it.unimi.dsi.fastutil.bytes.Byte2ObjectMap#put() . 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: NodeMetadataSocialProofTest.java    From GraphJet with Apache License 2.0 4 votes vote down vote up
@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 2
Source File: TweetSocialProofTest.java    From GraphJet with Apache License 2.0 4 votes vote down vote up
@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 3
Source File: TweetSocialProofTest.java    From GraphJet with Apache License 2.0 4 votes vote down vote up
@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 4
Source File: TweetSocialProofTest.java    From GraphJet with Apache License 2.0 4 votes vote down vote up
@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 5
Source File: TweetSocialProofTest.java    From GraphJet with Apache License 2.0 4 votes vote down vote up
@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));
}