gklearn.kernels.commonWalkKernel¶
@author: linlin
@references:
[1] Thomas Gärtner, Peter Flach, and Stefan Wrobel. On graph kernels: Hardness results and efficient alternatives. Learning Theory and Kernel Machines, pages 129–143, 2003.
-
commonwalkkernel
(*args, node_label='atom', edge_label='bond_type', weight=1, compute_method=None, n_jobs=None, verbose=True)[source]¶ Calculate common walk graph 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 symbolic label. The default node label is ‘atom’.
- edge_label : string
- Edge attribute used as symbolic label. The default edge label is ‘bond_type’.
- weight: integer
- Weight coefficient of different lengths of walks, which represents beta in ‘exp’ method and gamma in ‘geo’.
- compute_method : string
Method used to compute walk kernel. The Following choices are available:
‘exp’: method based on exponential serials applied on the direct product graph, as shown in reference [1]. The time complexity is O(n^6) for graphs with n vertices.
‘geo’: method based on geometric serials applied on the direct product graph, as shown in reference [1]. The time complexity is O(n^6) for graphs with n vertices.
- n_jobs : int
- Number of jobs for parallelization.
- Kmatrix : Numpy matrix
- Kernel matrix, each element of which is a common walk kernel between 2 graphs.
-
find_all_walks
(G, length)[source]¶ Find all walks with a certain length in a graph. A recursive depth first search is applied.
- G : NetworkX graphs
- The graph in which walks are searched.
- length : integer
- The length of walks.
- walk : list of list
- List of walks retrieved, where each walk is represented by a list of nodes.
-
find_all_walks_until_length
(G, length, node_label='atom', edge_label='bond_type', labeled=True)[source]¶ Find all walks with a certain maximum length in a graph. A recursive depth first search is applied.
- G : NetworkX graphs
- The graph in which walks are searched.
- length : integer
- The maximum length of walks.
- node_label : string
- node attribute used as label. The default node label is atom.
- edge_label : string
- edge attribute used as label. The default edge label is bond_type.
- labeled : boolean
- Whether the graphs are labeled. The default is True.
- walk : list
- List of walks retrieved, where for unlabeled graphs, each walk is represented by a list of nodes; while for labeled graphs, each walk is represented by a string consists of labels of nodes and edges on that walk.
-
find_walks
(G, source_node, length)[source]¶ Find all walks with a certain length those start from a source node. A recursive depth first search is applied.
- G : NetworkX graphs
- The graph in which walks are searched.
- source_node : integer
- The number of the node from where all walks start.
- length : integer
- The length of walks.
- walk : list of list
- List of walks retrieved, where each walk is represented by a list of nodes.