Thinklab-SJTU / pygmtools

A Python Graph Matching Toolkit.
https://pygmtools.readthedocs.io/
Other
310 stars 20 forks source link

In the RRWM(numpy) algorithm, can the batchsize of the input affinity matrix K be 1? #1

Closed wyupupup closed 2 years ago

wyupupup commented 2 years ago

When the batchsize of the affinity matrix K I input is 1, I get the following error:ValueError: Invalid norm order 'fro' for vectors. I observed the rrwm function in numpy_backend.py and found the following code(on line 162):if np.linalg.norm((v - last_v).squeeze(), ord='fro') < 1e-5:. When batchsize is 1, due to the existence of the squeeze() function, v - last_v will become a vector form, but when the value of the parameter ord of the np.linalg.norm() function is 'fro', the np.linalg.norm() function can only act on matrices, which leads to the above error. I think it is more appropriate when the value of the parameter ord is None, then the np.linalg.norm() function can work on matrices or vectors.

rogerwwww commented 2 years ago

Can you provide a minimal example to reproduce this issue? I will inspect it. Thank you!

wyupupup commented 2 years ago

Thanks for your reply, my example code is as follows: `import pygmtools as pygm import numpy as np

M = [[ [1, 0, 0, 1, 0, 0.1], [0, 0.1, 1, 0, 0.1, 0], [0, 1, 0.2, 0, 0, 0], [1, 0, 0, 1, 0, 0], [0, 0.1, 0, 0, 0.1, 0], [0.1, 0, 0, 0, 0, 0.1]]] pygm.BACKEND = 'numpy' M = np.array(M) n1 = np.array([2]) n2 = np.array([3])

X = pygm.rrwm(M, n1, n2)

print(pygm.hungarian(X))`

rogerwwww commented 2 years ago

I have done a bug fix and published 0.2.1, and your reported issue shall be fixed.

Please upgrade your pygmtools by pip install --upgrade pygmtools

wyupupup commented 2 years ago

Problem solved, thanks a lot!