-
-
Notifications
You must be signed in to change notification settings - Fork 188
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
Accuracy of normal_lccdf much worse than normal_lcdf #1985
Comments
@PhilClemson what do you think? |
Sorry, this is something that was mentioned in the original pull request for the @nhuurre mentioned that the functions could be standardised in a It seems In any case I don't think there's anything to stop us from adding the improvements to |
What parameters? As a distribution, std-normal doesn't have any parameters. It's just
lccdf should be more accurate when the cdf is near 1, and the lcdf should be more accurate when the cdf is near 0. Most of our lcdf and lccdf functions are terrible log(cdf) and log(1 - cdf) implementations, where the lccdf form will be terrible when the cdf is near 1 rather than better. |
@bob-carpenter Sorry, I should have been clearer. I meant "parameters" in a CS sense as in arguments. There could be a common C++ function (which @nhuurre called This is a log cdf so I am not sure your argument about the accuracy near 0 or 1 really applies. The domain is not (0,1) but (-inf,0). We do not need to sacrifice the accuracy on either side. The issue with CDF and CCDF is that when they are near 1 we have that the important digits are pushed away on the right of the binary representation because of the "big" (implicit) one on the left. This is not the case for logCDF or logCCDF as when the CDF is close to zero then logCDF and logCCDF become large and negative (retaining all their significant digits if computed right as in @PhilClemson 's implementation); on the other side, when the CDF is near one, logCDF and logCCDF are near zero and can retain all their significant digits if implemented right (as they do in @PhilClemson 's implementation). If we did The current implementation of |
I think the comment "this would require separate numerical approximations" only applies when you try to extend |
This gets confusing in stats. But whatever you want to call it, The move from The whole point of having
As the cdf approaches 0, log(cdf) approaches -infinity and log(1 - cdf) approaches 0. So you're right that we should be able to get decent accuracy both ways. I was tied up in our current implementations, which are a mess. Edit: I fat-fingered submitting this before finishing. We do need the complementary forms for the arguments, though. Just consider a So I don't think we can just drop the lcdf and lccdf distinction computationally. |
The normal is symmetric around the location parameter, so we can relate
|
Yes.
I see.
I was only referring to the Gaussian case. This is particularly useful for me because I can model an exponential distribution as a Gaussian in unconstrained space and then define my constrained variable just as |
Description
The implementation for
normal_lcdf
has been improved significantly following #1284 by introducing a polynomial approximation of the Mills ratio based on a paper by Cody (1969). It looks likenormal_lccdf
has not been updated accordingly and instead still uses the older and much less accurate solution.Incidentally, I also noticed that
normal_lcdf
andstd_normal_lcdf
implement the same solution with very similar code. I wonder if one could retain the current implementation ofstd_normal_lcdf
and writestd_normal_lccdf
,normal_lcdf
andnormal_lccdf
to simply callstd_normal_lcdf
with appropriate parameters (-x, (x-mu)/sigma, (mu-x)/sigma, respectively).Current Version:
v3.2.0
The text was updated successfully, but these errors were encountered: