0% found this document useful (0 votes)
2 views

Lecture 4 - Matrix Representation - Students

The document discusses matrix representation in the context of social networks, focusing on the relationship and adjacency matrices. It explains how these matrices capture relationships between nodes in a graph, providing analytical advantages over traditional graph representations. Additionally, it covers the process of building adjacency matrices and the significance of matrix operations in analyzing complex networks.

Uploaded by

ahmeddhamed179
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Lecture 4 - Matrix Representation - Students

The document discusses matrix representation in the context of social networks, focusing on the relationship and adjacency matrices. It explains how these matrices capture relationships between nodes in a graph, providing analytical advantages over traditional graph representations. Additionally, it covers the process of building adjacency matrices and the significance of matrix operations in analyzing complex networks.

Uploaded by

ahmeddhamed179
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

04.

Matrix
Representation
Lecturer: Dr. Reem Essameldin Ebrahim

Introduction to Social Networks


Based on CS224W Analysis of Networks Mining and Learning with Graphs: Stanford University
Copyright © Dr. Reem Essameldin 2023-2024
From Graph to Matrix

Relationship Matrix

Adjacency Matrix

Building Adiacency Matrix

In this Lecture Representing graph: Other ways


Topics to be covered are:
Adiacency Matrix: Examples

Copyright © Dr. Reem Essameldin 2023-2024


Note that Adjacent vs Terminal
Two vertices 𝑢 and 𝑣 in an undirected graph 𝐺 are called adjacent (or neighbors)
in 𝐺 if {𝑢, 𝑣} is an edge in 𝐺. The vertices 𝑢 and 𝑣 are called endpoints of the edge
{𝑢, 𝑣}.
Simple Example
Adjacent a
Vertex
Vertices

a b, c, d
b
b a, d d
c a, d

d a, b, c c

Copyright © Dr. Reem Essameldin 2023-2024


Note that Adjacent vs Terminal
When (𝑢, 𝑣) is an edge of the graph 𝐺 with directed edges, 𝑢 is said to be
adjacent to 𝑣, and 𝑣 is said to be adjacent from 𝑢.
The vertex 𝑢 is called the initial vertex of (𝑢, 𝑣), and 𝑣 is called the
terminal vertex of (𝑢, 𝑣). The initial vertex and terminal vertex of a
loop are the same.

Simple Example a
Initial Terminal
Vertex Vertices
b
a c
d
b a

c c
d c, b, a

Copyright © Dr. Reem Essameldin 2023-2024


From Graph to Matrix
Networks represented as graphs feel quite intuitive to us. With many tens,
hundreds, thousands, or millions of nodes and edges, creating a graph with these
amounts of data only results in what network analysts call a “hairball.” Nothing
can be understood through intuition.

Benefits of Matrix Representation


It provides us more analytical leverage when
we switch to representing the network as a
matrix. When we represent the network as a
matrix, we are able to efficiently calculate
features of the network that we would not be
able to see with our eyes alone.

Copyright © Dr. Reem Essameldin 2023-2024


Relationship Matrix
we will be focusing on a particular type of matrix called a relationship matrix. A
relationship matrix is when, instead of asking what value of an attribute a case
has, we ask about the value of describing how a case relates to another case.

Example of a Relationship Matrix

A relationship matrix thus captures the relationship between two cases. In the
above Figure, the relationship between Case 1 and Case 2 is Value 4, and the
relationship between Case 2 and Case 1 is Value 2. Wait, would that mean
Value 2 and 4 are the same? The answer is maybe. Depends on what type of
relationship is being captured.
We describe the size of the matrix by the number of rows
by the number of columns. 𝒏 is used to represent the
number of rows and m is the number of columns. Thus,
the above table is described as a 3x3 graph.

Copyright © Dr. Reem Essameldin 2023-2024


Adjacency Matrix
There are many types of relationship matrices as the basic principles just stated
can be varied to capture different underlying facets of relationships. The
adjacency matrix is the most important, most commonly used way of formatting
data in network analysis.

An adjacency matrix asks if two cases share a


relationship or not. If two actors have a
relationship, they are next to each other
(adjacent) in the network, whereas if they do
not share a relationship, they are not next to
each other.

Copyright © Dr. Reem Essameldin 2023-2024


Adjacency Matrix
There are many types of relationship matrices as the basic principles just stated
can be varied to capture different underlying facets of relationships. The
adjacency matrix is the most important, most commonly used way of formatting
data in network analysis.
The Mathematical Definition
Let 𝐺 = (𝑉, 𝐸) be a simple graph with |𝑉| = 𝑛. Suppose that
the vertices of 𝐺 are listed in arbitrary order as 𝑣1 , 𝑣2 , … . . , 𝑣𝑛 .
The adjacency matrix 𝐴 (or 𝐴𝐺 ) of 𝐺, with respect to this
listing of the vertices, is the n×n zero-one matrix. In other
words, for an adjacency matrix 𝐴 = [𝑎𝑖𝑗 ], 𝑎𝑖𝑗 = 1 if {𝑣𝑖 , 𝑣𝑗 } is an
edge of 𝐺, 𝑎𝑖𝑗 = 0 otherwise.

Copyright © Dr. Reem Essameldin 2023-2024


Building Adjacency Matrix
If we want to build an adjacency matrix of a network, we simply list all the actors
in the rows and columns, and ask if the two share a relationship in order to fill in
the values.
Illustrating Example
The first step in building the adjacency matrix that
represents the graph is to list all the nodes {A, B, C, D, E,
F, G, H, I} as both a row and a column entry for each node.
Next, one goes sequentially across the rows and columns,
asking the question “does actor i have the relationship I am
examining with actor j?” If the question asked is about the
absence or presence of a relationship, 0’s and 1’s are used.
If A has a relationship with B, the value 1 is marked.
Otherwise, 0.

Note that: It’s not sociologically meaningful for A to have a relationship with itself in
most cases. For example, asking “Is A friends with A?” does not make much sense, but
there are rare cases when it does, such as when A is a group of people and not an
individual, and the relationship under examination might occur both within and
between groups. These are called reflexive-ties or loops.
Copyright © Dr. Reem Essameldin 2023-2024
Building Adjacency Matrix
If we want to build an adjacency matrix of a network, we simply list all the actors
in the rows and columns, and ask if the two share a relationship in order to fill in
the values.
Illustrating Example 1

Copyright © Dr. Reem Essameldin 2023-2024


Building Adjacency Matrix
1
If we want to build an adjacency matrix of a network, we simply list all the actors in the rows
and columns,2 and ask if the two share a relationship in order to fill in the values.
Undirected Directed

Copyright © Dr. Reem Essameldin 2023-2024


Building Adjacency Matrix
1
If we want to build an adjacency matrix of a network, we simply list all the actors in the rows
and columns,2 and ask if the two share a relationship in order to fill in the values.
Undirected Directed

The adjacency matrix For a directed graph


of an undirected the matrix is
network is symmetric, asymmetric, 𝐴𝑖𝑗 ≠ 𝐴𝑗𝑖 ,
𝐴𝑖𝑗 = 𝐴𝑗𝑖 , 𝐴𝑖𝑖 = 0. 𝐴𝑖𝑖 = 0.

Copyright © Dr. Reem Essameldin 2023-2024


Building Adjacency Matrix
1
If we want to build an adjacency matrix of a network, we simply list all the actors in the rows
and columns,2 and ask if the two share a relationship in order to fill in the values.
Unweighted Weighted

Examples: Friendship, Hyperlink Examples: Internet, Roads

The adjacency matrix


of an undirected,
unweighted network is
symmetric, 𝐴𝑖𝑗 = 𝐴𝑗𝑖 ,
𝐴𝑖𝑖 = 0.
Copyright © Dr. Reem Essameldin 2023-2024
Building Adjacency Matrix
1
If we want to build an adjacency matrix of a network, we simply list all the actors in the rows
and columns,2 and ask if the two share a relationship in order to fill in the values.
Self-edges Multigraph

Examples: Proteins, Hyperlinks Examples: Communication, Collaboration

Copyright © Dr. Reem Essameldin 2023-2024


Building Adjacency Matrix
1
If we want to build an adjacency matrix of a network, we simply list all the actors in the rows
and columns,2 and ask if the two share a relationship in order to fill in the values.
Complete Bipartite

Copyright © Dr. Reem Essameldin 2023-2024


Building Adjacency Matrix
1
If we want to build an adjacency matrix of a network, we simply list all the actors in the rows
and columns,2 and ask if the two share a relationship in order to fill in the values.
Connected Disconnected

Copyright © Dr. Reem Essameldin 2023-2024


Representing Graph

Edge List Adjacent List


In lecture 3 while discussing the It allows us to quickly retrieve all
special graphs, we have seen neighbors of a given node. It is easier
another way of representing graphs; to work with if network is:
where relationships are represented • Large
as a set of edges. • Sparse

The edge list for the given The adjacent list for the given
graph is: graph is:
(2, 3)
(2, 4)
(3, 2) 1:
(3, 4) 2: 3, 4
(4, 5) 3: 2, 4
(5, 1) 4: 5
(5, 2) 5: 1, 2
Copyright © Dr. Reem Essameldin 2023-2024
Test Yourself
For the given directed graph, find the corresponding asymmetric adjacency matrix.

Solution:

Copyright © Dr. Reem Essameldin 2023-2024


Test Yourself
For the given weighted graph, find the corresponding weighted adjacency matrix.

Solution:

Copyright © Dr. Reem Essameldin 2023-2024


Matrix Operations
Taking the matrix and performing mathematical operations on the matrix can
actually unveil patterns or features about the social world that we are trying to
understand through the network.

While the matrices we’ve worked with so far are simple,


recall that in reality networks can be as complicated as
the social world they represent. e.g. Facebook’s friendship
networks, the connections between servers on the World Wide
Web, and airline transportation networks have millions of nodes
and edges.

It’s important to understand some of the fundamentals of


how to manipulate a matrix if we were to ever look at
networks beyond many of the simple examples.

Copyright © Dr. Reem Essameldin 2023-2024


Matrix Operations

Addition Scalar Multiplication Matrix Multiplication


By taking two matrices of the same When we multiply two matrices
dimension nXm, add up each together, we are fundamentally
Taking a single scalar, one
corresponding cell i,j in the two multiplying along rows in the first
can shape the original matrix
matrices, and return the result into matrix, and columns in the second
into an essentially larger or
the same cell i,j in a new matrix size matrix.
smaller version of itself, the
nxm.
scale changing based on the
size of the scalar.

Note that: Only matrices with the same Note that: Matrix multiplication is not
dimension nxm are capable of being commutative in the same way normal
summed together. Subtraction of two multiplication is. Multiplying two
matrices works in the same way as matrices together, in different orders,
addition. Copyright © Dr. Reem Essameldin 2023-2024
will not give the same results.

You might also like