quiz
play

Quiz Let a 1 = [1 , 0 , 1] , a 2 = [2 , 1 , 0] , a 3 = [10 , 1 , 2] - PowerPoint PPT Presentation

Quiz Let a 1 = [1 , 0 , 1] , a 2 = [2 , 1 , 0] , a 3 = [10 , 1 , 2] , a 4 = [0 , 0 , 1]. Compute the row-matrix-by-vector product a 1 a 2 times [7 , 6 , 5] a 3 a 4 Let v 1 = [2 , 1 , 0 , 1] , v 2 = [4 ,


  1. Quiz Let a 1 = [1 , 0 , − 1] , a 2 = [2 , 1 , 0] , a 3 = [10 , 1 , 2] , a 4 = [0 , 0 , 1]. Compute the row-matrix-by-vector product a 1   a 2    times [7 , 6 , 5]   a 3  a 4 Let v 1 = [2 , 1 , 0 , 1] , v 2 = [4 , − 1 , 0 , 2] , v 3 = [0 , 1 , 0 , 1]. Compute the column-matrix-by-vector product       v 1 v 2 v 3 times [2 , − 1 , 1]      

  2. The Matrix [3] The Matrix Neo: What is the Matrix? Trinity: The answer is out there, Neo, and it’s looking for you, and it will find you if you want it to. The Matrix , 1999

  3. Two views of same process Row-matrix-by-vector multiplication and column-matrix-by-vector multiplication are same!         a 1 b 1 c 1 a 2 b 2 c 2          times [ x 1 , x 2 , x 3 ]   .   .   .   . . .         . . .        a m b m c m       a 1 b 1 c 1 a 2 b 2 c 2       = x 1 + x 2 + x 3  .   .   .  . . .       . . .       a m b m c m       x 1 a 1 x 2 b 1 x 3 c 1 x 1 a 2 x 2 b 2 x 3 c 2       = + +  .   .   .  . . .       . . .       x 1 a m x 2 b m x 3 c m

  4. Two views of same process Row-matrix-by-vector multiplication and column-matrix-by-vector multiplication are same!       a 1 b 1 c 1 a 2 b 2 c 2       = + + x 1 x 2 x 3  .   .   .  . . .       . . .       a m b m c m       x 1 a 1 x 2 b 1 x 3 c 1 x 1 a 2 x 2 b 2 x 3 c 2       = + +  .   .   .  . . .       . . .       x 1 a m x 2 b m x 3 c m   x 1 a 1 + x 2 b 1 + x 3 c 1 x 1 a 2 + x 2 b 2 + x 3 c 2   = .   .   .   x 1 a m + x 2 b m + x 3 c m

  5. Two views of same process Row-matrix-by-vector multiplication and column-matrix-by-vector multiplication are same!       x 1 a 1 x 2 b 1 x 3 c 1 x 1 a 2 x 2 b 2 x 3 c 2       = + +  .   .   .  . . .       . . .       x 1 a m x 2 b m x 3 c m   x 1 a 1 + x 2 b 1 + x 3 c 1 x 1 a 2 + x 2 b 2 + x 3 c 2   =  .  .   .   x 1 a m + x 2 b m + x 3 c m

  6. Two views of same process   x 1 a 1 + x 2 b 1 + x 3 c 1 x 1 a 2 + x 2 b 2 + x 3 c 2   =  .  .   .   x 1 a m + x 2 b m + x 3 c m   ( a 1 , b 1 , c 1 ) · ( x 1 , x 2 , x 3 ) ( a 2 , b 2 , c 2 ) · ( x 1 , x 2 , x 3 )   = .   .   .   ( a m , b m , c m ) · ( x 1 , x 2 , x 3 )  [ a 1 , b 1 , c 1 ]  [ a 2 , b 2 , c 2 ]   =  times [ x 1 , x 2 , x 3 ]  .  .   .  [ a m , b m , c m ]

  7. Two views of same process         a 1 b 1 c 1 a 2 b 2 c 2         We showed  times [ x 1 , x 2 , x 3 ]   .   .   .   . . .         . . .        a m b m c m   [ a 1 , b 1 , c 1 ] [ a 2 , b 2 , c 2 ]   =  times [ x 1 , x 2 , x 3 ]  .  .   .  [ a m , b m , c m ]           [ a 1 , b 1 , c 1 ] a 1 b 1 c 1 a 2 b 2 c 2 [ a 2 , b 2 , c 2 ]           so  is same as   .   .   .    .  . . . .           . . . .          a m b m c m [ a m , b m , c m ]

  8. Row matrix and column matrix are same  1 2 3   1 2 3  4 5 6 4 5 6     Example:  same as     7 8 9 7 8 9    10 11 12 10 11 12 Same underlying math’l object, different representations ◮ column-list representation ◮ row-list representation of a MATRIX One operation, matrix-vector multiplication, with two interpretations: ◮ dot-product interpretation: output vector entries are dot-products of rows with input vector ◮ linear-combinations interpretation: output vector is linear combination of columns where coeff’s are input vector entries You must memorize which is which.

  9. The Matrix Traditional notion of a matrix: two-dimensional array. � 1 � 2 3 10 20 30 ◮ Two rows: [1 , 2 , 3] and [10 , 20 , 30]. ◮ Three columns: [1 , 10], [2 , 20], and [3 , 30]. ◮ A 2 × 3 matrix. For a matrix A , the i , j element of A ◮ is the element in row i , column j ◮ is traditionally written A i , j ◮ but we will use A [ i , j ]

  10. List of row-lists, list of column-lists ◮ One obvious Python representation for a matrix: a list of row-lists: � 1 � 2 3 represented by [[1,2,3],[10,20,30]] . 10 20 30 ◮ Another: a list of column-lists: � 1 � 2 3 represented by [[1,10],[2,20],[3,30]] . 10 20 30

  11. List of row-lists, list of column-lists Ungraded “Quiz”: Write a nested comprehension whose value is list-of- row -list representation of a 3 × 4 matrix all of whose elements are zero:   0 0 0 0 0 0 0 0   0 0 0 0 Hint: first write a comprehension for a typical row, then use that expression in a comprehension for the list of lists. Answer: >>> [[0 for j in range(4)] for i in range(3)] [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]

  12. The matrix revealed The Matrix Revisited (excerpt) http://xkcd.com/566/ Definition: For finite sets R and C , an R × C matrix over F is a function from R × C to F . ◮ R = { a , b } and C = { @ , # , ? } . @ # ? a 1 2 3 ◮ R is set of row labels b 10 20 30 ◮ C is set of column labels In Python, the function is represented by a dictionary: {(’a’,’@’):1, (’a’,’#’):2, (’a’, ’?’):3, (’b’, ’@’):10, (’b’, ’#’):20, (’b’,’?’):30}

  13. Rows, columns, and entries @ # ? a 1 2 3 b 10 20 30 Rows and columns are vectors, e.g. ◮ Row ’a’ is the vector Vec( { ’@’, ’#’, ’?’ } , { ’@’:1, ’#’:2, ’?’:3 } ) ◮ Column ’#’ is the vector Vec( { ’a’,’b’ } , { ’a’:2, ’b’:20 } )

  14. Dict-of-rows/dict-of-columns representations @ # ? a 1 2 3 b 10 20 30 One representation: dictionary of rows: {’a’: Vec({’#’, ’@’, ’?’}, {’@’:1, ’#’:2, ’?’:3}), ’b’: Vec({’#’, ’@’, ’?’}, {’@’:10, ’#’:20, ’?’:30})} Another representation: dictionary of columns: {’@’: Vec({’a’,’b’}, {’a’:1, ’b’:10}), ’#’: Vec({’a’,’b’}, {’a’:2, ’b’:20}), ’?’: Vec({’a’,’b’}, {’a’:3, ’b’:30})}

  15. Our Python implementation @ # ? a 1 2 3 b 10 20 30 >>> M=Mat(({’a’,’b’}, {’@’, ’#’, ’?’}), {(’a’,’@’):1, (’a’,’#’):2,(’a’,’?’):3, (’b’,’@’):10, (’b’,’#’):20, (’b’,’?’):30}) A class with two fields: ◮ D , a pair ( R , C ) of sets. ◮ f , a dictionary representing a function that maps pairs ( r , c ) ∈ R × C to field elements. We will later add lots of matrix class Mat: operations to this class. def __init__(self, labels, function): Example: For a Mat M , M [ r , c ] self.D = labels is the entry in row r , column c . self.f = function

  16. Identity matrix For any domain D , there is a matrix that represents the D -to- D identity function f ( x ) = x a b c ------- a | 1 0 0 b | 0 1 0 c | 0 0 1 Definition: D × D identity matrix is the matrix 1 D such that 1 D [ k , k ] = 1 for all k ∈ D and zero elsewhere. Usually we omit the subscript when D is clear from the context. Often letter I (for “identity”) is used instead of 1 Mat(({’a’,’b’,’c’},{’a’,’b’,’c’}),{(’a’,’a’):1,(’b’,’b’):1,(’c’,’c’):1}) Quiz: Write procedure identity( D ) that returns the D × D identity matrix over R represented as an instance of Mat . Answer: def identity(D): return Mat((D,D), (k,k):1 for k in D)

  17. Converting between representations Converting an instance of Mat to a column-dictionary representation: @ # ? 1 2 3 a b 10 20 30 Mat(({’a’,’b’}, {’@’, ’#’, ’?’}), {(’a’,’@’):1, (’a’,’#’):2, (’a’,’?’):3, (’b’,’@’):10, (’b’,’#’):20, (’b’,’?’):30}) ⇒ {’@’: Vec({’a’,’b’}, {’a’:1, ’b’:10}), ’#’: Vec({’a’,’b’}, {’a’:2, ’b’:20}), ’?’: Vec({’a’,’b’}, {’a’:3, ’b’:30})} Quiz: Write the procedure mat2coldict(A) that, given an instance of Mat , returns the column-dictionary representation of the same matrix. Answer: def mat2coldict(A): return {c:Vec(A.D[0],{r:A[r,c] for r in A.D[0]}) for c in A.D[1]}

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend