当前位置:网站首页>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
边栏推荐
- 【2019-CVPR-3D人体姿态估计】Fast and Robust Multi-Person 3D Pose Estimation from Multiple Views
- 想用Mac学习sql,主要给自己个充足理由买Mac听听意见
- WordPress calls the specified page content. 2 get_ children()
- 16、 Anomaly detection
- Day 3 of learning rhcsa
- Intelligent agricultural management model
- Rhcsa day 1 operation
- Rich intelligent auxiliary functions and exposure of Sihao X6 security configuration: it will be pre sold on April 23
- So library dependency
- 007_ Redis_ Jedis connection pool
猜你喜欢

Deploying sbert model based on torchserve < semantic similarity task >

How to solve the complexity of project document management?

They are all intelligent in the whole house. What's the difference between aqara and homekit?

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

Jupyter for local and remote access to ECS

After idea is successfully connected to H2 database, there are no sub files

day18--栈队列
![[untitled]](/img/60/421cda552055664357af47d1a956af.png)
[untitled]

Fast and robust multi person 3D pose estimation from multiple views

Want to experience homekit smart home? Why don't you take a look at this smart ecosystem
随机推荐
Rhcsa day 4 operation
php+mysql對下拉框搜索的內容修改
学习正则表达式选项、断言
Rhcsa second day operation
IAR embedded development stm32f103c8t6 Lighting LED
If 404 page is like this | daily anecdotes
认识进程(多线程_初阶)
本地远程访问云服务器的jupyter
So library dependency
Data warehouse construction table 111111
Download the genuine origin Pro 2022 tutorial and how to activate it
能做多大的单片机项目程序开发,就代表了你的敲代码的水平
C language 171 Number of recent palindromes
Synchronized锁及其膨胀
[XJTU計算機網絡安全與管理]第二講 密碼技術
SQL server2019无法下载所需文件,这可能表示安装程序的版本不再受支持,怎么办了
MySQL JDBC programming
002_ Redis_ Common operation commands of string type
leetcode 烹饪料理
OCR识别PDF文件
