360 likes | 504 Views
Graphs and Matrices. Four Representations of a Graph. G={V,E}. EDGE List AB AD AE BA BC BD CA CB CD DA DB DC EA. MATRIX. NODE List A B D E B A C D C A B D D A B C E A. E. A. B. D. C. Matrix. COLUMNS. ROWS. The MAIN DIAGONAL. A matrix ELEMENT. SQUARE MATRIX.
E N D
Four Representations of a Graph G={V,E} EDGE List AB AD AE BA BC BD CA CB CD DA DB DC EA MATRIX NODE List A B D E B A C D C A B D D A B C E A E A B D C
Matrix COLUMNS ROWS The MAIN DIAGONAL A matrix ELEMENT SQUARE MATRIX RECTANGULAR MATRIX
Nomenclature: nrows by mcols 2x4 matrix 3x3 matrix 5x2 matrix 3x1 matrix
Matrix • A table of values arranged in ordered rows and columns • Elements of matrix M referred to by row and column number as subscripts • An unspecified element is referred to generically as being in row i and column j
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 connectedto 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 • Multiplication • Row of first matrix times column of second • Element by element multiplication • Sum the products
Example: Convert 2-Mode to 1-Mode(s) • Write the rectangular incidence matrix I 1 2 3 GROUPS A B C D PEOPLE A “groups by people” matrix
Example: Convert 2-Mode to 1-Mode(s) • Compute transpose of I, IT 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) APxP 2122 1221 2232 2122 AGxG 313 122 324 I 1011 0110 1111 I 1011 0110 1111 x = x = IT 101 011 111 101 IT 101 011 111 101
Degree • DEF: degree of vertex is number of edges connected to it • Written as • For undirected graph, sum of row i of matrix - 1 0 0 0 1 - 0 1 0 0 0 - 1 1 0 1 1 - 1 0 0 1 1 -
Mean(average) Degree • The mean degree, c, in a graph is the sum of all the vertex degrees divided by the number of vertices:
Degree and Edges • Each of m edges has two ends and so contributes 2 to the total degree in graph. Thus • But • So • Which is just the sum of all the elements of the adjacency matrix (since we run through all the j’s for each i – adding up row by row as we go)
Adjacency Matrix • One row and one column for each vertex • Each matrix element describes link between row vertex and column vertex
Matrix Arithmetic • Addition and Subtraction • Element by element See also: http://www.jtaylor1142001.net/calcjat/Contents/CMatrix.htm#MatrixMult
- 1 0 0 0 0 - 0 1 0 0 0 - 0 0 0 1 1 - 1 0 0 1 0 - Directed Unweighted 1 1 E E E E 2 2 D D D D 5 5 C C C C dichotomize 1 1 symmetrize A A A A 4 4 B B B B Undirected Unweighted Directed Weighted - 1 0 0 0 - 0 1 0 - 1 1 - 1 - - 4 0 0 0 0 - 0 1 0 0 0 - 0 0 0 1 5 - 1 0 0 2 0 - symmetrize dichotomize Undirected Weighted - 4 0 0 0 4 - 0 1 0 0 0 - 5 2 0 1 5 - 1 0 0 2 1 -
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 Path A to C? A B C
Put another way • An edge from vertex j to vertex i means Aij=1 • If there is a 2-path from j to i then there is a k such that Aik=1 and Akj=1. j k i
Aik=1 and Akj=1 • That means: if there is a path from vertex j to vertex k to vertex i THENthere is a k such that AikAkj=1 There is an edge from k to i j c b There is an edge from j to k k i a
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 A2ij is how many times the row version and the column version have 1s in the same place j i
Are there other paths from j to i? • Yes, if there are other k’s such that AikAkj=1 • In fact, we can write • But this is just the number of times that we get 1 and 1 as we look down column j and across row i j k i
Example: Convert 2-Mode to 1-Mode(s) • Compute transpose of I, IT 1 2 3 A B C D
Degree Distribution • “Distribution of X” = pattern of different values X takes on • More specifically: the frequency of each value 1 || 2 |||| ||| 3 |||| 4 |||| | 5 ||| 2 2 3 4 4 4 4 5 3 5 2 5 2 3 2 4 2 4 3 2 4 4 3 3 4 2 4 1 5 3 2 2 5 1 2 5 2 3 4 4 2 3 3 2 1 2 2 1
Why? Degree equals number of “out and back” paths of length 2
PRACTICE:COMPUTE A2 W X Y Z
PRACTICE:COMPUTE A3 W X Y Z
Are there other paths from j to i? • Yes, if there are other k’s such that AikAkj=1 • In fact, we can write • But this is just the number of times that we get 1 and 1 as we look down column j and across row i j k i