ripser.Rips¶

class
ripser.
Rips
(maxdim=1, thresh=inf, coeff=2, do_cocycles=False, n_perm=None, verbose=True)[source]¶ sklearn style class interface for
ripser
withfit
andtransform
methods..Parameters:  maxdim (int, optional, default 1) – Maximum homology dimension computed. Will compute all dimensions lower than and equal to this value. For 1, H_0 and H_1 will be computed.
 thresh (float, default infinity) – Maximum distances considered when constructing filtration. If infinity, compute the entire filtration.
 coeff (int prime, default 2) – Compute homology with coefficients in the prime field Z/pZ for p=coeff.
 do_cocycles (bool) – Indicator of whether to compute cocycles, if so, we compute and store cocycles in the cocycles_ dictionary Rips member variable
 n_perm (int) – The number of points to subsample in a “greedy permutation,” or a furthest point sampling of the points. These points will be used in lieu of the full point cloud for a faster computation, at the expense of some accuracy, which can be bounded as a maximum bottleneck distance to all diagrams on the original point set
 verbose (boolean) – Whether to print out information about this object as it is constructed

`dgm_`
After transform, dgm_ contains computed persistence diagrams in each dimension
Type: list of ndarray, each shape (n_pairs, 2)

cocycles_
¶ A list of representative cocycles in each dimension. The list in each dimension is parallel to the diagram in that dimension; that is, each entry of the list is a representative cocycle of the corresponding point expressed as an ndarray(K, d+1), where K is the number of nonzero values of the cocycle and d is the dimension of the cocycle. The first d columns of each array index into the simplices of the (subsampled) point cloud, and the last column is the value of the cocycle at that simplex
Type: list (size maxdim) of list of ndarray

dperm2all_
¶ The distance matrix used in the computation if n_perm is none. Otherwise, the distance from all points in the permutation to all points in the dataset
Type: ndarray(n_samples, n_samples) or ndarray (n_perm, n_samples) if n_perm

metric_
¶ 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 pairwise_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.
Type: string or callable

num_edges
¶ The number of edges added during the computation
Type: int

idx_perm
¶ Index into the original point cloud of the points used as a subsample in the greedy permutation
Type: ndarray(n_perm) if n_perm > 0

r_cover
¶ Covering radius of the subsampled points. If n_perm <= 0, then the full point cloud was used and this is 0
Type: float
Examples
from ripser import Rips import tadasets data = tadasets.dsphere(n=110, d=2)[0] rips = Rips() rips.transform(data) rips.plot()

__init__
(maxdim=1, thresh=inf, coeff=2, do_cocycles=False, n_perm=None, verbose=True)[source]¶ Initialize self. See help(type(self)) for accurate signature.
Methods
__init__
([maxdim, thresh, coeff, …])Initialize self. fit_transform
(X[, distance_matrix, metric])Compute persistence diagrams for X data array and return the diagrams. plot
([diagrams])A helper function to plot persistence diagrams. transform
(X[, distance_matrix, metric])
fit_transform
(X, distance_matrix=False, metric='euclidean')[source]¶ Compute persistence diagrams for X data array and return the diagrams.
Parameters:  X (ndarray (n_samples, n_features)) – A numpy array of either data or distance matrix.
 distance_matrix (bool) – Indicator that X is a distance matrix, if not we compute a distance matrix from X using the chosen metric.
 metric (string or callable) – 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 pairwise_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.
Returns: dgms (list (size maxdim) of ndarray (n_pairs, 2)) – 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.

plot
(diagrams=None, *args, **kwargs)[source]¶ A helper function to plot persistence diagrams.
Parameters:  diagrams (ndarray (n_pairs, 2) or list of diagrams) – A diagram or list of diagrams as returned from self.fit. If diagram is None, we use self.dgm_ for plotting. If diagram is a list of diagrams, then plot all on the same plot using different colors.
 plot_only (list of numeric) – If specified, an array of only the diagrams that should be plotted.
 title (string, default is None) – If title is defined, add it as title of the plot.
 xy_range (list of numeric [xmin, xmax, ymin, ymax]) – User provided range of axes. This is useful for comparing multiple persistence diagrams.
 labels (string or list of strings) – Legend labels for each diagram. If none are specified, we use H_0, H_1, H_2,… by default.
 colormap (string, default is 'default') –
Any of matplotlib color palettes. Some options are ‘default’, ‘seaborn’, ‘sequential’. See all available styles with
import matplotlib as mpl print(mpl.styles.available)
 size (numeric, default is 20) – Pixel size of each point plotted.
 ax_color (any valid matplitlib color type.) – See [https://matplotlib.org/api/colors_api.html](https://matplotlib.org/api/colors_api.html) for complete API.
 diagonal (bool, default is True) – Plot the diagonal x=y line.
 lifetime (bool, default is False. If True, diagonal is turned to False.) – Plot life time of each point instead of birth and death. Essentially, visualize (x, yx).
 legend (bool, default is True) – If true, show the legend.
 show (bool, default is True) – Call plt.show() after plotting. If you are using self.plot() as part of a subplot, set show=False and call plt.show() only once at the end.