question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Wrong values from scipy.special.erf (erf(x) != -erf(-x))

See original GitHub issue

We are seeing incorrect values returned from scipy.special.erf

We have some equations that depend on the symmetry of the erf function, but scipy violates this assumption.

Mathematically, for reals, erf(x) == -erf(-x), but scipy.special.erf does not seem to honor this property.

The difference from expectation seems to be beyond a simple floating point representation problem.

Reproducing code example:

# succeeds
import math
difference = math.erf(5.905732037710919)+math.erf(-5.905732037710919)
assert abs(difference) == 0.0

# fails, difference should be 0.0, difference is actually -1.1102230246251565e-16
import scipy.special
difference = scipy.special.erf(5.905732037710919)+scipy.special.erf(-5.905732037710919)
assert abs(difference) == 0.0

Error message:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AssertionError

Scipy/Numpy/Python version information:

1.1.0 1.14.0 sys.version_info(major=3, minor=6, micro=3, releaselevel='final', serial=0)

(Older versions of scipy affected as well)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
person142commented, Oct 3, 2018

cut-off of scipy (cdflib)

We use Cephes erf, not cdflib.

0reactions
ev-brcommented, Oct 4, 2018

(just had an open environment and a bit of time to spare) It seems easiest to throw gh-9351 over the wall and forget.

Read more comments on GitHub >

github_iconTop Results From Across the Web

scipy.special.erf — SciPy v1.9.3 Manual
Returns the error function of complex argument. It is defined as 2/sqrt(pi)*integral(exp(-t**2), t=0.. z) .
Read more >
Is there an easily available implementation of erf() for Python?
FWIW, how are you using scipy's erf function? With the following setup: from scipy.special import erf; import numpy as np; data = np.random....
Read more >
Behavior of np.erf for complex arguments #12515 - GitHub
When np. erf is given a complex number, it returns the number itself instead of the value of the error function. For example,...
Read more >
Error function - Wikipedia
In mathematics, the error function often denoted by erf, is a complex function of a complex variable defined as: ... Two closely related...
Read more >
scipy.special.erf — SciPy v0.14.0 Reference Guide
scipy.special.erf¶ ... Returns the error function of complex argument. It is defined as 2/sqrt(pi)*integral(exp(-t**2), t=0..z). ... The cumulative of the unit ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found