-
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
Add regularized incomplete beta and gamma functions. Use them and their auxiliary functions as much possible. #148
Conversation
…ir auxiliary functions as much possible.
This is a pretty amazing body of work. Well done! My first order reaction is that (1) these new special functions should probably be in Base and (2) it would be great to use less Fortran-like names. |
Indeed, thanks @andreasnoackjensen . This is amazing. |
Agreed, thanks @andreasnoackjensen, it's some very impressive work. I agree with @johnmyleswhite on the names. There are a couple of cases where multiple dispatch could be used to cut down on prefixes. We could also take hints from functions like |
This is really impressive! The 3000+ lines of codes in specialfuns.jl is amazing. Some of these functions would have broader use than within this package -- actually I think they deserve in Base or a package of itself (say |
Do we want to merge this straight into |
These are probably the most useful functions, which we might want to consider renaming (/'s indicate Float32 and Float64 versions), I've also noted some possible names:
One potential problem is that some of these functions are only valid for certain values (e.g. Also, it seems the following already have equivalents in
|
@simonbyrne I don't know what is the easiest way to handle the merging. Please tell me if it is better to make the pull request against I kept the old names to make it easier to compare with the source, but now that the translation is done, I think it is good to change the names and use multiple dispatch. I think your name suggestions are fine. Some specific comments
|
I think I've made some conflicting changes, so I'll try to merge it in manually.
|
How about: import Base.realmax
realmax(::Type{BigFloat}) = prevfloat(inf(BigFloat))
realmaxexp(::Type{BigFloat}) = with_bigfloat_rounding(()-> log(realmax(BigFloat)), RoundDown) |
Just a clarification to avoid double work. Are you manually copying this into I just had a look at the source and it defines The |
I've merged it in via You could try |
I think that is too small. At least for
|
Ahh, I forgot about subnormals. However it seems that MPFR doesn't do subnormals (or at least if it does, it doesn't do them the same way), as for regular IEEE-754 floats: julia> z = zero(Float64)
0.0
julia> nextfloat(zero(Float64))
5.0e-324
julia> nextfloat(nextfloat(zero(Float64)))
1.0e-323 the second one doubles the first, wheras for BigFloats
there isn't a loss of granularity. Might want to get someone who understands this stuff to confirm it though... |
As the file |
Has there been further discussion of which of the special functions should go into Base? In particular have @ViralBShah or @StefanKarpinski expressed opinions yet? It may be my parochial point of view but I feel the incomplete beta function and incomplete gamma function should be in Base along with Bessel functions, etc. but my anti-Bessel function stance may have been influenced by a poorly-taught undergraduate applied math course. |
cc: @JeffBezanson as well. Have to catch up on this thread myself. |
It may be desirable to open an issue against https://github.com/JuliaLang/julia, liking back to this discussion, in order to have a little more visibility. |
What is the original fortran code some of this is based on? Can we call it? |
@andreasnoackjensen Would you please incorporate the latest changes to the master to make this mergeable again? |
@simonbyrne You did some further work on this, right? What is the status on that? |
My refactoring was not related to this PR. But I have moved stuff around. In particular, I move generic functions (and fallbacks) to |
I did merge this into #138, but I've since abandoned that in favour a piecewise approach. I've added some of the utility functions ( I've been slowly working on replacing these and comparing to alternative implementations (Rmath, Boost, GSL, etc.), but it's a slow process. We should probably implement some automatic tests that will compute error at some large number of points (similar to what Boost does): this would require some reference |
@andreasnoack Can you close this and make a PR to the StatsFuns package? |
I'll close her, but please keep the branch. I don't know when I'll prepare the new pull request. |
This is a big one. The three major functions are the incomplete beta and gamma functions and the inverse of the last, but these bring some auxiliary functions which are of interest by their own rights. For example, some are useful for precise calculations of pdfs. Please have a look at the headers and see if it can be used anywhere else.
I have done a lot of testing of the functions agains Rmath and the Fortran version of NSWC, but there are many possible combinations of parameter values so I cannot guarantee that all error are gone. When the new implementation differed (relatively) from the old by more than 1e-14 I compared to Mathematica and in all cases both versions were inaccurate by more that they differed from each other.
I have also written fallback quantile functions. The continuous one is just Newton's method and the discrete is a normal approximation and a search. The two quantile functions also allow for a fallback random number method. I did this because I saw that a couple of the R's quantile functions and RNGs worked through "generic" methods. Please consider the choice of initial value in the continuous quantile function. I am not sure my choice is the right thing to do.
What remains is specialised RNG's for at least binomial and Poisson. The code R uses is not free enough for our needs.