GithubHelp home page GithubHelp logo

Comments (9)

cartazio avatar cartazio commented on July 24, 2024

relatedly, whats the correct / recommend way to rewrite the sum over the gammas?

as written, its increment_log_prob = log_sum_exp(gamma)

should it be

a) target+= gamma
b) target+= something something gamma
c) something else?

from example-models.

bob-carpenter avatar bob-carpenter commented on July 24, 2024

The code is way out of date. It's in

https://github.com/stan-dev/example-models/blob/ec6d329bb5a88fa53e44c28fa01287701660933c/misc/cluster/lda/lda.stan

The current marginalization over the topic (k) for a given word (n) where is this:

  for (n in 1:N) {
    real gamma[K];
    for (k in 1:K) 
      gamma[k] <- log(theta[doc[n],k]) + log(phi[k,w[n]]);
    increment_log_prob(log_sum_exp(gamma));  // likelihood
  }

That can be reduced to

  for (n in 1:N)
    target += log_sum_exp(log(theta[doc[n]]) + to_vector(log(phi[ , w[n]])));

It'd be even better to define log_phi in vector form and reuse for each n. It would also be worth doing this for log_theta if the number of words per document is greater than the total number of topics.

from example-models.

bob-carpenter avatar bob-carpenter commented on July 24, 2024

@cartazio: Feel free to submit a pull request.

And a warning---you can't really do Bayesian inference for LDA because of the multimodality. You'll see that you won't satisfy convergence diagnostics running in multiple chains, and not just because of label switching.

from example-models.

cartazio avatar cartazio commented on July 24, 2024

@bob-carpenter thanks! Thats super helpful.

by multi-mode you mean: there are different local optima when viewed as an optimization problem / things are nonconvex? (ie vary the priors and there will be different local optima in the posterior?). I had to google around to figure out what you meant, https://scholar.harvard.edu/files/dtingley/files/multimod.pdf seemed the most clearly expositional despite the double spaced formatting :)

is there any good reading/references on how the "variational" formulations such as Mallet/VowpalWabbit etc deal with that issue? or is it just one of those things that tends to stay hidden in folklore common knowledge?

from example-models.

bob-carpenter avatar bob-carpenter commented on July 24, 2024

from example-models.

cartazio avatar cartazio commented on July 24, 2024

from example-models.

bob-carpenter avatar bob-carpenter commented on July 24, 2024

from example-models.

cartazio avatar cartazio commented on July 24, 2024

from example-models.

bob-carpenter avatar bob-carpenter commented on July 24, 2024

from example-models.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.