grakel.SubgraphMatching

class grakel.SubgraphMatching(n_jobs=None, verbose=False, normalize=False, k=5, kv=<function _dirac>, ke=<function _dirac>, lw='uniform')[source][source]

Calculate the subgraph matching kernel.

See [KM12].

Parameters
kint, default=5

The upper bound for the maximum size of subgraphs.

lwstr, valid_values={“uniform”, “increasing”, “decreasing”, “strong_decreasing”},
default=”uniform” | iterable, size=k+1,
| callable, num_of_arguments=1, argument_type=int

The lambda weights applied to the clique sizes.

kvfunction (vertex_label, `vertex_label, -> number), or None
default=:math:`k_{v}^{default}(l(a), l(b))= delta(l(a), l(b))`

The kernel function between two vertex_labels. If no function is provided, this is equivalent with not taking into account node labels.

kefunction (edge_label, edge_label -> number),
default=:math:`k_{e}^{default}(l(e), l(e’))= delta(l(e), l(e’))`

The kernel function between two edge_labels. If no function is provided, this is equivalent with not taking into account edge labels.

Attributes
lambdas_np.array, shape=(1, k+1)

All the lambdas corresponding to all the valid sizes of subgraphs.

Methods

diagonal(self)

Calculate the kernel matrix diagonal of the fit/transformed data.

fit(self, X[, y])

Fit a dataset, for a transformer.

fit_transform(self, X)

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 the subgraph_matching kernel.

parse_input(self, X)

Parse and create features for the subgraph_matching kernel.

set_params(self, \*\*params)

Call the parent method.

transform(self, X)

Calculate the kernel matrix, between given and fitted dataset.

Initialise a subgraph_matching kernel.

Attributes
X

Methods

diagonal(self)

Calculate the kernel matrix diagonal of the fit/transformed data.

fit(self, X[, y])

Fit a dataset, for a transformer.

fit_transform(self, X)

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 the subgraph_matching kernel.

parse_input(self, X)

Parse and create features for the subgraph_matching 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, verbose=False, normalize=False, k=5, kv=<function _dirac at 0x7f183e49f7b8>, ke=<function _dirac at 0x7f183e49f7b8>, lw='uniform')[source][source]

Initialise a subgraph_matching kernel.

diagonal(self)[source]

Calculate the kernel matrix diagonal of the fit/transformed data.

Parameters
None.
Returns
X_diagnp.array

The diagonal of the kernel matrix between the fitted data. This consists of each element calculated with itself.

Y_diagnp.array

The diagonal of the kernel matrix, of the transform. This consists of each element calculated 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)[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). If None the kernel matrix is calculated upon fit data. The test samples.

yNone

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

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][source]

Calculate the subgraph_matching kernel.

See [KM12].

Parameters
x, ytuples

Vertex-set, edge-dictionary, node-label-dictionary, edge-labels-dictionary tuple.

Returns
kernelnumber

The kernel value.

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

Parse and create features for the subgraph_matching 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
outlist

The extracted adjacency matrices for any given input.

set_params(self, **params)[source]

Call the parent method.

transform(self, X)[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

KM12(1,2)

Nils Kriege and Petra Mutzel. Subgraph Matching Kernels for Attributed Graphs. In Proceedings of the 29th International Conference on Machine Learning, 291–298. 2012.