Skip to content

Commit

Permalink
Merge pull request #55 from bgauzere/master
Browse files Browse the repository at this point in the history
patch for computation of treelet kernel: intersection does not induce…
  • Loading branch information
jajupmochi authored Dec 6, 2023
2 parents e735e9a + 32e8ccf commit f543eb1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
16 changes: 4 additions & 12 deletions gklearn/kernels/treelet.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,20 +452,12 @@ def _kernel_do(self, canonkey1, canonkey2):
kernel : float
Treelet kernel between 2 graphs.
"""
keys = set(canonkey1.keys()) & set(
canonkey2.keys()
) # find same canonical keys in both graphs
keys = set(canonkey1.keys()) | set(canonkey2.keys()) # find same canonical keys in both graphs
if len(keys) == 0: # There is nothing in common...
return 0
return 0

vector1 = np.array(
[(canonkey1[key] if (key in canonkey1.keys()) else 0) for key in
keys]
)
vector2 = np.array(
[(canonkey2[key] if (key in canonkey2.keys()) else 0) for key in
keys]
)
vector1 = np.array([canonkey1.get(key,0) for key in keys])
vector2 = np.array([canonkey2.get(key,0)for key in keys])

# vector1, vector2 = [], []
# keys1, keys2 = canonkey1, canonkey2
Expand Down
6 changes: 3 additions & 3 deletions gklearn/kernels/treeletKernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,9 @@ def _treeletkernel_do(canonkey1, canonkey2, sub_kernel):
kernel : float
Treelet Kernel between 2 graphs.
"""
keys = set(canonkey1.keys()) & set(canonkey2.keys()) # find same canonical keys in both graphs
vector1 = np.array([(canonkey1[key] if (key in canonkey1.keys()) else 0) for key in keys])
vector2 = np.array([(canonkey2[key] if (key in canonkey2.keys()) else 0) for key in keys])
keys = set(canonkey1.keys()) | set(canonkey2.keys()) # find union of canonical keys in both graphs
vector1 = np.array([canonkey1.get(key,0) for key in keys])
vector2 = np.array([canonkey2.get(key,0) for key in keys])
kernel = sub_kernel(vector1, vector2)
return kernel

Expand Down

0 comments on commit f543eb1

Please sign in to comment.