it.unimi.dsi.fastutil.longs.LongArraySet Java Examples

The following examples show how to use it.unimi.dsi.fastutil.longs.LongArraySet. 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: TweetAuthorFilterTest.java    From GraphJet with Apache License 2.0 6 votes vote down vote up
@Test
public void testBlacklistWhitelistPartialOverlap() {
  NodeMetadataLeftIndexedMultiSegmentBipartiteGraph mockGraph = getMockGraph();

  SmallArrayBasedLongToDoubleMap[] socialProofs = {};

  LongSet whitelistAuthors = new LongArraySet();
  whitelistAuthors.add(1L);
  whitelistAuthors.add(2L);
  whitelistAuthors.add(3L);

  LongSet blacklistAuthors = new LongArraySet();
  blacklistAuthors.add(2L);
  blacklistAuthors.add(3L);
  blacklistAuthors.add(4L);

  TweetAuthorFilter authorFilter = new TweetAuthorFilter(
      mockGraph, whitelistAuthors, blacklistAuthors, new NullStatsReceiver());

  // Only return 10, since it is whitelisted and not blacklisted
  assertEquals(false, authorFilter.filterResult(10, socialProofs));
  assertEquals(true, authorFilter.filterResult(20, socialProofs));
  assertEquals(true, authorFilter.filterResult(30, socialProofs));
  assertEquals(true, authorFilter.filterResult(40, socialProofs));
}
 
Example #2
Source File: AgreeSetGenerator.java    From metanome-algorithms with Apache License 2.0 6 votes vote down vote up
private boolean isSubset(IntList actuelList, Map<Long, LongSet> index) {

        boolean first = true;
        LongSet positions = new LongArraySet();
        for (long e : actuelList) {
            if (!index.containsKey(Long.valueOf(e))) {
                return false;
            }
            if (first) {
                positions.addAll(index.get(Long.valueOf(e)));
                first = false;
            } else {

                this.intersect(positions, index.get(Long.valueOf(e)));
                // FIXME: Throws UnsupportedOperationExeption within fastUtil
                // positions.retainAll(index.get(e));
            }
            if (positions.size() == 0) {
                return false;
            }
        }
        return true;
    }
 
Example #3
Source File: TweetAuthorFilterTest.java    From GraphJet with Apache License 2.0 6 votes vote down vote up
@Test
public void testBlacklistWhitelistFullOverlap() {
  NodeMetadataLeftIndexedMultiSegmentBipartiteGraph mockGraph = getMockGraph();

  SmallArrayBasedLongToDoubleMap[] socialProofs = {};

  LongSet whitelistAuthors = new LongArraySet();
  whitelistAuthors.add(1L);
  whitelistAuthors.add(2L);
  whitelistAuthors.add(3L);

  LongSet blacklistAuthors = new LongArraySet();
  blacklistAuthors.add(1L);
  blacklistAuthors.add(2L);
  blacklistAuthors.add(3L);

  TweetAuthorFilter authorFilter = new TweetAuthorFilter(
      mockGraph, whitelistAuthors, blacklistAuthors, new NullStatsReceiver());

  // No tweet should be returned. 10, 20, 30 filtered by blacklist, 40 filtered by whitelist
  assertEquals(true, authorFilter.filterResult(10, socialProofs));
  assertEquals(true, authorFilter.filterResult(20, socialProofs));
  assertEquals(true, authorFilter.filterResult(30, socialProofs));
  assertEquals(true, authorFilter.filterResult(40, socialProofs));
}
 
Example #4
Source File: BlockLeaves.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public int onUpdate(int type) {
    if (type == Level.BLOCK_UPDATE_RANDOM && !isPersistent() && !isCheckDecay()) {
        setCheckDecay(true);
        getLevel().setBlock(this, this, false, false);
    } else if (type == Level.BLOCK_UPDATE_RANDOM && isCheckDecay() && !isPersistent()) {
        setDamage(getDamage() & 0x03);
        int check = 0;

        LeavesDecayEvent ev = new LeavesDecayEvent(this);

        Server.getInstance().getPluginManager().callEvent(ev);
        if (ev.isCancelled() || findLog(this, new LongArraySet(), 0, check)) {
            getLevel().setBlock(this, this, false, false);
        } else {
            getLevel().useBreakOn(this);
            return Level.BLOCK_UPDATE_NORMAL;
        }
    }
    return 0;
}
 
Example #5
Source File: TransactionManager.java    From phoenix-tephra with Apache License 2.0 6 votes vote down vote up
private boolean doTruncateInvalidTxBefore(long time) throws InvalidTruncateTimeException {
  LOG.info("Removing tx ids before {} from invalid list", time);
  long truncateWp = time * TxConstants.MAX_TX_PER_MS;
  // Check if there any in-progress transactions started earlier than truncate time
  if (inProgress.lowerKey(truncateWp) != null) {
    throw new InvalidTruncateTimeException("Transactions started earlier than " + time + " are in-progress");
  }
  
  // Find all invalid transactions earlier than truncateWp
  LongSet toTruncate = new LongArraySet();
  LongIterator it = invalidTxList.toRawList().iterator();
  while (it.hasNext()) {
    long wp = it.nextLong();
    if (wp < truncateWp) {
      toTruncate.add(wp);
    }
  }
  LOG.info("Removing tx ids {} from invalid list", toTruncate);
  return invalidTxList.removeAll(toTruncate);
}
 
Example #6
Source File: SocialProofGenerator.java    From GraphJet with Apache License 2.0 6 votes vote down vote up
/**
 * Given a nodeInfo containing the social proofs and weight information regarding a rightNode,
 * convert and store these data in a SocialProofResult object, to comply with the class interface.
 *
 * @param nodeInfo Contains all the social proofs on a particular right node, along with the
 * accumulated node weight
 */
private SocialProofResult makeSocialProofResult(NodeInfo nodeInfo) {
  Byte2ObjectArrayMap<LongSet> socialProofsMap = new Byte2ObjectArrayMap<>();

  for (int socialProofType = 0; socialProofType < NUM_OF_SOCIAL_PROOF_TYPES; socialProofType++) {
    SmallArrayBasedLongToDoubleMap socialProofsByType = nodeInfo.getSocialProofs()[socialProofType];
    if (socialProofsByType == null || socialProofsByType.size() == 0) {
      continue;
    }
    LongSet rightNodeIds = new LongArraySet(
      Arrays.copyOfRange(socialProofsByType.keys(), 0, socialProofsByType.size()));
    socialProofsMap.put((byte)socialProofType, rightNodeIds);
  }

  return new SocialProofResult(
    nodeInfo.getNodeId(),
    socialProofsMap,
    nodeInfo.getWeight(),
    recommendationType
  );
}
 
Example #7
Source File: TweetAuthorFilterTest.java    From GraphJet with Apache License 2.0 6 votes vote down vote up
@Test
public void testBlacklistWhitelistNoOverlap() {
  NodeMetadataLeftIndexedMultiSegmentBipartiteGraph mockGraph = getMockGraph();

  SmallArrayBasedLongToDoubleMap[] socialProofs = {};

  LongSet whitelistAuthors = new LongArraySet();
  whitelistAuthors.add(1L);
  whitelistAuthors.add(2L);

  LongSet blacklistAuthors = new LongArraySet();
  blacklistAuthors.add(3L);
  blacklistAuthors.add(4L);

  TweetAuthorFilter authorFilter = new TweetAuthorFilter(
      mockGraph, whitelistAuthors, blacklistAuthors, new NullStatsReceiver());

  // Should only return whitelisted 10 and 20. 30 and 40 are filtered by blacklist
  assertEquals(false, authorFilter.filterResult(10, socialProofs));
  assertEquals(false, authorFilter.filterResult(20, socialProofs));
  assertEquals(true, authorFilter.filterResult(30, socialProofs));
  assertEquals(true, authorFilter.filterResult(40, socialProofs));
}
 
Example #8
Source File: TweetAuthorFilterTest.java    From GraphJet with Apache License 2.0 6 votes vote down vote up
@Test
public void testBlacklistOnlyTwoAuthors() {
  NodeMetadataLeftIndexedMultiSegmentBipartiteGraph mockGraph = getMockGraph();

  SmallArrayBasedLongToDoubleMap[] socialProofs = {};

  LongSet whitelistAuthors = new LongArraySet();
  LongSet blacklistAuthors = new LongArraySet();
  blacklistAuthors.add(3L);
  blacklistAuthors.add(4L);

  TweetAuthorFilter authorFilter = new TweetAuthorFilter(
      mockGraph, whitelistAuthors, blacklistAuthors, new NullStatsReceiver());

  // 10L and 20L are authored by user 1 and 2. Do not filter them
  assertEquals(false, authorFilter.filterResult(10, socialProofs));
  assertEquals(false, authorFilter.filterResult(20, socialProofs));
  // 30L and 40L are authored by user 3 and 4. Filter them
  assertEquals(true, authorFilter.filterResult(30, socialProofs));
  assertEquals(true, authorFilter.filterResult(40, socialProofs));
}
 
Example #9
Source File: TweetAuthorFilterTest.java    From GraphJet with Apache License 2.0 6 votes vote down vote up
@Test
public void testWhitelistOnlyTwoAuthors() {
  NodeMetadataLeftIndexedMultiSegmentBipartiteGraph mockGraph = getMockGraph();

  SmallArrayBasedLongToDoubleMap[] socialProofs = {};

  LongSet whitelistAuthors = new LongArraySet();
  whitelistAuthors.add(1L);
  whitelistAuthors.add(2L);

  LongSet blacklistAuthors = new LongArraySet();

  TweetAuthorFilter authorFilter = new TweetAuthorFilter(
      mockGraph, whitelistAuthors, blacklistAuthors, new NullStatsReceiver());

  // 10L and 20L are authored by user 1 and 2. Do not filter them
  assertEquals(false, authorFilter.filterResult(10, socialProofs));
  assertEquals(false, authorFilter.filterResult(20, socialProofs));
  // 30L and 40L are authored by user 3 and 4. Filter them
  assertEquals(true, authorFilter.filterResult(30, socialProofs));
  assertEquals(true, authorFilter.filterResult(40, socialProofs));
}
 
Example #10
Source File: TweetAuthorFilterTest.java    From GraphJet with Apache License 2.0 6 votes vote down vote up
@Test
public void testEmptyWhitelist() {
  NodeMetadataLeftIndexedMultiSegmentBipartiteGraph mockGraph = getMockGraph();

  SmallArrayBasedLongToDoubleMap[] socialProofs = {};

  LongSet whitelistAuthors = new LongArraySet();

  LongSet blacklistAuthors = new LongArraySet();

  TweetAuthorFilter authorFilter = new TweetAuthorFilter(
      mockGraph, whitelistAuthors, blacklistAuthors, new NullStatsReceiver());

  // None of the tweets should be filtered.
  assertEquals(false, authorFilter.filterResult(10, socialProofs));
  assertEquals(false, authorFilter.filterResult(20, socialProofs));
  assertEquals(false, authorFilter.filterResult(30, socialProofs));
  assertEquals(false, authorFilter.filterResult(40, socialProofs));
}
 
Example #11
Source File: TweetSocialProofTest.java    From GraphJet with Apache License 2.0 6 votes vote down vote up
@Test
public void testTweetSocialProofWithInvalidUnfavorites() {
  // Test cases where unfavorite social proof is the only social proof type. Nothing will return
  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[] {UNFAVORITE_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(0, results.size());
}
 
Example #12
Source File: TweetSocialProofTest.java    From GraphJet with Apache License 2.0 5 votes vote down vote up
@Test
public void testTweetSocialProofsWithInvalidType() {
  // Test cases where the requested social proof types yield no results
  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});

  // In the graph there are no valid social proofs corresponding to these types
  byte[] validSocialProofTypes = new byte[] {
    AUTHOR_SOCIAL_PROOF_TYPE,
    IS_MENTIONED_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));

  assertTrue(results.isEmpty());
}
 
Example #13
Source File: AgreeSetGenerator.java    From metanome-algorithms with Apache License 2.0 5 votes vote down vote up
private void handlePartitionConcurrent(IntList actuelList, long position, Map<Long, LongSet> index, Map<IntList, Object> max) {

        if (!this.isSubset(actuelList, index)) {
            max.put(actuelList, new Object());
            for (long e : actuelList) {
                if (!index.containsKey(Long.valueOf(e))) {
                    index.put(Long.valueOf(e), new LongArraySet());
                }
                index.get(Long.valueOf(e)).add(position);
            }
        }
    }
 
Example #14
Source File: AgreeSetGenerator.java    From metanome-algorithms with Apache License 2.0 5 votes vote down vote up
private void intersect(LongSet positions, LongSet indexSet) {

        LongSet toRemove = new LongArraySet();
        for (long l : positions) {
            if (!indexSet.contains(l)) {
                toRemove.add(l);
            }
        }
        positions.removeAll(toRemove);
    }
 
Example #15
Source File: AgreeSetGenerator.java    From metanome-algorithms with Apache License 2.0 5 votes vote down vote up
private void handlePartition(IntList actuelList, long position, Long2ObjectMap<LongSet> index, Set<IntList> max) {

        if (!this.isSubset(actuelList, index)) {
            max.add(actuelList);
            for (long e : actuelList) {
                if (!index.containsKey(e)) {
                    index.put(e, new LongArraySet());
                }
                index.get(e).add(position);
            }
        }
    }
 
Example #16
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 #17
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));
}
 
Example #18
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 #19
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 #20
Source File: MomentSocialProofTest.java    From GraphJet with Apache License 2.0 4 votes vote down vote up
@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);
    }
  }
}