Apache spark 如何理解ApacheGraphx的pregel实现中的maxIterations

Apache spark 如何理解ApacheGraphx的pregel实现中的maxIterations,apache-spark,iteration,spark-graphx,Apache Spark,Iteration,Spark Graphx,官方解释是,maxIterations将用于非收敛算法。 我的问题是:如果我不知道我的算法的收敛性,我应该如何设置maxIterations的值? 如果有一个收敛算法,那么这个值是什么意思 顺便说一句,我也对pregel的“迭代”感到困惑代码的执行如何算作迭代? 以下是pregel源代码的一部分: // Loop var prevG: Graph[VD, ED] = null var i = 0 while (activeMessages > 0 && i < max

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

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

以下是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
}
//循环
var prevG:图形[VD,ED]=null
变量i=0
而(activeMessages>0&&i

感谢您慷慨的回答:)

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

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

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