summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormathieu <mathieu.carriere3@gmail.com>2019-12-11 15:38:00 -0500
committermathieu <mathieu.carriere3@gmail.com>2019-12-11 15:38:00 -0500
commit7bd6907e577e22803fec179f652ecf0ec64dcb4a (patch)
treedb5e90a48b287e237cdf5c4aeb069c294e13436d /src
parent2886885ff4cf1f134863de0fa97b64f824d67622 (diff)
cleanup for landscape resolution
Diffstat (limited to 'src')
-rw-r--r--src/python/gudhi/representations/vector_methods.py17
1 files changed, 9 insertions, 8 deletions
diff --git a/src/python/gudhi/representations/vector_methods.py b/src/python/gudhi/representations/vector_methods.py
index 9b280f68..fe26dbe2 100644
--- a/src/python/gudhi/representations/vector_methods.py
+++ b/src/python/gudhi/representations/vector_methods.py
@@ -96,6 +96,7 @@ class Landscape(BaseEstimator, TransformerMixin):
"""
self.num_landscapes, self.resolution, self.sample_range = num_landscapes, resolution, sample_range
self.nan_in_range = np.isnan(np.array(self.sample_range))
+ self.new_resolution = self.resolution + self.nan_in_range.sum()
def fit(self, X, y=None):
"""
@@ -122,26 +123,26 @@ class Landscape(BaseEstimator, TransformerMixin):
numpy array with shape (number of diagrams) x (number of samples = **num_landscapes** x **resolution**): output persistence landscapes.
"""
num_diag, Xfit = len(X), []
- x_values = np.linspace(self.sample_range[0], self.sample_range[1], self.resolution + self.nan_in_range.sum())
+ x_values = np.linspace(self.sample_range[0], self.sample_range[1], self.new_resolution)
step_x = x_values[1] - x_values[0]
for i in range(num_diag):
diagram, num_pts_in_diag = X[i], X[i].shape[0]
- ls = np.zeros([self.num_landscapes, self.resolution + self.nan_in_range.sum()])
+ ls = np.zeros([self.num_landscapes, self.new_resolution])
events = []
- for j in range(self.resolution + self.nan_in_range.sum()):
+ for j in range(self.new_resolution):
events.append([])
for j in range(num_pts_in_diag):
[px,py] = diagram[j,:2]
- min_idx = np.clip(np.ceil((px - self.sample_range[0]) / step_x).astype(int), 0, self.resolution + self.nan_in_range.sum())
- mid_idx = np.clip(np.ceil((0.5*(py+px) - self.sample_range[0]) / step_x).astype(int), 0, self.resolution + self.nan_in_range.sum())
- max_idx = np.clip(np.ceil((py - self.sample_range[0]) / step_x).astype(int), 0, self.resolution + self.nan_in_range.sum())
+ min_idx = np.clip(np.ceil((px - self.sample_range[0]) / step_x).astype(int), 0, self.new_resolution)
+ mid_idx = np.clip(np.ceil((0.5*(py+px) - self.sample_range[0]) / step_x).astype(int), 0, self.new_resolution)
+ max_idx = np.clip(np.ceil((py - self.sample_range[0]) / step_x).astype(int), 0, self.new_resolution)
- if min_idx < self.resolution + self.nan_in_range.sum() and max_idx > 0:
+ if min_idx < self.new_resolution and max_idx > 0:
landscape_value = self.sample_range[0] + min_idx * step_x - px
for k in range(min_idx, mid_idx):
@@ -153,7 +154,7 @@ class Landscape(BaseEstimator, TransformerMixin):
events[k].append(landscape_value)
landscape_value -= step_x
- for j in range(self.resolution + self.nan_in_range.sum()):
+ for j in range(self.new_resolution):
events[j].sort(reverse=True)
for k in range( min(self.num_landscapes, len(events[j])) ):
ls[k,j] = events[j][k]