Skip to content
This repository
Browse code

DOC: document limitation of invgauss.cdf. Improve numerical accuracy …

…a little.

This closes #869.
  • Loading branch information...
commit ff96ef0767d1a60dec3ce59e05ec507113c0fdfb 1 parent 9176d49
Ralf Gommers authored August 19, 2011

Showing 1 changed file with 7 additions and 2 deletions. Show diff stats Hide diff stats

  1. 9  scipy/stats/distributions.py
9  scipy/stats/distributions.py
@@ -3768,6 +3768,10 @@ class invgauss_gen(rv_continuous):
3768 3768
 
3769 3769
     for ``x > 0``.
3770 3770
 
  3771
+    When `mu` is too small, evaluating the cumulative density function will be
  3772
+    inaccurate due to ``cdf(mu -> 0) = inf * 0``.
  3773
+    NaNs are returned for ``mu <= 0.0028``.
  3774
+
3771 3775
     %(example)s
3772 3776
 
3773 3777
     """
@@ -3779,8 +3783,9 @@ def _logpdf(self, x, mu):
3779 3783
         return -0.5*log(2*pi) - 1.5*log(x) - ((x-mu)/mu)**2/(2*x)
3780 3784
     def _cdf(self, x, mu):
3781 3785
         fac = sqrt(1.0/x)
  3786
+        # Numerical accuracy for small `mu` is bad.  See #869.
3782 3787
         C1 = norm.cdf(fac*(x-mu)/mu)
3783  
-        C1 += exp(2.0/mu)*norm.cdf(-fac*(x+mu)/mu)
  3788
+        C1 += exp(1.0/mu) * norm.cdf(-fac*(x+mu)/mu) * exp(1.0/mu)
3784 3789
         return C1
3785 3790
     def _stats(self, mu):
3786 3791
         return mu, mu**3.0, 3*sqrt(mu), 15*mu
@@ -5127,7 +5132,7 @@ class uniform_gen(rv_continuous):
5127 5132
     """A uniform continuous random variable.
5128 5133
 
5129 5134
     This distribution is constant between `loc` and ``loc = scale``.
5130  
-    
  5135
+
5131 5136
     %(before_notes)s
5132 5137
 
5133 5138
     %(example)s

0 notes on commit ff96ef0

Please sign in to comment.
Something went wrong with that request. Please try again.