pygmtools.utils.build_aff_mat_from_graphml

pygmtools.utils.build_aff_mat_from_graphml(G1_path, G2_path, node_aff_fn=None, edge_aff_fn=None, backend=None)[source]

Convert networkx object to affinity matrix

Parameters
  • G1_path – The file path of the graphml object

  • G2_path – The file path of the graphml object

  • node_aff_fn – (default: inner_prod_aff_fn) the node affinity function with the characteristic node_aff_fn(2D Tensor, 2D Tensor) -> 2D Tensor, which accepts two node feature tensors and outputs the node-wise affinity tensor. See inner_prod_aff_fn() as an example.

  • edge_aff_fn – (default: inner_prod_aff_fn) the edge affinity function with the characteristic edge_aff_fn(2D Tensor, 2D Tensor) -> 2D Tensor, which accepts two edge feature tensors and outputs the edge-wise affinity tensor. See inner_prod_aff_fn() as an example.

  • backend – (default: pygmtools.BACKEND variable) the backend for computation.

Returns

the affinity matrix corresponding to the graphml object G1 and G2

Example
>>> import pygmtools as pygm
>>> pygm.set_backend('numpy')

# example file (.graphml) path
>>> G1_path = 'examples/data/graph1.graphml'
>>> G2_path = 'examples/data/graph2.graphml'

# Obtain Affinity Matrix
>>> K = pygm.utils.build_aff_mat_from_graphml(G1_path, G2_path)
>>> K.shape
(121, 121)

# The affinity matrices K can be further processed by GM solvers