grakel.LovaszTheta

class grakel.LovaszTheta(n_jobs=None, normalize=False, verbose=False, random_state=None, n_samples=50, subsets_size_range=(2, 8), max_dim=None, base_kernel=None)[source][source]

Lovasz theta kernel as proposed in [JJDB14].

Parameters
X,Yvalid-graph-format

The pair of graphs on which the kernel is applied.

n_samplesint, default=50

The number of samples.

subsets_size_rangetuple, len=2, default=(2,8)

(min, max) size of the vertex set of sampled subgraphs.

random_stateRandomState or int, default=None

A random number generator instance or an int to initialize a RandomState as a seed.

base_kernelfunction (np.1darray, np.1darray -> number), default=None

The applied metric between the lovasz_theta numbers of subgraphs. If None \(f(x,y) = x*y\)

max_dimint, default=None

The maximum graph size that can appear both in fit or transform. When None, max_dim is calculated based on the size of the biggest graph on fit. This can lead to a crash in case a graph appears in transform with size bigger than in fit.

Attributes
d_int,

The maximum matrix dimension of fit plus 1. Signifies the number of features assigned for lovasz labelling.

random_state_RandomState

A RandomState object handling all randomness of the class.

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)

Lovasz theta kernel as proposed in [JJDB14].

parse_input(self, X)

Parse and create features for lovasz_theta kernel.

set_params(self, \*\*params)

Call the parent method.

transform(self, X)

Calculate the kernel matrix, between given and fitted dataset.

Initialise a lovasz_theta 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)

Lovasz theta kernel as proposed in [JJDB14].

parse_input(self, X)

Parse and create features for lovasz_theta 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, random_state=None, n_samples=50, subsets_size_range=(2, 8), max_dim=None, base_kernel=None)[source][source]

Initialise a lovasz_theta 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]

Lovasz theta kernel as proposed in [JJDB14].

Parameters
x, ydict

Subgraph samples metric dictionaries for all levels.

Returns
kernelnumber

The kernel value.

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

Parse and create features for lovasz_theta 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 lovasz metrics for the 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

JJDB14(1,2,3,4)

Fredrik Johansson, Vinay Jethava, Devdatt Dubhashi, and Chiranjib Bhattacharyya. Global graph kernels using geometric embeddings. In Proceedings of the 31st International Conference on Machine Learning, 694–702. 2014.