giotto.homology
.VietorisRipsPersistence¶
-
class
giotto.homology.
VietorisRipsPersistence
(metric='euclidean', max_edge_length=inf, homology_dimensions=(0, 1), coeff=2, infinity_values=None, n_jobs=None)¶ Persistence diagrams resulting from Vietoris-Rips filtrations.
Given a point cloud in Euclidean space, or an abstract metric space encoded by a distance matrix, information about the appearance and disappearance of topological features (technically, homology classes) of various dimensions and at different scales is summarised in the corresponding persistence diagram.
- Parameters
- metricstring or callable, optional, default:
'euclidean'
If set to ‘precomputed’, input data is to be interpreted as a collection of distance matrices. Otherwise, input data is to be interpreted as a collection of point clouds (i.e. feature arrays), and metric determines a rule with which to calculate distances between pairs of instances (i.e. rows) in these arrays. If metric is a string, it must be one of the options allowed by
scipy.spatial.distance.pdist
for its metric parameter, or a metric listed insklearn.pairwise.PAIRWISE_DISTANCE_FUNCTIONS
, including “euclidean”, “manhattan”, or “cosine”. If metric is a callable function, it is called on each pair of instances and the resulting value recorded. The callable should take two arrays from the entry in X as input, and return a value indicating the distance between them.- homology_dimensionsiterable, optional, default:
(0, 1)
Dimensions (non-negative integers) of the topological features to be detected.
- coeffint prime, optional, default:
2
Compute homology with coefficients in the prime field \(\mathbb{F}_p = \{ 0, \ldots, p - 1 \}\) where \(p\) equals coeff.
- max_edge_lengthfloat, optional, default:
numpy.inf
Upper bound on the maximum value of the Vietoris-Rips filtration parameter. Points whose distance is greater than this value will never be connected by an edge, and topological features at scales larger than this value will not be detected.
- infinity_valuesfloat or None, default
Which death value to assign to features which are still alive at filtration value max_edge_length.
None
has the same behaviour as max_edge_length.- n_jobsint or None, optional, default:
None
The number of jobs to use for the computation.
None
means 1 unless in ajoblib.parallel_backend
context.-1
means using all processors.
- metricstring or callable, optional, default:
See also
Notes
Ripser is used as a C++ backend for computing Vietoris-Rips persistent homology. Python bindings were modified for performance from the ripser.py package.
Persistence diagrams produced by this class must be interpreted with care due to the presence of padding triples which carry no information. See
transform
for additional information.References
[1] U. Bauer, “Ripser: efficient computation of Vietoris-Rips persistence barcodes”, 2019; arXiv:1908.02518.
Methods
fit
(self, X[, y])Do nothing and return the estimator unchanged.
fit_transform
(self, X[, y])Fit to data, then transform it.
get_params
(self[, deep])Get parameters for this estimator.
set_params
(self, \*\*params)Set the parameters of this estimator.
transform
(self, X[, y])Compute, for each point cloud or distance matrix in X, the relevant persistence diagram as an array of triples [b, d, q].
-
__init__
(self, metric='euclidean', max_edge_length=inf, homology_dimensions=(0, 1), coeff=2, infinity_values=None, n_jobs=None)¶ Initialize self. See help(type(self)) for accurate signature.
-
fit
(self, X, y=None)¶ Do nothing and return the estimator unchanged.
This method is there to implement the usual scikit-learn API and hence work in pipelines.
- Parameters
- Xndarray, shape (n_samples, n_points, n_points) or (n_samples, n_points, n_dimensions)
Input data. If
metric == 'precomputed'
, the input should be an ndarray whose each entry along axis 0 is a distance matrix of shape(n_points, n_points)
. Otherwise, each such entry will be interpreted as an ndarray ofn_points
row vectors inn_dimensions
-dimensional space.- yNone
There is no need for a target in a transformer, yet the pipeline API requires this parameter.
- Returns
- selfobject
-
fit_transform
(self, X, y=None, **fit_params)¶ Fit to data, then transform it.
Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X.
- Parameters
- Xnumpy array of shape [n_samples, n_features]
Training set.
- ynumpy array of shape [n_samples]
Target values.
- Returns
- X_newnumpy array of shape [n_samples, n_features_new]
Transformed array.
-
get_params
(self, deep=True)¶ Get parameters for this estimator.
- Parameters
- deepboolean, optional
If True, will return the parameters for this estimator and contained subobjects that are estimators.
- Returns
- paramsmapping of string to any
Parameter names mapped to their values.
-
set_params
(self, **params)¶ Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as pipelines). The latter have parameters of the form
<component>__<parameter>
so that it’s possible to update each component of a nested object.- Returns
- self
-
transform
(self, X, y=None)¶ Compute, for each point cloud or distance matrix in X, the relevant persistence diagram as an array of triples [b, d, q]. Each triple represents a persistent topological feature in dimension q (belonging to homology_dimensions) which is born at b and dies at d. Only triples in which b < d are meaningful. Triples in which b and d are equal (“diagonal elements”) may be artificially introduced during the computation for padding purposes, since the number of non-trivial persistent topological features is typically not constant across samples. They carry no information and hence should be effectively ignored by any further computation.
- Parameters
- Xndarray, shape (n_samples, n_points, n_points) or (n_samples, n_points, n_dimensions)
Input data. If
metric == 'precomputed'
, the input should be an ndarray whose each entry along axis 0 is a distance matrix of shape(n_points, n_points)
. Otherwise, each such entry will be interpreted as an ndarray ofn_points
row vectors inn_dimensions
-dimensional space.- yNone
There is no need for a target in a transformer, yet the pipeline API requires this parameter.
- Returns
- Xtndarray, shape (n_samples, n_features, 3)
Array of persistence diagrams computed from the feature arrays or distance matrices in X.
n_features
equals \(\sum_q n_q\), where \(n_q\) is the maximum number of topological features in dimension \(q\) across all samples in X.