假设我有一个边属性双值的图,我
想找到我的图的最大边权重。如果我这样做:
val max = sc.accumulator(0.0) //max holds the maximum edge weight
g.edges.distinct.collect.foreach{ e => if (e.attr > max.value) max.value
= e.attr }
我想问一下在master上做了多少工作,在master上做了多少
执行者,因为我知道 collect() 方法将整个 RDD 带到
大师?是否发生并行?有没有更好的办法找到
最大边缘重量?
笔记:
g.edges.distinct.foreach{ e => if (e.attr > max.value) max.value =
e.attr } // does not work without the collect() method.
//I use an accumulator because I want to use the max edge weight later
如果我想对两个图之间具有相同 srcId 和 dstId 的边的属性应用一些平均函数,最好的方法是什么?
最佳答案
您可以聚合:
graph.edges.aggregate(Double.NegativeInfinity)(
(m, e) => e.attr.max(m),
(m1, m2) => m1.max(m2)
)
或映射并取最大值:
graph.edges.map(_.attr).max
关于你的尝试:
accumulator
. 关于scala - 在 Spark GraphX 中寻找最大边权重,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32267199/