grakel
.ShortestPathAttr¶
-
class
grakel.
ShortestPathAttr
(n_jobs=None, normalize=False, verbose=False, algorithm_type='auto', metric=<function dot>)[source][source]¶ The shortest path kernel for attributes.
The Graph labels are considered as attributes. The computational efficiency is decreased to \(O(|V|^4)\) See [BK05].
- Parameters
- algorithm_typestr, default={“dijkstra”, “floyd_warshall”, “auto”}
Apply the dijkstra or floyd_warshall algorithm for calculating shortest path, or chose automatically (“auto”) based on the current graph format (“auto”).
- metricfunction, default=:math:f(x,y)=sum_{i}x_{i}*y_{i},
The metric applied between attributes of the graph labels. The user must provide a metric based on the format of the provided labels (considered as attributes).
- Attributes
- Xlist
A list of tuples, consisting of shortest path matrices and their feature vectors.
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)Calculate shortests paths on attributes.
parse_input
(self, X)Parse and create features for the shortest_path kernel.
set_params
(self, \*\*params)Call the parent method.
transform
(self, X)Calculate the kernel matrix, between given and fitted dataset.
Initialise a shortest_path_attr 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)Calculate shortests paths on attributes.
parse_input
(self, X)Parse and create features for the shortest_path 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, algorithm_type='auto', metric=<function dot at 0x7f18a56f6840>)[source][source]¶ Initialise a shortest_path_attr 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]¶ Calculate shortests paths on attributes.
- Parameters
- x, ytuple
Tuples of shortest path matrices and their attribute dictionaries.
- Returns
- kernelnumber
The kernel value.
-
parse_input
(self, X)[source][source]¶ Parse and create features for the shortest_path 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
- sp_attr_tuplist
A list of tuples of shortest path matrices and tehir attributes.
-
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