TensorFlow-数学基础
TensorFlow-数学基础 (TensorFlow - Mathematical Foundations)
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.
在TensorFlow中创建基本应用程序之前,了解TensorFlow所需的数学概念非常重要。 数学被视为任何机器学习算法的核心。 借助于数学的核心概念,定义了针对特定机器学习算法的解决方案。
向量 (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.
机器学习算法处理多维数据,因此向量起着至关重要的作用。
The pictorial representation of vector model is as shown below −
向量模型的图形表示如下所示-
标量 (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.
矩阵可以定义为多维数组,以行和列的格式排列。 矩阵的大小由行长和列长定义。 下图显示了任何指定矩阵的表示形式。
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.
考虑如上所述的具有“ m”行和“ n”列的矩阵,矩阵表示将被指定为“ m * n矩阵”,其也定义了矩阵的长度。
数学计算 (Mathematical Computations)
In this section, we will learn about the different Mathematical Computations in TensorFlow.
在本部分中,我们将学习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=\begin{bmatrix}1 & 2 \\3 & 4 \end{bmatrix}B=\begin{bmatrix}5 & 6 \\7 & 8 \end{bmatrix}\:then\:A+B=\begin{bmatrix}1+5 & 2+6 \\3+7 & 4+8 \end{bmatrix}=\begin{bmatrix}6 & 8 \\10 & 12 \end{bmatrix}$$
$$示例:A = \ begin {bmatrix} 1&2 \\ 3&4 \ end {bmatrix} B = \ begin {bmatrix} 5&6 \\ 7&8 \ end {bmatrix} \:then \:A + B = \开始{bmatrix} 1 + 5&2 + 6 \\ 3 + 7&4 + 8 \ end {bmatrix} = \ begin {bmatrix} 6&8 \\ 10&12 \ end {bmatrix} $$
矩阵相减 (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-\begin{bmatrix}1 & 2 \\3 & 4 \end{bmatrix}B-\begin{bmatrix}5 & 6 \\7 & 8 \end{bmatrix}\:then\:A-B-\begin{bmatrix}1-5 & 2-6 \\3-7 & 4-8 \end{bmatrix}-\begin{bmatrix}-4 & -4 \\-4 & -4 \end{bmatrix}$$
$$示例:A- \ begin {bmatrix} 1&2 \\ 3&4 \ end {bmatrix} B- \ begin {bmatrix} 5&6 \\ 7&8 \ end {bmatrix} \:then \:AB -\ begin {bmatrix} 1-5&2-6 \\ 3-7&4-8 \ end {bmatrix}-\ begin {bmatrix} -4&-4 \\-4&-4 \ end {bmatrix} $$
矩阵相乘 (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 −
对于两个矩阵A m * n和B p * q是可乘的, n应该等于p 。 所得矩阵为-
C m*q
立方米
$$A=\begin{bmatrix}1 & 2 \\3 & 4 \end{bmatrix}B=\begin{bmatrix}5 & 6 \\7 & 8 \end{bmatrix}$$
$$ A = \ begin {bmatrix} 1&2 \\ 3&4 \ end {bmatrix} B = \ begin {bmatrix} 5&6 \\ 7&8 \ end {bmatrix} $$
$$c_{11}=\begin{bmatrix}1 & 2 \end{bmatrix}\begin{bmatrix}5 \\7 \end{bmatrix}=1\times5+2\times7=19\:c_{12}=\begin{bmatrix}1 & 2 \end{bmatrix}\begin{bmatrix}6 \\8 \end{bmatrix}=1\times6+2\times8=22$$
$$ c_ {11} = \ begin {bmatrix} 1&2 \ end {bmatrix} \ begin {bmatrix} 5 \\ 7 \ end {bmatrix} = 1 \ times5 + 2 \ times7 = 19 \:c_ {12} = \ begin {bmatrix} 1&2 \ end {bmatrix} \ begin {bmatrix} 6 \\ 8 \ end {bmatrix} = 1 \ times6 + 2 \ times8 = 22 $$
$$c_{21}=\begin{bmatrix}3 & 4 \end{bmatrix}\begin{bmatrix}5 \\7 \end{bmatrix}=3\times5+4\times7=43\:c_{22}=\begin{bmatrix}3 & 4 \end{bmatrix}\begin{bmatrix}6 \\8 \end{bmatrix}=3\times6+4\times8=50$$
$$ c_ {21} = \ begin {bmatrix} 3&4 \ end {bmatrix} \ begin {bmatrix} 5 \\ 7 \ end {bmatrix} = 3 \ times5 + 4 \ times7 = 43 \:c_ {22} = \ begin {bmatrix} 3&4 \ end {bmatrix} \ begin {bmatrix} 6 \\ 8 \ end {bmatrix} = 3 \ times6 + 4 \ times8 = 50 $$
$$C=\begin{bmatrix}c_{11} & c_{12} \\c_{21} & c_{22} \end{bmatrix}=\begin{bmatrix}19 & 22 \\43 & 50 \end{bmatrix}$$
$$ C = \ begin {bmatrix} c_ {11}和c_ {12} \\ c_ {21}和c_ {22} \ end {bmatrix} = \ begin {bmatrix} 19和22 \\ 43和50 \ end {bmatrix} $$
矩阵转置 (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.
矩阵A的转置m * n通常由AT(转置)n * m表示,并且通过将列向量转置为行向量而获得。
$$Example:A=\begin{bmatrix}1 & 2 \\3 & 4 \end{bmatrix}\:then\:A^{T}\begin{bmatrix}1 & 3 \\2 & 4 \end{bmatrix}$$
$$示例:A = \ begin {bmatrix} 1&2 \\ 3&4 \ end {bmatrix} \:then \:A ^ {T} \ begin {bmatrix} 1&3 \\ 2&4 \ end { bmatrix} $$
向量的点积 (Dot product of vectors)
Any vector of dimension n can be represented as a matrix v = R^n*1.
尺寸为n的任何矢量都可以表示为矩阵v = R ^ n * 1。
$$v_{1}=\begin{bmatrix}v_{11} \\v_{12} \\\cdot\\\cdot\\\cdot\\v_{1n}\end{bmatrix}v_{2}=\begin{bmatrix}v_{21} \\v_{22} \\\cdot\\\cdot\\\cdot\\v_{2n}\end{bmatrix}$$
$$ v_ {1} = \开始{bmatrix} v_ {11} \\ v_ {12} \\\ cdot \\\ cdot \\\ cdot \\ v_ {1n} \ end {bmatrix} v_ {2} = \ begin {bmatrix} v_ {21} \\ v_ {22} \\\ cdot \\\ cdot \\\ cdot \\ v_ {2n} \ end {bmatrix} $$
The dot product of two vectors is the sum of the product of corresponding components − Components along the same dimension and can be expressed as
两个向量的点积是相应分量乘积的总和-沿相同维的分量,可以表示为
$$v_{1}\cdot v_{2}=v_1^Tv_{2}=v_2^Tv_{1}=v_{11}v_{21}+v_{12}v_{22}+\cdot\cdot+v_{1n}v_{2n}=\displaystyle\sum\limits_{k=1}^n v_{1k}v_{2k}$$
$$ v_ {1} \ cdot v_ {2} = v_1 ^ Tv_ {2} = v_2 ^ Tv_ {1} = v_ {11} v_ {21} + v_ {12} v_ {22} + \ cdot \ cdot + v_ {1n} v_ {2n} = \ displaystyle \ sum \ limits_ {k = 1} ^ n v_ {1k} v_ {2k} $$
The example of dot product of vectors is mentioned below −
向量的点积示例如下:
$$Example:v_{1}=\begin{bmatrix}1 \\2 \\3\end{bmatrix}v_{2}=\begin{bmatrix}3 \\5 \\-1\end{bmatrix}v_{1}\cdot v_{2}=v_1^Tv_{2}=1\times3+2\times5-3\times1=10$$
$$示例:v_ {1} = \ begin {bmatrix} 1 \\ 2 \\ 3 \ end {bmatrix} v_ {2} = \ begin {bmatrix} 3 \\ 5 \\-1 \ end {bmatrix} v_ {1} \ cdot v_ {2} = v_1 ^ Tv_ {2} = 1 \ times3 + 2 \ times5-3 \ times1 = 10 $$
翻译自: https://www.tutorialspoint.com/tensorflow/tensorflow_mathematical_foundations.htm