ysig / GraKeL

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

Singular matrix for RandomWalk kernel #4

Closed xia0pin9 closed 6 years ago

xia0pin9 commented 6 years ago

I was testing some directed unlabeled unweighted graphs. One of them triggered the "Singular matrix" error, which corresponds to the following code:

                def invert(n, w, v):
                    return (np.real(np.sum(v, axis=0))/n, np.real(w), np.real(np.sum(inv(v), axis=1))/n)

                def add_input(x):
                    return invert(x.shape[0], *eig(x))
ysig commented 6 years ago

As you can see here this line has been resolved 4 days before your post so it is normal that you have not seen it.

Please install the latest grakel from the repository.

Note: Random walk kernel was originally designed for undirected graphs (i.e. directed with both directions of each edge - a symmetric adjacency matrix). Instead of doing inv(v) this was replaced with v.T as in the original paper, in order for the kernel to be faster in most cases and not to crash. The problem is that this equality (i.e. inv(v) = v.T) only holds if the adjacency matrix A is symmetric. In any other case it is an approximation.