grakel.ShortestPath

class grakel.ShortestPath(n_jobs=None, normalize=False, verbose=False, with_labels=True, algorithm_type='auto')[source][source]

The shortest path kernel class.

See [BK05].

Parameters
algorithm_typestr, default={“dijkstra”, “floyd_warshall”, “auto”}

Apply the dijkstra or floyd_warshall algorithm for calculating shortest path, or chose automatically (“auto”) based on the current graph format (“auto”).

with_labelsbool, default=True, case_of_existence=(as_attributes==True)

Calculate shortest path using graph labels.

Attributes
Xdict

A dictionary of pairs between each input graph and a bins where the sampled graphlets have fallen.

_with_labelsbool

Defines if the shortest path kernel considers also labels.

_enumdict

A dictionary of graph bins holding pynauty objects

_ltstr

A label type needed for build shortest path function.

_lhashstr

A function for hashing labels, shortest paths.

_nxint

Holds the number of sampled X graphs.

_nyint

Holds the number of sampled Y graphs.

_X_diagnp.array, shape=(_nx, 1)

Holds the diagonal of X kernel matrix in a numpy array, if calculated (fit_transform).

_phi_Xnp.array, shape=(_nx, len(_graph_bins))

Holds the features of X in a numpy array, if calculated. (fit_transform).

Methods

diagonal(self)

Calculate the kernel matrix diagonal for fitted data.

fit(self, X[, y])

Fit a dataset, for a transformer.

fit_transform(self, X[, y])

Fit and transform, on the same dataset.

get_params(self[, deep])

Get parameters for this estimator.

initialize(self)

Initialize all transformer arguments, needing initialization.

pairwise_operation(self, x, y)

Calculate a pairwise kernel between two elements.

parse_input(self, X)

Parse and create features for “shortest path” kernel.

set_params(self, \*\*params)

Call the parent method.

transform(self, X)

Calculate the kernel matrix, between given and fitted dataset.

Initialize a shortest_path kernel.

Attributes
X

Methods

diagonal(self)

Calculate the kernel matrix diagonal for fitted data.

fit(self, X[, y])

Fit a dataset, for a transformer.

fit_transform(self, X[, y])

Fit and transform, on the same dataset.

get_params(self[, deep])

Get parameters for this estimator.

initialize(self)

Initialize all transformer arguments, needing initialization.

pairwise_operation(self, x, y)

Calculate a pairwise kernel between two elements.

parse_input(self, X)

Parse and create features for “shortest path” kernel.

set_params(self, \*\*params)

Call the parent method.

transform(self, X)

Calculate the kernel matrix, between given and fitted dataset.

__init__(self, n_jobs=None, normalize=False, verbose=False, with_labels=True, algorithm_type='auto')[source][source]

Initialize a shortest_path kernel.

diagonal(self)[source][source]

Calculate the kernel matrix diagonal for fitted data.

A funtion called on transform on a seperate dataset to apply normalization on the exterior.

Parameters
None.
Returns
X_diagnp.array

The diagonal of the kernel matrix, of the fitted data. This consists of kernel calculation for each element with itself.

Y_diagnp.array

The diagonal of the kernel matrix, of the transformed data. This consists of kernel calculation for each element with itself.

fit(self, X, y=None)[source]

Fit a dataset, for a transformer.

Parameters
Xiterable

Each element must be an iterable with at most three features and at least one. The first that is obligatory is a valid graph structure (adjacency matrix or edge_dictionary) while the second is node_labels and the third edge_labels (that fitting the given graph format). The train samples.

yNone

There is no need of a target in a transformer, yet the pipeline API requires this parameter.

Returns
selfobject
Returns self.
fit_transform(self, X, y=None)[source][source]

Fit and transform, on the same dataset.

Parameters
Xiterable

Each element must be an iterable with at most three features and at least one. The first that is obligatory is a valid graph structure (adjacency matrix or edge_dictionary) while the second is node_labels and the third edge_labels (that fitting the given graph format).

yObject, default=None

Ignored argument, added for the pipeline.

Returns
Knumpy array, shape = [n_targets, n_input_graphs]

corresponding to the kernel matrix, a calculation between all pairs of graphs between target an features

get_params(self, deep=True)[source]

Get parameters for this estimator.

Parameters
deepbool, default=True

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.

initialize(self)[source][source]

Initialize all transformer arguments, needing initialization.

pairwise_operation(self, x, y)[source]

Calculate a pairwise kernel between two elements.

Parameters
x, yObject

Objects as occur from parse_input.

Returns
kernelnumber

The kernel value.

parse_input(self, X)[source][source]

Parse and create features for “shortest path” kernel.

Parameters
Xiterable

For the input to pass the test, we must have: Each element must be an iterable with at most three features and at least one. The first that is obligatory is a valid graph structure (adjacency matrix or edge_dictionary) while the second is node_labels and the third edge_labels (that correspond to the given graph format). A valid input also consists of graph type objects.

Returns
sp_countsdict

A dictionary that for each vertex holds the counts of shortest path tuples.

set_params(self, **params)[source]

Call the parent method.

transform(self, X)[source][source]

Calculate the kernel matrix, between given and fitted dataset.

Parameters
Xiterable

Each element must be an iterable with at most three features and at least one. The first that is obligatory is a valid graph structure (adjacency matrix or edge_dictionary) while the second is node_labels and the third edge_labels (that fitting the given graph format). If None the kernel matrix is calculated upon fit data. The test samples.

Returns
Knumpy array, shape = [n_targets, n_input_graphs]

corresponding to the kernel matrix, a calculation between all pairs of graphs between target an features

Bibliography

BK05

Karsten M. Borgwardt and Hans-Peter Kriegel. Shortest-path kernels on graphs. In Proceedings of the 5th International Conference on Data Mining, 74–81. 2005.