Skip to content

Commit 69f4bac

Browse files
author
Nathaniel Saul
committed
add a verbose flag and prints out own constructor
1 parent 14f21c5 commit 69f4bac

File tree

1 file changed

+30
-8
lines changed

1 file changed

+30
-8
lines changed

ripser/ripser.py

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,19 @@ class Rips(BaseEstimator):
4949
5050
"""
5151

52-
53-
54-
def __init__(self, maxdim=1, thresh=-1, coeff=2):
52+
def __init__(self, maxdim=1, thresh=-1, coeff=2, verbose=True):
5553
self.maxdim = maxdim
5654
self.thresh = thresh
5755
self.coeff = coeff
56+
self.verbose = verbose
57+
5858
self.dgm_ = None
59+
self.distance_matrix_ = None # indicator
60+
self.metric_ = None
61+
62+
if self.verbose:
63+
print("Rips(maxdim={}, thres={}, coef={}, verbose={})".format(
64+
maxdim, thresh, coeff, verbose))
5965

6066
def transform(self, X, distance_matrix=False, metric='euclidean'):
6167
"""Compute persistence diagrams for X data array.
@@ -64,31 +70,47 @@ def transform(self, X, distance_matrix=False, metric='euclidean'):
6470
----------
6571
X: ndarray (n_samples, n_features)
6672
A numpy array of either data or distance matrix.
73+
6774
distance_matrix: bool
6875
Indicator that X is a distance matrix, if not we compute a
6976
distance matrix from X using the chosen metric.
77+
7078
metric: string or callable
7179
The metric to use when calculating distance between instances in a feature array. If metric is a string, it must be one of the options specified in PAIRED_DISTANCES, including “euclidean”, “manhattan”, or “cosine”. Alternatively, if metric is a callable function, it is called on each pair of instances (rows) and the resulting value recorded. The callable should take two arrays from X as input and return a value indicating the distance between them.
7280
7381
"""
7482

75-
76-
# Default is to input point cloud data
7783
if not distance_matrix:
7884
X = pairwise_distances(X, metric=metric)
7985

8086
dgm = self._compute_rips(X)
8187
self.dgm_ = dgm
82-
83-
return dgm
8488

8589
def fit_transform(self, X, distance_matrix=False, metric='euclidean'):
86-
""" Run transform and return results
90+
"""Compute persistence diagrams for X data array and return the diagrams.
91+
92+
Parameters
93+
----------
94+
X: ndarray (n_samples, n_features)
95+
A numpy array of either data or distance matrix.
96+
97+
distance_matrix: bool
98+
Indicator that X is a distance matrix, if not we compute a
99+
distance matrix from X using the chosen metric.
100+
101+
metric: string or callable
102+
The metric to use when calculating distance between instances in a feature array. If metric is a string, it must be one of the options specified in PAIRED_DISTANCES, including “euclidean”, “manhattan”, or “cosine”. Alternatively, if metric is a callable function, it is called on each pair of instances (rows) and the resulting value recorded. The callable should take two arrays from X as input and return a value indicating the distance between them.
103+
104+
Return
105+
------
106+
dgms: list (size maxdim) of ndarray (n_pairs, 2)
107+
A list of persistence diagrams, one for each dimension less than maxdim. Each diagram is an ndarray of size (n_pairs, 2) with the first column representing the birth time and the second column representing the death time of each pair.
87108
88109
"""
89110
self.transform(X, distance_matrix, metric)
90111
return self.dgm_
91112

113+
92114
def _compute_rips(self, dm):
93115
""" Compute the persistence diagram
94116

0 commit comments

Comments
 (0)