Blog Logo
AIML Resident @ Apple
·
read
Image Source: https://ka-perseus-images.s3.amazonaws.com/6eca6b57567643dd7743f2efc5c90e6bad3133d8.png
· · ·

Basics of Machine Learning Series

Index

· · ·

Matrices

In mathematics, a matrix is a rectangular array of numbers, symbols, or expressions, arranged in rows and columns. For example, A is a matrix below,

Dimension of a matrix is given by n * m where n is number of rows and m is number of columns. So the matrix above is a 2*3 matrix. It is also sometimes represented as \(\mathbb{R}^{2*3}\).

Matrices are generally represented with uppercase. Also, if A is a matrix, \(A_{ij}\) is the i,j entry i.e. the element in \(i^{th}\) row and \(j^{th}\) column. For example,

Vectors

In mathematics, vector is a matrix that has only one column. For example, x is a vector below,

So effectively vector is a n * 1 matrix where n is the number of rows. It is termed as n-dimensional vector. It is also sometimes represented as \(\mathbb{R}^n\).

Vectors are generally represented with lowercase. Also, if x is a matrix, \(x_{i}\) is the element in \(i^{th}\) row. For example,

Vectors can be 0 or 1 indexed i.e. the start of index numbering may begin with 0 or 1. Generally in mathematics, 1-indexed notation is followed while in computer science 0-indexed notation is more popular.

Matrix Addition

  • Matrix addition is nothing but adding them element by element.
  • Only matrices of same dimensions can be added
  • The resultant matrix has same dimension.
  • The operation is commutative, associative and distributive.

For example,

Scalar Multiplication

  • Scalar multiplication is multiplication of a real number with each element of the matrix.
  • The resultant matrix has the same dimension.
  • The operation is commutative, associative and distributive.

For example,

Matrix operation follow the BODMAS rule for the order of precedence.

Matrix Vector Multiplication

Consider matrix A and vector x, then the matrix-vector multiplication is given by,

Following properties are inferred:

  • Operation is not always commutative.
  • Number of columns in matrix A has to match the number of rows in vector x.
  • The resultant vector of the multiplication is of dimension n as can be seen above. So if A is m*n and x is n-dimensional then, resultant is m-dimensional vector.

Application A hypothesis \(h_\theta(x) = -40 + 0.25\,x\) can be applied to a set of x’s such as (2104, 1416, 1534, 852) then it can be done as follows,

Matrix-Matrix Multiplication

It is a binary operation that produces a matrix from two matrices. So, if A is \(n * m\) matrix and B is a \(m * p\) matrix, then their product AB is a \(n * p\) matrix. The m enteries along rows of A are multiplied with the m enteries along the column of B and summed to produce elements of AB. When two linear transformations are represented by matrices, then the matrix product represents the composition of the two transformations.

Following properties are inferred:

  • Operation is not always commutative.
  • Number of columns in matrix A has to match the number of rows in vector x.

Application Consider three hypothesis as follows,

All three can be applied to a set of inputs as shown in matrix-vector multiplication.

Here, each column corresponds to a specific hypothesis.

Matrix Multiplication Properties

  • Commutative Property: Scalar multiplication is commutative while matrix multiplication is not commutative.
  • Associative Property: Scalar and matrix multiplication are both associative.
  • Identity Matrix: Denoted by I (or \(I_{n*n}\)) has all elements zero except for the main diagonal elements which are set to 1. It has the following properties.

Inverse

In the space of real numbers each number is said to have an inverse if the product of the number and the inverse results in the identity i.e. 1. Also not all the real numbers have an inverse, for example, the number 0 does not have an inverse, because 1/0 is undefined.

Similarly, a matrix A is said to have an inverse if there exists a \(A^{-1}\) such that

Only square matrices have inverses.

Matrices that do not have an inverse are called singular or degenerate matrices.

Transpose

Given a matrix A, having dimension m * n and let \(B = A^T\) be its transpose, then B is a n * m matrix such that,

It is basically the operation where each row is sequentially replaced as a column in the resultant matrix.

REFERENCES:

Machine Learning: Coursera - Matrices and Vectors
Machine Learning: Coursera - Addition and Scalar Multiplication
Machine Learning: Coursera - Matrix Vector Multiplication
Machine Learning: Coursera - Matrix Matrix Multiplication
Machine Learning: Coursera - Matrix Multiplication Properties
Machine Learning: Coursera - Inverse and Transpose
Matrix Multiplication: Wikipedia

· · ·