TransitionGraph¶

class gtda.graphs.TransitionGraph(func=<function argsort>, func_params=None, n_jobs=None)[source]

Undirected transition graphs from arrays of time-evolving states.

Let A be a two-dimensional array viewed as a time series (along the row axis) of one-dimensional arrays encoding the “state” of a system. The corresponding undirected transition graph (or network) has as vertex set the set of all unique states (rows) in A, and there is an edge between vertex i and vertex j≠i if and only if the state corresponding to vertex j immediately follows the one corresponding to vertex i, somewhere in A.

Given a collection of two-dimensional arrays, this transformer performs two tasks:

1. Optionally, it preprocesses the arrays by applying a function row by row to them. This can be used e.g. as a “compression” step to reduce the size of the state space.

2. It computes the transition graph of each array as a sparse matrix of zeros and ones.

Parameters
• func (None or callable, optional, default: numpy.argsort) – If a callable, it is the function to be applied to each row of each array as a preprocessing step. Allowed callables are functions mapping 1D arrays to 1D arrays of constant length, and must be compatible with numpy.apply_along_axis. If None, this function is the identity (no preprocessing). The default is numpy.argsort, which makes the final transition graphs ordinal partition networks 1 2 3.

• func_params (None or dict, optional, default: None) – Additional keyword arguments for func.

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

effective_func_params_

A copy of func_params if this was not set to None, otherwise an empty dictionary.

Type

dict

Examples

>>> import numpy as np
>>> from gtda.graphs import TransitionGraph
>>> X = np.array([[[1, 0], [2, 3], [5, 4]],
...               [[5, 4], [5, 4], [5, 4]]])
>>> X_tg = TransitionGraph().fit_transform(X)
>>> print(X_tg[0].toarray())
[[0 1]
[1 0]]
>>> print(X_tg[1].toarray())
[[0]]


Notes

In general, the shapes of the sparse matrices output by transform will be different across samples, and the same row or column index will refer to different states in different samples.

References

1

M. Small, “Complex networks from time series: Capturing dynamics”, 2013 IEEE International Symposium on Circuits and Systems (IS-CAS2013), 2013; DOI: 10.1109/iscas.2013.6572389.

2

M. McCullough, M. Small, T. Stemler, and H. Ho-Ching Iu, “Time lagged ordinal partition networks for capturing dynamics of continuous dynamical systems”; Chaos: An Interdisciplinary Journal of Nonlinear Science 25 (5), p. 053101, 2015; DOI: 10.1063/1.4919075.

3

A. Myers, E. Munch, and F. A. Khasawneh, “Persistent homology of complex networks for dynamic state detection”; Phys. Rev. E 100, 022314, 2019; DOI: 10.1103/PhysRevE.100.022314.

__init__(func=<function argsort>, func_params=None, n_jobs=None)[source]

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

fit(X, y=None)[source]

Do nothing and return the estimator unchanged.

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

Parameters
• X (list of length n_samples, or ndarray of shape (n_samples, n_timestamps, n_features)) – Input data: a collection of 2D arrays of shape (n_timestamps, n_features).

• 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 (list of length n_samples, or ndarray of shape (n_samples, n_timestamps, n_features)) – Input data: a collection of 2D arrays of shape (n_timestamps, n_features).

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

Returns

Xt – Collection of n_samples transition graphs. Each transition graph is encoded by a sparse CSR matrix of ones and zeros.

Return type

list of length n_samples

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

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]

Create transition graphs from the input data and return their adjacency matrices. The graphs are simple and unweighted.

Parameters
• X (list of length n_samples, or ndarray of shape (n_samples, n_timestamps, n_features)) – Input data: a collection of 2D arrays of shape (n_timestamps, n_features).

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

Returns

Xt – Collection of n_samples transition graphs. Each transition graph is encoded by a sparse CSR matrix of ones and zeros.

Return type

list of length n_samples