Skip to content

Latest commit

 

History

History
589 lines (294 loc) · 14.1 KB

plot_isomorphic_graphs_jittor.rst

File metadata and controls

589 lines (294 loc) · 14.1 KB

html

Note

Go to the end <sphx_glr_download_auto_examples_1.matching_isomorphic_graphs_plot_isomorphic_graphs_jittor.py> to download the full example code

sphx-glr-example-title

Jittor Backend Example: Matching Isomorphic Graphs

This example is an introduction to pygmtools which shows how to match isomorphic graphs. Isomorphic graphs mean graphs whose structures are identical, but the node correspondence is unknown.

Note

The following solvers support QAP formulation, and are included in this example:

  • ~pygmtools.classic_solvers.rrwm (classic solver)
  • ~pygmtools.classic_solvers.ipfp (classic solver)
  • ~pygmtools.classic_solvers.sm (classic solver)
  • ~pygmtools.neural_solvers.ngm (neural network solver)

Generate two isomorphic graphs

Visualize the graphs

/auto_examples/1.matching_isomorphic_graphs/images/sphx_glr_plot_isomorphic_graphs_jittor_001.png

These two graphs look dissimilar because they are not aligned. We then align these two graphs by graph matching.

Build affinity matrix

To match isomorphic graphs by graph matching, we follow the formulation of Quadratic Assignment Problem (QAP):

$$\begin{aligned} &\max_{\mathbf{X}} \ \texttt{vec}(\mathbf{X})^\top \mathbf{K} \texttt{vec}(\mathbf{X})\\\ s.t. \quad &\mathbf{X} \in \{0, 1\}^{n_1\times n_2}, \ \mathbf{X}\mathbf{1} = \mathbf{1}, \ \mathbf{X}^\top\mathbf{1} \leq \mathbf{1} \end{aligned}$$

where the first step is to build the affinity matrix (K)

Visualization of the affinity matrix. For graph matching problem with N nodes, the affinity matrix has N2 × N2 elements because there are N2 edges in each graph.

Note

The diagonal elements of the affinity matrix are empty because there is no node features in this example.

/auto_examples/1.matching_isomorphic_graphs/images/sphx_glr_plot_isomorphic_graphs_jittor_002.png

sphx-glr-script-out

<matplotlib.image.AxesImage object at 0x7fd947c5ac50>

Solve graph matching problem by RRWM solver

See ~pygmtools.classic_solvers.rrwm for the API reference.

The output of RRWM is a soft matching matrix. Visualization:

/auto_examples/1.matching_isomorphic_graphs/images/sphx_glr_plot_isomorphic_graphs_jittor_003.png

sphx-glr-script-out

<matplotlib.image.AxesImage object at 0x7fd947d39c30>

Get the discrete matching matrix

Hungarian algorithm is then adopted to reach a discrete matching matrix

Visualization of the discrete matching matrix:

/auto_examples/1.matching_isomorphic_graphs/images/sphx_glr_plot_isomorphic_graphs_jittor_004.png

sphx-glr-script-out

<matplotlib.image.AxesImage object at 0x7fd947a8a530>

Align the original graphs

Draw the matching (green lines for correct matching, red lines for wrong matching):

/auto_examples/1.matching_isomorphic_graphs/images/sphx_glr_plot_isomorphic_graphs_jittor_005.png

Align the nodes:

/auto_examples/1.matching_isomorphic_graphs/images/sphx_glr_plot_isomorphic_graphs_jittor_006.png

Other solvers are also available

Classic IPFP solver

See ~pygmtools.classic_solvers.ipfp for the API reference.

Visualization of IPFP matching result:

/auto_examples/1.matching_isomorphic_graphs/images/sphx_glr_plot_isomorphic_graphs_jittor_007.png

sphx-glr-script-out

<matplotlib.image.AxesImage object at 0x7fda50d6b010>

Classic SM solver

See ~pygmtools.classic_solvers.sm for the API reference.

Visualization of SM matching result:

/auto_examples/1.matching_isomorphic_graphs/images/sphx_glr_plot_isomorphic_graphs_jittor_008.png

sphx-glr-script-out

<matplotlib.image.AxesImage object at 0x7fda50e496f0>

NGM neural network solver

See ~pygmtools.neural_solvers.ngm for the API reference.

Visualization of NGM matching result:

/auto_examples/1.matching_isomorphic_graphs/images/sphx_glr_plot_isomorphic_graphs_jittor_009.png

sphx-glr-script-out

<matplotlib.image.AxesImage object at 0x7fda2c29b610>

sphx-glr-timing

Total running time of the script: (0 minutes 6.864 seconds)

html

Download Python source code: plot_isomorphic_graphs_jittor.py <plot_isomorphic_graphs_jittor.py>

Download Jupyter notebook: plot_isomorphic_graphs_jittor.ipynb <plot_isomorphic_graphs_jittor.ipynb>

html