giotto.graphs
.GraphGeodesicDistance¶
-
class
giotto.graphs.
GraphGeodesicDistance
(n_jobs=None)¶ Distance matrices arising from geodesic distances on graphs.
For each (possibly weighted and/or directed) graph in a collection, this transformer calculates the length of the shortest (directed or undirected) path between any two of its vertices, setting it to
numpy.inf
when two vertices cannot be connected by a path.The graphs are encoded as sparse adjacency matrices, while the outputs are dense distance matrices of variable size.
- Parameters
- 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.
- n_jobsint or None, optional, default:
Examples
>>> import numpy as np >>> from giotto.graphs import TransitionGraph, GraphGeodesicDistance >>> X = np.arange(4).reshape(1, -1, 1) >>> tg = TransitionGraph(func=None).fit_transform(X) >>> print(tg[0].toarray()) [[False True False False] [ True False True False] [False True False True] [False False True False]] >>> ggd = GraphGeodesicDistance().fit_transform(tg) >>> print(ggd[0]) [[0. 1. 2. 3.] [1. 0. 1. 2.] [2. 1. 0. 1.] [3. 2. 1. 0.]]
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])Use
sklearn.utils.graph_shortest_path.graph_shortest_path
to compute the lengths of graph shortest paths between any two vertices.-
__init__
(self, 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 of sparse or dense arrays, shape (n_samples,)
Input data, i.e. a collection of adjacency matrices of graphs.
- 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)¶ Use
sklearn.utils.graph_shortest_path.graph_shortest_path
to compute the lengths of graph shortest paths between any two vertices.- Parameters
- Xndarray of sparse or dense arrays, shape (n_samples,)
Input data, i.e. a collection of adjacency matrices of graphs.
- yNone
Ignored.
- Returns
- Xtndarray, shape (n_samples,) or (n_samples, n_vertices, n_vertices)
Array of distance matrices. If the distance matrices have variable size across samples, Xt is a one-dimensional array of dense arrays.