本文整理汇总了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);
}
示例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);
}
示例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");
}