1
- #!python
2
- #cython: boundscheck=False
3
- #cython: wraparound=False
4
- #cython: initializedcheck=False
5
- #cython: cdivision=True
1
+ # cython: boundscheck=False
2
+ # cython: cdivision=True
3
+ # cython: initializedcheck=False
4
+ # cython: wraparound=False
6
5
7
6
# By Jake Vanderplas (2013) <jakevdp@cs.washington.edu>
8
7
# written for the scikit-learn project
@@ -19,7 +18,7 @@ cdef extern from "arrayobject.h":
19
18
int typenum, void * data)
20
19
21
20
22
- cdef inline np .ndarray _buffer_to_ndarray (DTYPE_t * x , np .npy_intp n ):
21
+ cdef inline np.ndarray _buffer_to_ndarray(const DTYPE_t* x, np.npy_intp n):
23
22
# Wrap a memory buffer with an ndarray. Warning: this is not robust.
24
23
# In particular, if x is deallocated before the returned array goes
25
24
# out of scope, this could cause memory errors. Since there is not
@@ -33,8 +32,8 @@ cdef inline np.ndarray _buffer_to_ndarray(DTYPE_t* x, np.npy_intp n):
33
32
from libc.math cimport fabs, sqrt, exp, pow , cos, sin, asin
34
33
cdef DTYPE_t INF = np.inf
35
34
36
- from ._typedefs cimport DTYPE_t , ITYPE_t , DITYPE_t , DTYPECODE
37
- from ._typedefs import DTYPE , ITYPE
35
+ from ..utils. _typedefs cimport DTYPE_t, ITYPE_t, DITYPE_t, DTYPECODE
36
+ from ..utils. _typedefs import DTYPE, ITYPE
38
37
39
38
40
39
# #####################################################################
@@ -98,7 +97,7 @@ cdef class DistanceMetric:
98
97
99
98
Examples
100
99
--------
101
- >>> from sklearn.neighbors import DistanceMetric
100
+ >>> from sklearn.metrics import DistanceMetric
102
101
>>> dist = DistanceMetric.get_metric('euclidean')
103
102
>>> X = [[0, 1, 2],
104
103
[3, 4, 5]]
@@ -291,14 +290,13 @@ cdef class DistanceMetric:
291
290
292
291
cdef DTYPE_t rdist(self , const DTYPE_t* x1, const DTYPE_t* x2,
293
292
ITYPE_t size) nogil except - 1 :
294
- """Compute the reduced distance between vectors x1 and x2.
293
+ """ Compute the rank-preserving surrogate distance between vectors x1 and x2.
295
294
296
295
This can optionally be overridden in a base class.
297
296
298
- The reduced distance is any measure that yields the same rank as the
299
- distance, but is more efficient to compute. For example, for the
300
- Euclidean metric, the reduced distance is the squared-euclidean
301
- distance.
297
+ The rank-preserving surrogate distance is any measure that yields the same
298
+ rank as the distance, but is more efficient to compute. For example, for the
299
+ Euclidean metric, the surrogate distance is the squared-euclidean distance.
302
300
"""
303
301
return self .dist(x1, x2, size)
304
302
@@ -323,25 +321,24 @@ cdef class DistanceMetric:
323
321
return 0
324
322
325
323
cdef DTYPE_t _rdist_to_dist(self , DTYPE_t rdist) nogil except - 1 :
326
- """Convert the reduced distance to the distance"""
324
+ """ Convert the rank-preserving surrogate distance to the distance"""
327
325
return rdist
328
326
329
327
cdef DTYPE_t _dist_to_rdist(self , DTYPE_t dist) nogil except - 1 :
330
- """Convert the distance to the reduced distance"""
328
+ """ Convert the distance to the rank-preserving surrogate distance"""
331
329
return dist
332
330
333
331
def rdist_to_dist (self , rdist ):
334
- """Convert the Reduced distance to the true distance.
332
+ """ Convert the rank-preserving surrogate distance to the distance.
335
333
336
- The reduced distance, defined for some metrics, is a computationally
337
- more efficient measure which preserves the rank of the true distance.
338
- For example, in the Euclidean distance metric, the reduced distance
339
- is the squared-euclidean distance.
334
+ The surrogate distance is any measure that yields the same rank as the
335
+ distance, but is more efficient to compute. For example, for the
336
+ Euclidean metric, the surrogate distance is the squared-euclidean distance.
340
337
341
338
Parameters
342
339
----------
343
340
rdist : double
344
- Reduced distance.
341
+ Surrogate distance.
345
342
346
343
Returns
347
344
-------
@@ -351,12 +348,11 @@ cdef class DistanceMetric:
351
348
return rdist
352
349
353
350
def dist_to_rdist (self , dist ):
354
- """Convert the true distance to the reduced distance.
351
+ """ Convert the true distance to the rank-preserving surrogate distance.
355
352
356
- The reduced distance, defined for some metrics, is a computationally
357
- more efficient measure which preserves the rank of the true distance.
358
- For example, in the Euclidean distance metric, the reduced distance
359
- is the squared-euclidean distance.
353
+ The surrogate distance is any measure that yields the same rank as the
354
+ distance, but is more efficient to compute. For example, for the
355
+ Euclidean metric, the surrogate distance is the squared-euclidean distance.
360
356
361
357
Parameters
362
358
----------
@@ -366,7 +362,7 @@ cdef class DistanceMetric:
366
362
Returns
367
363
-------
368
364
double
369
- Reduced distance.
365
+ Surrogate distance.
370
366
"""
371
367
return dist
372
368
@@ -519,7 +515,7 @@ cdef class ChebyshevDistance(DistanceMetric):
519
515
520
516
Examples
521
517
--------
522
- >>> from sklearn.neighbors .dist_metrics import DistanceMetric
518
+ >>> from sklearn.metrics .dist_metrics import DistanceMetric
523
519
>>> dist = DistanceMetric.get_metric('chebyshev')
524
520
>>> X = [[0, 1, 2],
525
521
... [3, 4, 5]]
0 commit comments