LocalLDAModel源码中的getTopicDistributionMethod

LocalLDAModel源码中的getTopicDistributionMethod 方法是这样的

 private[spark] def getTopicDistributionMethod(sc: SparkContext): Vector => Vector = {
    val expElogbeta = exp(LDAUtils.dirichletExpectation(topicsMatrix.toBreeze.toDenseMatrix.t).t)
    val expElogbetaBc = sc.broadcast(expElogbeta)
    val docConcentrationBrz = this.docConcentration.toBreeze
    val gammaShape = this.gammaShape
    val k = this.k


    (termCounts: Vector) =>
      if (termCounts.numNonzeros == 0) {
        Vectors.zeros(k)
      } else {
        val (gamma, _) = OnlineLDAOptimizer.variationalTopicInference(
          termCounts,
          expElogbetaBc.value,
          docConcentrationBrz,
          gammaShape,
          k)
        Vectors.dense(normalize(gamma, 1.0).toArray)
      }
  }


这个broadcast 根本没有必要,完全是照搬了def topicDistributions(documents: RDD[(Long, Vector)]),其实就是把参数从RDD换成一个Vector。

而且这个broadcast 最好要destory。所以参数sc 是没有必要的。

看了issue mail,2017年的3月份改了。

SPARK的官方代码都有这样的问题,说明代码走读还是有必要的。


猜你喜欢

转载自blog.csdn.net/hhtop112408/article/details/79148476
今日推荐