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, chunksize=None, verbose=True)[source]
Compute common walk graph kernels between graphs.
Parameters
- GnList of NetworkX graph
List of graphs between which the kernels are computed.
- G1, G2NetworkX graphs
Two graphs between which the kernel is computed.
- node_labelstring
Node attribute used as symbolic label. The default node label is ‘atom’.
- edge_labelstring
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_methodstring
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_jobsint
Number of jobs for parallelization.
Return
- KmatrixNumpy 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.
Parameters
- GNetworkX graphs
The graph in which walks are searched.
- lengthinteger
The length of walks.
Return
- walklist 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.
Parameters
- GNetworkX graphs
The graph in which walks are searched.
- lengthinteger
The maximum length of walks.
- node_labelstring
node attribute used as label. The default node label is atom.
- edge_labelstring
edge attribute used as label. The default edge label is bond_type.
- labeledboolean
Whether the graphs are labeled. The default is True.
Return
- walklist
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.
Parameters
- GNetworkX graphs
The graph in which walks are searched.
- source_nodeinteger
The number of the node from where all walks start.
- lengthinteger
The length of walks.
Return
- walklist of list
List of walks retrieved, where each walk is represented by a list of nodes.