ysig / GraKeL

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

Datatype issue in VertexHistogram kernel for sparse feature matrix #113

Closed klausweinbauer closed 1 month ago

klausweinbauer commented 2 months ago

Describe the bug When the features in the VertexHistogram kernel are initialized by a sparse matrix the matrix elements are of type int64. This causes a type casting error when normalizing the kernel matrix in the transform call in line 167:

https://github.com/ysig/GraKeL/blob/523d642faae19c870cddea2028c8d65ecfc3042c/grakel/kernels/kernel.py#L165-L168

To Reproduce

from grakel.kernels import VertexHistogram
from grakel.graph import Graph

data = [
    Graph([(0, 1)], node_labels={0: "0", 1: "1"}),
    Graph([(0, 1)], node_labels={0: "2", 1: "3"}),
]
kernel = VertexHistogram(normalize=True)
kernel.fit_transform(data)
kernel.transform(data)

Error numpy.core._exceptions._UFuncOutputCastingError: Cannot cast ufunc 'divide' output from dtype('float64') to dtype('int64') with casting rule 'same_kind'