Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Fize Jacques
GMatch4py
Commits
8ec5562e
Commit
8ec5562e
authored
Sep 13, 2018
by
Fize Jacques
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Debug Weisfeiler_lehman + ADD BagOfNode approach
parent
c874deaa
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
10 deletions
+44
-10
gmatch4py/bow.pyx
gmatch4py/bow.pyx
+38
-0
gmatch4py/kernels/weisfeiler_lehman.pyx
gmatch4py/kernels/weisfeiler_lehman.pyx
+6
-10
No files found.
gmatch4py/bow.pyx
0 → 100644
View file @
8ec5562e
# coding = utf-8
import
networkx
as
nx
import
numpy
as
np
cimport
numpy
as
np
from
sklearn.metrics.pairwise
import
cosine_similarity
from
.base
cimport
Base
cdef
class
BOW
(
Base
):
def
__init__
(
self
):
Base
.
__init__
(
self
,
0
,
True
)
cpdef
np
.
ndarray
compare
(
self
,
list
graph_list
,
list
selected
):
nodes
=
list
()
for
g
in
graph_list
:
nodes
.
extend
(
list
(
g
.
nodes
()))
vocabulary
=
list
(
set
(
nodes
))
hash_voc
=
{}
i
=
0
for
se
in
vocabulary
:
hash_voc
[
se
]
=
i
i
+=
1
n
,
m
=
len
(
graph_list
),
len
(
hash_voc
)
bow_matrix
=
np
.
zeros
((
n
,
m
))
i
=
0
for
g
in
range
(
len
(
graph_list
)):
graph
=
graph_list
[
g
]
nodes
=
list
(
graph
.
nodes
())
for
nod
in
nodes
:
j
=
hash_voc
[
nod
]
bow_matrix
[
i
,
j
]
=
1
i
+=
1
sim_matrix
=
cosine_similarity
(
bow_matrix
)
np
.
fill_diagonal
(
sim_matrix
,
1
)
return
sim_matrix
gmatch4py/kernels/weisfeiler_lehman.pyx
View file @
8ec5562e
...
...
@@ -18,6 +18,8 @@ import networkx as nx
import
numpy
as
np
cimport
numpy
as
np
from
..base
cimport
Base
from
..base
import
minmax_scale
from
scipy.sparse
import
csc_matrix
,
lil_matrix
cdef
class
WeisfeleirLehmanKernel
(
Base
):
...
...
@@ -51,7 +53,6 @@ cdef class WeisfeleirLehmanKernel(Base):
"""
cdef
int
n
=
len
(
graph_list
)
cdef
np
.
ndarray
phi
cdef
int
n_nodes
=
0
cdef
int
n_max
=
0
cdef
int
i
,
j
...
...
@@ -67,6 +68,7 @@ cdef class WeisfeleirLehmanKernel(Base):
n_max
=
graph_list
[
i
].
number_of_nodes
()
phi
=
np
.
zeros
((
n_nodes
,
n
),
dtype
=
np
.
uint64
)
phi
=
lil_matrix
(
phi
)
# INITIALIZATION: initialize the nodes labels for each graph
# with their labels or with degrees (for unlabeled graphs)
...
...
@@ -101,9 +103,9 @@ cdef class WeisfeleirLehmanKernel(Base):
graph_list
[
i
]
=
nx
.
relabel_nodes
(
graph_list
[
i
],
label_lookup
)
cdef
np
.
ndarray
[
np
.
float64_t
]
k
#
cdef np.ndarray[np.float64_t] k
k
=
np
.
dot
(
phi
.
transpose
(),
phi
)
print
(
1
)
# MAIN LOOP
cdef
int
it
=
0
...
...
@@ -140,10 +142,4 @@ cdef class WeisfeleirLehmanKernel(Base):
k
+=
np
.
dot
(
phi
.
transpose
(),
phi
)
it
=
it
+
1
# Compute the normalized version of the kernel
cdef
np
.
ndarray
[
np
.
float64_t
]
k_norm
=
np
.
zeros
((
k
.
shape
[
0
],
k
.
shape
[
1
]))
for
i
in
range
(
k
.
shape
[
0
]):
for
j
in
range
(
k
.
shape
[
1
]):
k_norm
[
i
,
j
]
=
k
[
i
,
j
]
/
np
.
sqrt
(
k
[
i
,
i
]
*
k
[
j
,
j
])
return
k_norm
\ No newline at end of file
return
minmax_scale
(
k
).
todense
()
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment