Improve floating point accuracy - #463
Conversation
|
This is how benchmark results would change (along with a 95% confidence interval in relative change) if 700d18d is merged into master:
|
|
Nice! I added one comment and one suggestion for inline comment. |
Co-authored-by: Noa Kallioinen <33577035+n-kall@users.noreply.github.com>
|
Here is the Sol generated summary of the effect of the fixes Expected benefit by fix 1. GPD tail probabilities and quantiles — high benefitAffected code:
in Herbie improved the upper-tail log-probability quantile kernel from 53% to 100%. The original implementation converted a log probability to ordinary scale and then subtracted it The CDF had the corresponding problem: Herbie scored the upper-CDF kernel at 100% even before rewriting. This demonstrates a sampling The new implementation carries a log-survival probability through the calculation and only converts Expected benefits:
2. Pareto convergence rate — high benefit near transition pointsAffected code: Herbie results: The general score concealed severe cancellation in narrow neighborhoods. For the next representable double above The exact Expected benefits:
Away from the transition regions, the new and old formulas agreed within approximately 3. Pareto smoothing tail differences — moderate to high benefitAffected code: Herbie improved the focused log-weight exceedance kernel from 7% to 100%. The original implementation exponentiated shifted log weights and then subtracted the exponentiated Expected benefits:
4.
|
…/posterior into improve-floating-point-accuracy
|
As Herbie didn't consider what happens with probabilities / densities / weights equal to 0 and log of them equal to -Inf, I added edge tests and fixed behavior for edge cases. Full NEWS
|
|
Alright, I made the changes to the file structure otherwise looks good to me. |
|
Thank you all! Feel free to merge when you think it's ready. |
Summary
Herbie https://herbie.uwplse.org/ checks floating point computations, detects inaccurate expressions and finds more accurate replacements. I used Herbie with Sol to find these fixes. I have checked that all of them make sense.
gdp.R: Stable upper-tail and log-probability handlinggdp.R: Treat only an exactly zero GPD shape as exponential. Small nonzero shapes now retain their shape correction and finite-support behavior through the stablelog1p()formulation.pareto_smooth.R: Stableps_convergence_rate()aroundk = 0.5andk = 1pareto_smooth.R: Useexpm1()for log-weight differencesconvergence.R: Centered fourth-moment variance calculationdiscrete-summaries.R: Uselog1p()in dissent calculationNew tests
All new and old tests are passing
There are two new helper functions which are used once or twice, and they could be also inlined, but I think using them improves the readability.
Copyright and Licensing
By submitting this pull request, the copyright holder is agreeing to
license the submitted work under the following licenses:
Aki Vehtari