gklearn.kernels.structuralspKernel¶
Created on Thu Sep 27 10:56:23 2018
@author: linlin
@references:
[1] Suard F, Rakotomamonjy A, Bensrhair A. Kernel on Bag of Paths For Measuring Similarity of Shapes. InESANN 2007 Apr 25 (pp. 355-360).
-
get_shortest_paths
(G, weight, directed)[source]¶ Get all shortest paths of a graph.
- G : NetworkX graphs
- The graphs whose paths are calculated.
- weight : string/None
- edge attribute used as weight to calculate the shortest path.
- directed: boolean
- Whether graph is directed.
- sp : list of list
- List of shortest paths of the graph, where each path is represented by a list of nodes.
-
get_sps_as_trie
(G, weight, directed)[source]¶ Get all shortest paths of a graph and insert them into a trie.
- G : NetworkX graphs
- The graphs whose paths are calculated.
- weight : string/None
- edge attribute used as weight to calculate the shortest path.
- directed: boolean
- Whether graph is directed.
- sp : list of list
- List of shortest paths of the graph, where each path is represented by a list of nodes.
-
ssp_do_trie
(g1, g2, trie1, trie2, ds_attrs, node_label, edge_label, node_kernels, edge_kernels)[source]¶
-
structuralspkernel
(*args, node_label='atom', edge_weight=None, edge_label='bond_type', node_kernels=None, edge_kernels=None, compute_method='naive', parallel='imap_unordered', n_jobs=None, verbose=True)[source]¶ Calculate mean average structural shortest path kernels between graphs.
- Gn : List of NetworkX graph
- List of graphs between which the kernels are calculated.
- G1, G2 : NetworkX graphs
- Two graphs between which the kernel is calculated.
- node_label : string
- Node attribute used as label. The default node label is atom.
- edge_weight : string
- Edge attribute name corresponding to the edge weight. Applied for the computation of the shortest paths.
- edge_label : string
- Edge attribute used as label. The default edge label is bond_type.
- node_kernels : dict
- A dictionary of kernel functions for nodes, including 3 items: ‘symb’ for symbolic node labels, ‘nsymb’ for non-symbolic node labels, ‘mix’ for both labels. The first 2 functions take two node labels as parameters, and the ‘mix’ function takes 4 parameters, a symbolic and a non-symbolic label for each the two nodes. Each label is in form of 2-D dimension array (n_samples, n_features). Each function returns a number as the kernel value. Ignored when nodes are unlabeled.
- edge_kernels : dict
- A dictionary of kernel functions for edges, including 3 items: ‘symb’ for symbolic edge labels, ‘nsymb’ for non-symbolic edge labels, ‘mix’ for both labels. The first 2 functions take two edge labels as parameters, and the ‘mix’ function takes 4 parameters, a symbolic and a non-symbolic label for each the two edges. Each label is in form of 2-D dimension array (n_samples, n_features). Each function returns a number as the kernel value. Ignored when edges are unlabeled.
- compute_method : string
Computation method to store the shortest paths and compute the graph kernel. The Following choices are available:
‘trie’: store paths as tries.
‘naive’: store paths to lists.
- n_jobs : int
- Number of jobs for parallelization.
- Kmatrix : Numpy matrix
- Kernel matrix, each element of which is the mean average structural shortest path kernel between 2 praphs.