Unit 7 - Communities - Exercises Solution
Unit 7 - Communities - Exercises Solution
UNIT 7 – Algorithms for the detection of communities
and influential nodes
Exercises
1
Graphs and Network Analysis Artificial Intelligence Degree ‐ UAB
Maximal cliques
• For the graph of the Figure, indicate which communities
would be detected by a clustering algorithm based on
maximal cliques.
2
Graphs and Network Analysis Artificial Intelligence Degree ‐ UAB
Maximal cliques ‐ solution
• Cliques:
– Order 1: {1}, {2}, {3}, {4}, {5}, {6}, {7}
– Order 2: {1,2}, {1,3}, {1,4}, {2,3}, {2,4}, {3,4}, {5,6}
– Order 4: {1,2,3,4}
• Maximal cliques:
– {7}, {5,6}, {1,2,3,4}
• Communities:
3
Graphs and Network Analysis Artificial Intelligence Degree ‐ UAB
Agglomerative hierarchical clustering
C1 C2 C3
C1
C2
C3
4
Graphs and Network Analysis Artificial Intelligence Degree ‐ UAB
Agglomerative hierarchical clustering ‐ solution
5
Graphs and Network Analysis Artificial Intelligence Degree ‐ UAB
Agglomerative hierarchical clustering
• Given the graph of the Figure, draw the dendrogram that would be
generated if we apply a bottom‐up algorithm for detecting
communities. The values of the edges are the weights (distances
between the nodes). Use the single linkage criterion to define the
distance between clusters.
6
Graphs and Network Analysis Artificial Intelligence Degree ‐ UAB
Agglomerative hierarchical clustering ‐ solution
7
Graphs and Network Analysis Artificial Intelligence Degree ‐ UAB
Divisive hierarchical clustering
• Apply the divisive algorithm (e.g. Girvan‐Newman) for detecting
communities in the graph of the Figure until you find 3 communities.
You do not need to make calculations numerically for the different
decision steps (centralities, densities ...), just indicate it intuitively.
•
8
Graphs and Network Analysis Artificial Intelligence Degree ‐ UAB
9
Graphs and Network Analysis Artificial Intelligence Degree ‐ UAB
Community detection
1 4
3
10
Graphs and Network Analysis Artificial Intelligence Degree ‐ UAB
• Maximal Cliques:
– {1,5}, {1,4}, {1,2,3}, {5,6,7,8,9} 8 9
7
6
5
1 4
3
11
Graphs and Network Analysis Artificial Intelligence Degree ‐ UAB
• K‐cores: 8 9
– 1‐Core: tot el graf
– 1‐Shell: node 4 7
12
Graphs and Network Analysis Artificial Intelligence Degree ‐ UAB
• Min‐Cut partition. In each iteration we contract the pair of "closest" nodes
until we have a graph of as many nodes as the number of partitions we want.
For 2 partitions, a possible sequence would be:
•
8 9 8 9 8 9 9
7 7 7 7, 8
6 6 6 6
5 5 5 5
1 4 1,2
4 1,2, 3
4 1,2, 3
4
2
3 3
9
5,7, 8 5,7, 8 5,6,7, 8,9 5,6,7, 8,9
6 6,9
1,2, 3
4 1,2, 3
4 1,2, 3
4 1,2, 3 13
Graphs and Network Analysis Artificial Intelligence Degree ‐ UAB
• Girvan‐Newman clustering:
– It would be necessary to calculate the 8 9
centralities of the edges, since the
algorithm eliminates in each iteration the 7
edge of more centrality. Intuitively, the
edges of greater centrality would be (1.5) 6
and (1.4). So in 3 iterations Girvan 5
Newman's divisive algorithm would give 3
communities: {4}, {1,2,3} and {5,6,7,8,9}
–
1 4
3
14
Graphs and Network Analysis Artificial Intelligence Degree ‐ UAB
Exam scheduling
Four students have to take exams of different disciplines:
– Maria: Maths, Physics, Chemistry
– Marc: Maths, Biology, Programming
– Pol: Maths, Chemistry, Economy
– Claire: Physics, Programming, History
We have to find a schedule for the exams. What is the minimum number
of time slots to be provided so that no student has to take two exams
simultaneously?
15
Graphs and Network Analysis Artificial Intelligence Degree ‐ UAB
• It can be solved as a graph coloring problem. It consists in labeling with colors
the nodes of a graph such that no two adjacent nodes are of the same color.
• In graph coloring problem, the chromatic number is the number of required
colors.
– The lower bound of the chromatic number is size of the maximum clique (a perfect graph is a
graph in which the chromatic number equals the size of the maximum clique).
– The upper bound of the chromatic number is one more color than the maximum vertex
degree.
– We construct a graph where the nodes are the disciplines, and the edges correspond to the
disciplines that are not compatible in the same time slot.
Maths Biology
Physics History
Chemistry Programming
16
Economy
Graphs and Network Analysis Artificial Intelligence Degree ‐ UAB
Chemistry Programming
Biology Programming Programming
Maths Economy
Economy
Economy Chemistry
Maths Physics
Chemistry Programming
Economy
18
Graphs and Network Analysis Artificial Intelligence Degree ‐ UAB
Exam scheduling
There is a fifth student that has to take exams:
– Maria: Maths, Physics, Chemistry
– Marc: Maths, Biology, Programming
– Pol: Maths, Chemistry, Economy
– Claire: Physics, Programming, History
– Daniel: Chemistry, Programming, History
What is the minimum number of time slots to be provided so that no
student has to take two exams simultaneously?
19
Graphs and Network Analysis Artificial Intelligence Degree ‐ UAB
Chemistry Programming
Biology Programming Programming
Economy
Maths Economy
Cliques order 3
Economy Chemistry
Maths Maths
Physics Physics History
Maths Physics
Chemistry History
Maths Physics
Clique order 4
Chemistry Programming Chemistry Programming
Physics History
History Physics
Chemistry Programming
Chemistry Programming Chemistry History
20
Graphs and Network Analysis Artificial Intelligence Degree ‐ UAB
Clique order 4
Physics History
Physics History
Chemistry Programming
Chemistry Programming
Maximum flow
The following graph represents a flow graph. It can be interpreted as a
network of pipes. The number in the edges indicates the capacity
(maximum flow) through the pipe (for example, liters/minute). It could
also be interpreted as a traffic network (cars/minute).
What is the maximum flow capacity between the source and the sink?
5
2 4
6 4
Source 1 9 6 Sink
8 9
3 5
5
22
Graphs and Network Analysis Artificial Intelligence Degree ‐ UAB
Maximum Flow: solution
• The max‐flow min‐cut theorem states that the maximum flow through any
network from a given source to a given sink is exactly equal to the minimum
sum of a cut.
• Therefore, the maximum flow can be calculated by the sum of the weights of
the edges that define the minimum cut partition in two subgraphs containing
the source and the sink respectively.
• Some possible cuts:
Cut 2: 5+9+5 = 19
Cut 1: 6+8 = 14
5
2 4
6 4 Cut 3: 5+4 = 9
Cut 4: 6+9+5 = 20
Source 1 9 6 Sink
8 9
3 5
5
23
Graphs and Network Analysis Artificial Intelligence Degree ‐ UAB
Maximum Flow: solution
5
2 4 2
6 4 6 5
4
Source 1 9 6 Sink Source 1 6 Sink
3+4
8
8 9 5 9
3 5 5
5
Contraction of the
biggest edge
2 2
6 5 6 5
Source 1 4 Sink 4
3+4 Source 1+3+4 Sink
8
5 5+6 5+6
5
Source 4 Sink
1+2+3+4
5 5+6
24
Graphs and Network Analysis Artificial Intelligence Degree ‐ UAB
We have the following information of people (work shift/slot schedule,
home city and use of public transportation to go to their work).
In COVID‐19 period, we want to detect the risk communities (groups of
people with high contagion risk).
Can you propose a graph‐based solution?
Community detection
Graph visualization:
26
(*) Edge weights: Same shift (+1), same city (+1), if same shift and same city, public transportation (+1)
Graphs and Network Analysis Artificial Intelligence Degree ‐ UAB
Community detection
1 1
1 3 1
1
1
3 1
1
3
1
1
1
3
1
1
1
1
1 1
1 1 1
2
27
Graphs and Network Analysis Artificial Intelligence Degree ‐ UAB
['Jaume', 'Raquel', 'Maria’] ['Jaume', 'Raquel', 'Cesc', 'Anna’]
['Cesc', 'Montse', 'Anna’] ['Eva', 'Joan’] ['Eva', 'Cristina', 'Marta', 'David’]
['Pau', 'Maria', 'Joan', 'Montse’] ['Pau', 'Cristina', 'Marta', 'David']
28
Graphs and Network Analysis Artificial Intelligence Degree ‐ UAB
29