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

    https://github.com/apache/spark/pull/7916#discussion_r36150055
  
    --- 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)]
    --- End diff --
    
    Is this really a bound still? E[log p(beta | eta) - log q(beta | lambda)] 
~== E[log (p(beta | eta) / q(beta | lambda)] is more of a KL divergence... 
"Bound" was correct earlier because we were "conditioning" out the topic 
distributions by taking an expectation over q i.e. E[log p(corpus, topics | 
hyperparams)] - E[log q(topics | hyperparams)] ~= E[log ( p(corpus, topics | 
hyperparams) / q(topics | hyperparams) )] ~= E[ log p(corpus | hyperparams) ]


---
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