当前位置: 首页>>代码示例>>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;未经允许,请勿转载。