Skip to content

Latest commit

 

History

History
693 lines (352 loc) · 16.5 KB

plot_seed_graph_match_jittor.rst

File metadata and controls

693 lines (352 loc) · 16.5 KB

html

Note

Go to the end <sphx_glr_download_auto_examples_2.seeded_graph_matching_plot_seed_graph_match_jittor.py> to download the full example code

sphx-glr-example-title

Jittor Backend Example: Seeded Graph Matching

Seeded graph matching means some partial of the matching result is already known, and the known matching results are called "seeds". In this example, we show how to exploit such prior with pygmtools.

Note

How to perform seeded graph matching is still an open research problem. In this example, we show a simple yet effective approach that works with pygmtools.

Note

The following solvers 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 (with seeds)

In this example, we assume the first three nodes are already aligned. Firstly, we generate the seed matching matrix:

Then we generate the isomorphic graphs:

Visualize the graphs and seeds

The seed matching matrix:

/auto_examples/2.seeded_graph_matching/images/sphx_glr_plot_seed_graph_match_jittor_001.png

sphx-glr-script-out

<matplotlib.image.AxesImage object at 0x7fda50d6abf0>

The blue lines denote the matching seeds.

/auto_examples/2.seeded_graph_matching/images/sphx_glr_plot_seed_graph_match_jittor_002.png

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

Build affinity matrix with seed prior

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). We firstly build a "standard" affinity matrix:

The next step is to add the seed matching information as priors to the affinity matrix. The matching priors are treated as node affinities and the corresponding node affinity is added by 10 if there is an matching prior.

Note

The node affinity matrix is transposed because in the graph matching formulation followed by pygmtools, vec(X) means column vectorization. The node affinity should also be column-vectorized.

Visualization of the affinity matrix.

Note

In this example, the diagonal elements reflect the matching prior.

/auto_examples/2.seeded_graph_matching/images/sphx_glr_plot_seed_graph_match_jittor_003.png

sphx-glr-script-out

<matplotlib.image.AxesImage object at 0x7fd947d39db0>

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. The matching prior is well-preserved:

/auto_examples/2.seeded_graph_matching/images/sphx_glr_plot_seed_graph_match_jittor_004.png

sphx-glr-script-out

<matplotlib.image.AxesImage object at 0x7fd94c637c70>

Get the discrete matching matrix

Hungarian algorithm is then adopted to reach a discrete matching matrix

Visualization of the discrete matching matrix:

/auto_examples/2.seeded_graph_matching/images/sphx_glr_plot_seed_graph_match_jittor_005.png

sphx-glr-script-out

<matplotlib.image.AxesImage object at 0x7fd94c72ce80>

Align the original graphs

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

/auto_examples/2.seeded_graph_matching/images/sphx_glr_plot_seed_graph_match_jittor_006.png

Align the nodes:

/auto_examples/2.seeded_graph_matching/images/sphx_glr_plot_seed_graph_match_jittor_007.png

Other solvers are also available

Only the affinity matrix is modified to encode matching priors. Thus, other graph matching solvers are also available to handle this seeded graph matching setting.

Classic IPFP solver

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

Visualization of IPFP matching result:

/auto_examples/2.seeded_graph_matching/images/sphx_glr_plot_seed_graph_match_jittor_008.png

sphx-glr-script-out

<matplotlib.image.AxesImage object at 0x7fda2c0f6080>

Classic SM solver

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

Visualization of SM matching result:

/auto_examples/2.seeded_graph_matching/images/sphx_glr_plot_seed_graph_match_jittor_009.png

sphx-glr-script-out

<matplotlib.image.AxesImage object at 0x7fda3c98c250>

NGM neural network solver

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

Visualization of NGM matching result:

/auto_examples/2.seeded_graph_matching/images/sphx_glr_plot_seed_graph_match_jittor_010.png

sphx-glr-script-out

<matplotlib.image.AxesImage object at 0x7fda3c840790>

sphx-glr-timing

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

html

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

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

html