Linear Algebra
Introduction to Linear Algebra:
Scalars:
A scalar is just a single number. A scalars type is defined of being either a real number or an integer
Vectors:
A vector is an array of numbers arranged in an order. We need to specify what kind of numbers are stored in the vector.
We can think of a vector as identifying a point in space, with each element giving the coordinate along a different axis
Matrices:
A matrix is a 2-D array of numbers, so each element is identified using two indices.
What are linear transformations?
A transformation is linear if all lines must remain lines without getting curved and origin must remain fixed in its place.
Think of rotation transformation as a linear transformation.
Now given a single point in the reference space how can we get the coordinates of that point in the transformed space?
We can do this by creating a matrix that can represent the trasformation. Then by doing the matrix multiplication with the vector of the point, we can get the coordinates of the point in the transformed space.
Thus linear transformation can be understood as a function that takes in a vector and produces a vector.
Tensors:
In some cases we will need array of more than two axes. In the general case, an array of numbers arranged on a regular grid with a variable number of axes is known as a tensor.
Operations on Matrices:
Transpose:
One important operation of matrices is transpose. The transpose of a matrix is its mirror image across a diagonal line called the main diagonal, running down and to the right, strating from the top left corner
Adding Matrices:
We can add matrices together as long as they have the same shape just by adding their corresponding elements
Scalar Multiplication and Addition:
We can also add a scalar to a matric or multiply a matrix by a scalar just by performing that operation on each element of a matrix.
Multiplying Matrices and Vectors:
The matrix product of the matrices A and B is a third matrix C.
For the product to be valid the number of columns of A should be equal to the number of rows of B
The dot product between two vectors and of same dimensionality is the matrix product
We can think of matrix product as computing the as the dot product between row i of the and column j of
Matrix Product is distributive:
Matrix Product is associative
What is the significance of Matrix Multiplication?
Matrix Multiplication can be thought of as a composition of linear transformation. When applying transformation one after another we can simply compute their multiplication and get a single linear transformer.
This makes the associativity of the matrix multiplication intuitive.
Hadamard Product:
Hadamard product or elementwise product is an operation betwen two matrices where the corresponding elements are multiplie together
Identity and Inverse Matrices:
An identity matrix is a matrix that does not change any vector when we multiply that vector by that matrix.
For identity matrix all the entries along the main diagonal are 1 else are 0
The matrix inverse of is denoted as , and is defined as the matrix such that
Determinants:
Determinants give the factor by which the space is modified.
For a 2D matrix the determinant will tess us how the area is modified
For a 3D matrix the determinant will tess us how the volume is modified
System of Linear Equations:
where is a known matrix, is a vector of unknown variables we would like to solve for.
We can rewrite the equation as follows
Using inverse matrices we can write the solution for the above equation as follows:
In order for to exists the equation must have exactly one solution for every value of b.
To analyze how many solutions the equation has, we can think of the columns of as specifying different directions we can travel from origin and specifying how far we should travel in each of those directions.
In general this kind of operation is called a linear combination.
The span of a set of vectors is the set of all points obtainable by the linear combination of the original vectors.
Thus, determining whether has a solution amounts to testing whether is in the span of columns of
In order for the system to have solution for all values of we therefore require that the column span of be all of
The requirement that the column span of be all of implies that must have atleast columns
This is a necessary condition but not sufficient. It is possible for some of the columns to be redundant.
Formally, this kind of redundancy is known as linear dependence. For the columns space of the matrix to encompass all of , the matrix must contain atleast one set of linearly independent columns.
A set of vectors is linearly independent if no vector in the set is a linear combination of the other vectors
In order for the matrix to have an inverse, we additionally need to ensure that has atmost one solution for each for this we need to ensure that the matrix has atmost columns.
Together this means that the matrix must be square and that all the columns of the matrix are linearly independent.
Norms:
the norm of a vector measures the distance from the origin to the point .
In machine learning, we usually measure the size of the vectors using a function called a norm.
Formally the norm is given by:
The norm is called the euclidean norm. The norm is most frequently used in Machine learning and is denoted simply as
The norm is commonly used in machine learning when difference between zero and non-zero elements is very important.
Another norm that commonly arises in machine learning is the norm also known as the max norm. this norm simplifies to the maximum absolute value of the element in the vector.
Special Matrices and Vectors:
1. Diagonal Matrices
Consists of non-zero entries only along the main diagonal and have zero elsewhere.
We write to denote a square diagonal matrix whose diagonal entries are given by the entries of the vector .
Diagonal matrix are of interest because multiplying by a diagonal matrix is very computationally efficient.
To compute , we only need to scale each element by . In other words
Inverting a square diagonal matrix is also efficient.
The inverse exists if every diagonal entry is nonzero, and in that case,
2. Symmetric Matrix
is any matrix that is also equal to its transpose
3. A unit vector
is a vector with unit norm
4. Orthogonal vectors
A vector and vector are orthogonal to one another if
Eigen decomposition:
Many mathematical objects can be understood better by breaking them into its constituent parts, or finding some properties of them that are universal.
We can also decompose matrices in ways that show us information about their functional properties that is not obvious from the representation of the matrix
Eigen decomposition decomposes a matrix into a set of eigenvectors and eigenvalues.
An eigenvector of a square matrix is a non-zero vector such that multiplication by alters only the scale of
the scalar is called the eigenvalue corresponding to the eigenvector .
If is a eigenvector of then so is any rescaled vector where , with the same eigenvalue .
Suppose that a matrix has linearly independent eigen vectors with corresponding eigen values . We can concatenate all of the eigen vectors to form the matrix with one eigen vector per column .
Likewise we can concatenate eigenvalues to form a vector . The eigendecomposition of is then given by
A matrix whose eigenvalues:
- all positive is called positive definite.
- all non-negative is called positive semi-definite.
- all negative is called negative definite.
- all non-positive is called negative semi-definite.
SVD - Singular value Decomposition:
SVD provides another way to factorize a matrix into singular vectors and singular values.
Every real matrix has a singular value decomposition, but the same is not true of the eigenvalue decomposition.
For SVD we can rewrite as the product of three matrices.
- - matrix
- - matrix is the left singular matrix and are the eigen vectors of
- - matrix is the right singular matrix and are the eigen vectors of
- - matrix are the singular values and are the eigen values of either or
The most useful feature of the SVD is that we can use it to partially generalize matrix inversion to non-square matrices.
Moore Penrose Pseudo Inverse:
Matrix inversion is not defined for matrices that are not square.
Suppose we want to solve the linear equation where is a rectangular matrix then following cases arise for
: there can be multiple many solution:
Solving the linear equation with gives one of the many possible solutions with the minimal norm
there might not be any possible solution:
Solving the linear equation with gives for which is as close as possible to .
Trace Operator:
the trace operator gives the sum of all diagonal entries of a matrix.
Determinant:
The determinant is equal to the product of all the eigen values of the matrix.
The absolute value of the determinant can be through of as a measure of how much multiplication by the matrix expands or contracts the space.
If the determinant is , then the space is contracted completely along atleast one dimension, causing it to lose all of its volume.
If the determinant then the transformation is volume preserving.
Principal Component Analysis:
We have a collection of points. We would like to apply lossy compression to the points. Lossy compression means storing the points in a way that requires less memory but may loose some precision.
For each point we will find a corresponding code vector such that .
We will want to find some encoding function that produces the code for an input and a decoding function that produces the reconstructed input given its code
Here the encoding function is given by
The decoding function is given by
The encoding matrix is given by the eigen vectors of corresponding to the largest eigen values.
