Skip to content

Commit

Permalink
Merge pull request #58 from jajupmochi/master
Browse files Browse the repository at this point in the history
Fix treelet
  • Loading branch information
jajupmochi authored Dec 7, 2023
2 parents 13fbce2 + f543eb1 commit f9af4df
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 16 deletions.
30 changes: 30 additions & 0 deletions .github/ISSUE_TEMPLATE/issue-template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
name: Issue template
about: Issue template
title: ''
labels: ''
assignees: ''

---

<!-- Please describe the issue in detail here, and fill in the fields below -->

### Reproducing code example:

<!-- A short code example that reproduces the problem/missing feature. It should be
self-contained, i.e., possible to run as-is via 'python myproblem.py' -->

```python
import gklearn
<< your code here >>
```

<!-- Remove these sections for a feature request -->

### Error message:

<!-- Full error message, if any (starting from line Traceback: ...) -->

### graphkit-learn/Python version information:

<!-- Output from 'import sys, gklearn; print(gklearn.__version__, sys.version)' -->
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
[![Build status](https://ci.appveyor.com/api/projects/status/bdxsolk0t1uji9rd?svg=true)](https://ci.appveyor.com/project/jajupmochi/graphkit-learn)
[![codecov](https://codecov.io/gh/jajupmochi/graphkit-learn/branch/master/graph/badge.svg)](https://codecov.io/gh/jajupmochi/graphkit-learn)
[![Documentation Status](https://readthedocs.org/projects/graphkit-learn/badge/?version=master)](https://graphkit-learn.readthedocs.io/en/master/?badge=master)
[![PyPI version](https://badge.fury.io/py/graphkit-learn.svg)](https://badge.fury.io/py/graphkit-learn)
[![PyPI version](https://badge.fury.io/py/graphkit-learn.svg)](https://badge.fury.io/py/graphkit-learn)
[![Join the chat at https://gitter.im/graphkit-learn/graphkit-learn](https://badges.gitter.im/graphkit-learn/graphkit-learn.svg)](https://gitter.im/graphkit-learn/graphkit-learn?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

A Python package for graph kernels, graph edit distances and graph pre-image problem.

Expand Down
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 f9af4df

Please sign in to comment.