Skip to content

ENH: improve halfnorm CDF precision #18003

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

Merged
merged 1 commit into from
Feb 20, 2023
Merged

Conversation

dschmitz89
Copy link
Contributor

@dschmitz89 dschmitz89 commented Feb 19, 2023

Reference issue

No directly related issue.

What does this implement/fix?

Increases the precision of the halfnormal distribution's CDF method in the left tail. The formula was simply changed to use the one from Wikipedia to avoid substracting 1.

Additional information

Comparison of main branch and this PR:

halfnorm_cdf

import numpy as np
import matplotlib.pyplot as plt
from scipy import stats
from scipy import special as sc

x = np.logspace(-17, -14, 200)
print(stats.halfnorm.cdf(x))
plt.semilogx(x, stats.halfnorm.cdf(x), label="main", ls="dashed")
plt.semilogx(x, sc.erf(x/np.sqrt(2)), label="PR", ls="dotted")
plt.legend()
plt.title("Halfnorm CDF")
plt.show()

@dschmitz89 dschmitz89 added scipy.stats enhancement A new feature or improvement labels Feb 19, 2023
Copy link
Contributor

@mdhaber mdhaber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This improves the precision at small values of the argument.

@mdhaber mdhaber merged commit 5b701b8 into scipy:main Feb 20, 2023
@WarrenWeckesser WarrenWeckesser added this to the 1.11.0 milestone Mar 7, 2023
@dschmitz89 dschmitz89 deleted the halfnorm_cdf branch July 18, 2023 21:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement A new feature or improvement scipy.stats
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants