Graphs and Matrices Spring 2012 Mills College Dan Ryan Lecture Slides by Dan Ryan is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.Dan RyanCreative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
Four Representations of a Graph G={V,E} NODE List A B D E B A C D C A B D D A B C E A EDGE List AB AD AE BA BC BD CA CB CD DA DB DC EA A C B D E MATRIX
Matrix ROWSCOLUMNS A matrix ELEMENT The MAIN DIAGONAL SQUARE MATRIX RECTANGULAR MATRIX
Nomenclature: nrows by mcols x2 matrix 2x4 matrix 3x1 matrix 3x3 matrix
Matrix
Sometimes we say “Vector” Each row (or column) in a matrix can be thought of as an ordered set of numbers describing an object. For a graph matrix, a row or a column is a “vector” of a vertex’s connections The fourth vertex is connected to the first, second, and third, but not the fifth
Transpose The transpose of a matrix is a swapping of its rows and columns
Transposing a Matrix transpose i j
Matrix Arithmetic
Example: Convert 2-Mode to 1-Mode(s) 1.Write the rectangular incidence matrix I A 123 BDC ABCD GROUPS PEOPLE A “groups by people” matrix
Example: Convert 2-Mode to 1-Mode(s) 2.Compute transpose of I, I T ABCD A101 B011 C111 D101 A “groups by people” matrix A “people by groups” matrix
When we multiply matrices… Columns of first factor = rows of second factor (People x Groups) X (Groups x People) = (People x People) (Groups x People) X (People x Groups) = (Groups x Groups) I T I A GxG I T I A PxP =x = x
Degree
Mean(average) Degree
Degree and Edges
Adjacency Matrix
Matrix Arithmetic See also:
Directed Unweighted Undirected Weighted Undirected Unweighted Directed Weighted dichotomize symmetrize E A B C D E A B C D E A B C D E A B C D
Paths If there is a path from vertex A to vertex B… …then there is a sequence of edges connecting them E.g., if there is a 2-path from A to C then there is some vertex B such that there is an edge AB and an edge BC AC B Path A to C?
Put another way An edge from vertex j to vertex i means A ij =1 If there is a 2-path from j to i then there is a k such that A ik =1 and A kj =1. …i…j…k… i j k j i k
A ik =1 and A kj =1 That means: if there is a path from vertex j to vertex k to vertex i THEN there is a k such that A ik A kj =1 …i…j…k… i j k j i k a b c There is an edge from k to i There is an edge from j to k
Another way to see it… If vertex j is connected to vertex k AND Vertex I is connected to k THEN Row I will have a 1 in position k AND Column j will have a 1 in position k
Elements of Product Matrix are Vector Products = X i j A 2 ij is how many times the row version and the column version have 1s in the same place
…i…j…k… i j k Are there other paths from j to i? j i k
Look for vertices between j and i …i…j……… i j j i k
Example: Convert 2-Mode to 1-Mode(s) 2.Compute transpose of I, I T A 123 BDC ABCD
Degree Distribution “Distribution of X” = pattern of different values X takes on More specifically: the frequency of each value || 2 |||| ||| 3 |||| 4 |||| | 5 |||
Diagonal Elements of A 2 are Vertex Degree A= A2=A2=
Why? = A2A A X A Degree equals number of “out and back” paths of length 2
How about A 3 ? = A3A X A A2A2
What do these represent? = A3A X A A2A2
PRACTICE:COMPUTE A 2 FROM WXYZ W -100 TO X 0-11 Y 10-0 Z 0010 A W Z X Y FROM WXYZ W 0011 TO X 1010 Y 0100 Z 1000 A2A2
PRACTICE:COMPUTE A 3 FROM WXYZ W -100 TO X 0-11 Y 10-0 Z 0010 A W Z X Y FROM WXYZ W 0011 TO X 1010 Y 0100 Z 1000 A2A2 FROM WXYZ W 1010 TO X 1100 Y 0011 Z 0100 A3A3
…i…j…k… i j k Are there other paths from j to i? j i k