Skip to content

Conversation

@xukai92
Copy link
Member

@xukai92 xukai92 commented Jun 5, 2017

On working of #255

I'm trying to vectorize the transformation as well (#276). I already done that for univariate and simplex.

TODOs

  • vec mat
  • vec mat transformation(s)

@xukai92
Copy link
Member Author

xukai92 commented Jun 5, 2017

Note about using array of array v.s. mat result from vec_assume_mv.jl:

N = 20
beta = [0.5, 0.5]
setchunksize(N*length(beta))
alg = HMC(1000, 0.2, 4)

# Test for vectorize UnivariateDistribution
@model vdemo() = begin
  phi = Vector{Vector{Real}}(N)
  phi ~ [Dirichlet(beta)]
end

t_vec = @elapsed res_vec = sample(vdemo(), alg)

@model vdemo() = begin
  phi = Matrix(2,N)
  phi ~ [Dirichlet(beta)]
end

t_vec_mat = @elapsed res_vec_mat = sample(vdemo(), alg)

@model vdemo() = begin
  phi = Vector{Vector{Real}}(N)
  for i = 1:N
    phi[i] ~ Dirichlet(beta)
  end
end

t_loop = @elapsed res = sample(vdemo(), alg)

println("Time for")
println("  Loop : $t_loop")
println("  Vec  : $t_vec")
println("  Vec2 : $t_vec_mat")

gives

Time for
  Loop : 9.823776041
  Vec  : 21.934951717
  Vec2 : 6.140146129

with N=20.

Mat seems much faster (should be also related to my implementation of converting mat back to nested array)

@xukai92 xukai92 mentioned this pull request Jun 5, 2017
2 tasks
@xukai92
Copy link
Member Author

xukai92 commented Jun 5, 2017

Note: Distributions.jl doesn't support vectorisation version of logpdf of matrixvariate variables.

@xukai92
Copy link
Member Author

xukai92 commented Jun 5, 2017

Also there is a typo(bug) in their fake verctorization implementation. For this reason I will not include the test file in runtest.jl

@xukai92 xukai92 requested a review from yebai June 5, 2017 21:54
@yebai
Copy link
Member

yebai commented Jun 6, 2017

@xukai92 Do you want me to review this PR? Seems tests are currently broken.

@xukai92
Copy link
Member Author

xukai92 commented Jun 6, 2017

Seems there is a bug of the resuming MCMC feature which may cause numerical error very easily. I guess it might be the case that when a chain is resumed, I call the find_good_eps again, which should be disabled. Let me fix this first.

@xukai92
Copy link
Member Author

xukai92 commented Jun 6, 2017

@yebai I fixed few bugs and improve the stability a bit. Could you have a review now plz?

@yebai
Copy link
Member

yebai commented Jun 8, 2017

Time for
Loop : 9.823776041
Vec : 21.934951717
Vec2 : 6.140146129
with N=20.
Mat seems much faster (should be also related to my implementation of converting mat back to nested array)

impressive speedup! I've started reviewing this PR and will add my comments soon.


rs
if isa(dist, UnivariateDistribution) || isa(dist, MatrixDistribution)
var = rs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps we should add a dimensionality assertion here:

@assert size(var) == size(rs)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah the assertions makes sense to me!

var[i] = rs[:,i]
end
elseif isa(var, Matrix)
var = rs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dimensionality assertion?

for i = 1:n
push!(vi, vns[i], rs[i], dist, 0)
end
var = rs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dimensionality assertion?

var[i] = rs[:,i]
end
elseif isa(var, Matrix)
var = rs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dimensionality assertion?

lp
end

# REVIEW: why do we put this piece of code here?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the distributions package does not check d.p[x] > 0.0, so I override their definition here. It's probably better to submit a PR to Distributions package to fix this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I created an issue (#285) for this.

@xukai92
Copy link
Member Author

xukai92 commented Jun 12, 2017

@yebai Tests on Travis look fine now. But tests on Apprvor got the same problem before - freeze before running actual tests. I'm playing around the settings/scripts to see if I can resolve it.

@xukai92
Copy link
Member Author

xukai92 commented Jun 12, 2017

NOTE: I did a profiling on the vectorized version of LDA model and it shows >70% time is spent by gradient2().

@xukai92
Copy link
Member Author

xukai92 commented Jun 13, 2017

@yebai Can you give me permissions on appveyor so that I can terminate or restart tests? I have to wait for each one to be terminated by the sever to try to fix the issue, which is a bit slow-responsed.

@yebai
Copy link
Member

yebai commented Jun 14, 2017

Done - I've added you to appveyor permissions list.

@xukai92
Copy link
Member Author

xukai92 commented Jun 15, 2017

@yebai Appveyor actually freezes when executing using Turing. Any idea why this happens?

@yebai
Copy link
Member

yebai commented Jun 15, 2017

@yebai Appveyor actually freezes when executing using Turing. Any idea why this happens?

Turing imports other packages when loaded. It's possible some packages being imported have errors/conflicts, most likely due to pre-compilation. To see these warnings or errors, try temporarily disable @supress_err function in Turing.

@yebai yebai merged commit 9812ebc into master Jun 19, 2017
@yebai yebai deleted the vec-assume branch June 19, 2017 10:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants