当前位置:网站首页>Huashu "deep learning" and code implementation: 01 Linear Algebra: basic concepts + code implementation basic operations
Huashu "deep learning" and code implementation: 01 Linear Algebra: basic concepts + code implementation basic operations
2022-04-23 02:40:00 【LiBiGor】
1 Scalar 、 vector 、 Matrices and tensors
2 Matrix and vector multiply
3 Identity matrix and inverse matrix
3.0 Unit matrix
a = np.identity(3) # Three row and three column identity matrix
3.1 The matrix of the inverse
A = [[1.0,2.0],[3.0,4.0]]
A_inv = np.linalg.inv(A)
print("A The inverse matrix ", A_inv)
3.1 Transposition
A = np.array([[1.0,2.0],[1.0,0.0],[2.0,3.0]])
A_t = A.transpose()
print("A:", A)
print("A The transpose :", A_t)
3.2 Matrix addition
a = np.array([[1.0,2.0],[3.0,4.0]])
b = np.array([[6.0,7.0],[8.0,9.0]])
print(" Matrix addition : ", a + b)
3.3 Matrix multiplication
m1 = np.array([[1.0,3.0],[1.0,0.0]])
m2 = np.array([[1.0,2.0],[5.0,0.0]])
print(" According to the rules of matrix multiplication : ", np.dot(m1, m2))
print(" Multiply by element : ", np.multiply(m1, m2))
print(" Multiply by element : ", m1*m2)
v1 = np.array([1.0,2.0])
v2 = np.array([4.0,5.0])
print(" Vector inner product : ", np.dot(v1, v2))
4 Linear correlation and generating subspace
5 norm
5.0 Code implementation
5.0.1 Vectorial L1 L2 The infinite norm
a = np.array([1.0,3.0])
print(" vector 2 norm ", np.linalg.norm(a,ord=2))
print(" vector 1 norm ", np.linalg.norm(a,ord=1))
print(" Vector infinite norm ", np.linalg.norm(a,ord=np.inf))
5.0.2 Matrix F norm
a = np.array([[1.0,3.0],[2.0,1.0]])
print(" matrix F norm ", np.linalg.norm(a,ord="fro"))
5.1 The general definition of norm
A norm is a function that maps a vector to a nonnegative value . Intuitively speaking , vector x From the origin to the point x Distance of .
5.1.1 Definition

5.1 L1 norm
5.1.1 Definition
When the difference between zero and non-zero elements in machine learning is very important , In these cases , Instead, use the same slope at each position , You usually use L1 norm , It is also often used as an alternative function to represent the number of non-zero elements .
5.1.2 Mathematical expression

5.2 L2 norm / Euclid Norm
Represents starting from the origin to the vector x Euclidean distance of a certain point .
5.2.1 square L2 norm
It is also often used to measure the size of vectors , It can be calculated simply by point product , It grows very slowly near the origin .
5.2.2 square L2 Norm and L2 Norm comparison
square L2 Norm pair x The derivative of each element in depends only on the corresponding element .
L2 The derivative of the norm for each element is related to the entire vector .
5.3 Maximum norm
5.3.1 meaning
Represents the absolute value of the element with the largest amplitude in the vector :
5.3.2 Definition

5.4 F norm
5.4.1 meaning
F Norm is used to measure the size of the matrix
5.4.2 Mathematical definition

5.5 Use norm to express dot product

6 Special matrix
6.1 Diagonal matrix
Contains only non-zero elements on the main diagonal , All other positions are zero .
6.1.1 The meaning of diagonal matrix
By limiting some matrices to diagonal matrices , We can get a lower computational cost ( And to the point ) Algorithm .
6.1.2 Multiplication calculation of nonstandard diagonal matrix

6.2 Symmetric matrix

6.3 Orthogonal matrix
Row vector and column vector are square matrices which are respectively standard orthogonal :

6.4 Unit vector and orthogonal

6.5 Orthonormal
If these vectors are not only orthogonal to each other , And the norm is 1, So we call them orthonormal .
7 Characteristics of decomposition
7.0 Code implementation : Characteristics of decomposition
A = np.array([[1.0,2.0,3.0],
[4.0,5.0,6.0],
[7.0,8.0,9.0]])
# Calculate eigenvalues
print(" The eigenvalue :", np.linalg.eigvals(A))
# Calculate the eigenvalues and eigenvectors
eigvals,eigvectors = np.linalg.eig(A)
print(" The eigenvalue :", eigvals)
print(" Eigenvector :", eigvectors)
7.1 Definition
The matrix is decomposed into a set of eigenvectors and eigenvalues .
7.2 computing method

7.3 Tip
Not every matrix can be decomposed into eigenvalues and eigenvectors .
Every real symmetric matrix can be decomposed into real eigenvector and real eigenvalue .

7.4 Positive definite 、 Semi positive definite 、 Negative definite 、 Seminegative definite matrix
- A matrix in which all eigenvalues are positive is called a positive definite matrix .
- A matrix whose eigenvalues are nonnegative is called a positive semidefinite matrix .
- A matrix in which all eigenvalues are negative is called a negative definite matrix .
- A matrix whose eigenvalues are all non positive numbers is called a semi negative definite matrix .
8 Singular value decomposition (singular value decomposition, SVD)
8.0 The code realizes singular value decomposition
A = np.array([[1.0,2.0,3.0],
[4.0,5.0,6.0]])
U,D,V = np.linalg.svd(A)
print("U:", U)
print("D:", D)
print("V:", V)
8.1 meaning
The matrix is decomposed into singular vectors and singular values .
8.1 Decomposition calculation method

9 Pseudo inverse
9.1 Problem solved

If matrix A The number of rows is greater than the number of columns , Then the above equation may not have a solution . If matrix A The number of rows is less than the number of columns , Then the above matrix may have multiple solutions .
9.2 The calculation process

10 Trace operation
10.1 The definition of trace

10.2 Trace operation provides a description matrix Frobenius The way of norm :
10.3 Operational rules
10.3.1 Trace operation is invariant under transpose operation

10.3.2 Trace of square matrix obtained by multiplication of multiple matrices , It's the same trace that multiplies the last of these matrices when they're moved to the front .

10.3.3 After cyclic permutation, the shape of the matrix obtained by the matrix product changes , The result of trace operation remains unchanged .

10.3.4 Scalar is still itself after trace operation

11 determinant
11.1 Definition
determinant , Write it down as det(A), It's a general square A Functions mapped to real numbers .
11.2 The characteristics of determinant
- Determinant is equal to the product of matrix eigenvalue .
- The absolute value of determinant can be used to measure the expansion or reduction of space after matrix multiplication .
- If the determinant is 0, Then space shrinks completely along at least one dimension , Make it lose all its volume .
- If the determinant is 1, So this transformation keeps the volume of space constant .
版权声明
本文为[LiBiGor]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220810526212.html
边栏推荐
- Develop a chrome plug-in from 0 (2)
- PTA: praise the crazy devil
- 在MySQL Workbench中执行外部的SQL脚本,报错
- Rhcsa day 1 operation
- PTA: Romantic reflection [binary tree reconstruction] [depth first traversal]
- 009_ Redis_ Getting started with redistemplate
- Flink stream processing engine system learning (II)
- 013_ Analysis of SMS verification code login process based on session
- wordpress 调用指定页面内容详解2 get_children()
- Data warehouse construction table 111111
猜你喜欢

Understanding process (multithreading primary)

SQL server2019无法下载所需文件,这可能表示安装程序的版本不再受支持,怎么办了

手写内存池以及原理代码分析【C语言】

Flink stream processing engine system learning (III)

009_ Redis_ Getting started with redistemplate

下载正版Origin Pro 2022 教程 及 如何 激 活

双亲委派模型【理解】
![[XJTU computer network security and management] Lecture 2 password technology](/img/b0/263e8dcbfeb2ce9f504a9c8eb76b07.png)
[XJTU computer network security and management] Lecture 2 password technology

谷雨

Rhcsa day 1 operation
随机推荐
013_ Analysis of SMS verification code login process based on session
grain rain
全局、獨享、局部路由守衛
智能辅助功能丰富,思皓X6安全配置曝光:将于4月23日预售
16、 Anomaly detection
A domestic image segmentation project is heavy and open source!
定了,今日起,本号粉丝可免费参与网易数据分析培训营!
windows MySQL8 zip安装
012_ Access denied for user ‘root‘@‘localhost‘ (using password: YES)
005_ redis_ Set set
TypeScript(1)
Rich intelligent auxiliary functions and exposure of Sihao X6 security configuration: it will be pre sold on April 23
机器学习(周志华) 第十四章概率图模型
Suggestion: block reference sorting is in the order of keywords
Devil cold rice 𞓜 078 devil answers the market in Shanghai and Nanjing; Communication and guidance; Winning the country and killing and screening; The purpose of making money; Change other people's op
WordPress calls the specified page content. 2 get_ children()
C language 171 Number of recent palindromes
Modify the content of MySQL + PHP drop-down box
Using go language to build web server
下载正版Origin Pro 2022 教程 及 如何 激 活
