-
Notifications
You must be signed in to change notification settings - Fork 422
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
Type parameterization #771
Comments
Would parametrizing by the support of the distribution forbid having mixtures of distributions with different supports? This would be a setback in my opinion... Alternatively, one could make a mixture of two distributions be always allowed, with a support which is the union of the supports. |
I am not sure that a very rich type system like this a good match for describing various features of distributions. Is it used much for dispatch? Could accessor/query function for various properties, ideally type stable (= traits) be a better match? |
I am also pushing this view a bit. Imho most of the time this type system doesn't help but goes into the way of usability. Usually a single abstract supertype ( |
Thanks for the responses. Here are a few possibilities:
For (1), I would expect the mixtures to result in a
For (2), the biggest (only?) issue is that it breaks existing use. The information returned by the current implementation is useful, but it's wrong. A "support" has a well-established use in measure theory. There are several variants of this that tend to coincide on "well-behaved" measures, and are all entirely different than the current implementation in Distributions.jl. Some CAS systems (it's like "PIN number", I know) involve the concept of a carrier. For example, if you sample from a gamma distribution the result will be positive, but you may still represent it as a The implementation of this could involve something like an abstract type |
@cscherrer @mschauer we could progress on this. One thing that would be acceptable is replace the current "Discrete" with an IntegerSupport, possibly sub-typed with FullInteger and PositiveInteger. Overall, I think keeping the two parameters is fine, but the type hierarchy could be made more flexible with this. Thoughts |
@matbesancon: can you clarify what the type hierarchy is actually used for? |
It is used:
|
Sure — in general, this is what types are used for. But I meant specifically in this package. My understanding of the code suggests that while it is used in a few places, eg for There are a lot of instances when the type is just used to dispatch to a I respect that different programmers have different styles, and that a package as large and complex as Distributions can benefit from some structure. But I wonder if the type hierarchy in Distributions reflects a design that was replaced by using traits as Julia evolved. |
It is exposed behavior and I would believe it is used for packages depending on Distributions in an 'advanced' way.
Agreed, this can be removed, but it's a common pattern to explicitly show errors where an interface must be implemented.
Traits are still not used everywhere and I believe we should not throw the type parameter baby with the bath of current types |
Reasonable uses are imho: indicating what |
Revisiting this issue: traits are now used pervasively in Julia, so a potential redesign could just replace (a lot of) the type hierarchy with traits, addressing this and a host of related issues. |
It would help me to switch to traits for this: JuliaPOMDP/POMDPs.jl#473 (comment) |
Currently, a
Distribution
, sayD
, is parameterized by aF <: VariateForm
andS <: ValueSupport
, whereF
can beUnivariate
,Multivariate
, orMatrixvariate
S
can beDiscrete
orContinuous
.There's a lot of useful structural information missing in this parameterization.
D
is one-dimensional, can it be negative? Is there an upper bound?D
is multivariate, is it over R^n, or constrained, for example to a simplex?D
is matrix-variate, does it have to be positive definite?It seems the current type hierarchy could be replaced by one that that's parameterized by the supports of the parameter space and the observation space. This would make it much easier, for example, to automate the kind of transformations done by Stan and replicated in some of @tpapp's libraries. And it would make it natural to extend to distributions over data structures. For example a Markov chain would be a distribution over an iterator.
All of the functionality I'm describing could instead be implemented in a bolt-on sort of way, but it would be much more usable to have it all in one place. Also, my suggestion would break a lot of existing code. I wonder if there may be a way to have an alternate constructor and gracefully transition to something more informative.
I could try to take a crack at this, but it would be helpful to know...
As it is, this library is already a lot more enjoyable to use than its counterpart in other languages. Thank you for your work on it, and for any insights you might have into this issue.
The text was updated successfully, but these errors were encountered: