Create new graph of all nodes that are a part of 4-node clique

72 views
Skip to first unread message

Curtis Hampton

unread,
Aug 11, 2014, 6:57:10 PM8/11/14
to networkx...@googlegroups.com

I have a network that I would like to bound by clique, but I haven't quite figured out how to do this correctly. I am able to do this same process using k-cores, but not sure what the right process for creating a graph with only cliques in it.

I was hoping if I show my process for find subgraphs using the k_core function, someone could help me alter my process to find subgraphs using the clique function.

To start, I create a graph, I'll use the karate club one:

In [1]: import networkx as nx

In [2]: g = nx.karate_club_graph()

Plot to graph in iPython:

In [3]: pylab inline
Populating the interactive namespace from numpy and matplotlib

In [4]: nx.draw(g)


Next, I find all edges that are within the 4-core (have 4 or more edges):

In [5]: g_4k_edges = nx.k_core(g, k=4).edges()


Add those edges to a new graph:

In [6]: g_4k = nx.Graph() In [7]: g_4k.add_edges_from(g_4k_edges)

Plot the 4-core graph:

In [8]: nx.draw(g_4k)

Any idea on how to do this, but instead of using k-cores to bound the network, use cliques that have 4 or more vertices?

Aric Hagberg

unread,
Aug 11, 2014, 7:35:21 PM8/11/14
to networkx...@googlegroups.com
Maybe networkx.find_cliques() will help you?
Aric


--
You received this message because you are subscribed to the Google Groups "networkx-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to networkx-discu...@googlegroups.com.
To post to this group, send email to networkx...@googlegroups.com.
Visit this group at http://groups.google.com/group/networkx-discuss.
For more options, visit https://groups.google.com/d/optout.

Curtis Hampton

unread,
Aug 11, 2014, 7:59:59 PM8/11/14
to networkx...@googlegroups.com
Thanks Aric.

I've tried to figure out how I could use find_cliques() and find_cliques_recursive() to answer this question, but haven't been able to work it out yet.


import networkx as nx

# load graph as g
g = nx.karate_club_graph()

# find cliques in g
cliques = nx.find_cliques(g)


I'm not sure what to do next to limit my graph to only cliques of 4 or more.  I tried adding .edges() to the end of my last command to return all the edges found, and then adding those edges to a blank graph, but I received an error.

Daπid

unread,
Aug 12, 2014, 8:24:28 AM8/12/14
to networkx...@googlegroups.com

On 12 August 2014 01:59, Curtis Hampton <curtisl...@gmail.com> wrote:

I'm not sure what to do next to limit my graph to only cliques of 4 or more.  I tried adding .edges() to the end of my last command to return all the edges found, and then adding those edges to a blank graph, but I received an error.

 
All the clicques of k nodes or more are inside the (k-1)-core of the network; and vice versa. So, take the core and find cliques there.


/David.

Reply all
Reply to author
Forward
0 new messages