TensorFlow – Mathematical Foundations

In this guide, we will discuss Mathematical Foundations in Tensorflow. It is important to understand mathematical concepts needed for TensorFlow before creating the basic application in TensorFlow. Mathematics is considered as the heart of any machine learning algorithm. It is with the help of core concepts of Mathematics, a solution for specific machine learning algorithm is defined.

Vector

An array of numbers, which is either continuous or discrete, is defined as a vector. Machine learning algorithms deal with fixed length vectors for better output generation.

Machine learning algorithms deal with multidimensional data so vectors play a crucial role.

vector

The pictorial representation of vector model is as shown below βˆ’

vector model

Scalar

Scalar can be defined as one-dimensional vector. Scalars are those, which include only magnitude and no direction. With scalars, we are only concerned with the magnitude.

Examples of scalar include weight and height parameters of children.

Matrix

Matrix can be defined as multi-dimensional arrays, which are arranged in the format of rows and columns. The size of matrix is defined by row length and column length. Following figure shows the representation of any specified matrix.

multi dimensional arrays

Consider the matrix with β€œm” rows and β€œn” columns as mentioned above, the matrix representation will be specified as β€œm*n matrix” which defined the length of matrix as well.

Mathematical Computations

In this section, we will learn about the different Mathematical Computations in TensorFlow.

Addition of matrices

Addition of two or more matrices is possible if the matrices are of the same dimension. The addition implies addition of each element as per the given position.

Consider the following example to understand how addition of matrices works βˆ’

Example:A=[1324]B=[5768]thenA+B=[1+53+72+64+8]=[610812]Example:A=[1234]B=[5678]thenA+B=[1+52+63+74+8]=[681012]

Subtraction of matrices

The subtraction of matrices operates in similar fashion like the addition of two matrices. The user can subtract two matrices provided the dimensions are equal.Example:Aβˆ’[1324]Bβˆ’[5768]thenAβˆ’Bβˆ’[1βˆ’53βˆ’72βˆ’64βˆ’8]βˆ’[βˆ’4βˆ’4βˆ’4βˆ’4]Example:Aβˆ’[1234]Bβˆ’[5678]thenAβˆ’Bβˆ’[1βˆ’52βˆ’63βˆ’74βˆ’8]βˆ’[βˆ’4βˆ’4βˆ’4βˆ’4]

Multiplication of matrices

For two matrices A m*n and B p*q to be multipliable, n should be equal to p. The resulting matrix is βˆ’

C m*qA=[1324]B=[5768]A=[1234]B=[5678]c11=[12][57]=1Γ—5+2Γ—7=19c12=[12][68]=1Γ—6+2Γ—8=22c11=[12][57]=1Γ—5+2Γ—7=19c12=[12][68]=1Γ—6+2Γ—8=22c21=[34][57]=3Γ—5+4Γ—7=43c22=[34][68]=3Γ—6+4Γ—8=50c21=[34][57]=3Γ—5+4Γ—7=43c22=[34][68]=3Γ—6+4Γ—8=50C=[c11c21c12c22]=[19432250]C=[c11c12c21c22]=[19224350]

Transpose of matrix

The transpose of a matrix A, m*n is generally represented by AT (transpose) n*m and is obtained by transposing the column vectors as row vectors.Example:A=[1324]thenAT[1234]Example:A=[1234]thenAT[1324]

Dot product of vectors

Any vector of dimension n can be represented as a matrix v = R^n*1.v1=⎑⎣⎒⎒⎒⎒⎒⎒⎒⎒v11v12β‹…β‹…β‹…v1n⎀⎦βŽ₯βŽ₯βŽ₯βŽ₯βŽ₯βŽ₯βŽ₯βŽ₯v2=⎑⎣⎒⎒⎒⎒⎒⎒⎒⎒v21v22β‹…β‹…β‹…v2n⎀⎦βŽ₯βŽ₯βŽ₯βŽ₯βŽ₯βŽ₯βŽ₯βŽ₯v1=[v11v12β‹…β‹…β‹…v1n]v2=[v21v22β‹…β‹…β‹…v2n]

The dot product of two vectors is the sum of the product of corresponding components βˆ’ Components along the same dimension and can be expressed asv1β‹…v2=vT1v2=vT2v1=v11v21+v12v22+β‹…β‹…+v1nv2n=βˆ‘k=1nv1kv2kv1β‹…v2=v1Tv2=v2Tv1=v11v21+v12v22+β‹…β‹…+v1nv2n=βˆ‘k=1nv1kv2k

The example of dot product of vectors is mentioned below βˆ’Example:v1=⎑⎣⎒123⎀⎦βŽ₯v2=⎑⎣⎒35βˆ’1⎀⎦βŽ₯v1β‹…v2=vT1v2=1Γ—3+2Γ—5βˆ’3Γ—1=10

Next Topic : Click Here

This Post Has One Comment

Leave a Reply