ysig / GraKeL

A scikit-learn compatible library for graph kernels
https://ysig.github.io/GraKeL/
Other
601 stars 97 forks source link

SubgraphMatching can not use normalize=True #72

Closed anonymous-author-here closed 1 year ago

anonymous-author-here commented 3 years ago

When I try to use SubgraphMatching(normalize=True), it gives me an error:

Code:

from grakel.kernels import SubgraphMatching

k = SubgraphMatching(normalize=True) print("fit") k.fit([({(1, 2), (2, 3), (2, 1), (3, 2)}, {1: 'N', 2: 'C', 3: 'O'}, {(1, 2): ('N', 'C'), (2, 1): ('C', 'N'), (2, 3): ('C', 'O'), (3, 2): ('O', 'C')})])

print("transform") print(k.transform([({(1, 2), (2, 3), (2, 1), (3, 2)}, {1: 'N', 2: 'C', 3: 'O'}, {(1, 2): ('N', 'C'), (2, 1): ('C', 'N'), (2, 3): ('C', 'O'), (3, 2): ('O', 'C')})]))

print(k.transform([({(1, 2), (2, 3), (3, 4), (3, 5), (5, 6), (2, 1), (3, 2), (4, 3), (5, 3), (6, 5)}, {1: 'O', 2: 'C', 3: 'N', 4: 'C', 5: 'C', 6: 'O'}, {(1, 2): ('O', 'C'), (2, 3): ('C', 'N'), (3, 4): ('N', 'C'), (3, 5): ('N', 'C'), (5, 6): ('C', 'O'), (2, 1): ('C', 'O'), (3, 2): ('N', 'C'), (4, 3): ('C', 'N'), (5, 3): ('C', 'N'), (6, 5): ('O', 'C')})]))

Error: Traceback (most recent call last): File "try.py", line 20, in (2, 3): ('C', 'O'), (3, 2): ('O', 'C')})])) File "/home/anaconda3/envs/peter/lib/python3.6/site-packages/grakel/kernels/kernel.py", line 165, in transform X_diag, Y_diag = self.diagonal() File "/home/anaconda3/envs/peter/lib/python3.6/site-packages/grakel/kernels/kernel.py", line 302, in diagonal return self._X_diag, Y_diag AttributeError: 'SubgraphMatching' object has no attribute '_X_diag'

Thank you!

giannisnik commented 3 years ago

Hi @anonymous-author-here ,

I tried to reproduce the error, but I could not. Have a look here: https://colab.research.google.com/drive/16dLHV-4vksiid80ryMxDlRCjHlAwOXV3?usp=sharing

Which version of GraKeL have you installed?