-
Notifications
You must be signed in to change notification settings - Fork 410
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
Minimal API that a new distribution must implement #525
Comments
I don't have an immediate answer, but this is also important for, e.g., parameterizing Truncated, which has exactly this kind of ambiguity problem. I'm happy to help discuss and document, though as I said, I don't know the answer. |
Ok, I'm starting to try to wrap my head around what exists. Here's my thinking about big high-level design principles we might aspire to.
This is a pretty complicated restriction and may be intractable given our use of integer parameters for some distributions. But I think it would help to resolve some of the current issues in the code that worry me as we move forward with parametric types. Consider using the following functions against both
To me, this seems like it ought to be something like For another example, consider:
This seems to have the same problem of fixing precision backs towards In contrast, a method definition like this one strikes me as being near perfect:
The only problem I can see here is the use of The other alternative is where I think we lived before: all methods are generally restricted to |
This is very much the content of @jmxpearson's PRs and I think we are almost there. The rules are that you cannot use floating point literals in any method and that you should let the inputs determine the type of the result by having them first in expressions, e.g. not |
Good to know. We might not support
If this is the direction we're heading, should we then also move in the direction that new distributions should aspire to define a method like Does that seem feasible as our eventual API? We'd have to write down all of the functions, but if they all have the form |
Thanks for correcting me. I don't know why I haven't noticed that change. I think that most methods could just be defined for |
Ok. I'll try to write up the minimal API in a Gist and link to it here. We can adapt it over time (along with strategies for handling hard problems like the one you mention) as John's work continues to show how these issues play out for specific distributions. |
I made a start here: https://gist.github.com/johnmyleswhite/c2ec16dd57ebb43799ed5e141c6a1a93 The hardest thing for me is deciding on the return types for these functions. I've used |
Just to echo Andreas's remarks:
I'll also add some comments to the gist. Oh, and loosening the signature for |
Thanks for taking the time to collate those ideas @johnmyleswhite.
There seem to be common (natural?) cases where you just want to compile code related one of those domains ():
Given the compile times will be a perennial issue (it'll never be never fast enough).... there is some user benefit to keeping the package smaller by keeping it specialized, rather than keeping it smaller by keeping it limited to some smaller subset of distributions, but with bells and whistles included. It would also lower the barrier to contributions for each domain (but increase it a little to contribute across domains - multiple packages/repos). Of course there would be the issue of whether these three packages should be synchronized - I'd argue for loose coupling and that the current package contents are a MVP. Bike shedding names: |
While working on some new distributions for a separate package, I've found that I frequently hit ambiguity warnings when defining operations like
pdf(d::MyNewAbstractDistribution, x::Real)
because those operations are ambiguous with operations likepdf(d::Distribution, x::Int)
.In the past, I could resolve these issues by only implementing a basic core API that defined operations like
pdf(d::MyNewConcreteDistribution, x::Float64)
and trusting that the fallbacks would handle conversions for me. With the increase in abstraction we've achieved thanks to the work on parametric distributions, I've lost track of what the core minimal API is. Which functions must a new distribution implement?If someone is familiar with what the minimal API is off the top of their head, I can write documentation for it. If we need to decide this, I'd be happy to be involved in figuring out what the minimal API ought to be.
The text was updated successfully, but these errors were encountered: