Skip to content

Commit f3606b5

Browse files
authored
Update persistent_entropy.py
1 parent 76110b7 commit f3606b5

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

persim/persistent_entropy.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# -*- import
12
"""
23
34
The persistent entropy has been defined in [1]. A precursor of this definition was given in [2]
@@ -73,11 +74,14 @@ def persistent_entropy(
7374
ps = []
7475
for dgm in dgms:
7576
l = dgm[:, 1] - dgm[:, 0]
76-
L = np.sum(l)
77-
p = l / L
78-
E = -np.sum(p * np.log(p))
79-
if normalize == True:
80-
E = E / np.log(len(l))
81-
ps.append(E)
77+
if all(l > 0):
78+
L = np.sum(l)
79+
p = l / L
80+
E = -np.sum(p * np.log(p))
81+
if normalize == True:
82+
E = E / np.log(len(l))
83+
ps.append(E)
84+
else:
85+
raise Exception("A bar is born after dying")
8286

8387
return np.array(ps)

0 commit comments

Comments
 (0)