FlagserPersistence

class gtda.homology.FlagserPersistence(homology_dimensions=0, 1, directed=True, filtration='max', coeff=2, max_edge_weight=inf, infinity_values=None, reduced_homology=True, max_entries=- 1, n_jobs=None)[source]

Persistence diagrams resulting from filtrations of directed or undirected flag complexes 1.

Given a weighted directed or undirected graph, information about the appearance and disappearance of topological features (technically, homology classes) of various dimension and at different scales is summarised in the corresponding persistence diagram.

Important note:

  • 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.

Parameters
  • homology_dimensions (list or tuple, optional, default: (0, 1)) – Dimensions (non-negative integers) of the topological features to be detected.

  • directed (bool, optional, default: True) –

    If True, transform computes the persistence diagrams of the filtered directed flag complexes arising from the input collection of weighted directed graphs. If False, transform computes the persistence diagrams of the filtered undirected flag complexes obtained by regarding all input weighted graphs as undirected, and:

    • if max_edge_weight is numpy.inf, it is sufficient to pass a collection of (dense or sparse) upper-triangular matrices;

    • if max_edge_weight is finite, it is recommended to pass either a collection of symmetric dense matrices, or a collection of sparse upper-triangular matrices.

  • filtration (string, optional, default: 'max') – Algorithm determining the filtration values of higher order simplices from the weights of the vertices and edges. Possible values are: [‘dimension’, ‘zero’, ‘max’, ‘max3’, ‘max_plus_one’, ‘product’, ‘sum’, ‘pmean’, ‘pmoment’, ‘remove_edges’, ‘vertex_degree’]

  • coeff (int 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_weight (float, optional, default: numpy.inf) – Maximum edge weight to be considered in the filtration. All edge weights greater than this value will be considered as absent from the filtration and topological features at scales larger than this value will not be detected.

  • infinity_values (float or None, default: None) – Which death value to assign to features which are still alive at filtration value max_edge_weight. None means that this death value is declared to be equal to max_edge_weight.

  • reduced_homology (bool, optional, default: True) – If True, the earliest-born triple in homology dimension 0 which has infinite death is discarded from each diagram computed in transform.

  • max_entries (int, optional, default: -1) – Number controlling the degree of precision in the matrix reductions performed by the the backend. Corresponds to the parameter approximation in pyflagser.flagser_weighted and pyflagser.flagser_unweighted. Increase for higher precision, decrease for faster computation. A good value is often 100000 in hard problems. A negative value computes highest possible precision.

  • n_jobs (int or None, optional, default: None) – The number of jobs to use for the computation. None means 1 unless in a joblib.parallel_backend context. -1 means using all processors.

infinity_values_

Effective death value to assign to features which are still alive at filtration value max_edge_weight.

Type

float

See also

VietorisRipsPersistence, SparseRipsPersistence, WeakAlphaPersistence, EuclideanCechPersistence, ConsistentRescaling, ConsecutiveRescaling

Notes

The pyflagser Python package is used for binding Flagser, a C++ backend for computing the (persistent) homology of (filtered) directed flag complexes. For more details, please refer to the flagser documentation.

References

1

D. Luetgehetmann, D. Govc, J. P. Smith, and R. Levi, “Computing persistent homology of directed flag complexes”, Algorithms, 13(1), 2020.

__init__(homology_dimensions=0, 1, directed=True, filtration='max', coeff=2, max_edge_weight=inf, infinity_values=None, reduced_homology=True, max_entries=- 1, n_jobs=None)[source]

Initialize self. See help(type(self)) for accurate signature.

fit(X, y=None)[source]

Calculate infinity_values_. Then, return the estimator.

This method is here to implement the usual scikit-learn API and hence work in pipelines.

Parameters
  • X (ndarray or list of length n_samples) – Input collection of adjacency matrices of weighted directed or undirected graphs. Can be either a 3D ndarray whose zeroth dimension has size n_samples, or a list containing n_samples 2D ndarrays/sparse matrices. In each adjacency matrix, diagonal elements are vertex weights and off-diagonal elements are edges weights. It is assumed that a vertex weight cannot be larger than the weight of the edges it forms. The way zero values are handled depends on the format of the matrix. If the matrix is a dense numpy.ndarray, zero values denote zero-weighted edges. If the matrix is a sparse scipy.sparse matrix, explicitly stored off-diagonal zeros and all diagonal zeros denote zero-weighted edges. Off-diagonal values that have not been explicitly stored are treated by scipy.sparse as zeros but will be understood as infinitely-valued edges, i.e., edges absent from the filtration.

  • y (None) – There is no need for a target in a transformer, yet the pipeline API requires this parameter.

Returns

self

Return type

object

fit_transform(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
  • X (ndarray or list of length n_samples) – Input collection of adjacency matrices of weighted directed or undirected graphs. Can be either a 3D ndarray whose zeroth dimension has size n_samples, or a list containing n_samples 2D ndarrays/sparse matrices. In each adjacency matrix, diagonal elements are vertex weights and off-diagonal elements are edges weights. It is assumed that a vertex weight cannot be larger than the weight of the edges it forms. The way zero values are handled depends on the format of the matrix. If the matrix is a dense numpy.ndarray, zero values denote zero-weighted edges. If the matrix is a sparse scipy.sparse matrix, explicitly stored off-diagonal zeros and all diagonal zeros denote zero-weighted edges. Off-diagonal values that have not been explicitly stored are treated by scipy.sparse as zeros but will be understood as infinitely-valued edges, i.e., edges absent from the filtration.

  • y (None) – There is no need for a target in a transformer, yet the pipeline API requires this parameter.

Returns

Xt – 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.

Return type

ndarray of shape (n_samples, n_features, 3)

fit_transform_plot(X, y=None, sample=0, **plot_params)

Fit to data, then apply transform_plot.

Parameters
  • X (ndarray of shape (n_samples, ..)) – Input data.

  • y (ndarray of shape (n_samples,) or None) – Target values for supervised problems.

  • sample (int) – Sample to be plotted.

  • **plot_params – Optional plotting parameters.

Returns

Xt – Transformed one-sample slice from the input.

Return type

ndarray of shape (1, ..)

get_params(deep=True)

Get parameters for this estimator.

Parameters

deep (bool, default=True) – If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns

params – Parameter names mapped to their values.

Return type

mapping of string to any

static plot(Xt, sample=0, homology_dimensions=None, plotly_params=None)[source]

Plot a sample from a collection of persistence diagrams, with homology in multiple dimensions.

Parameters
  • Xt (ndarray of shape (n_samples, n_features, 3)) – Collection of persistence diagrams, such as returned by transform.

  • sample (int, optional, default: 0) – Index of the sample in Xt to be plotted.

  • homology_dimensions (list, tuple or None, optional, default: None) – Which homology dimensions to include in the plot. None means plotting all dimensions present in Xt[sample].

  • plotly_params (dict or None, optional, default: None) – Custom parameters to configure the plotly figure. Allowed keys are "traces" and "layout", and the corresponding values should be dictionaries containing keyword arguments as would be fed to the update_traces and update_layout methods of plotly.graph_objects.Figure.

Returns

fig – Plotly figure.

Return type

plotly.graph_objects.Figure object

set_params(**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.

Parameters

**params (dict) – Estimator parameters.

Returns

self – Estimator instance.

Return type

object

transform(X, y=None)[source]

For each adjacency matrix in X, compute 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
  • X (ndarray or list of length n_samples) – Input collection of adjacency matrices of weighted directed or undirected graphs. Can be either a 3D ndarray whose zeroth dimension has size n_samples, or a list containing n_samples 2D ndarrays/sparse matrices. In each adjacency matrix, diagonal elements are vertex weights and off-diagonal elements are edges weights. It is assumed that a vertex weight cannot be larger than the weight of the edges it forms. The way zero values are handled depends on the format of the matrix. If the matrix is a dense numpy.ndarray, zero values denote zero-weighted edges. If the matrix is a sparse scipy.sparse matrix, explicitly stored off-diagonal zeros and all diagonal zeros denote zero-weighted edges. Off-diagonal values that have not been explicitly stored are treated by scipy.sparse as zeros but will be understood as infinitely-valued edges, i.e., edges absent from the filtration.

  • y (None) – There is no need for a target in a transformer, yet the pipeline API requires this parameter.

Returns

Xt – 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.

Return type

ndarray of shape (n_samples, n_features, 3)

transform_plot(X, sample=0, **plot_params)

Take a one-sample slice from the input collection and transform it. Before returning the transformed object, plot the transformed sample.

Parameters
  • X (ndarray of shape (n_samples, ..)) – Input data.

  • sample (int) – Sample to be plotted.

  • **plot_params – Optional plotting parameters.

Returns

Xt – Transformed one-sample slice from the input.

Return type

ndarray of shape (1, ..)