-
Notifications
You must be signed in to change notification settings - Fork 423
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
Introduce ArrayLikeVariate as common supertype for Univariate, Multivariate and Matrixvariate #1313
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1313 +/- ##
=======================================
Coverage 81.51% 81.51%
=======================================
Files 115 115
Lines 6626 6626
=======================================
Hits 5401 5401
Misses 1225 1225
Continue to review full report at Codecov.
|
so in principle, can this accommodate random tensors? |
Yes, that would be a logical next step. I'm prototyping something here, but not all tests pass yes. That would generalize I thought it would be best to generalize |
I think the proposal is reasonable, and it would even be non-breaking since it just introduces a new supertype in the type hierarchy 🙂 I wonder though if a more descriptive name such as e.g. |
Yes, also with the follow up step (generalizing
Yes, I thought about |
|
Should we define something like |
It is not clear to me when and how this would be useful. Do you have an example where it would be helpful? |
I just thought it would be elegant to have a common type for the variate values as well as the variates and distributions. But I guess that's something that would, if useful, emerge naturally during the second step (higher-dimensional variates). How would you like me to proceed regarding |
I'd prefer |
Should I just go ahead with |
I'd suggest
|
src/common.jl
Outdated
struct Matrixvariate <: VariateForm end | ||
|
||
""" | ||
`F <: NVariate{N}` specifies the form of the variate a sample for |
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.
`F <: NVariate{N}` specifies the form of the variate a sample for | |
`F <: NVariate{N}` specifies the `size` of the variates or samples for |
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.
How about "specifies the dimemsionality of the size
..."?
On the other hand, julia> Base.IteratorSize((rand() for _ in 1:3))
Base.HasShape{1}() |
That would be the right direction. Note that
|
I don't think the behaviour of On a side note (I really think one should discuss this somewhere else): IMO it is a bit unfortunate that one uses this convention (not only in Distributions) instead of properly indicating the size and orientation of the samples with efficient |
What is a single sample if not what |
Sure, a single sample is what julia> Base.IteratorSize((rand() for _ in 1:3))
Base.HasShape{1}() above. This example just tried to show that one might assume that |
I think |
No, this whole thing (call it |
In my opinion, the variates are still vectors, though: It's indeed unfortunate that rand returns a flat matrix instead of a vector-of-vectors (or vector-of-vectors view of a matrix, like It's basically impossible to deprecate the behavior of |
Ok, I've renamed it to |
Gentle bump, @devmotion do you think this can go ahead like it is now? |
I'm fine with it as it is, I would just prefer if some other maintainer would approve it as well. |
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 one could also mention ArrayVariate
in the documentation.
Serves a common supertype for Univariate, Multivariate and Matrixvariate to ease writing generic code that deals with distributions with scalar/array-like variates.
Co-authored-by: Moritz Schauer <[email protected]>
Oh, good point, just added that. |
Sure, I understand, esp. in this case. Another maintainer, pretty please? :-) |
I requested some additional reviews, so hopefully someone will comment on the PR 🙂 |
there is one comment left by @mschauer, otherwise looks good |
Co-authored-by: Moritz Schauer <[email protected]>
Sorry, overlooked that one, just committed that suggestion. |
Thanks! I would go ahead then generalizing I have an early draft here (doesn't pass tests yet): master...oschulz:array-distributions |
Why would we need |
This suggestion is about the element types and not the containers, as far as I understand. It only brings more structure to the current system of |
But that is my point: If you don't want code duplication between a product of univariate and a multivariate distribution you need to avoid to bake difference between those things into the abstract super types. Now we are talking about baking difference between |
Maybe I misunderstand the proposal but I don't think any of this is part of the suggestion above. To me it is mainly a more convenient alias that allows you to make use of these more general const ArrayDistribution{S<:ValueSupport,N} = Distribution{ArrayLikeVariate{N},S} There is nothing conceptually new here, it's just more convenient and more general than the aliases |
That is be a misinterpretation on my side, I thought the plan was to introduce |
Uh, we don't have an
I assume you mean the container for multiple samples/variates? The type of the distribution should definitely convey information about the type of a single sample/variate, though (i.e. the return type of
Indeed - we currently have
Oh, no - sorry if I have been unclear, I don't want that at all! A product of univariate and a multivariate distribution should of course have the same abstract supertype. Which would be
No, no, I definitely didn't want to introduce a separate |
Oh, yes, it would be nice to be able to make a product of multivariate distributions, resulting in a matrixvariate distribution, and so on. |
Just a bit about my perspective, I think we agree all. I think we need to avoid repeating the same mistakes:
|
I agree, there are many things that can be improved in Distributions and to a large extent problems are caused by design choices that turned out to be problematic later on (to be honest, some of these choices such as
This is not the case anymore, e.g., Dirac and DiscreteNonParametric support sets of floats (but maybe that's why you wrote "couldn't have" instead of "can't have"?). |
Yes, that's what I think as well. |
When writing generic code that deals with Univariate, Multivariate and Matrixvariate distributions, I often find myself having to code separate methods for each variate type. Having a common supertype
NVariate{N}
should make generic coding for distributions a bit easier.I propose to introduce
Union{Univariate,Multivariate,Matrixvariate} <: NVariate <: VariateForm
here, instead of changingVariateForm
toVariateForm{N}
, to continue leaving room for custom non-scalar/matrix-like variate type (representated by other subtypes ofVariateForm
). ValueShapes.jl, for example, supports distributions withNamedTuple
variates.