[Scipy-tickets] [SciPy] #1430: scipy.spatial.distance.canberra not correctly implemented

SciPy Trac scipy-tickets@scipy....
Fri Apr 29 02:37:11 CDT 2011


#1430: scipy.spatial.distance.canberra not correctly implemented
---------------------+------------------------------------------------------
 Reporter:  k00aher  |       Owner:  somebody
     Type:  defect   |      Status:  new     
 Priority:  normal   |   Milestone:          
Component:  Other    |     Version:  0.9.0   
 Keywords:           |  
---------------------+------------------------------------------------------
 In the docstrings in distance.py two different formulas for the canberra
 distance are given. One in the cdist and pdist docstrings, which is
 correct, and one in the canberra function docstring which is wrong. The
 implementation is unfortunately wrong. A simple example is
 canberra([1.0,0.0,1.0,0.0],[1.0,1.0,0.0,0.0]) which should result in 2.0
 but results in 0.5. This example also highlights the problem in the
 canberra method with division by zero for empty columns ie last column
 gives 0/0 which here should equate to 0 and not NaN.

 a correct implementation is

 return np.nansum(abs(u-v)/(abs(u)+abs(v)))

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


More information about the Scipy-tickets mailing list