grakel.GraphKernel

class grakel.GraphKernel(kernel='shortest_path', normalize=False, verbose=False, n_jobs=None, random_state=None, Nystroem=False)[source][source]

A generic wrapper for graph kernels.

Parameters
kernellist*(dict or str)

A single element or a list of dict with:

  • “name” : [str] - with the kernel name

  • “name_of_parameter_1” : value

  • “name_of_parameter_2” : value

  • \(\;\cdots\;\)

  • “name_of_parameter_k” : value

or of str, designating a kernel name.

available “name” or “name-alias” / “parametres” are:
  1. base_graph_kernels (the structure must always reach a base kernel)

    • “vertex_histogram” or “subtree_wl” or “VH” or “ST-WL”
      • (o) “sparse” : bool or ‘auto’

    • “edge_histogram” or “EH”
      • (o) “sparse” : bool or ‘auto’

    • “random_walk” or “RW”
      • (o) “with_labels” : bool

      • (o) “lamda” : float

      • (o) “method_type” : [str], “baseline”, “fast”

      • (o) “kernel_type” : [str], “geometric”, “exponential”

      • (o) “p” : [int] > 0

    • “shortest_path” or “SP”
      • (o) “algorithm_type” : [str] “dijkstra”, “floyd_warshall”

      • (o) “as_attributes” : [bool]

      • (o) “metric” : [function] : (attribute_x, attribute_y) -> number

      • (o) “with_labels” : [bool]

    • “graphlet_sampling” or “GR”
      • (o) “k” : [int]

      • (o) “sampling” : [dict] or None

    • “multiscale_laplacian” or “ML”
      • (o) “which” : [str] “slow”, “fast”

      • (o) “L” : [int] > 0

      • (o) “gamma” : [float] > .0

      • (o) “heta” : [float] > .0

      • (o) “n_samples” : [int] > 0, if “which”: “fast”

      • (o) “P” : [int] > 0, if “which”: “fast”

    • “subgraph_matching” or “SM”
      • (o) “kv” : [function] : (node_x, node_y, Lx, Ly) -> number

      • (o) “ke” : [function] : (edge_x, edge_y, Lx, Ly) -> number

      • (o) “lw” : a lambda weight function for cliques: set -> number

    • “lovasz_theta” or “LOVT”
      • (o) “n_samples” : [int] > 1

      • (o) “subsets_size_range” : [tuple] of two [int]

      • (o) “metric” : [function] (number, number) -> number

    • “svm_theta” or “SVMT”
      • (o) “n_samples” : [int] > 1

      • (o) “subsets_size_range” : [tuple] with 2 [int] elements

      • (o) “metric” : [function] (number, number) -> number

    • “neighborhood_hash” or “NH”
      • (o) “nh_type” : [str] “simple” or “count-sensitive”

      • (o) “R” : [int] > 0

      • (o) “bits” : [int] > 0

    • “neighborhood_subgraph_pairwise_distance” or “NSPD”
      • (o) “r” : (int) positive integer

      • (o) “d” : (int) positive integer

    • “odd_sth” or “ODD”
      • (o) “h” : [int] > 0

    • “propagation” or “PR”
      • (o) t_max: [int] > 0

      • (o) T: [dict] [int]: [np.arrays]

      • (o) with_attributes: [bool], default=False

      • (o) M: [str] {“H”, “TV”} if with_attributes=True else {“L1”, “L2”}

      • (o) w: [int] > 0

      • (o) metric: [function] x:[Counter] , y:[Counter] -> [number]

    • “pyramid_match” or “PM”
      • (o) with_labels: [bool]

      • (o) d: [int] > 0

      • (o) L: [int] >= 0

    • “graph_hopper” or “GH”
      • (o) kernel_type: [str: {‘linear’, ‘gaussian’}] or [tuple: {(‘gaussian’, mu)}] or [function] x:[(np.array, np.array)] , y:[(np.array, np.array)] -> [number]

  2. frameworks (if a next kernel in the list it asssigned as a base-kernel, else see default)
    • “weisfeiler_lehman” or “WL” / default=”VH”
      • (o) “n_iter” : [int] >= 0

    • “hadamard_code” or “HC” / default=”VH”
      • (o) “n_iter” : [int] > 0

    • “core_framework” or “CORE” / default=”SP”
      • (o) “min_core” : [int] >= -1

where (o): stands for optional parameters

Nystroemint or bool, optional

Defines the number of nystroem components. To initialize the default (100 components), set -1 or 0.

n_jobsint or None, optional

Defines the number of jobs of a joblib.Parallel objects needed for parallelization or None for direct execution. The use or not of this function depends on each kernel.

normalizebool, optional

Normalize the output of the graph kernel. Ignored when Nystroem GraphKernel object is instanciated.

verbosebool, optional

Define if messages will be printed on stdout.

random_stateRandomState or int, default=None

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

Attributes
_initializeddict

Monitors which parameter derived object should be _initialized.

kernel_function

The full kernel applied between graph objects.

nystroem_int

Holds the nystroem, number of components. If not _initialized, it stands as a False boolean variable.

components_array, shape=(n_components, n_features)

Subset of training graphs used to construct the feature map.

nystroem_normalization_array, shape=(n_components, n_components)

Normalization matrix needed for embedding. Square root of the kernel matrix on components_.

component_indices_array, shape=(n_components)

Indices of components_ in the training set.

random_state_RandomState

A RandomState object handling all randomness of the class.

Methods

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

make_kernel_(self, kernel_list, hidden_args)

Produce the desired kernel function.

set_params(self, \*\*params)

Call the parent method.

transform(self, X)

Calculate the kernel matrix, between given and fitted dataset.

__init__ for GraphKernel object.

Methods

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

make_kernel_(self, kernel_list, hidden_args)

Produce the desired kernel function.

set_params(self, \*\*params)

Call the parent method.

transform(self, X)

Calculate the kernel matrix, between given and fitted dataset.

__init__(self, kernel='shortest_path', normalize=False, verbose=False, n_jobs=None, random_state=None, Nystroem=False)[source][source]

__init__ for GraphKernel object.

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

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.

make_kernel_(self, kernel_list, hidden_args)[source][source]

Produce the desired kernel function.

Parameters
kernel_list(list)

List of kernel dictionaries as defined at the documentation of class parameters.

Returns
kernelkernel (class).

Returns an instance of a kernel type object corresponding to the certain kernel.

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