Comments (9)
Dear @sbonner0 ,
Thank you for your interest in GraKeL.
The graph_from_networkx()
function transforms an iterable of NetworkX objects to an iterable of GraKeL's internal graph representations. Therefore, instead of:
graph = grakel.graph_from_networkx(G)
you should use the following:
graph = grakel.graph_from_networkx([G])
Note also that GraKeL contains implementations of kernels between graphs (i.e., kernels that compare graphs to each other). Therefore, feeding a single graph to the fit_transform()
function will just produce a single number (i.e., the kernel value between the input graph and itself). Furthermore, the shortest path kernel expects the input graphs to contain node labels. If they do not, you should set the parameter with_labels=False
.
from grakel.
Great thanks, this works now! It might be worth updating your documentation on your webpage to make this a bit more clear for everyone.
As an aside, how many graphs and at what scale would you expect the kernels to be able to work on? For example, I have a set of 50,000 graphs of 100,000 vertices each, would you expect that I would be able to use GraKel to process this?
from grakel.
Dear @sbonner0 ,
Your graphs are very large. Most benchmark datasets contain graphs with up to thousands of nodes (i.e., two orders of magnitude smaller than your graphs). If your graphs are unlabeled, then you can use the graphlet kernel (but you need to make sure that you set the number of samples to some large value). If your graphs are also sparse, then I guess that the Weisfeiler-Lehman subtree kernel and the shortest path kernel can also handle your dataset. You can give it a try.
With regards to the number of graphs, 50,000 is quite a large number. This would correspond to a 50,000 X 50,000 gram matrix which may not fit in your main memory. Therefore, I would suggest that you use the Nystrom method and generate a low-dimensional representation for each graph (see the corresponding section here: https://ysig.github.io/GraKeL/dev/user_manual/longer_introduction.html).
from grakel.
This is great, thanks for all your help and work on GraKel.
from grakel.
Hi @giannisnik ,
I have a similar setup--many undirected large graphs with no attributes--and had a question regarding the use of the Weisfeiler-Lehman subtree and the shortest path kernel setup. I have a list of networkx graphs that I'm sending to:
graphs = graph_from_networkx(nx_graphs)
then initializing the kernel as:
gk = GraphKernel(kernel=[{"name": "subtree_wl"}, {"name": "shortest_path", "normalize": True, "with_labels": False}])
and then finally calling:
gk.fit_transform(x_train)
However, I'm running into an error "AttributeError: 'NoneType' object has no attribute 'values'" in line 110, in parse_input
for (label, frequency) in iteritems(Counter(itervalues(L))):
Any ideas what I'm doing wrong here?
from grakel.
Hi @safreita1 ,
The problem is that WL expects the nodes of the graphs to be annotated with discrete labels. To run the kernel, you can just assign the same discrete label to all the vertices. See for instance the following example:
G1 = nx.cycle_graph(3)
nx.set_node_attributes(G1, {0:'a', 1:'a', 2:'a'}, 'label')
G2 = nx.cycle_graph(4)
nx.set_node_attributes(G2, {0:'a', 1:'a', 2:'a', 3:'a'}, 'label')
G3 = nx.cycle_graph(5)
nx.set_node_attributes(G3, {0:'a', 1:'a', 2:'a', 3:'a', 4:'a'}, 'label')
nx_graphs = [G1, G2, G3]
graphs = graph_from_networkx(nx_graphs, node_labels_tag='label')
gk = GraphKernel(kernel=[{"name": "weisfeiler_lehman", "n_iter": 5}, {"name": "shortest_path"}], normalize=True)
K = gk.fit_transform(graphs)
The above code computes the WL shortest path kernel. It is not clear to me if you want to compute this kernel or if you want to compute the WL subtree kernel and separately, the shortest path kernel. Note that the latter can be computed even if the nodes of the graphs are unlabeled.
from grakel.
Thanks for the great example @giannisnik!
My primary goal is a kernel that can work with many large graphs (e.g., 50k nodes). Now that I'm re-reading your post a few messages above, I realize that you were probably saying you can use either the Weisfeiler-Lehman subtree kernel or the shortest path kernel to handle a dataset this large.
For the graphlet kernel, would the default parameters suffice or do you recommend a specific setup?
from grakel.
Dear @safreita1 ,
These graphs are indeed very large. These kernels have mainly been applied to much smaller graphs. But if the graphs are sparse, I guess that some kernels can handle them. See below how you can compute the two kernels: the shortest path kernel and the WL subtree kernel.
graphs = graph_from_networkx(nx_graphs)
sp_kernel = GraphKernel(kernel=[{"name": "shortest_path", "with_labels": False}], normalize=True)
K = sp_kernel.fit_transform(graphs)
print(K)
graphs = graph_from_networkx(nx_graphs, node_labels_tag='label')
wl_subtree_kernel = GraphKernel(kernel=[{"name": "weisfeiler_lehman", "n_iter": 5}, {"name": "subtree_wl"}], normalize=True)
K = wl_subtree_kernel.fit_transform(graphs)
print(K)
With regards to the graphlet kernel, since the graphs are very large, it would be infeasible to extract all graphlets. Thus, you need to perform sampling as follows.
graphs = graph_from_networkx(nx_graphs)
graphlet_kernel = GraphKernel(kernel=[{"name": "graphlet_sampling", "sampling": {"n_samples":100}}], normalize=True)
K = graphlet_kernel.fit_transform(graphs)
print(K)
Note that the above code samples 100 graphlets of size from 3 to 5 from each graph. In your case, since the graphs are very large, 100 samples is not enough. You should sample a much larger number of graphlets. Note also that as you increase the number of samples, the running time of the kernel also increases.
from grakel.
Thank you for all your assistance, it's been incredibly helpful. Great job on this library!
from grakel.
Related Issues (20)
- Print <class 'grakel.graph.Graph'>
- The Weisfeiler-Lehman Edge Kernel
- fetch_dataset not working HOT 1
- Graph hopper kernel unable to transfom the data
- Edge labels not working for custom dataset HOT 1
- Fingerprint dataset not accessible using fetch_dataset function HOT 13
- NaN error when using Random walk kernel on certain datasets HOT 3
- I don't know how to use my own data for input HOT 5
- MultiDiGraph: graph_from_networkx() ValueError HOT 1
- modified random walk kernel giving all 1 scores for normalize=true HOT 1
- Difference between ShortestPath and ShortestPathAttr HOT 2
- Generating graphs from dense/numpy matrices HOT 1
- Graph.clone() or Graph.copy() HOT 3
- Explicit graph kernels HOT 2
- Graphlet kernel HOT 1
- NeighborhoodSubgraphPairwiseDistance kernel returns diagonal elements less than 1 HOT 5
- One vs many comparison for WeisfeilerLehman; `.transform` gives `TypeError: each element of X must have either a graph with...` HOT 1
- RWK matrix returns by fit_transform by RandomWalkLabeled() contains only 1.0 HOT 7
- Error when using EdgeHistogram HOT 1
- Can't install on Windows 10, keep getting same error HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from grakel.