ClusteringCoefficient
runLocalClusteringCoefficient API
- API
def runLocalClusteringCoefficient[VD: ClassTag, ED: ClassTag](graph: Graph[VD, ED], isDirected: Boolean, isWeighted: Boolean): Graph[Double, ED]
- 功能描述
- API描述
- 包名:package org.apache.spark.graphx.lib.ClusteringCoefficient
- 类名:ClusteringCoefficient
- 方法名:runLocalClusteringCoefficien
- 输入:
- Graph[VD, ED]
- isDirected: Boolean
- isWeighted: Boolean
- 参数详情:
参数名称
取值类型
描述
graph
Graph[VD, ED],VD表示结点属性,ED表示边属性
有向图或无向图。
isDirected
true或false,boolean类型,true表示有向图
图类型,有向/无向图。
isWeighted
为true,算法按有权图场景计算;为false,按无权图场景计算
输入图数据是否为有向图。
- 输出:Graph[Double, ED]:输出一个Graph,Vertex属性中存储着每个点的局部聚集系数值。
- 使用样例
val conf = new SparkConf().setAppName("clusteringcoefficient").setMaster(host) val sc = new SparkContext(conf) val input = sc.parallelize(Array((1L, 2L), (3L, 1L), (3L, 2L), (2L, 4L), (3L, 4L))) val graph = Graph.fromEdgeTuples(input, false).mapEdges(f => 1.0) val nodesInfo = ClusteringCoefficient.runLocalClusteringCoefficient(graph,false,false).vertices.sortByKey().collect().foreach(println)
- 样例结果:
第一列为结点ID,第二列为该结点对应聚集系数值。
1;2,3;0 2;4,5;1 3;6,7;1 4;;2 5;;2 6;;2 7;;2
runAverageClusteringCoefficient API
- API
def runAverageClusteringCoefficient[VD: ClassTag, ED: ClassTag](graph: Graph[VD, ED], isDirected: Boolean, isWeighted: Boolean): Double
- 功能描述
- API描述
- 包名:package org.apache.spark.graphx.lib.ClusteringCoefficient
- 类名:ClusteringCoefficient
- 方法名:runAverageClusteringCoefficient
- 输入:
- Graph[VD, ED]
- isDirected: Boolean
- isWeighted: Boolean
- 参数详情:
参数名称
取值类型
描述
graph
Graph[VD, ED],VD表示结点属性,ED表示边属性。
有向图或无向图。
isDirected
true或false,boolean类型,true表示有向图。
图类型,有向/无向图。
isWeighted
为true,算法按有权图场景计算;为false,按无权图场景计算。
输入图数据是否为有向图。
- 输出:Double,返回图数据的平均聚集系数值。
- 使用样例
val conf = new SparkConf().setAppName("clusteringcoefficient").setMaster(host) val sc = new SparkContext(conf) val input = sc.parallelize(Array((1L, 2L), (3L, 1L), (3L, 2L), (2L, 4L), (3L, 4L))) val graph = Graph.fromEdgeTuples(input, false) val nodesInfo = ClusteringCoefficient.runAverageClusteringCoefficient(graph,false,false)
- 样例结果:
该输出为所有结点聚集系数均值。
0.8333
runGlobalClusteringCoefficient API
- API
def runGlobalClusteringCoefficient[VD: ClassTag, ED: ClassTag](graph: Graph[VD, ED]): Double
- 功能描述
- API描述
- 包名:package org.apache.spark.graphx.lib.ClusteringCoefficient
- 类名:ClusteringCoefficient
- 方法名:runGlobalClusteringCoefficient
- 输入:Graph[VD, ED]
- 参数详情:
参数名称
取值类型
描述
graph
Graph[VD, ED],VD表示结点属性,ED表示边属性
有向图或无向图
- 输出:Double,返回图数据全局聚集系数。
- 使用样例
val conf = new SparkConf().setAppName("clusteringcoefficient").setMaster(host) val sc = new SparkContext(conf) val input = sc.parallelize(Array((1L, 2L), (3L, 1L), (3L, 2L), (2L, 4L), (3L, 4L))) val graph = Graph.fromEdgeTuples(input, false) val nodesInfo = ClusteringCoefficient.runGlobalClusteringCoefficient(graph)
- 样例结果:
该输出为图数据全局聚集系数。
0.75
父主题: 拓扑度量