Lecture 9 Flashcards
Vector space
Set V of vectors and a field F of scalars with addition and multiplication ⍺v∈V, u+v∈V
- associativity, commutativity, additive identity, additive inverse, associativity wrt scalar multiplication, distributivity wrt scalar/vector addition, scalar multiplication identity
Linear function
f(u+v) = f(u) + f(v) f(⍺u) = ⍺f(u)
f(x) = |x|/x, f:R>R linear?
No
f(x) = ax+b, f:R>R linear?
No
Linear functions as matrix-vector multiplication ?
y = f(x) > y = Ax A(u+v) = Au + Av A(⍺u) = ⍺Au
Shear operator
Change in angle:
1 b
a 1
Rotation operator
cos(θ) -sin(θ)
sin(θ) cos(θ)
Scale operator
a=x-direction, b=y-direction
a 0
0 b
Reflection operator
-a:y-axis symmetry
-a 0
0 -b
Translation
+ (a b)
1 0
0 1
nonlinear!
Permutation matrix
permutation of the identity matrix (swap rows):
0 0 1
1 0 0
0 1 0
Lower/Upper triangular matrix
lower: 0 j more than i, upper: 0 i more than j
Rank
- number of linearly independent columns of the matrix
- rank(A) ≤ min(m,n), if = min(m,n) then full-rank otherwise rank deficient
Singular matrix
A square matrix which is not invertible, that is det(A) = 0 (linearly independent row/columns) - if not singular then rank = n
Sparse matrix
O(min(n,m)) non-zero entries
A+B number of operations dense vs sparse matrices
O(n^2) vs
O(nnz(A)+nnz(B))
Dense representation (DNS)
AA = [#rows #col v1 v2 v3…]
stores zeros, row-wise..
Coordinate representation (COO)
data = [v1 v2 v3...] row = [rowv1, rowv2,...] col = [colv1, colv2...] nnz*doubles + 2nnz*integers no zeros and not sorted
COO how many bytes? (32 bits integer, 64 bits float, 1 byte = 8 bits) 0 0 1.3 -1.5 0.2 0 5 0 0 0 0.3 3 0 0 0
nnz64+2nnz32 = 96 bytes
Compressed Sparse Row representation (CSR)
data = [v1, v2,…] (nnz integers)
col = [colv1, colv2,…] (nnz doubles)
rowptr = [i1, i2,.., in, nnz] (size n+1)
i1 is the starting index in data of row1 (row offset) - always 0!
fast operations between sparse matrices / matrix-vector product.
CSR representation (rowptr) 1 5 0 0 1 0 2 3 0 0 0 0 0 0 0 0 0 0 4 0 0 0 6 9 7
rowptr = [0 3 5 5 6 9]
Inverse of a permutation matrix - nnz
its transpose, nnz = n
Matrix in block form / block diagonal
matrix partitioned into blocks (sub matrices)
M =
A B
C D
block diagonal if off-diagonal matrices are zero matrices (C and B here)
A rotates θ, what rotates -θ?
A.T, A^-1
How many solutions Ax = b if A is non-singular?
1 solution, x=A^-1 b
How many solutions Ax = b if A is singular?
It depends on b
from/to CSR python
import scipy as sp
import scipy.sparse
csr = sp.sparse.csr_matrix(A)
print(csr.indptr)
sp.sparse.csr_matrix( (data,indices,indptr), shape=(x,y) ).todense()