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

Abc rejection looks to be slow #12

Closed
marcjwilliams1 opened this issue Jul 4, 2017 · 5 comments
Closed

Abc rejection looks to be slow #12

marcjwilliams1 opened this issue Jul 4, 2017 · 5 comments

Comments

@marcjwilliams1
Copy link
Owner

Lots of time spent in getproposal function?

@ChrisRackauckas
Copy link
Contributor

ChrisRackauckas commented Oct 17, 2017

It's because you're using an array of distributions. That's not type-stable. If you instead made the priors a tuple of distributions then it would have the right type information.

However, you have to go a little further than that as well. Since p.distributions[i] will be iterating over different types, the getindex function is still not type-stable. The way to handle this is thus to write it as an inlining set of recursive calls:

update_newparams!(newparams,p::Prior) = update_newparams!(newparams,1,p.distributions...)
@inline function update_newparams!(newparams,i,x,y...)
  newparams[i] = rand(x)
  update_newparams!(newparams,i,y...)
end
@inline function update_newparams!(newparams,i,x)
  newparams[i] = rand(x)
end

should be it. That's thus infer everything when the number of prior distributions is <16, and then do indefinitely more after JuliaLang/julia#23912 (so the limit is already fixed in v0.7)

@marcjwilliams1
Copy link
Owner Author

@ChrisRackauckas great, thanks for the tip and the nice proposed solution

@marcjwilliams1
Copy link
Owner Author

marcjwilliams1 commented Oct 20, 2017

Needed to add i+1 to the above code to implement the recursion

So code is:

update_newparams!(newparams,p::Prior) = update_newparams!(newparams, 1, p.distribution...)

@inline function update_newparams!(newparams, i, x, y...)
  newparams[i] = rand(x)
  update_newparams!(newparams, i + 1, y...)
end
@inline function update_newparams!(newparams,i,x)
  newparams[i] = rand(x)
end

@marcjwilliams1
Copy link
Owner Author

this results in about a 10-20% speed up

@marcjwilliams1
Copy link
Owner Author

should do something similar for calculating prior prob. priorprob function in util.jl

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

No branches or pull requests

2 participants