-
Notifications
You must be signed in to change notification settings - Fork 415
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
Generalize Product
#1391
Generalize Product
#1391
Conversation
I like the ability to create Question: Shouldn't we also allow for products of multivaritate dists (of same length) that result in matrixvariate dists, and so on for higher orders? |
That's exactly what the PR proposes to do 🙂 And it is done in |
Oh, silly me! Sorry for the misunderstanding - now I like it even more! :-) |
Codecov Report
@@ Coverage Diff @@
## master #1391 +/- ##
==========================================
- Coverage 85.52% 84.57% -0.95%
==========================================
Files 128 125 -3
Lines 7863 7140 -723
==========================================
- Hits 6725 6039 -686
+ Misses 1138 1101 -37
Continue to review full report at Codecov.
|
like the idea as well |
Any news on this one? |
I have quite many changes in a local branch but haven't had time to clean and polish them. There were some test errors caused by bugs in upstream packages such as StatsBase, so I had to fix these first. I'll try to finish the PR this week. |
ccf4f8e
to
c951804
Compare
How do you treat the value support? Force all factors to have the same value support? |
Thanks for doing this, @devmotion , this will come in so handy! |
Sure, this could be done (and I've thought of it - with a different notation) but I thought such convenience functions could be discussed and possibly added in a separate PR as it is not needed for this PR. Hence I don't really want to start a discussion here but just mention that I thought |
Ideally, yes, but in LinearAlgebra, It's unfortunate, because the symbol is very common in other contexts. But at least for now, IMO this is reason enough to avoid it when possible. |
Sure, of course.
Oh yes, that would be neat too, and avoid the |
@cscherrer, maybe you can start playing with |
I think we'll need to step back and look at the notation as a whole, hopefully get something self-consistent that doesn't conflict too badly with Distributions. But let's discuss this elsewhere 🙂 |
Product
and MatrixReshaped
Product
Principally, this PR is ready for review - but I really would like to revert the last commit which fixed the downstream tests. It introduces an annoying inconsistency, namely that |
independent `M`-dimensional distributions by stacking them. | ||
|
||
The function falls back to constructing a [`ProductDistribution`](@ref) distribution but | ||
specialized methods can be defined. |
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.
Should we say here what pdf(d::ProductDistribution, x)
does?
This is going to be awesome, thanks so much for this @devmotion ! |
Any comments? In principle the PR seems ready. |
Just that I can't wait to use it! :-) |
@devmotion I'll let you do the corresponding release? |
Base.depwarn( | ||
"`Product(v)` is deprecated, please use `product_distribution(v)`", | ||
:Product, | ||
) |
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.
Maybe I'm just brainfarting, but it seems like this combined with the @deprecate
below means that no matter which constructor I use for a vector of univariate distributions, I'm going to get a deprecation-warning?
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.
Yes, at the moment one always get's a depwarn ... #1589
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.
Yeah it's unfortunate and fixed by #1590. I thought someone would approve the PR and I would be able to make a bugfix release shortly after the issue was discovered but it seems nobody has approved it within almost two weeks. I'm going to merge it and tag a release now since the issue is quite annoying for downstream packages (and AFAICT even causes time outs in Turing).
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.
Thanks @devmotion !
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.
Wonderful stuff @devmotion !
DistributionsAD contains custom distribution types for vectors of multivariate distributions and matrices of univariate distributions. I think it would be good to add support for such more general product distributions to Distributions and remove them from DistributionsAD.
In this PR, I propose to generalize the existing
Product
such that it allows to constructM + N
-dimensional product distributions fromAbstractArray{<:Distribution{ArrayLikeVariate{M}},N}
by stacking theM
-dimensional distributions. TheArrayLikeVariate
variate form (thanks to @oschulz!) enables us nicely to define these product distributions in an even more general way than what currently is implemented in DistributionsAD.I tried to perform this generalization in a non-breaking way by adding a new type
ProductDistribution
, making.Product
a special alias of it, and deprecating theProduct
constructor. I did not find a way to deprecateProduct
withBase.@deprecate_binding
, it seems it can't deal with type parameters: JuliaLang/julia#9830Product
still exists andproduct_distribution(::AbstractVector{<:UnivariateDistribution})
still creates aProduct
to avoid breaking changes (otherwise e.g. the downstream tests fail).This PR requires:
MatrixOfUnivariateDistribution
VectorOfMultivariateDistribution
Fill{<:Distribution{<:ArrayLikeVariate}}
(if necessary; not all implementations in DistributionsAD might be needed)cc: @yebai