【问题标题】:How to understand the maxIterations in pregel implement of Apache GraphX如何理解 Apache GraphX 的 pregel 实现中的 maxIterations
【发布时间】:2019-10-06 03:29:22
【问题描述】:

官方的解释是 ma​​xIterations 将用于非收敛算法。 我的问题是:如果我不知道我的算法的收敛性,我应该如何设置 maxIterations 的值? 而且,如果有收敛算法,那么这个值是什么意思?

顺便说一句,我也对 pregel 的“迭代”感到困惑。 代码执行如何算作一次迭代?

这是部分预凝胶源代码:

// Loop
var prevG: Graph[VD, ED] = null
var i = 0
while (activeMessages > 0 && i < maxIterations) {
  // Receive the messages and update the vertices.
  prevG = g
  g = g.joinVertices(messages)(vprog)
  graphCheckpointer.update(g)

  val oldMessages = messages
  // Send new messages, skipping edges where neither side received a message. We must cache
  // messages so it can be materialized on the next line, allowing us to uncache the previous
  // iteration.
  messages = GraphXUtils.mapReduceTriplets(
    g, sendMsg, mergeMsg, Some((oldMessages, activeDirection)))
  // The call to count() materializes `messages` and the vertices of `g`. This hides oldMessages
  // (depended on by the vertices of g) and the vertices of prevG (depended on by oldMessages
  // and the vertices of g).
  messageCheckpointer.update(messages.asInstanceOf[RDD[(VertexId, A)]])
  activeMessages = messages.count()

  logInfo("Pregel finished iteration " + i)

  // Unpersist the RDDs hidden by newly-materialized RDDs
  oldMessages.unpersist(blocking = false)
  prevG.unpersistVertices(blocking = false)
  prevG.edges.unpersist(blocking = false)
  // count the iteration
  i += 1
}

感谢您的慷慨回答:)

【问题讨论】:

    标签: apache-spark iteration spark-graphx


    【解决方案1】:

    maxIterations 用于确保算法终止。 请注意,Pregel 只是一个范例,因此它的收敛取决于您的算法(sendMessagevertexProgram)。这就是为什么当我们确定我们的算法会收敛时,我们使用Int.MaxValue 作为最大迭代次数。

    如果您不确定您的算法的终止,最好根据经验测试来设置它。例如,如果您的算法是优化某个值的启发式算法,那么显然 maxiterations 越高,越接近你是你的目标。在这里,您根据您愿意使用多少时间和资源来决定何时停止以获得答案(例如 100 次迭代)。

    最后,代码使用变量i 来计算迭代次数,并在每次迭代时递增。 Pregel 在i 达到最大迭代次数或什至在没有消息交换之前(算法收敛时)停止。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多