Skip to content Skip to sidebar Skip to footer

Why The Result Is Incorrect To Find 3-cliques Using Networkx In Python?

I am trying to find all 3-cliques using networkx's find_cliques method. However, there should be far more than 2 as the result shows. Please help me to figure out why. import netwo

Solution 1:

According to the document, find_cliques returns all maximal cliques. In your case there are cliques with size greater than 3 (abcde)(cdeg) and you will need to also have all possible 3-combination in that bigger clique. This is because each sub-clique of a clique is also a clique but it's not maximal.

EDIT: You will also need use set to avoid overlapped cliques.

Use the following code:

import itertools
cliques3 = set(sum([list(itertools.combinations(set(clq), 3)) for clq in cliques iflen(clq)>=3],[]))

Alternatively, using enumerate_all_cliques will also give cliques of size (cardinality) k = 1, 2, 3, ..., maxDegree - 1. See the document here: http://networkx.github.io/documentation/development/reference/generated/networkx.algorithms.clique.enumerate_all_cliques.html

Post a Comment for "Why The Result Is Incorrect To Find 3-cliques Using Networkx In Python?"