Professional Documents
Culture Documents
Lecture 6
Mohsin Abbas
Network vs Graph
Different Networks – Same Graph
• A network of Computers
3
Different Networks – Same Graph
• Hollywood actor network:
• where two actors are connected if they played in the same movie
4
Different Networks – Same Graph
• Graph representing Hollywood actor network
5
Network vs Graph
• To understand a complex system we need a map of its “wiring
diagram”
6
Network vs Graph
• To understand a complex system we need a map of its “wiring
diagram”
• The complex system is the Network
7
Network vs Graph
• To understand a complex system we need a map of its “wiring
diagram”
• The complex system is the Network
• This “wiring diagram” will be the Graph of the Network
8
Nodes and Links
in
a Network
Graph Theory
Graph
Vertex
Edge
10
Graph Theory Network Science
Graph Network
Vertex Node
Edge Link
11
Nodes vs Links
• Nodes/Vertices: components of the Network
12
Nodes vs Links
• Nodes/Vertices: components of the Network
• Number of nodes, or N, represents the number of components in the system.
13
Nodes vs Links
• Nodes/Vertices: components of the Network
• Number of nodes, or N, represents the number of components in the system.
• We will often call N the size of the network.
14
Nodes vs Links
• Nodes/Vertices: components of the Network
• Number of nodes, or N, represents the number of components in the system.
• We will often call N the size of the network.
• To distinguish the nodes, we label them with i = 1, 2, ..., N.
15
NetworkX – naming the nodes
import networkx as nx
import matplotlib.pyplot as plt
G = nx.Graph()
G.add_edge(1,2)
G.add_edge(2,3)
G.add_edge(3,1)
G.add_edge(2,4)
16
17
Nodes vs Links
• Nodes/Vertices: components of the Network
• Number of nodes, or N, represents the number of components in the system.
• We will often call N the size of the network.
• To distinguish the nodes, we label them with i = 1, 2, ..., N.
• Links/Edges: Interactions between them nodes/vertices
18
Nodes vs Links
• Nodes/Vertices: components of the Network
• Number of nodes, or N, represents the number of components in the system.
• We will often call N the size of the network.
• To distinguish the nodes, we label them with i = 1, 2, ..., N.
• Links/Edges: Interactions between them nodes/vertices
• Number of links, which we denote with L, represents the total number of
interactions between the nodes.
19
Nodes vs Links
• Nodes/Vertices: components of the Network
• Number of nodes, or N, represents the number of components in the system.
• We will often call N the size of the network.
• To distinguish the nodes, we label them with i = 1, 2, ..., N.
• Links/Edges: Interactions between them nodes/vertices
• Number of links, which we denote with L, represents the total number of
interactions between the nodes.
• Links are rarely labelled, as they can be identified through the nodes they
connect.
20
Nodes vs Links
• Nodes/Vertices: components of the Network
• Number of nodes, or N, represents the number of components in the system.
• We will often call N the size of the network.
• To distinguish the nodes, we label them with i = 1, 2, ..., N.
• Links/Edges: Interactions between them nodes/vertices
• Number of links, which we denote with L, represents the total number of
interactions between the nodes.
• Links are rarely labelled, as they can be identified through the nodes they
connect.
• For example, the (2, 4) link connects nodes 2 and 4.
21
Nodes vs Links
N = 4 and L = 4.
22
NetworkX – number of nodes and links
import networkx as nx
import matplotlib.pyplot as plt
G = nx.Graph()
G.add_edge(1,2)
G.add_edge(2,3)
G.add_edge(3,1)
G.add_edge(2,4)
N = G.number_of_nodes()
L = G.number_of_edges()
print(N)
print(L)
23
Directed and Undirected
Networks
Directed and Undirected Networks
• A network is called directed (or digraph) if all of its links are directed
• It is called undirected if all of its links are undirected
25
NetworkX – directed graphs
import networkx as nx
import matplotlib.pyplot as plt
G = nx.DiGraph()
G.add_edge(1,2)
G.add_edge(3,1)
G.add_edge(3,2)
G.add_edge(2,4)
G = nx.DiGraph()
G.add_edge(1,2)
G.add_edge(3,1)
G.add_edge(3,2)
G.add_edge(2,4)
29
Examples of Different Networks
30
Examples of Different Networks
31
Examples of Different Networks
32
Examples of Different Networks
33
Network Degree
Degree of a Node
• Defined as the number of links a node has to other nodes
35
Degree of a Node
• Defined as the number of links a node has to other nodes
• ki is degree of the ith node in the network
36
Degree of a Node
k1 = 2, k2 = 3, k3 = 2, k4 = 1
37
NetworkX – Degree of Nodes
import networkx as nx
import matplotlib.pyplot as plt
G = nx.Graph()
G.add_edge(1,2)
G.add_edge(3,1)
G.add_edge(3,2)
G.add_edge(2,4)
print(G.degree[1])
print(G.degree[2])
print(G.degree[3])
print(G.degree[4])
G = nx.Graph()
G.add_edge(1,2)
G.add_edge(3,1)
G.add_edge(3,2)
G.add_edge(2,4)
print(G.degree[1])
print(G.degree[2])
print(G.degree[3])
print(G.degree[4])
Output:
1
2
3
4
40
NetworkX – Degree of Nodes
import networkx as nx
import matplotlib.pyplot as plt
G = nx.Graph()
G.add_edge(1,2)
G.add_edge(3,1)
G.add_edge(3,2)
G.add_edge(2,4)
print(G.degree[1])
print(G.degree[2])
print(G.degree[3])
print(G.degree[4])
G = nx.Graph()
G.add_edge(1,2)
G.add_edge(3,1)
G.add_edge(3,2)
G.add_edge(2,4)