當前位置: 首頁>>代碼示例>>Java>>正文


Java PageRank類代碼示例

本文整理匯總了Java中org.apache.flink.graph.examples.PageRank的典型用法代碼示例。如果您正苦於以下問題:Java PageRank類的具體用法?Java PageRank怎麽用?Java PageRank使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


PageRank類屬於org.apache.flink.graph.examples包,在下文中一共展示了PageRank類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testPageRankWithThreeIterations

import org.apache.flink.graph.examples.PageRank; //導入依賴的package包/類
@Test
public void testPageRankWithThreeIterations() throws Exception {
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	Graph<Long, Double, Double> inputGraph = Graph.fromDataSet(
		PageRankData.getDefaultEdgeDataSet(env), new InitMapper(), env);

	List<Vertex<Long, Double>> result = inputGraph.run(new PageRank<>(0.85, 3))
		.collect();

	compareWithDelta(result, 0.01);
}
 
開發者ID:axbaretto,項目名稱:flink,代碼行數:13,代碼來源:PageRankITCase.java

示例2: testPageRankWithThreeIterationsAndNumOfVertices

import org.apache.flink.graph.examples.PageRank; //導入依賴的package包/類
@Test
public void testPageRankWithThreeIterationsAndNumOfVertices() throws Exception {
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	Graph<Long, Double, Double> inputGraph = Graph.fromDataSet(
		PageRankData.getDefaultEdgeDataSet(env), new InitMapper(), env);

	List<Vertex<Long, Double>> result = inputGraph.run(new PageRank<>(0.85, 3))
		.collect();

	compareWithDelta(result, 0.01);
}
 
開發者ID:axbaretto,項目名稱:flink,代碼行數:13,代碼來源:PageRankITCase.java

示例3: main

import org.apache.flink.graph.examples.PageRank; //導入依賴的package包/類
@SuppressWarnings("serial")
public static void main(String[] args) throws Exception {

	String edgeInputPath;
	int maxIterations;
	String outputPath;

	if (args.length == 3) {
		edgeInputPath = args[0];
		outputPath = args[1];
		maxIterations = Integer.parseInt(args[2]);

	} else {
		System.err.println("Usage: <input edges path> <output path> <num iterations>");
		return;
	}

	ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	//read the Edge DataSet from the input file
	DataSet<Edge<String, Double>> links = env.readCsvFile(edgeInputPath)
			.fieldDelimiter("\t")
			.lineDelimiter("\n")
			.types(String.class, String.class, Double.class)
			.map(new Tuple3ToEdgeMap<String, Double>());
	

	//create a Graph with vertex values initialized to 1.0
	Graph<String, Double, Double> network = Graph.fromDataSet(links,
			new MapFunction<String, Double>() {
				public Double map(String value) throws Exception {
					return 1.0;
				}
			}, env);
	
	
	//for each vertex calculate the total weight of its outgoing edges
	DataSet<Tuple2<String, Double>> sumEdgeWeights = 
			network.reduceOnEdges(new SumWeight(), EdgeDirection.OUT);
				

	// assign the transition probabilities as edge weights:
	//divide edge weight by the total weight of outgoing edges for that source 
	Graph<String, Double, Double> networkWithWeights = network
			.joinWithEdgesOnSource(sumEdgeWeights,
					new EdgeJoinFunction<Double, Double>() {
						@Override
						public Double edgeJoin(Double v1, Double v2) throws Exception {
							return v1 / v2;
						}
					});

	//Now run the Page Rank algorithm over the weighted graph
	DataSet<Vertex<String, Double>> pageRanks = networkWithWeights.run(
			new PageRank<String>(DAMPENING_FACTOR, maxIterations));

	pageRanks.writeAsCsv(outputPath, "\n", "\t");
	// since file sinks are lazy,trigger the execution explicitly
	env.execute("PageRank with Edge Weights");

}
 
開發者ID:dataArtisans,項目名稱:flink-training-exercises,代碼行數:62,代碼來源:PageRankWithEdgeWeights.java


注:本文中的org.apache.flink.graph.examples.PageRank類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。