summaryrefslogtreecommitdiff
path: root/src/python/gudhi/representations/vector_methods.py
diff options
context:
space:
mode:
authorManu <msoriano4@us.es>2022-02-14 13:58:01 +0100
committerManu <msoriano4@us.es>2022-02-14 13:58:01 +0100
commit3b7bd4fd8b21fc8ce0d7b2848b5ac9bdd397c080 (patch)
tree2c11c4069382ae138576d0dcaa023d8bdd9551d7 /src/python/gudhi/representations/vector_methods.py
parent2a2aae065bf34cfcf8bba52695ce3ae3ca6d4048 (diff)
A bug in the Entropy function has been solved
Diffstat (limited to 'src/python/gudhi/representations/vector_methods.py')
-rw-r--r--src/python/gudhi/representations/vector_methods.py13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/python/gudhi/representations/vector_methods.py b/src/python/gudhi/representations/vector_methods.py
index f8078d03..57ca5999 100644
--- a/src/python/gudhi/representations/vector_methods.py
+++ b/src/python/gudhi/representations/vector_methods.py
@@ -510,16 +510,19 @@ class Entropy(BaseEstimator, TransformerMixin):
for i in range(num_diag):
orig_diagram, diagram, num_pts_in_diag = X[i], new_X[i], X[i].shape[0]
try:
- new_diagram = DiagramScaler(use=True, scalers=[([1], MaxAbsScaler())]).fit_transform([diagram])[0]
+ #new_diagram = DiagramScaler(use=True, scalers=[([1], MaxAbsScaler())]).fit_transform([diagram])[0]
+ new_diagram = DiagramScaler().fit_transform([diagram])[0]
except ValueError:
# Empty persistence diagram case - https://github.com/GUDHI/gudhi-devel/issues/507
assert len(diagram) == 0
new_diagram = np.empty(shape = [0, 2])
-
+
+ p = new_diagram[:,1]
+ L = sum(p)
+ p = p/L
if self.mode == "scalar":
- ent = - np.sum( np.multiply(new_diagram[:,1], np.log(new_diagram[:,1])) )
+ ent = -np.dot(p, np.log(p))
Xfit.append(np.array([[ent]]))
-
else:
ent = np.zeros(self.resolution)
for j in range(num_pts_in_diag):
@@ -527,7 +530,7 @@ class Entropy(BaseEstimator, TransformerMixin):
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) * new_diagram[j,1] * np.log(new_diagram[j,1])
+ ent[k] += (-1) * p[j] * np.log(p[j])
if self.normalized:
ent = ent / np.linalg.norm(ent, ord=1)
Xfit.append(np.reshape(ent,[1,-1]))