[Scipy-tickets] [SciPy] #1328: scipy.spatial.distance.sqeuclidean broken: Invalid results

SciPy Trac scipy-tickets@scipy....
Mon Nov 29 19:01:54 CST 2010


#1328: scipy.spatial.distance.sqeuclidean broken: Invalid results
------------------------------------------------------------------------------------+
 Reporter:  stefan_r                                                                |       Owner:  peridot
     Type:  defect                                                                  |      Status:  new    
 Priority:  high                                                                    |   Milestone:  0.9.0  
Component:  scipy.spatial                                                           |     Version:  0.8.0  
 Keywords:  squared euclidean distance,distance,scipy.spatial.distance.sqeuclidean  |  
------------------------------------------------------------------------------------+

Old description:

> scipy.spatial.distance.sqeuclidean does not work as expected. The
> returned squared distance is invalid.
> See below how to reproduce and test:
>
> Enthought Python Distribution -- http://www.enthought.com
> Python 2.6.6 |EPD 6.3-1 (64-bit)| (r266:84292, Sep 20 2010, 14:23:15)
> [MSC v.1500 64 bit (AMD64)]
> Type "copyright", "credits" or "license" for more information.
>
> In [1]: import numpy as np
> In [2]: import random
> In [3]: import scipy
>
> In [42]: scipy.__version__
>
> Out[42]: '0.8.0'
>
> In [43]: scipy.__numpy_version__
>
> Out[43]: '1.4.0'
>
> In [17]: x = np.random.random( (1,100) )
>
> In [18]: x
>
> Out[18]:
> array([[ 0.48595212,  0.00858261,  0.2236471 ,  0.18313458,  0.15134747,
>          0.0727474 ,  0.06531691,  0.84794749,  0.13963439,  0.05748809,
>          0.43968815,  0.52994896,  0.87943175,  0.77730106,  0.67913321,
>          0.02647698,  0.20545057,  0.46727115,  0.57113443,  0.41432112,
>          0.13196391,  0.56318421,  0.83975474,  0.35432455,  0.17605498,
>          0.60603054,  0.63042551,  0.47965296,  0.65571853,  0.19719946,
>          0.31688635,  0.88326223,  0.22138698,  0.44898613,  0.43109711,
>          0.91003005,  0.37640504,  0.13621161,  0.22940519,  0.97607098,
>          0.30158635,  0.66682858,  0.9577887 ,  0.38809919,  0.18852224,
>          0.68848247,  0.76550575,  0.26087833,  0.6568179 ,  0.56849634,
>          0.82575082,  0.83294453,  0.87206557,  0.52383044,  0.76953623,
>          0.9166807 ,  0.64164198,  0.89720401,  0.13378139,  0.04894561,
>          0.98135305,  0.7441703 ,  0.16886033,  0.96414571,  0.04787505,
>          0.38342266,  0.01587971,  0.53574709,  0.69853709,  0.69838509,
>          0.55200112,  0.66322354,  0.00272411,  0.16802023,  0.41641729,
>          0.50232636,  0.19477993,  0.89347851,  0.17238129,  0.6588238 ,
>          0.46308484,  0.45745335,  0.928706  ,  0.78447353,  0.09885932,
>          0.84522186,  0.09177187,  0.07021405,  0.12124147,  0.71949766,
>          0.99788648,  0.31235075,  0.12800102,  0.21255529,  0.4097645 ,
>          0.17343364,  0.58994694,  0.69530292,  0.53952727,
> 0.67645979]])
>
> In [19]: y = np.random.random( (1,100) )
>
> In [20]: y
>
> Out[20]:
> array([[ 0.7995916 ,  0.50234357,  0.0156822 ,  0.12927104,  0.15400475,
>          0.93278193,  0.92398302,  0.91047929,  0.04805954,  0.88029141,
>          0.45886629,  0.76182724,  0.63914385,  0.08064302,  0.65318621,
>          0.05821975,  0.06247843,  0.83705328,  0.15022162,  0.87442888,
>          0.21438652,  0.98421258,  0.36857529,  0.27019668,  0.12957902,
>          0.77606284,  0.82560299,  0.07788998,  0.782069  ,  0.10996114,
>          0.69530622,  0.07913858,  0.43428193,  0.9612014 ,  0.32677694,
>          0.71639339,  0.16281247,  0.34671045,  0.4163046 ,  0.80265938,
>          0.82537614,  0.94201288,  0.09668671,  0.94549124,  0.54912399,
>          0.63897389,  0.62315385,  0.70811873,  0.95666219,  0.838747  ,
>          0.60824994,  0.81890863,  0.46670795,  0.18010272,  0.04944863,
>          0.12786636,  0.26086503,  0.74274217,  0.04881725,  0.60158282,
>          0.46347241,  0.69351719,  0.81248071,  0.33209248,  0.4135145 ,
>          0.85516927,  0.18136555,  0.96710757,  0.78492171,  0.80392683,
>          0.04398294,  0.83045095,  0.69568478,  0.23451623,  0.20733289,
>          0.37455921,  0.23743431,  0.57762762,  0.93271692,  0.57212842,
>          0.34697878,  0.44662209,  0.87802109,  0.48081905,  0.11077816,
>          0.87601317,  0.98199734,  0.95157318,  0.4822475 ,  0.83759506,
>          0.57440614,  0.4493696 ,  0.34993933,  0.27192895,  0.00340568,
>          0.10402222,  0.94553401,  0.87175997,  0.82406534,
> 0.58048189]])
>
> In [24]: import scipy.spatial.distance
>
> In [25]: d1 = scipy.spatial.distance.euclidean(x, y)
>
> In [26]: d1
>
> Out[26]: 3.9013019241811246
>
> In [31]: d1**2
>
> Out[31]: 15.220156703619345
>
> In [32]: d2 = scipy.spatial.distance.sqeuclidean(x, y)
>
> In [33]: d2
>
> Out[33]: 27.985993011297221
>
> In [34]: d1 == d2
>
> Out[34]: False

New description:

 scipy.spatial.distance.sqeuclidean does not work as expected. The returned
 squared distance is invalid.
 See below how to reproduce and test:
 {{{
 Enthought Python Distribution -- http://www.enthought.com
 Python 2.6.6 |EPD 6.3-1 (64-bit)| (r266:84292, Sep 20 2010, 14:23:15) [MSC
 v.1500 64 bit (AMD64)]
 Type "copyright", "credits" or "license" for more information.

 In [1]: import numpy as np
 In [2]: import random
 In [3]: import scipy

 In [42]: scipy.__version__

 Out[42]: '0.8.0'

 In [43]: scipy.__numpy_version__

 Out[43]: '1.4.0'

 In [17]: x = np.random.random( (1,100) )

 In [18]: x

 Out[18]:
 array([[ 0.48595212,  0.00858261,  0.2236471 ,  0.18313458,  0.15134747,
          0.0727474 ,  0.06531691,  0.84794749,  0.13963439,  0.05748809,
          0.43968815,  0.52994896,  0.87943175,  0.77730106,  0.67913321,
          0.02647698,  0.20545057,  0.46727115,  0.57113443,  0.41432112,
          0.13196391,  0.56318421,  0.83975474,  0.35432455,  0.17605498,
          0.60603054,  0.63042551,  0.47965296,  0.65571853,  0.19719946,
          0.31688635,  0.88326223,  0.22138698,  0.44898613,  0.43109711,
          0.91003005,  0.37640504,  0.13621161,  0.22940519,  0.97607098,
          0.30158635,  0.66682858,  0.9577887 ,  0.38809919,  0.18852224,
          0.68848247,  0.76550575,  0.26087833,  0.6568179 ,  0.56849634,
          0.82575082,  0.83294453,  0.87206557,  0.52383044,  0.76953623,
          0.9166807 ,  0.64164198,  0.89720401,  0.13378139,  0.04894561,
          0.98135305,  0.7441703 ,  0.16886033,  0.96414571,  0.04787505,
          0.38342266,  0.01587971,  0.53574709,  0.69853709,  0.69838509,
          0.55200112,  0.66322354,  0.00272411,  0.16802023,  0.41641729,
          0.50232636,  0.19477993,  0.89347851,  0.17238129,  0.6588238 ,
          0.46308484,  0.45745335,  0.928706  ,  0.78447353,  0.09885932,
          0.84522186,  0.09177187,  0.07021405,  0.12124147,  0.71949766,
          0.99788648,  0.31235075,  0.12800102,  0.21255529,  0.4097645 ,
          0.17343364,  0.58994694,  0.69530292,  0.53952727,  0.67645979]])

 In [19]: y = np.random.random( (1,100) )

 In [20]: y

 Out[20]:
 array([[ 0.7995916 ,  0.50234357,  0.0156822 ,  0.12927104,  0.15400475,
          0.93278193,  0.92398302,  0.91047929,  0.04805954,  0.88029141,
          0.45886629,  0.76182724,  0.63914385,  0.08064302,  0.65318621,
          0.05821975,  0.06247843,  0.83705328,  0.15022162,  0.87442888,
          0.21438652,  0.98421258,  0.36857529,  0.27019668,  0.12957902,
          0.77606284,  0.82560299,  0.07788998,  0.782069  ,  0.10996114,
          0.69530622,  0.07913858,  0.43428193,  0.9612014 ,  0.32677694,
          0.71639339,  0.16281247,  0.34671045,  0.4163046 ,  0.80265938,
          0.82537614,  0.94201288,  0.09668671,  0.94549124,  0.54912399,
          0.63897389,  0.62315385,  0.70811873,  0.95666219,  0.838747  ,
          0.60824994,  0.81890863,  0.46670795,  0.18010272,  0.04944863,
          0.12786636,  0.26086503,  0.74274217,  0.04881725,  0.60158282,
          0.46347241,  0.69351719,  0.81248071,  0.33209248,  0.4135145 ,
          0.85516927,  0.18136555,  0.96710757,  0.78492171,  0.80392683,
          0.04398294,  0.83045095,  0.69568478,  0.23451623,  0.20733289,
          0.37455921,  0.23743431,  0.57762762,  0.93271692,  0.57212842,
          0.34697878,  0.44662209,  0.87802109,  0.48081905,  0.11077816,
          0.87601317,  0.98199734,  0.95157318,  0.4822475 ,  0.83759506,
          0.57440614,  0.4493696 ,  0.34993933,  0.27192895,  0.00340568,
          0.10402222,  0.94553401,  0.87175997,  0.82406534,  0.58048189]])

 In [24]: import scipy.spatial.distance

 In [25]: d1 = scipy.spatial.distance.euclidean(x, y)

 In [26]: d1

 Out[26]: 3.9013019241811246

 In [31]: d1**2

 Out[31]: 15.220156703619345

 In [32]: d2 = scipy.spatial.distance.sqeuclidean(x, y)

 In [33]: d2

 Out[33]: 27.985993011297221

 In [34]: d1 == d2

 Out[34]: False
 }}}

--

Comment(by warren.weckesser):

 Added markup in the description to quote the ipython session.

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


More information about the Scipy-tickets mailing list