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.

BUG: scipy.stats.norm wrong expected value of function when loc is large

See original GitHub issue

The expected value of a normal distribution should be the center of the distribution, but scipy gives wrong results when loc/scale is large.

Reproducing code example:

>>> import scipy.stats as stats
>>> stats.norm.expect(loc=10, scale=1)
10.000000000000004
>>> stats.norm.expect(loc=20, scale=1)
20.0
>>> stats.norm.expect(loc=30, scale=1)
30.0
>>> stats.norm.expect(loc=36, scale=1)
3.3637320653305685e-10
>>> stats.norm.expect(loc=40, scale=1)
1.5746385460369797e-26
>>> stats.norm.expect(loc=10, scale=0.1)
2.3378433179863228e-37

Scipy/Numpy/Python version information:

Scipy 1.1.0
Numpy 1.14.3

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
lovis-heindrichcommented, May 4, 2021

The same issue also occurs when using a small loc and a large upper or lower bound:

>>> norm.expect(loc=1, scale=1, ub=10, conditional=True)
0.9999999999982133

>>> norm.expect(loc=1, scale=1, ub=20, conditional=True)
0.9999999999999999

>>> norm.expect(loc=1, scale=1, ub=30, conditional=True)
1.0

>>> norm.expect(loc=1, scale=1, ub=40, conditional=True)
3.4007656189526604e-22

>>> norm.expect(loc=1, scale=1, ub=50, conditional=True)
8.381344573482554e-89
1reaction
adeharo9commented, Nov 22, 2019

Could there be a way of throwing a warning or similar when this kind of inconsistencies occur? At least users would be aware that there might be problems with the obtained results.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use scipy.stats expect function? - python - Stack Overflow
You have understood the manual correctly, but it turns out that if the "loc" is greater than 35.6, then things get abnormal. Otherwise,...
Read more >
scipy.stats.norm — SciPy v1.9.3 Manual
A normal continuous random variable. The location ( loc ) keyword specifies the mean. The scale ( scale ) keyword specifies the standard...
Read more >
Statistics (scipy.stats) — SciPy v1.9.3 Manual
All continuous distributions take loc and scale as keyword parameters to adjust the location and scale of the distribution, e.g., for the standard...
Read more >
SciPy 1.9.0 Release Notes — SciPy v1.9.3 Manual
Speed up the RBFInterpolator evaluation with high dimensional interpolants. ... #8928: BUG: scipy.stats.norm wrong expected value of function when loc…
Read more >
scipy.stats.ttest_ind — SciPy v1.9.3 Manual
This is a test for the null hypothesis that 2 independent samples have identical average (expected) values. This test assumes that the populations...
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