summaryrefslogtreecommitdiff
path: root/src/python/gudhi/representations/vector_methods.py
diff options
context:
space:
mode:
authorManu <msoriano4@us.es>2022-03-07 09:55:17 +0100
committerManu <msoriano4@us.es>2022-03-07 09:55:17 +0100
commit77cd751b729d6b68a49ae99e86cff481220ec367 (patch)
treebdef6bfee68ae23cd3918ca0e3e511dfcedc86e3 /src/python/gudhi/representations/vector_methods.py
parent9c0b0d348b448d68d28fbab661626ab2263e77d0 (diff)
minor changes in entropy
Diffstat (limited to 'src/python/gudhi/representations/vector_methods.py')
-rw-r--r--src/python/gudhi/representations/vector_methods.py6
1 files changed, 2 insertions, 4 deletions
diff --git a/src/python/gudhi/representations/vector_methods.py b/src/python/gudhi/representations/vector_methods.py
index 57ca5999..7d6a7f27 100644
--- a/src/python/gudhi/representations/vector_methods.py
+++ b/src/python/gudhi/representations/vector_methods.py
@@ -518,8 +518,7 @@ class Entropy(BaseEstimator, TransformerMixin):
new_diagram = np.empty(shape = [0, 2])
p = new_diagram[:,1]
- L = sum(p)
- p = p/L
+ p = p/np.sum(p)
if self.mode == "scalar":
ent = -np.dot(p, np.log(p))
Xfit.append(np.array([[ent]]))
@@ -529,8 +528,7 @@ class Entropy(BaseEstimator, TransformerMixin):
[px,py] = orig_diagram[j,:2]
min_idx = np.clip(np.ceil((px - self.sample_range[0]) / step_x).astype(int), 0, self.resolution)
max_idx = np.clip(np.ceil((py - self.sample_range[0]) / step_x).astype(int), 0, self.resolution)
- for k in range(min_idx, max_idx):
- ent[k] += (-1) * p[j] * np.log(p[j])
+ ent[min_idx:max_idx]-=p[j]*np.log(p[j])
if self.normalized:
ent = ent / np.linalg.norm(ent, ord=1)
Xfit.append(np.reshape(ent,[1,-1]))