|
3 | 3 | from collections import namedtuple, deque, defaultdict |
4 | 4 | from operator import attrgetter |
5 | 5 | from itertools import count |
6 | | -from distutils.version import LooseVersion as _LooseVersion |
7 | 6 |
|
8 | 7 | import heapq |
9 | 8 | import numpy |
|
23 | 22 | WEIGHTED = "weighted" |
24 | 23 | WARD = "ward" |
25 | 24 |
|
26 | | -# Does scipy implement a O(n**2) NN chain algorithm? |
27 | | -_HAS_NN_CHAIN = hasattr(scipy.cluster.hierarchy, "_hierarchy") and \ |
28 | | - hasattr(scipy.cluster.hierarchy._hierarchy, "nn_chain") |
29 | | - |
30 | | -# Prior to 0.18 scipy.cluster.hierarchical's python interface disallowed |
31 | | -# ward clustering from a precomputed distance matrix even though it's cython |
32 | | -# implementation allowed it and was documented to support it (scipy issue 5220) |
33 | | -_HAS_WARD_LINKAGE_FROM_DIST = \ |
34 | | - _LooseVersion(scipy.__version__) >= _LooseVersion("0.18") and \ |
35 | | - _HAS_NN_CHAIN |
36 | | - |
37 | 25 |
|
38 | 26 | def condensedform(X, mode="upper"): |
39 | 27 | X = numpy.asarray(X) |
@@ -105,23 +93,7 @@ def dist_matrix_linkage(matrix, linkage=AVERAGE): |
105 | 93 | """ |
106 | 94 | # Extract compressed upper triangular distance matrix. |
107 | 95 | distances = condensedform(matrix) |
108 | | - if linkage == WARD and not _HAS_WARD_LINKAGE_FROM_DIST: |
109 | | - # Avoid `scipy.cluster.hierarchy.linkage` and dispatch to it's |
110 | | - # cython implementation directly. |
111 | | - # This the core of the scipy.cluster.hierarchy.linkage in |
112 | | - # scipy 0.16, 0.17. Assuming the branches are in bug fix mode |
113 | | - # only so this interface will not change. |
114 | | - y = numpy.asarray(distances, dtype=float) |
115 | | - scipy.spatial.distance.is_valid_y(y, throw=True) |
116 | | - N = scipy.spatial.distance.num_obs_y(y) |
117 | | - # allocate the output linkage matrix |
118 | | - Z = numpy.zeros((N - 1, 4)) |
119 | | - # retrieve the correct method flag |
120 | | - method = scipy.cluster.hierarchy._cpy_euclid_methods["ward"] |
121 | | - scipy.cluster.hierarchy._hierarchy.linkage(y, Z, int(N), int(method)) |
122 | | - return Z |
123 | | - else: |
124 | | - return scipy.cluster.hierarchy.linkage(distances, method=linkage) |
| 96 | + return scipy.cluster.hierarchy.linkage(distances, method=linkage) |
125 | 97 |
|
126 | 98 |
|
127 | 99 | def dist_matrix_clustering(matrix, linkage=AVERAGE): |
|
0 commit comments