grakel.WeisfeilerLehman

class grakel.WeisfeilerLehman(n_jobs=None, verbose=False, normalize=False, n_iter=5, base_graph_kernel=<class 'grakel.kernels.vertex_histogram.VertexHistogram'>)[source][source]

Compute the Weisfeiler Lehman Kernel.

See [SSVL+11].

Parameters
n_iterint, default=5

The number of iterations.

base_graph_kernelgrakel.kernels.Kernel or tuple, default=None

If tuple it must consist of a valid kernel object and a dictionary of parameters. General parameters concerning normalization, concurrency, .. will be ignored, and the ones of given on __init__ will be passed in case it is needed. Default base_graph_kernel is VertexHistogram.

Attributes
Xdict

Holds a dictionary of fitted subkernel modules for all levels.

_nxnumber

Holds the number of inputs.

_n_iterint

Holds the number, of iterations.

_base_graph_kernelfunction

A void function that initializes a base kernel object.

_inv_labelsdict

An inverse dictionary, used for relabeling on each iteration.

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 input for weisfeiler lehman.

set_params(self, \*\*params)

Call the parent method.

transform(self, X)

Calculate the kernel matrix, between given and fitted dataset.

Initialise a weisfeiler_lehman 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 input for weisfeiler lehman.

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, n_iter=5, base_graph_kernel=<class 'grakel.kernels.vertex_histogram.VertexHistogram'>)[source][source]

Initialise a weisfeiler_lehman 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). If None the kernel matrix is calculated upon fit data. The test samples.

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 input for weisfeiler lehman.

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
base_graph_kernelobject
Returns base_graph_kernel.
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

SSVL+11

Nino Shervashidze, Pascal Schweitzer, Erik Jan van Van Leeuwen, Kurt Mehlhorn, and Karsten M. Borgwardt. Weisfeiler-Lehman Graph Kernels. Journal of Machine Learning Research, 12:2539–2561, 2011.