Github user jkbradley commented on a diff in the pull request:

    https://github.com/apache/spark/pull/7916#discussion_r36150374
  
    --- Diff: 
mllib/src/main/scala/org/apache/spark/mllib/clustering/LDAModel.scala ---
    @@ -267,32 +304,42 @@ class LocalLDAModel private[clustering] (
         // by topic (columns of lambda)
         val Elogbeta = LDAUtils.dirichletExpectation(lambda.t).t
     
    -    var score = documents.filter(_._2.numNonzeros > 0).map { case (id: 
Long, termCounts: Vector) =>
    -      var docScore = 0.0D
    +    // Sum bounds for each document:
    +    //  bounds for prob(tokens) + bounds for prob(document-topic 
distribution)
    +    documents.filter(_._2.numNonzeros > 0).map { case (id: Long, 
termCounts: Vector) =>
    +      var docBound = 0.0D
           val (gammad: BDV[Double], _) = 
OnlineLDAOptimizer.variationalTopicInference(
             termCounts, exp(Elogbeta), brzAlpha, gammaShape, k)
           val Elogthetad: BDV[Double] = LDAUtils.dirichletExpectation(gammad)
     
           // E[log p(doc | theta, beta)]
           termCounts.foreachActive { case (idx, count) =>
    -        docScore += count * LDAUtils.logSumExp(Elogthetad + Elogbeta(idx, 
::).t)
    +        docBound += count * LDAUtils.logSumExp(Elogthetad + Elogbeta(idx, 
::).t)
           }
    -      // E[log p(theta | alpha) - log q(theta | gamma)]; assumes alpha is 
a vector
    -      docScore += sum((brzAlpha - gammad) :* Elogthetad)
    -      docScore += sum(lgamma(gammad) - lgamma(brzAlpha))
    -      docScore += lgamma(sum(brzAlpha)) - lgamma(sum(gammad))
    +      // E[log p(theta | alpha) - log q(theta | gamma)]
    +      docBound += sum((brzAlpha - gammad) :* Elogthetad)
    +      docBound += sum(lgamma(gammad) - lgamma(brzAlpha))
    +      docBound += lgamma(sum(brzAlpha)) - lgamma(sum(gammad))
     
    -      docScore
    +      docBound
         }.sum()
    +  }
     
    -    // E[log p(beta | eta) - log q (beta | lambda)]; assumes eta is a 
scalar
    -    score += sum((eta - lambda) :* Elogbeta)
    -    score += sum(lgamma(lambda) - lgamma(eta))
    -
    +  /**
    +   * Bound for prob(topic-term distributions):
    +   *   E[log p(beta | eta) - log q(beta | lambda)]
    +   *
    +   * See Equation (16) in original Online LDA paper, as well as Appendix 
A.3 in the JMLR version of
    +   * the original LDA paper.
    +   * @param eta topic-word Dirichlet prior parameter
    +   * @param lambda parameters for variational q(beta | lambda) topic-word 
distributions
    +   */
    +  private def topicsBound(eta: Double, lambda: BDM[Double]): Double = {
    --- End diff --
    
    yeah, that's what I was thinking, but maybe I should have looked more 
carefully....it does look like you can't really separate out the pieces from 
the bound.  I'll revert some stuff.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to