grakel
.GraphHopper¶
-
class
grakel.
GraphHopper
(n_jobs=None, normalize=False, verbose=False, kernel_type='linear')[source][source]¶ Graph Hopper Histogram kernel as found in [FKP+13].
- Parameters
- kernel_typestr, tuple or function
- For kernel_type of type:
str can either be ‘linear’, ‘gaussian’, ‘bridge’.
tuple can be of the form (‘gaussian’, mu) where mu is a number.
function can be a function that takes two tuples of np.arrays for each graph corresponding to the M matrix and the attribute matrix and returns a number.
- Attributes
- metric_function
The base metric applied between features.
- calculate_norm_bool
Defines if the norm of the attributes will be calculated (in order to avoid recalculation when using it with e.g. gaussian).
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)Graph Hopper kernel as proposed in [FKP+13].
parse_input
(self, X)Parse and check the given input for the Graph Hopper kernel.
set_params
(self, \*\*params)Call the parent method.
transform
(self, X)Calculate the kernel matrix, between given and fitted dataset.
Initialize an Graph Hopper 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)Graph Hopper kernel as proposed in [FKP+13].
parse_input
(self, X)Parse and check the given input for the Graph Hopper 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, kernel_type='linear')[source][source]¶ Initialize an Graph Hopper 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.
-
pairwise_operation
(self, x, y)[source][source]¶ Graph Hopper kernel as proposed in [FKP+13].
- Parameters
- x, ytuple
Extracted features from parse_input.
- Returns
- kernelnumber
The kernel value.
-
parse_input
(self, X)[source][source]¶ Parse and check the given input for the Graph Hopper 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 fitting the given graph format).
- Returns
- outnp.array, shape=(len(X), n_labels)
A np array for frequency (cols) histograms for all Graphs (rows).
-
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