Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing attribute when try to use NeighborhoodSubgraphPairwiseDistance as base kernel in WeisfeilerLehman #120

Open
Astromis opened this issue Jan 5, 2025 · 0 comments

Comments

@Astromis
Copy link

Astromis commented Jan 5, 2025

Describe the bug
When try to use NeighborhoodSubgraphPairwiseDistance as a base kernel to the WeisfeilerLehman, get the error that AttributeError: 'int' object has no attribute 'flags'.

To Reproduce

gk = WeisfeilerLehman(n_iter=2, normalize=True, 
                      base_graph_kernel=(NeighborhoodSubgraphPairwiseDistance, {"verbose":True}), )
gk.fit(all_graphs) # all_graphs is a list of any `Graph` objects
gk.transform(all_graphs)

Expected behavior
A similarity matrix.

Stack Trace

---------------------------------------------------------------------------
NotFittedError                            Traceback (most recent call last)
File /usr/local/lib/python3.10/dist-packages/grakel/kernels/weisfeiler_lehman.py:483, in WeisfeilerLehman.diagonal(self)
    482 try:
--> 483     check_is_fitted(self, ['_X_diag'])
    484     if self._is_transformed:

File /usr/local/lib/python3.10/dist-packages/sklearn/utils/validation.py:1661, in check_is_fitted(estimator, attributes, msg, all_or_any)
   1660 if not _is_fitted(estimator, attributes, all_or_any):
-> 1661     raise NotFittedError(msg % {"name": type(estimator).__name__})

NotFittedError: This WeisfeilerLehman instance is not fitted yet. Call 'fit' with appropriate arguments before using this estimator.

During handling of the above exception, another exception occurred:

AttributeError                            Traceback (most recent call last)
Cell In[19], line 1
----> 1 gk.transform(all_graphs)

File /usr/local/lib/python3.10/dist-packages/sklearn/utils/_set_output.py:313, in _wrap_method_output.<locals>.wrapped(self, X, *args, **kwargs)
    311 @wraps(f)
    312 def wrapped(self, X, *args, **kwargs):
--> 313     data_to_wrap = f(self, X, *args, **kwargs)
    314     if isinstance(data_to_wrap, tuple):
    315         # only wrap the first output for cross decomposition
    316         return_tuple = (
    317             _wrap_data_with_container(method, data_to_wrap[0], X, self),
    318             *data_to_wrap[1:],
    319         )

File /usr/local/lib/python3.10/dist-packages/grakel/kernels/weisfeiler_lehman.py:452, in WeisfeilerLehman.transform(self, X)
    450 self._is_transformed = True
    451 if self.normalize:
--> 452     X_diag, Y_diag = self.diagonal()
    453     old_settings = np.seterr(divide='ignore')
    454     K = np.nan_to_num(np.divide(K, np.sqrt(np.outer(Y_diag, X_diag))))

File /usr/local/lib/python3.10/dist-packages/grakel/kernels/weisfeiler_lehman.py:493, in WeisfeilerLehman.diagonal(self)
    491 X_diag, Y_diag = self.X[0].diagonal()
    492 # X_diag is considered a mutable and should not affect the kernel matrix itself.
--> 493 X_diag.flags.writeable = True
    494 for i in range(1, self._n_iter):
    495     x, y = self.X[i].diagonal()

AttributeError: 'int' object has no attribute 'flags'

Possible solution

If I haven't mistaken, and it's allowed to use this kernel with WeisfeilerLehman, so maybe the error goes from the fact that diagonal method of NeighborhoodSubgraphPairwiseDistance returns int and not numpy.array. I've done this, all works fine, but I'm not sure whether it is actually feasible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant