Maximal cliques

Introduction to Network Analysis in Python

Eric Ma

Data Carpentry instructor and author of nxviz package

Maximal cliques

  • Definition: a clique that, when extended by one node is no longer a clique

A graph with five nodes. Four nodes form a clique: each node is connected to all other nodes. Three of the nodes in the clique are highlighted green. The fifth node is only connected to one other node.

Introduction to Network Analysis in Python

Maximal cliques

  • Definition: a clique that, when extended by one node is no longer a clique

The same graph with five nodes. This time, the four nodes in the clique are all highlighted green.

Introduction to Network Analysis in Python

Maximal cliques

  • Applications: community finding

The same graph with five nodes.

Introduction to Network Analysis in Python

Communities

  • Find cliques
  • Find unions of cliques

The same graph with five nodes.

Introduction to Network Analysis in Python

NetworkX API

  • find_cliques finds all maximal cliques
Introduction to Network Analysis in Python

Maximal cliques

import networkx as nx
G = nx.barbell_graph(m1=5, m2=1)

nx.find_cliques(G)
<generator object find_cliques at 0x1043f1f68>
list(nx.find_cliques(G))
[[4, 0, 1, 2, 3], [4, 5], [6, 8, 9, 10, 7], [6, 5]]

Introduction to Network Analysis in Python

Maximal cliques

import networkx as nx
G = nx.barbell_graph(m1=5, m2=1)
nx.find_cliques(G)
<generator object find_cliques at 0x1043f1f68>
list(nx.find_cliques(G))
[[4, 0, 1, 2, 3], [4, 5], [6, 8, 9, 10, 7], [6, 5]]

Two graphs, each with five nodes forming maximal cliques.

Introduction to Network Analysis in Python

Maximal cliques

import networkx as nx
G = nx.barbell_graph(m1=5, m2=1)
nx.find_cliques(G)
<generator object find_cliques at 0x1043f1f68>
list(nx.find_cliques(G))
[[4, 0, 1, 2, 3], [4, 5], [6, 8, 9, 10, 7], [6, 5]]

Four graphs: the two five node cliques from before, plus two new graphs each consisting of two nodes connected by an edge.

Introduction to Network Analysis in Python

Let's practice!

Introduction to Network Analysis in Python

Preparing Video For Download...