[Scipy-tickets] [SciPy] #807: More accurate tail probability and quantile for exponential distribution

SciPy scipy-tickets@scipy....
Mon Dec 1 06:49:56 CST 2008


#807: More accurate tail probability and quantile for exponential distribution
-------------------------+--------------------------------------------------
 Reporter:  pbrod        |       Owner:  somebody
     Type:  enhancement  |      Status:  new     
 Priority:  normal       |   Milestone:  0.8     
Component:  scipy.stats  |     Version:  devel   
 Severity:  normal       |    Keywords:          
-------------------------+--------------------------------------------------
 The sf and isf functions for the exponential distribution are inaccurate
 for small upper tail probabilities as exemplified here:
 {{{
 In [108]: import scipy.stats.distributions as dst
 In [109]: dst.expon.isf(dst.expon.sf(40))
 Out[109]: 1.#INF
 }}}
 The exact quantile in this case is 40.

 For small lower tails the probabilities are truncated to zero as shown
 here:
 {{{
 In [113]: dst.expon.cdf(1e-18)
 Out[113]: 0.0
 }}}
 but it should be 1e-18.


 Solution: put the following methods in the expon_gen class

 {{{
  def _cdf(self, x):
      return -expm1(-x)
  def _sf(self,x):
      return exp(-x)
  def _isf(self,q):
      return -log(q)
 }}}

 In general there are several places in scipy.stats.distributions where one
 can improve the accuracy of the calculations by just replacing expressions
 involving
 log(1+x) and exp(x)-1 with log1p(x) and expm1(x), respectively.

-- 
Ticket URL: <http://scipy.org/scipy/scipy/ticket/807>
SciPy <http://www.scipy.org/>
SciPy is open-source software for mathematics, science, and engineering.


More information about the Scipy-tickets mailing list