April 2, 2018

What is graph (Network) ?

Network1

What is graph (Network) ?

Network2

What is graph (Network) ?

Network3

What is graph?

  • Binary relation
    EDGES between elements of a set ( = VERTICES)
  • For example

  • Vertices = {A,B,C,D,E}

  • Edges = ({A,B},{A,C},{B,C},{C,E})

  • It is "better" to draw it:

Undirected and directored graph

  • If the pairs are unordered, then the graph is undirected

Network4

Undirected and directed graph

  • Otherwise, it is directed

Network5

Weighted and unweighted graph

  • A graph called weighted if both edges and vertices have some weights or values

Network6

Weighted and unweighted graph

  • Otherwise, it is unweighted

Network7

Features of graphs

  • Random Network
    Randomply connecting pairs of nodes with some probabily \(p\)

  • Scale-Free Network Few nodes has a large number of links, most nodes have very few.

Random Network

## Random Graph
g <- erdos.renyi.game(10, 1/10)
plot(g)

degree_distribution(g)
## [1] 0.4 0.4 0.2

Scale-Free Network

## Scale Free
N <- 20
g <- sample_fitness(5*N, sample((1:20)^-2, N, replace=TRUE))
plot(g)

Igraph package

  • For classic graph theory and network science
  • Core functionally is implemented as a C library
  • High level interfaces from R and Python
  • http: //igraph.sf.net

Vertex and edge ids

  • Vertices are always numbered from zero
  • Numbering is continual from 1 to |V|

V = {A,B,C,D,E}
Edges = ((A,B),(A,C),(B,C),(C,E))
A = 1, B = 2, C = 3, D = 4, E = 5

g <- graph(c(1,2, 1,3, 2,3, 3,5),n =5)

Vertex and edge ids

g <- graph(c(1,2, 1,3, 2,3, 3,5),n =5)
plot(g)

Creating igraph graphs

  • igraph object
print(g)
## IGRAPH 356935f D--- 5 4 -- 
## + edges from 356935f:
## [1] 1->2 1->3 2->3 3->5
vcount(g)
## [1] 5
ecount(g)
## [1] 4

Adjacency matrix

\[ \begin{bmatrix} & A & B & C & D & E\\ A & 0 & 1 & 1 & 0 & 0\\ B & 1 & 0 & 1 & 0 & 0\\ C & 1 & 1 & 0 & 0 & 1\\ D & 0 & 0 & 0 & 0 & 0\\ E & 0 & 0 & 1 & 0 & 0 \end{bmatrix} \]

Strongly Connected Components

A directed graph is called strongly connected if there is a path in each direction between each pair of vertices of the graph.

– In a directed graph G that may not itself be strongly connected, a pair of vertices u and v are said to be strongly connected to each other if there is a path in each direction between them.

SCC

g <- erdos.renyi.game(20, 1/15)
plot.igraph(g)

Homework

Either: Just simulate a random graph (n = 10, p = 0.3) and print out its adjacency matrix

Or: Download any network data and print it as a graph.