-
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
WIP: Add keyword constructors #823
base: master
Are you sure you want to change the base?
Conversation
I don't necessarily oppose this, but seeing it implemented, I kind of like it less than I thought I would. |
Good to speak up now. Why so? |
It's hard to pinpoint, I guess it just seems a bit noisy, plus I worry that the names chosen for keyword arguments won't necessarily match all literature on a particular distribution, which will leave people confused. (Though I suppose positional arguments aren't necessarily better in that regard.) |
Yeah, I concede it perhaps isn't as concise as I would have liked. Keyword aliases (simonbyrne/KeywordDispatch.jl#2) would help reduce some of the verbosity. |
That said, I do look forward to being able to write things like |
Why not have both positional and keyword argument versions? |
It still does: I'm just deprecating some of what I think are ambiguous positional ones (e.g. single argument |
I think |
Good idea. |
As discussed in the issue, I find the design better if we can keep error messages helpful, which is often the big point against macros |
With this PR, if you use invalid keywords you'll get:
|
I notice above the use of keywords Does that feel inconsistent? If you write out I'd vote for |
No, that was intentional! If you specify julia> using Distributions
julia> LogNormal(mu=1.0, sigma=1.0)
LogNormal{Float64}(μ=1.0, σ=1.0)
julia> LogNormal(mean=1.0, sigma=1.0)
LogNormal{Float64}(μ=-0.5, σ=1.0)
julia> LogNormal(mean=1.0, std=1.0)
LogNormal{Float64}(μ=-0.34657359027997264, σ=0.8325546111576977) The reason I used the lognormal is that in some cases you know the sigma variable, but want to match a particular mean (e.g. using geometric Brownian motion) |
OK, sounds great overall! KeywordDispatch is really useful here. I just wonder why Also, some docstrings still need to be adjusted to the changes. |
I think I had never dug that deep into the tests in JSON madness before :'( |
Yeah, I would love to rethink how we handle the tests. Not sure what the best options are. |
these are weird because we write Julia code in a JSON, to then execute it, instead of having plain Julia files |
@@ -879,7 +879,7 @@ | |||
] | |||
}, | |||
{ | |||
"expr": "Erlang(3)", | |||
"expr": "Erlang(alpha=3)", |
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.
are you manually editing these, or were they generated from the R script?
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.
These are supposed to be generated by the gendref.R
file.
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.
ok, but the .lst
is supposed to contain the Julia syntax correct?
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.
Honestly, I didn't try to figure it out.
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.
I'm getting the R deps now to re-generate the JSON and see if all good
Manually editing, how can the R script edit those?
…On Tue, Feb 26, 2019 at 9:04 PM Simon Byrne ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In test/ref/continuous_test.ref.json
<#823 (comment)>
:
> @@ -879,7 +879,7 @@
]
},
{
- "expr": "Erlang(3)",
+ "expr": "Erlang(alpha=3)",
are you manually editing these, or were they generated from the R script?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#823 (review)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AHRRsip3OjAk1RjdjX8mKjjMuWAmS7yIks5vRZNpgaJpZM4aVB8Z>
.
--
Mathieu Besançon
|
Error while running the R script On Binomial() --> Binomial: n=1 p=0.5
On Binomial(n=3) --> Binomial: n=NA p=0.5
Error in if (vmax - vmin + 1 <= 10) { :
missing value where TRUE/FALSE needed |
I'm pretty short on time at the moment, so don't really time to spare on this: if someone wants to tackle the tests (or just leave them?), I'd be grateful. |
It would be great to how that JuliaLang/julia/issues/9498 has no impact here, and for users employing this package. Not sure if this can be answered/assured via tests? |
It won’t be an issue in this case, since all the keyword based constructors have no positional arguments. |
Disclaimer: I am no Julia guru.... May be paranoid here..... but personally I'd avoid all this until Julia matures on a solution. Ack that right now such time appears to be Julia 2.0 - or whenever Julia dispatches on keyword arguments. Even more heuristic reasoning: Julia's special sauce/advantage is multiple dispatch. Keyword arguments can't be dispatched on - the duck-test suggests keyword arguments aren't quite ready for prime time. Also, wouldn't it be relatively simple to make a |
Named arguments would definitely be a big improvement in code readability. But KeywordDispatch seems like a fairly complex and fragile way to accomplish this, compared to a simpler solution using |
Are there still any plans to add this to Distributions.jl? I've definitely felt like this could be very useful before. |
Has there been any progress on this idea that isn't recorded here? It would be really great functionality to have - especially when trying to tempt new users over from other languages. Our specific use case (https://github.com/CDCgov/Rt-without-renewal/tree/main/EpiAware) is a case in point as aimed at epidemiologists who may not have the background needed to get the transforms right all the time without package support. |
I don't think there have been any developments and I completely agree that this would be very useful. |
I tried to start with a smaller PR a while ago because I thought it might be easier to move forward in smaller chunks: #1405 But there was no response so I did not push it further. |
Yes I saw that and it seemed like a nice simple solution to be getting on with.
I'm not clear how dev works around here or how to find out but this seems like a shame! |
Fixes #768, fixes #977.