Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix when graph grakel is initialized with attributes #93

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions grakel/kernels/edge_histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,11 @@ def parse_input(self, X):
continue
else:
# Our element is an iterable of at least 2 elements
L = x[2]
elements = list(itervalues( x[2] ))
if( isinstance( elements[0], Iterable) ):
L = list( map( lambda y: y[0], elements ))
else:
L = elements
elif type(x) is Graph:
# get labels in any existing format
L = x.get_labels(purpose="any", label_type="edge")
Expand All @@ -107,7 +111,7 @@ def parse_input(self, X):
'dict \n')

# construct the data input for the numpy array
for (label, frequency) in iteritems(Counter(itervalues(L))):
for (label, frequency) in iteritems(Counter( L )):
# for the row that corresponds to that graph
rows.append(ni)

Expand Down
8 changes: 6 additions & 2 deletions grakel/kernels/vertex_histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,11 @@ def parse_input(self, X):
continue
else:
# Our element is an iterable of at least 2 elements
L = x[1]
elements = list(itervalues( x[1] ))
if( isinstance( elements[0], Iterable) ):
L = list( map( lambda y: y[0], elements ))
else:
L = elements
elif type(x) is Graph:
# get labels in any existing format
L = x.get_labels(purpose="any")
Expand All @@ -107,7 +111,7 @@ def parse_input(self, X):
'dict \n')

# construct the data input for the numpy array
for (label, frequency) in iteritems(Counter(itervalues(L))):
for (label, frequency) in iteritems(Counter( L )):
# for the row that corresponds to that graph
rows.append(ni)

Expand Down
23 changes: 20 additions & 3 deletions grakel/kernels/weisfeiler_lehman.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,16 @@ def parse_input(self, X):
Gs_ed[nx] = x.get_edge_dictionary()
L[nx] = x.get_labels(purpose="dictionary")
extras[nx] = extra
distinct_values |= set(itervalues(L[nx]))
elements = list(itervalues(L[nx]))
if( isinstance( elements[0], Iterable) ):
el = list( map( lambda y: y[0], elements ))
else:
el = elements
temp={}
for k,v in zip( list(L[nx].keys()), el):
temp[k] = v
L[nx] = temp
distinct_values |= set( el )
nx += 1
if nx == 0:
raise ValueError('parsed input is empty')
Expand Down Expand Up @@ -357,10 +366,18 @@ def transform(self, X):
'least one and at most 3 elements\n')
Gs_ed[nx] = x.get_edge_dictionary()
L[nx] = x.get_labels(purpose="dictionary")

elements = list(itervalues( L[nx] ))
if( isinstance( elements[0], Iterable) ):
el = list( map( lambda y: y[0], elements ))
else:
el = elements
temp={}
for k,v in zip( list(L[nx].keys()), el):
temp[k] = v
L[nx] = temp
# Hold all the distinct values
distinct_values |= set(
v for v in itervalues(L[nx])
v for v in el
if v not in self._inv_labels[0])
nx += 1
if nx == 0:
Expand Down