class ripser.Rips(maxdim=1, thresh=inf, coeff=2, do_cocycles=False, n_perm=None, verbose=True)[source]

sklearn style class interface for ripser with fit and transform methods..

  • 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


After transform, dgm_ contains computed persistence diagrams in each dimension


list of ndarray, each shape (n_pairs, 2)


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


list (size maxdim) of list of ndarray


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


ndarray(n_samples, n_samples) or ndarray (n_perm, n_samples) if n_perm


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.


string or callable


The number of edges added during the computation




Index into the original point cloud of the points used as a subsample in the greedy permutation


ndarray(n_perm) if n_perm > 0


Covering radius of the subsampled points. If n_perm <= 0, then the full point cloud was used and this is 0




from ripser import Rips
import tadasets

data = tadasets.dsphere(n=110, d=2)[0]
rips = Rips()
__init__(maxdim=1, thresh=inf, coeff=2, do_cocycles=False, n_perm=None, verbose=True)[source]


__init__([maxdim, thresh, coeff, ...])

fit_transform(X[, distance_matrix, metric])

Compute persistence diagrams for X data array and return the diagrams.


A helper function to plot persistence diagrams.

set_output(*[, transform])

Set output container.

transform(X[, distance_matrix, metric])