org.apache.flink.graph.library.linkanalysis.HITS.Result Java Examples

The following examples show how to use org.apache.flink.graph.library.linkanalysis.HITS.Result. 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: HITSTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithSimpleGraph() throws Exception {
	DataSet<Result<IntValue>> hits = new HITS<IntValue, NullValue, NullValue>(20)
		.run(directedSimpleGraph);

	List<Tuple2<Double, Double>> expectedResults = new ArrayList<>();
	expectedResults.add(Tuple2.of(0.54464336064, 0.0));
	expectedResults.add(Tuple2.of(0.0, 0.836329364957));
	expectedResults.add(Tuple2.of(0.607227075863, 0.268492484699));
	expectedResults.add(Tuple2.of(0.54464336064, 0.395445020996));
	expectedResults.add(Tuple2.of(0.0, 0.268492484699));
	expectedResults.add(Tuple2.of(0.194942293412, 0.0));

	for (Result<IntValue> result : hits.collect()) {
		int id = result.getVertexId0().getValue();
		assertEquals(expectedResults.get(id).f0, result.getHubScore().getValue(), ACCURACY);
		assertEquals(expectedResults.get(id).f1, result.getAuthorityScore().getValue(), ACCURACY);
	}
}
 
Example #2
Source File: HITSTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithSimpleGraph() throws Exception {
	DataSet<Result<IntValue>> hits = new HITS<IntValue, NullValue, NullValue>(20)
		.run(directedSimpleGraph);

	List<Tuple2<Double, Double>> expectedResults = new ArrayList<>();
	expectedResults.add(Tuple2.of(0.54464336064, 0.0));
	expectedResults.add(Tuple2.of(0.0, 0.836329364957));
	expectedResults.add(Tuple2.of(0.607227075863, 0.268492484699));
	expectedResults.add(Tuple2.of(0.54464336064, 0.395445020996));
	expectedResults.add(Tuple2.of(0.0, 0.268492484699));
	expectedResults.add(Tuple2.of(0.194942293412, 0.0));

	for (Result<IntValue> result : hits.collect()) {
		int id = result.getVertexId0().getValue();
		assertEquals(expectedResults.get(id).f0, result.getHubScore().getValue(), ACCURACY);
		assertEquals(expectedResults.get(id).f1, result.getAuthorityScore().getValue(), ACCURACY);
	}
}
 
Example #3
Source File: HITSTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithSimpleGraph() throws Exception {
	DataSet<Result<IntValue>> hits = new HITS<IntValue, NullValue, NullValue>(20)
		.run(directedSimpleGraph);

	List<Tuple2<Double, Double>> expectedResults = new ArrayList<>();
	expectedResults.add(Tuple2.of(0.54464336064, 0.0));
	expectedResults.add(Tuple2.of(0.0, 0.836329364957));
	expectedResults.add(Tuple2.of(0.607227075863, 0.268492484699));
	expectedResults.add(Tuple2.of(0.54464336064, 0.395445020996));
	expectedResults.add(Tuple2.of(0.0, 0.268492484699));
	expectedResults.add(Tuple2.of(0.194942293412, 0.0));

	for (Result<IntValue> result : hits.collect()) {
		int id = result.getVertexId0().getValue();
		assertEquals(expectedResults.get(id).f0, result.getHubScore().getValue(), ACCURACY);
		assertEquals(expectedResults.get(id).f1, result.getAuthorityScore().getValue(), ACCURACY);
	}
}
 
Example #4
Source File: HITS.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public Result<T> map(Tuple3<T, DoubleValue, DoubleValue> value) throws Exception {
	output.setVertexId0(value.f0);
	output.setHubScore(value.f1);
	output.setAuthorityScore(value.f2);
	return output;
}
 
Example #5
Source File: HITSTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * Validate a test where each result has the same values.
 *
 * @param graph input graph
 * @param count number of results
 * @param score result hub and authority score
 * @param <T> graph ID type
 * @throws Exception on error
 */
private static <T> void validate(Graph<T, NullValue, NullValue> graph, long count, double score) throws Exception {
	DataSet<Result<T>> hits = new HITS<T, NullValue, NullValue>(ACCURACY)
		.run(graph);

	List<Result<T>> results = hits.collect();

	assertEquals(count, results.size());

	for (Result<T> result : results) {
		assertEquals(score, result.getHubScore().getValue(), ACCURACY);
		assertEquals(score, result.getAuthorityScore().getValue(), ACCURACY);
	}
}
 
Example #6
Source File: HITSTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithRMatGraph() throws Exception {
	DataSet<Result<LongValue>> hits = directedRMatGraph(10, 16)
		.run(new HITS<>(ACCURACY));

	Map<Long, Result<LongValue>> results = new HashMap<>();
	for (Result<LongValue> result :  new Collect<Result<LongValue>>().run(hits).execute()) {
		results.put(result.getVertexId0().getValue(), result);
	}

	assertEquals(902, results.size());

	Map<Long, Tuple2<Double, Double>> expectedResults = new HashMap<>();
	// a pseudo-random selection of results, both high and low
	expectedResults.put(0L, Tuple2.of(0.231077034503, 0.238110215657));
	expectedResults.put(1L, Tuple2.of(0.162364053853, 0.169679504542));
	expectedResults.put(2L, Tuple2.of(0.162412612418, 0.161015667467));
	expectedResults.put(8L, Tuple2.of(0.167064641648, 0.158592966732));
	expectedResults.put(13L, Tuple2.of(0.0419155956364, 0.0407091624972));
	expectedResults.put(29L, Tuple2.of(0.0102017346609, 0.0146218045619));
	expectedResults.put(109L, Tuple2.of(0.00190531000308, 0.00481944991974));
	expectedResults.put(394L, Tuple2.of(0.0122287016151, 0.0147987969383));
	expectedResults.put(652L, Tuple2.of(0.0109666592418, 0.0113713306828));
	expectedResults.put(1020L, Tuple2.of(0.0, 0.000326973733252));

	for (Map.Entry<Long, Tuple2<Double, Double>> expected : expectedResults.entrySet()) {
		double hubScore = results.get(expected.getKey()).getHubScore().getValue();
		double authorityScore = results.get(expected.getKey()).getAuthorityScore().getValue();

		assertEquals(expected.getValue().f0, hubScore, ACCURACY);
		assertEquals(expected.getValue().f1, authorityScore, ACCURACY);
	}
}
 
Example #7
Source File: HITS.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public Result<T> map(Tuple3<T, DoubleValue, DoubleValue> value) throws Exception {
	output.setVertexId0(value.f0);
	output.setHubScore(value.f1);
	output.setAuthorityScore(value.f2);
	return output;
}
 
Example #8
Source File: HITSTest.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Validate a test where each result has the same values.
 *
 * @param graph input graph
 * @param count number of results
 * @param score result hub and authority score
 * @param <T> graph ID type
 * @throws Exception on error
 */
private static <T> void validate(Graph<T, NullValue, NullValue> graph, long count, double score) throws Exception {
	DataSet<Result<T>> hits = new HITS<T, NullValue, NullValue>(ACCURACY)
		.run(graph);

	List<Result<T>> results = hits.collect();

	assertEquals(count, results.size());

	for (Result<T> result : results) {
		assertEquals(score, result.getHubScore().getValue(), ACCURACY);
		assertEquals(score, result.getAuthorityScore().getValue(), ACCURACY);
	}
}
 
Example #9
Source File: HITSTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithRMatGraph() throws Exception {
	DataSet<Result<LongValue>> hits = directedRMatGraph(10, 16)
		.run(new HITS<>(ACCURACY));

	Map<Long, Result<LongValue>> results = new HashMap<>();
	for (Result<LongValue> result :  new Collect<Result<LongValue>>().run(hits).execute()) {
		results.put(result.getVertexId0().getValue(), result);
	}

	assertEquals(902, results.size());

	Map<Long, Tuple2<Double, Double>> expectedResults = new HashMap<>();
	// a pseudo-random selection of results, both high and low
	expectedResults.put(0L, Tuple2.of(0.231077034503, 0.238110215657));
	expectedResults.put(1L, Tuple2.of(0.162364053853, 0.169679504542));
	expectedResults.put(2L, Tuple2.of(0.162412612418, 0.161015667467));
	expectedResults.put(8L, Tuple2.of(0.167064641648, 0.158592966732));
	expectedResults.put(13L, Tuple2.of(0.0419155956364, 0.0407091624972));
	expectedResults.put(29L, Tuple2.of(0.0102017346609, 0.0146218045619));
	expectedResults.put(109L, Tuple2.of(0.00190531000308, 0.00481944991974));
	expectedResults.put(394L, Tuple2.of(0.0122287016151, 0.0147987969383));
	expectedResults.put(652L, Tuple2.of(0.0109666592418, 0.0113713306828));
	expectedResults.put(1020L, Tuple2.of(0.0, 0.000326973733252));

	for (Map.Entry<Long, Tuple2<Double, Double>> expected : expectedResults.entrySet()) {
		double hubScore = results.get(expected.getKey()).getHubScore().getValue();
		double authorityScore = results.get(expected.getKey()).getAuthorityScore().getValue();

		assertEquals(expected.getValue().f0, hubScore, ACCURACY);
		assertEquals(expected.getValue().f1, authorityScore, ACCURACY);
	}
}
 
Example #10
Source File: HITS.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public Result<T> map(Tuple3<T, DoubleValue, DoubleValue> value) throws Exception {
	output.setVertexId0(value.f0);
	output.setHubScore(value.f1);
	output.setAuthorityScore(value.f2);
	return output;
}
 
Example #11
Source File: HITSTest.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Validate a test where each result has the same values.
 *
 * @param graph input graph
 * @param count number of results
 * @param score result hub and authority score
 * @param <T> graph ID type
 * @throws Exception on error
 */
private static <T> void validate(Graph<T, NullValue, NullValue> graph, long count, double score) throws Exception {
	DataSet<Result<T>> hits = new HITS<T, NullValue, NullValue>(ACCURACY)
		.run(graph);

	List<Result<T>> results = hits.collect();

	assertEquals(count, results.size());

	for (Result<T> result : results) {
		assertEquals(score, result.getHubScore().getValue(), ACCURACY);
		assertEquals(score, result.getAuthorityScore().getValue(), ACCURACY);
	}
}
 
Example #12
Source File: HITSTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithRMatGraph() throws Exception {
	DataSet<Result<LongValue>> hits = directedRMatGraph(10, 16)
		.run(new HITS<>(ACCURACY));

	Map<Long, Result<LongValue>> results = new HashMap<>();
	for (Result<LongValue> result :  new Collect<Result<LongValue>>().run(hits).execute()) {
		results.put(result.getVertexId0().getValue(), result);
	}

	assertEquals(902, results.size());

	Map<Long, Tuple2<Double, Double>> expectedResults = new HashMap<>();
	// a pseudo-random selection of results, both high and low
	expectedResults.put(0L, Tuple2.of(0.231077034503, 0.238110215657));
	expectedResults.put(1L, Tuple2.of(0.162364053853, 0.169679504542));
	expectedResults.put(2L, Tuple2.of(0.162412612418, 0.161015667467));
	expectedResults.put(8L, Tuple2.of(0.167064641648, 0.158592966732));
	expectedResults.put(13L, Tuple2.of(0.0419155956364, 0.0407091624972));
	expectedResults.put(29L, Tuple2.of(0.0102017346609, 0.0146218045619));
	expectedResults.put(109L, Tuple2.of(0.00190531000308, 0.00481944991974));
	expectedResults.put(394L, Tuple2.of(0.0122287016151, 0.0147987969383));
	expectedResults.put(652L, Tuple2.of(0.0109666592418, 0.0113713306828));
	expectedResults.put(1020L, Tuple2.of(0.0, 0.000326973733252));

	for (Map.Entry<Long, Tuple2<Double, Double>> expected : expectedResults.entrySet()) {
		double hubScore = results.get(expected.getKey()).getHubScore().getValue();
		double authorityScore = results.get(expected.getKey()).getAuthorityScore().getValue();

		assertEquals(expected.getValue().f0, hubScore, ACCURACY);
		assertEquals(expected.getValue().f1, authorityScore, ACCURACY);
	}
}