-
Notifications
You must be signed in to change notification settings - Fork 31
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
Implement FillDist and ArrayDist #19
Conversation
What additional information does |
Yes the plan is to make |
Note that with |
CC: @cscherrer |
I still need to add some tests before merging and releasing. |
Also for the names, |
No reason. I can change it. What do you recommend? |
Is it possible to unify both as |
Also we might consider use lowercase here as things like |
Both |
It seems both Moreover, since @xukai92 mentioned |
I don't think |
|
57d4387
to
60920b4
Compare
I rebased on the Zygote PR #25. This PR still needs tests. |
I still fail to see what advantage
|
Fair enough. I will refactor and rethink this PR after the Zygote one is merged. |
I think the only place where we may need to subtype |
I also like the fact that |
The same is true for product_distribution(dist::UnivariateDistribution, n::Int) = Product(fill(dist, n))
product_distribution(dist::Normal, n::Int) = MvNormal(Fill(mean(dist), n), std(dist)) one could use |
Yes with
I think it's nice to think in terms of a few higher level abstract types instead of |
I like the |
I'm sorry, I can't follow - you're definitely more familiar with these methods than I am 😛 Why would it not "just work"?
You could always define aliases such as const ProductVectorDiscreteUnivariate{T<:DiscreteUnivariateDistribution,V<:AbstractVector{T}} = Product{Discrete,T,V}
const ProductVectorContinuousUnivariate{T<:ContinuousUnivariateDistribution,V<:AbstractVector{T}} = Product{Continuous,T,V} if needed. Is that what you mean? |
Let's take vectorize(d::UnivariateDistribution, r::Real) = [r]
vectorize(d::MultivariateDistribution, r::AbstractVector{<:Real}) = copy(r)
vectorize(d::MatrixDistribution, r::AbstractMatrix{<:Real}) = copy(vec(r))
I see advantages and disadvantages to both approaches. |
I see your point, and actually I think the problem is the current type system in Distributions. Too often I get the feeling that it is more prohibitive than actually useful. IMO it would be much nicer to use traits more, so, e.g., usually it should be fine to query |
60920b4
to
33badcd
Compare
77d4428
to
2f97eaa
Compare
This one is ready for a review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work, I'll have a more thorough look at it this afternoon! I've already added some comments.
Co-Authored-By: David Widmann <[email protected]>
Co-Authored-By: David Widmann <[email protected]>
Co-Authored-By: David Widmann <[email protected]>
Co-Authored-By: David Widmann <[email protected]>
…ng/DistributionsAD.jl into mt/array_dist_and_multi
If no further comments here, I will go ahead and merge tonight (Australia time). |
Note: this comment was edited to reflect the final state of the PR so some of the discussions below may not make sense.
This PR introduces the
filldist
function which takes any univariate or multivariate distribution and returns another distribution that repeats the input distribution. Examples:filldist(Normal(), 10)
andfilldist(Bernoulli(), 10)
return continuous and discrete multivariate distributions respectively.filldist(Normal(), 10, 10)
andfilldist(Bernoulli(), 10, 10)
return continuous and discrete matrix-variate distributions respectively.filldist(MvNormal(rand(4), 1.0), 10)
andfilldist(Multinomial(4, [0.5, 0.5]) , 10)
return continuous and discrete matrix-variate distributions respectively.In this PR I also implemented the
arraydist
function which wraps an array of distributions returning a new distribution sampling from the individual distributions:arraydist(Normal.(rand(4)))
andarraydist(Bernoulli.(rand(4)))
return continuous and discrete multivariate distributions respectively.arraydist(Normal.(rand(4, 4)))
andarraydist(Bernoulli.(rand(4, 4)))
return continuous and discrete matrix-variate distributions respectively.arraydist(MvNormal.([rand(4) for i in 1:2], 1.0))
andarraydist(Multinomial.(4, [[0.5, 0.5] for i in 1:2]))
return continuous and discrete matrix-variate distributions respectively.