### Basic

Transpose:

We use upper case for matrix $M$and lower case for vector $v$.

Distributive, associative & communicative:

Element-wise product:

### Norms

Norms measures the size of vectors.

L1-norm (Manhattan distance):

L2-norm (Euclidian distance): it is commonly used in deep learning and with notation simplified as $\| x\|$. However, L2-norm may not penalize the near-zero parameters enough to push it to 0. Hence, L1-norm is preferable if the sparsity of the model’s parameters is important.

A unit vector is a vector with $\| x \| = 1$.

Lp-norm

$\text{L}_\infty$-norm (max norm)

Frobenius norm: It measures the size of a matrix:

Sometimes, we count the number of non-zero element: add 1 for every non-zero elements.

### Diagonal matrix

A diagonal matrix is a matrix with all non-diagonal element being zero. We form a square diagonal matrix by moving vector elements into the diagonal position of the matrix.

Providing $v$ has no element with zero value, we replace each diagonal element with $\frac{1}{v_{i}}$ to form its inverse $M^{-1}$.

Machine learning may approximate solutions with diagonal matrices because finding inverse or performing matrix multiplication is easy. Non-square diagonal matrix does not have an inverse matrix.

### Symmetric matrix

A symmetric matrix is a matrix with $A_{ij} = A_{ji}$.

In machine learning, many equations in calculating elements between $i \leftrightarrow j$ are not directional ($f(x,y) = f(y,x)$). For example, the distance between 2 points is not directional. Hence, many matrices in machine learning is symmetrical. The inverse of a symmetric matrix is also symmetric. Any real $n \times n$ symmetric matrices can be decomposed into $n$ eigenvalues and eigenvectors which is very desirable in matrix factorization. Symmetric matrix can easily decompose into orthogonal matrices: $A=Q \Lambda Q^T$ which its inverse equals to its transpose.

### Inverse matrix

Properties:

Solving linear equation with an inverse matrix:

$Ax$ is equivalent to the multiplication of each column vectors $A_{:, j}$ with vector element $x_i$:

The span of a set of vectors is the set of points reachable by linear combination of those vectors. The column vectors of $A$ form a column space. A square matrix with linearly dependent columns is known as singular. If $A$ is singular, its inverse does not exist.

In machine learning, we rarely use inverse matrix to solve linear equation. $A^{-1}$ is often not numerical stable: small input errors amplifies output errors. In machine learning, $A$ is often a sparse matrix, however, the inverse is not which will take too much memory.

### Orthogonal matrix

A set of vectors are orthonormal if and only if the inner product of any two vectors are zero. An orthogonal matrix is a square matrix whose rows (columns) are mutually orthonormal. i.e. no dot products of 2 row vectors (column vectors) are 0.

For an orthogonal matrix, there is one important property. Its inverse is the transpose which is very easy to compute. $A A^T = I \Rightarrow A^{-1} A A^T = A^{-1} I \Rightarrow A^T = A^{-1}$.

Also orthogonal matrices $Q$ does not amplify errors which is very desirable.

The size of the multiplication result $\|Qx\|$ has the same size as $\|x\|$. If we multiple $x$ with orthogonal matrices, the errors present in $x$ will not be amplified by the multiplication. i.e. it is more numeric stable.

Decompose matrix into smaller components helps us to solve some problems faster with better numeric stability. Here is the pseudo code to use SVD to decompose matrix into orthogonal matrices and solve the linear equation with the result.

where $D^{+}$ takes the reciprocal $\frac{1}{x_i}$ of the non-zero elements of $D$ and then transpose.

### Quadric form equation in Matrix

A quadric form equation contains terms $x^2, y^2$ and $xy$.

The matrix form of a quadratic equation:

With 3 variables:

### Eigen vector & eigen value

Scalar $\lambda$ and vector $v$ are the eigenvalue and eigenvector of $A$ respectively if:

Properties:

• A $n \times n$ matrix has at most $n$ eigenvalues and eigenvectors.
• A matrix is singular iff any eigenvalues are 0.

Find the eigenvalues and eigenvectors for $A$.

#### Finding the eigenvalues

Find the eigenvalues of:

To solve:

The possible factors for 16 are 1, 2, 4, 8, 16.

when $λ=4$, $λ^3 - 12 λ - 16 = 0$

So $λ^3 - 12 λ - 16 = (λ − 4)(λ^2 + 4λ + 4) = 0$

By solving the root, the eigenvalues are -4, 2, -2.

#### Finding the eigenvectors

Doing row reduction to solve the linear equation $(A - \lambda I) v = 0$

Appending 0:

Perform $R_1 = - \frac{1}{3} R_1$

Perform row subtraction/multiplication:

After many more reductions:

So for $\lambda=4$, the eigenvector is:

### Eigendecomposition

Matrix decomposition decompose a matrix into special type of matrices for easy manipulation in solving problems like linear equations. But eigendecomposition is only defined for square matrices.

Say $A$ has $n$ eigenvalues $\lambda_1, \lambda_2, \cdots, \lambda_n$. We concatenate all values to form a column vector $\lambda = [\lambda_1, \lambda_2, \cdots, \lambda_n]^T$. $A$ also has $n$ eigenvectors $v_1, v_2, \cdots, v_n$. We compose a matrix $V$ with $v_i$ as the column $i$ of the matrix. $V= [v^{(1)}, . . . ,v^{(n)}]$. The eigen decomposition of A is:

Not every $A$ has eigendecomposition. But in deep learning, we often due with real symmetric metrics. Real symmetric metrics are eigendecomposable and the equation can be further simplify to:

which $Q$ is an orthogonal matrix composed of eigenvectors of $A$. $\Lambda$ is a diagonal matrix. The value of diagonal element $\Lambda_{ii}$ is the eigenvalue of the corresponding eigenvector in column $i$ of $Q$. We do not specify the order of eigenvectors. Therefore different order of $v^{(i)}$ creates different $V$. By convention, we re-arrange the column order $v^{(i)}$ in $v$ by the descending sorting order of its eigenvalue $\lambda_i$. It helps us to decompose $A$ in a more deterministic way.

In eigendecomposition, we decompose the matrix $A$ into different eigenvectors $v^{(i)}$ scaled by the eigenvalue $\lambda_i$. Therefore, for any vectors pointing at the same direction of eigenvector $v^{(i)}$, $Ax$ scales $x$ by the corresponding eigenvalue $\lambda_i$.

For a quadratic equation in the form of $f(x) = x^TAx$, if $x$ is an unit vector equal to $v^{(i)}$, $f(x)$ will be equal to the eigenvalues $\lambda_i$. Therefore, the max and min of $f(x)$ is the max and min of the eigenvalues.

### Singular value decomposition (SVD)

SVD factorizes a matrix into singular vectors and singular values. Every real matrix has a SVD but not true for eigendecomposition.

• A is a m×n matrix. (Does not need to be a square matrix like eigendecomposition.)
• Left-singular vector: U is a m×m orthogonal matrix (the eigenvectors of $A A^T$)
• Reft-singular vector: V is a n×n orthogonal matrix (the eigenvectors of $A^T A$)
• Singular values: D is a m×n diagonal matrix (square roots of the eigenvalues of $A A^T$ and $A^T A$ )

SVD is a powerful but expensive matrix factorization method. In numerical linear algebra, many problems can be solved to represent $A$ in this form.

### Positive definite or negative definite matrix

If all eigenvalues of $A$ are:

• positive: the matrix is positive definite.
• positive or zero: positive semi-deﬁnite.
• negative: the matrix is negative definite.

If a matrix is positive semi-deﬁnite, $x^TAx \geq 0$. If a matrix is positive definite and $x^TAx = 0$, it implies $x = 0$.

Positive definite or negative definite helps us to solve optimization problem. Quadratic equation $x^TAx$ with positive definite matrices $A$ are always positive for non-zero $x$ and the function is convex. i.e. it guarantees the existences of the global minimum. This allows us to use Hessian matrix to solve the optimization problem. Similar arguments hold true for negative definite.

### Trace

Trace is the sum of all diagonal elements

We can rewrite some operations using Trace to get rid of the summation (like the summation in the Frobenius norm):

Other properties:

### Derivative of matrix

For vector $x$:

For matrix $X$:

Example, Optimize mean square error of a linear regression.

Given: $N$ is the size of the dataset, $\hat{y} , y \in \mathbb{R}^N$, $w \in \mathbb{R}^k$, $X \in \mathbb{R}^{N \times k}$.

### Principal Component Analysis (PCA)

PCA encodes a n-dimensional input space into an m-dimensional output space with $n > m$. We want to minimize the amount of information lost during the reduction and minimize the difference if it is reconstructed.

Let’s $f$ and $g$ be the encoder and the decoder:

We apply a linear transformation to decode $c$. We constraint $D$ to be a matrix $\mathbb{R}^{n \times m}$ composed of columns that is orthogonal to each other with unit norm. (i.e. $D^TD = I_l$.)

PCA uses L2-norm to minimize the reconstruction error.

Compute L2-norm:

Optimize $c$:

To optimize it:

So, the optimize encode and decode scheme is

To find the optimal transformation $D^{*}$, we want to optimize $D$ over all datapoint $x^{(i)}$:

Let’s consider $l=1$, so D is just a vector $d$.

where $X$ contains all datapoints. Xdd $% $

This equation can be solved using eigendecomposition. Optimal $d$ is the eigenvector of $X^TX$ that has the largest eigenvalue. For $l > 1$, the matrix D is given by the eigenvectors corresponding to the $l$ largest eigenvalues.

### Moore-Penrose Pseudoinverse

For a linear equation:

A^{+} is a pseudo inverse of matrix A. We do not called it $A^{-1}$ because inverse matrix is only defined for a square matrix.

$A^{+}$ is computed as (if exist):

which $U, D \text{ and } V$ are the SVD of $A$. The pseudoinverse $D^{+}$ of a diagonal matrix D is computed by taking the reciprocal $\frac{1}{x}$ of all non-zero elements then taking the transpose of the resulting matrix.

### Determinant

The determinant of the matrix $A$ is the product of all eigenvalues. If the absolute value is greater than 1, $Ax$ expands the output space. If it is between 0 and 1, it shrinks the space.