gklearn.utils.utils

direct_product(G1, G2, node_label, edge_label)[source]

Return the direct/tensor product of directed graphs G1 and G2.

G1, G2 : NetworkX graph
The original graphs.
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’.
gt : NetworkX graph
The direct product graph of G1 and G2.

This method differs from networkx.tensor_product in that this method only adds nodes and edges in G1 and G2 that have the same labels to the direct product graph.

[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.

floydTransformation(G, edge_weight=None)[source]

Transform graph G to its corresponding shortest-paths graph using Floyd-transformation.

G : NetworkX graph
The graph to be tramsformed.
edge_weight : string
edge attribute corresponding to the edge weight. The default edge weight is bond_type.
S : NetworkX graph
The shortest-paths graph corresponding to G.

[1] Borgwardt KM, Kriegel HP. Shortest-path kernels on graphs. InData Mining, Fifth IEEE International Conference on 2005 Nov 27 (pp. 8-pp). IEEE.

getSPGraph(G, edge_weight=None)[source]

Transform graph G to its corresponding shortest-paths graph.

G : NetworkX graph
The graph to be tramsformed.
edge_weight : string
edge attribute corresponding to the edge weight.
S : NetworkX graph
The shortest-paths graph corresponding to G.

For an input graph G, its corresponding shortest-paths graph S contains the same set of nodes as G, while there exists an edge between all nodes in S which are connected by a walk in G. Every edge in S between two nodes is labeled by the shortest distance between these two nodes.

[1] Borgwardt KM, Kriegel HP. Shortest-path kernels on graphs. InData Mining, Fifth IEEE International Conference on 2005 Nov 27 (pp. 8-pp). IEEE.

getSPLengths(G1)[source]
get_edge_labels(Gn, edge_label)[source]

Get edge labels of dataset Gn.

get_node_labels(Gn, node_label)[source]

Get node labels of dataset Gn.

graph_deepcopy(G)[source]

Deep copy a graph, including deep copy of all nodes, edges and attributes of the graph, nodes and edges.

It is the same as the NetworkX function graph.copy(), as far as I know.

graph_isIdentical(G1, G2)[source]

Check if two graphs are identical, including: same nodes, edges, node labels/attributes, edge labels/attributes.

  1. The type of graphs has to be the same.
  2. Global/Graph attributes are neglected as they may contain names for graphs.
untotterTransformation(G, node_label, edge_label)[source]

Transform graph G according to Mahé et al.’s work to filter out tottering patterns of marginalized kernel and tree pattern kernel.

G : NetworkX graph
The graph to be tramsformed.
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’.
gt : NetworkX graph
The transformed graph corresponding to G.

[1] Pierre Mahé, Nobuhisa Ueda, Tatsuya Akutsu, Jean-Luc Perret, and Jean-Philippe Vert. Extensions of marginalized graph kernels. In Proceedings of the twenty-first international conference on Machine learning, page 70. ACM, 2004.