Reputation: 543
What is the GraphLab equivalent to the following NetworkX code?
for nodeset in nx.connected_components(G):
In GraphLab, I would like to obtain a set of Vertex IDs for each connected component.
Upvotes: 0
Views: 170
Reputation: 1027
The component IDs returned by graphlab.graph_analytics.connected_components
are in the form of an SFrame, so the easiest way to get the IDs for a given component is by filtering the SFrame:
# Make a graph with two components.
import graphlab
G = graphlab.SGraph().add_edges(
[graphlab.Edge(i, i+1) for i in range(3)])
G = G.add_edges([graphlab.Edge(i, i+1) for i in range(4, 6)])
# Get the connected components.
cc = graphlab.connected_components.create(G)
# Find the vertices for a given component (0, in this example).
nodes = cc.component_id.filter_by(0, 'component_id')
print nodes
+------+--------------+
| __id | component_id |
+------+--------------+
| 5 | 0 |
| 6 | 0 |
| 4 | 0 |
+------+--------------+
[3 rows x 2 columns]
Upvotes: 1
Reputation: 543
Here is the first cut at porting from NetworkX to GraphLab. However, iterating appears to be very slow.
temp1 = cc['component_id']
temp1.remove_column('__id')
id_set = set()
id_set = temp1['component_id']
for item in id_set:
nodeset = cc_out[cc_out['component_id'] == item]['__id']
Upvotes: 0