[Scipy-tickets] [SciPy] #1181: gaussian_kde evaluate fails with integers

SciPy Trac scipy-tickets@scipy....
Fri May 28 12:02:15 CDT 2010


#1181: gaussian_kde evaluate fails with integers
-------------------------------------------------------+--------------------
 Reporter:  jakebiesinger                              |       Owner:  somebody
     Type:  defect                                     |      Status:  new     
 Priority:  normal                                     |   Milestone:  0.7.2   
Component:  scipy.stats                                |     Version:  0.7.0   
 Keywords:  gaussian_kde int kernel density estimator  |  
-------------------------------------------------------+--------------------
 Creating a gaussian_kde with integer data causes the evaluate function to
 return all 0's.

 '''Some info''':
 {{{
 $ python --version
 Python 2.6.5
 $ ipython --Version
 0.10
 In [13]: scipy.__version__
 Out[13]: '0.7.2'
 }}}

 '''Repro''':
 {{{
 $ ipython
 In [1]: from scipy.stats import gaussian_kde
 In [2]: import scipy
 In [3]: randDistFromCenter = map(int, scipy.rand(10000) * 500 - 250)  #
 should be uniform on [-250,250)
 In [4]: k = gaussian_kde(randDistFromCenter)
 /usr/lib/python2.6/dist-packages/scipy/stats/stats.py:1486:
 DeprecationWarning: scipy.stats.cov is deprecated; please update your code
 to use numpy.cov.
 Please note that:
     - numpy.cov rowvar argument defaults to true, not false
     - numpy.cov bias argument defaults to false, not true

   """, DeprecationWarning)
 /usr/lib/python2.6/dist-packages/scipy/stats/stats.py:420:
 DeprecationWarning: scipy.stats.mean is deprecated; please update your
 code to use numpy.mean.
 Please note that:
     - numpy.mean axis argument defaults to None, not 0
     - numpy.mean has a ddof argument to replace bias in a more general
 manner.
       scipy.stats.mean(a, bias=True) can be replaced by numpy.mean(x,
 axis=0, ddof=1).
   axis=0, ddof=1).""", DeprecationWarning)

 In [5]: x = scipy.linspace(-300,300,100)
 In [6]: y = k.evaluate(x)
 In [7]: y
 Out[7]:
 array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 0,
        0, 0, 0, 0, 0, 0, 0, 0])

 # the bandwidth/covariance is calculated correctly
 In [8]: k.covariance
 Out[8]: array([[ 523.56767608]])
 }}}

 '''Workaround:''' Convert the datatype to floats
 {{{
 k = gaussian_kde(scipy.array(randDistFromCenter, float))
 y = k.evaluate(x)
 [  2.37718449e-05   4.59333855e-05   8.33629081e-05   1.42283310e-04
   2.28733649e-04   3.46958715e-04   4.97636815e-04   6.76566775e-04
   8.74448533e-04   1.07809127e-03   1.27285862e-03   1.44565290e-03
   1.58750741e-03   1.69501260e-03   1.77025571e-03   1.81947393e-03
 ....
 }}}

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


More information about the Scipy-tickets mailing list