Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vectorising likelihood computations #117

Closed
yebai opened this issue Mar 24, 2017 · 2 comments
Closed

vectorising likelihood computations #117

yebai opened this issue Mar 24, 2017 · 2 comments

Comments

@yebai
Copy link
Member

yebai commented Mar 24, 2017

There are certain cases where the efficiency of HMC sampler can be substantially improved, such as the following example

@model nbmodel begin
  theta ~ Dirichlet(alpha)
  phi = Array{Any}(K)
  for k = 1:K
    phi[k] ~ Dirichlet(β)
  end
  for m = 1:M
    z[m] ~ Categorical(theta)
  end
  for n = 1:N
    w[n] ~ Categorical(phi[z[doc[n]]])
  end
  phi
end

(The full model can be found here)

If we introduce a vectorising notation, the likelihood computation step can be re-written as

@model nbmodel begin
  theta ~ Dirichlet(alpha)
  phi = Array{Any}(K)
  for k = 1:K
    phi[k] ~ Dirichlet(β)
  end
  z ~ Categorical(theta)                     #  z[m] ~ Categorical(theta)
  w ~ [Categorical(phi[z[doc[n]]) for n=1:n] # w[n] ~ Categorical(phi[z[doc[n]]])
  phi
end

The reason that vectorising code can be more efficient is due to improved automatic differentiation and inefficiency associated with loops.

Reference: Stan documentation (see the section 4.2)

@yebai
Copy link
Member Author

yebai commented May 12, 2017

Ref: #255

yebai pushed a commit that referenced this issue May 13, 2017
@yebai yebai added this to the Release 0.3 milestone May 25, 2017
@xukai92
Copy link
Member

xukai92 commented Jun 12, 2017

Do we also want to support observations of multivariate distributions for data with nested-arrays?

xukai92 added a commit that referenced this issue Jun 30, 2017
@xukai92 xukai92 mentioned this issue Jun 30, 2017
1 task
@yebai yebai closed this as completed in #304 Jul 3, 2017
yebai added a commit that referenced this issue Jul 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants