grakel.Kernel

class grakel.Kernel(n_jobs=None, normalize=False, verbose=False)[source][source]

A general class for graph kernels.

At default a kernel is considered as pairwise. Doing so the coder that adds a new kernel, possibly only needs to overwrite the attributes: parse_input and pairwise_operation on the new kernel object.

Parameters
n_jobsint or None, optional

Defines the number of jobs of a joblib.Parallel objects needed for parallelization or None for direct execution.

normalizebool, optional

Normalize the output of the graph kernel.

verbosebool, optional

Define if messages will be printed on stdout.

Attributes
Xlist

Stores the input that occurs from parse input, on fit input data. Default format of the list objects is grakel.graph.graph.

_graph_formatstr

Stores in which type the graphs will need to be stored.

_verbosebool

Defines if two print arguments on stdout.

_normalizebool

Defines if normalization will be applied on the kernel matrix.

_valid_parametersset

Holds the default valid parameters names for initialization.

_method_callingint
An inside enumeration defines which method calls another method.
  • 1 stands for fit

  • 2 stands for fit_transform

  • 3 stands for transform

_parallelsklearn.external.joblib.Parallel or None

A Parallel initialized object to imply parallelization to kernel execution. The use of this object depends on the implementation of each base kernel.

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

pairwise_operation(self, x, y)

Calculate a pairwise kernel between two elements.

parse_input(self, X)

Parse the given input and raise errors if it is invalid.

set_params(self, \*\*params)

Call the parent method.

transform(self, X)

Calculate the kernel matrix, between given and fitted dataset.

__init__ for kernel object.

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

pairwise_operation(self, x, y)

Calculate a pairwise kernel between two elements.

parse_input(self, X)

Parse the given input and raise errors if it is invalid.

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

__init__ for kernel object.

diagonal(self)[source][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][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][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 initialisation.

pairwise_operation(self, x, y)[source][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 the given input and raise errors if it is invalid.

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
Xplist

List of graph type objects.

set_params(self, **params)[source][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