在 Spark GraphX 中查找最大边权重
Finding maximum edge weight in Spark GraphX
假设我有一个边属性值为双精度的图,我
想找到我的图形的最大边缘权重。如果我这样做:
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
。
- 它不起作用,因为累加器从工作人员的角度来看是只写的。
假设我有一个边属性值为双精度的图,我 想找到我的图形的最大边缘权重。如果我这样做:
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
。 - 它不起作用,因为累加器从工作人员的角度来看是只写的。