@@ -27,9 +27,9 @@ def bottleneck(dgm1, dgm2, matching=False):
27
27
28
28
Parameters
29
29
-----------
30
- dgm1: Mx(>=2)
30
+ dgm1: Mx(>=2)
31
31
array of birth/death pairs for PD 1
32
- dgm2: Nx(>=2)
32
+ dgm2: Nx(>=2)
33
33
array of birth/death paris for PD 2
34
34
matching: bool, default False
35
35
if True, return matching infromation and cross-similarity matrix
@@ -47,15 +47,13 @@ def bottleneck(dgm1, dgm2, matching=False):
47
47
"""
48
48
49
49
return_matching = matching
50
-
51
50
S = np .array (dgm1 )
52
51
M = min (S .shape [0 ], S .size )
53
52
if S .size > 0 :
54
53
S = S [np .isfinite (S [:, 1 ]), :]
55
54
if S .shape [0 ] < M :
56
55
warnings .warn (
57
- "dgm1 has points with non-finite death times;" +
58
- "ignoring those points"
56
+ "dgm1 has points with non-finite death times;" + "ignoring those points"
59
57
)
60
58
M = S .shape [0 ]
61
59
T = np .array (dgm2 )
@@ -64,8 +62,7 @@ def bottleneck(dgm1, dgm2, matching=False):
64
62
T = T [np .isfinite (T [:, 1 ]), :]
65
63
if T .shape [0 ] < N :
66
64
warnings .warn (
67
- "dgm2 has points with non-finite death times;" +
68
- "ignoring those points"
65
+ "dgm2 has points with non-finite death times;" + "ignoring those points"
69
66
)
70
67
N = T .shape [0 ]
71
68
@@ -101,7 +98,7 @@ def bottleneck(dgm1, dgm2, matching=False):
101
98
102
99
# Step 2: Perform a binary search + Hopcroft Karp to find the
103
100
# bottleneck distance
104
- ds = np .sort (np .unique (D .flatten ()))[0 :- 1 ] # Everything but np.inf
101
+ ds = np .sort (np .unique (D .flatten ())) # [0:-1] # Everything but np.inf
105
102
bdist = ds [- 1 ]
106
103
matching = {}
107
104
while len (ds ) >= 1 :
@@ -118,18 +115,18 @@ def bottleneck(dgm1, dgm2, matching=False):
118
115
matching = res
119
116
ds = ds [0 :idx ]
120
117
else :
121
- ds = ds [idx + 1 : :]
118
+ ds = ds [idx + 1 : :]
122
119
123
120
if return_matching :
124
121
matchidx = []
125
- for i in range (M + N ):
122
+ for i in range (M + N ):
126
123
j = matching ["{}" .format (i )]
127
124
d = D [i , j ]
128
125
if i < M :
129
126
if j >= N :
130
- j = - 1 # Diagonal match from first persistence diagram
127
+ j = - 1 # Diagonal match from first persistence diagram
131
128
else :
132
- if j >= N : # Diagonal to diagonal, so don't include this
129
+ if j >= N : # Diagonal to diagonal, so don't include this
133
130
continue
134
131
i = - 1
135
132
matchidx .append ([i , j , d ])
0 commit comments