当前位置:网站首页>"Statistical learning methods (2nd Edition)" Li Hang Chapter 15 singular value decomposition SVD mind map notes and after-school exercise answers (detailed steps) SVD matrix singular value Chapter 15
"Statistical learning methods (2nd Edition)" Li Hang Chapter 15 singular value decomposition SVD mind map notes and after-school exercise answers (detailed steps) SVD matrix singular value Chapter 15
2022-07-24 05:50:00 【Ml -- xiaoxiaobai】
15.1
Try to find the matrix
A = [ 1 2 0 2 0 2 ] A=\left[\begin{array}{lll}1 & 2 & 0 \\ 2 & 0 & 2\end{array}\right] A=[122002]
Singular value decomposition of .
Calculate the result by hand ,
U = 1 5 [ 1 2 2 − 1 ] , Σ = [ 3 0 0 0 2 0 ] , V T = 1 5 [ 5 3 2 3 4 3 0 2 − 1 − 2 1 2 ] U = \frac{1}{\sqrt{5}}\left[\begin{array}{ll}1 & 2 \\ 2 & -1 \end{array}\right], \Sigma = \left[\begin{array}{lll}3 & 0 & 0 \\ 0 & 2 & 0 \end{array}\right], V^{T} = \frac{1}{\sqrt{5}}\left[\begin{array}{lll}\frac{5}{3} & \frac{2}{3} & \frac{4}{3} \\ 0 & 2 & -1 \\ -2 & 1 & 2\end{array}\right] U=51[122−1],Σ=[300200],VT=51⎣⎡350−2322134−12⎦⎤
Check it out :
import numpy as np
U = 1 / np.sqrt(5) * np.array([[1, 2], [2, -1]])
Sigma = np.array([[3, 0, 0], [0, 2, 0]])
V_transpose = 1 / np.sqrt(5) * np.array([[5/3, 2/3, 4/3], [0, 2, -1], [-2, 1, 2]])
U @ Sigma @ V_transpose
array([[1., 2., 0.],
[2., 0., 2.]])
to glance at numpy Decomposition in :
A = np.array([[1, 2, 0], [2, 0, 2]])
U, Sigma, V_transpose = np.linalg.svd(A)
print('U:\n', U)
print('Sigma:\n', Sigma)
print('V_transpose:\n', V_transpose)
U:
[[ 0.4472136 -0.89442719]
[ 0.89442719 0.4472136 ]]
Sigma:
[3. 2.]
V_transpose:
[[ 7.45355992e-01 2.98142397e-01 5.96284794e-01]
[ 1.94726023e-16 -8.94427191e-01 4.47213595e-01]
[-6.66666667e-01 3.33333333e-01 6.66666667e-01]]
1 / np.sqrt(5) * np.array([[1, 2], [2, -1]]) # Hand calculated U
array([[ 0.4472136 , 0.89442719],
[ 0.89442719, -0.4472136 ]])
1 / np.sqrt(5) * np.array([[5/3, 2/3, 4/3], [0, 2, -1], [-2, 1, 2]]) # Hand calculated V Transposition
array([[ 0.74535599, 0.2981424 , 0.59628479],
[ 0. , 0.89442719, -0.4472136 ],
[-0.89442719, 0.4472136 , 0.89442719]])
You can find ,numpy Self contained decomposition , The second basis of the left singular matrix is one sign away from the result of the manual calculation , It shows that the selection of decomposition time base is not unique , Corresponding V.T The second line of is also a minus sign , And for V.T The third line of is a A Base of zero space , My choice is not very strict , Just meet in zero space , and numpy I don't know how to guarantee V.T Row orthogonality of , So as to ensure the orthogonality of its columns , But in fact, the direction of our basis vector is the same , This degree of freedom is being restored A Time does not make an impression , As verified above .
15.2
Try to find the matrix
A = [ 2 4 1 3 0 0 0 0 ] A=\left[\begin{array}{ll}2 & 4 \\ 1 & 3 \\ 0 & 0 \\ 0 & 0\end{array}\right] A=⎣⎢⎢⎡21004300⎦⎥⎥⎤
And write its outer product expansion .
This A T A A^{T}A ATA The eigenvalue of is an irrational number , Manual calculation is a little cumbersome , So I solved it directly with code :
15 - np.sqrt(13*17), 15 + np.sqrt(13*17) # The above two eigenvalues
(0.13393125268149397, 29.866068747318508)
A = np.array([[2, 4], [1, 3], [0, 0], [0, 0]])
U, Sigma, V_transpose = np.linalg.svd(A)
print('U:\n', U)
print('Sigma:\n', Sigma)
print('V_transpose:\n', V_transpose)
U:
[[-0.81741556 -0.57604844 0. 0. ]
[-0.57604844 0.81741556 0. 0. ]
[ 0. 0. 1. 0. ]
[ 0. 0. 0. 1. ]]
Sigma:
[5.4649857 0.36596619]
V_transpose:
[[-0.40455358 -0.9145143 ]
[-0.9145143 0.40455358]]
So the original matrix is the superposition of two outer products , The first outer product is :
first_item = Sigma[0] * U[:, 0][:, None] @ V_transpose[0][None, :]
first_item
array([[1.80720735, 4.08528566],
[1.27357371, 2.87897923],
[0. , 0. ],
[0. , 0. ]])
The second outer product is :
second_item = Sigma[1] * U[:, 1][:, None] @ V_transpose[1][None, :]
second_item
array([[ 0.19279265, -0.08528566],
[-0.27357371, 0.12102077],
[ 0. , 0. ],
[ 0. , 0. ]])
See if the result of addition is equal to the original :
A == first_item + second_item
array([[ True, True],
[ True, True],
[ True, True],
[ True, True]])
15.3
Compare the similarities and differences between singular value decomposition of matrix and diagonalization of symmetric matrix .
identical :
Eigenvalues are required 、 Calculation of eigenvectors ;
Eigenvalues are nonnegative ;
The number of positive eigenvalues is equal to the rank of the original matrix ;
The eigenvectors corresponding to eigenvalues are orthogonal .
Different :
The eigenvalue eigenvector of singular value decomposition solution is not of the original matrix , But the symmetric matrix formed by the product of the original matrix and its transpose ;
The diagonalization of symmetric matrix only needs to find the eigenvalue eigenvector once , Singular value decomposition can only get part of the column vector on one side of the left or right singular matrix , You need to solve the eigenvalue eigenvector twice , Or by the correspondence between the column vectors of left and right singular matrices , Find the other side again , Finally, we need to find the standard orthogonal basis of zero space , To complete the left and right singular matrix ;
For singular value decomposition , There are certain degrees of freedom for matrices in zero space , So it makes U There may be non orthogonality between the rows of , V T V^{T} VT There may be non orthogonality between the columns of ( Of course, you can choose a more strictly orthogonal value ). Diagonalization of symmetric matrices , It is orthogonal. .
15.4
Prove that any rank is 1 The matrix of can be written as the outer product of two vectors , And give an example .
Prove one :
If the rank of a matrix is 1, Then we can know from the knowledge of elementary transformation of linear algebra , There must be a column vector of a matrix , By multiplying by a certain coefficient , Equal to any other column , So you can subtract and eliminate other columns , That is to say, the column vector of the matrix is only a coefficient times of this column vector , Thus, the outer product of the column vector is a row vector corresponding to each column coefficient to obtain the matrix .( Just scrape together examples )
Proof II :
If the rank of the matrix is 1, Then the singular value decomposition diagonal matrix has only the first principal diagonal element σ 1 \sigma_{1} σ1 Not 0, The other elements are 0, be A = U Σ V T A=U\Sigma V^{T} A=UΣVT Turn into A = u 1 σ 1 v 1 T A=u_{1}\sigma_{1}v_{1}^{T} A=u1σ1v1T, among u 1 u_{1} u1 and v 1 T v_{1}^{T} v1T by U U U The first column and V T V^{T} VT The first line of . Because the singular value decomposition of matrix must exist , At this time, the decomposition is the vector outer product , So the rank is 1 The matrix of must have the outer product form of two vectors .
15.5
Click data in search records query statements submitted by users during search , Click on the page URL, And the number of clicks , Form a bipartite graph , One of the node sets { q i } \{q_{i}\} { qi} Represents a query , Another node set { u j } \{u_{j}\} { uj} Express URL, The edge indicates the click relationship , The weight on the edge indicates the number of clicks . As shown in the following figure, click on the data example . Click data can be represented by matrix , Try singular value decomposition , And explain the contents of the three matrix representations .
# Construct a data matrix
A = np.array([[0, 20, 5, 0, 0],
[10, 0, 0, 3, 0],
[0, 0, 0, 0, 1],
[0, 0, 1, 0, 0]])
U, Sigma, V_transpose = np.linalg.svd(A)
print('U:\n', U)
print('Sigma:\n', Sigma)
print('V_transpose:\n', V_transpose)
U:
[[ 9.99930496e-01 -1.01352447e-16 0.00000000e+00 -1.17899939e-02]
[ 0.00000000e+00 1.00000000e+00 0.00000000e+00 -8.65973959e-15]
[ 0.00000000e+00 0.00000000e+00 1.00000000e+00 0.00000000e+00]
[ 1.17899939e-02 8.65973959e-15 0.00000000e+00 9.99930496e-01]]
Sigma:
[20.61695792 10.44030651 1. 0.97007522]
V_transpose:
[[ 0.00000000e+00 9.70007796e-01 2.43073808e-01 0.00000000e+00
0.00000000e+00]
[ 9.57826285e-01 -2.31404926e-16 8.02571613e-16 2.87347886e-01
0.00000000e+00]
[-0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00
1.00000000e+00]
[-7.97105437e-16 -2.43073808e-01 9.70007796e-01 0.00000000e+00
0.00000000e+00]
[ 2.87347886e-01 -1.01402229e-16 2.10571835e-16 -9.57826285e-01
0.00000000e+00]]
For the convenience of observation , give :
explain :
You can see that the first two singular values are much larger than the last two , Refer to above Mind mapping in , The geometric meaning of singular value decomposition and the physical meaning of outer product representation are described , It can be analyzed in this way . The main contribution of this clicked data matrix comes from the patterns corresponding to the first two singular values . For the first mode , see U The first column , The direction of its base is mainly in the first element , This is the original A The basis vector of the range space of a matrix , This vector corresponds to the largest singular value , Indicates that this base is query The main contributors to this model , And mainly from the original A The first contribution of the representation of the matrix , namely q 1 q_{1} q1 The contribution of , Then its corresponding V T V^{T} VT The first line of , It said A The basis vector of the row space of , This basis vector is mainly in the original A The direction of the second coordinate under the representation , namely u 2 u_{2} u2, Explain that in this mode , stay url In the space u 2 u_{2} u2 Direction data , After linear transformation, it mainly becomes query In the space q 1 q_{1} q1 Direction data . Empathy , For the mode of the second singular value , Similar analysis can be obtained , stay url In the space u 1 u_{1} u1 Direction data , After linear transformation, it mainly becomes query In the space q 2 q_{2} q2 Direction data .
Sum up , You can get , This data matrix , The main contribution comes from two modes , The main contribution of the first model is q 1 q_{1} q1 To u 2 u_{2} u2, The main contribution of the second model is q 2 q_{2} q2 To u 1 u_{1} u1, Because this bipartite graph is not complicated , As you can see intuitively in the figure , The main mode is 20,10 Weighted ,20 The pattern of corresponds to q 1 q_{1} q1 To u 2 u_{2} u2,10 The pattern of corresponds to q 2 q_{2} q2 To u 1 u_{1} u1.
You can verify the above explanation :
first_item = Sigma[0] * U[:, 0][:, None] @ V_transpose[0][None, :]
first_item
array([[ 0. , 19.99721992, 5.01109415, 0. , 0. ],
[ 0. , 0. , 0. , 0. , 0. ],
[ 0. , 0. , 0. , 0. , 0. ],
[ 0. , 0.23578349, 0.05908488, 0. , 0. ]])
second_item = Sigma[1] * U[:, 1][:, None] @ V_transpose[1][None, :]
second_item[second_item<0.001] = 0
second_item
array([[ 0., 0., 0., 0., 0.],
[10., 0., 0., 3., 0.],
[ 0., 0., 0., 0., 0.],
[ 0., 0., 0., 0., 0.]])
third_item = Sigma[2] * U[:, 2][:, None] @ V_transpose[2][None, :]
third_item[third_item<0.001] = 0
third_item
array([[0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0.],
[0., 0., 0., 0., 1.],
[0., 0., 0., 0., 0.]])
fourth_item = Sigma[3] * U[:, 3][:, None] @ V_transpose[3][None, :]
fourth_item[fourth_item<0.001] = 0
fourth_item
array([[0. , 0.00278008, 0. , 0. , 0. ],
[0. , 0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. , 0. ],
[0. , 0. , 0.94091512, 0. , 0. ]])
边栏推荐
- Multi merchant mall system function disassembly lecture 07 - platform side commodity management
- 达梦数据库_常用初始化参数
- 《机器学习》(周志华)第一章 绪论 笔记 学习心得
- My little idea -- using MATLAB to realize reading similar to ring buffer
- 【activiti】流程变量
- Two architectures of data integration: ELT and ETL
- 多商户商城系统功能拆解14讲-平台端会员等级
- Highcharts use custom vector maps
- likeshop单商户SAAS商城系统无限多开
- Target detection tagged data enhancement code
猜你喜欢

【activiti】流程实例

程序员常说的API是什么意思?API类型有什么呢?

Delete the weight of the head part of the classification network pre training weight and modify the weight name

Multi merchant mall system function disassembly lecture 04 - platform side merchants settling in

【mycat】mycat介绍

PLSQL query data garbled

主成分分析计算步骤

Recommend a fully open source, feature rich, beautiful interface mall system

Multi merchant mall system function disassembly lecture 08 - platform end commodity classification

Mysqldump export Chinese garbled code
随机推荐
Problems in SSM project configuration, various dependencies, etc. (for personal use)
西瓜书/南瓜书--第1,2章总结
【activiti】activiti介绍
Flink watermark mechanism
在网络中添加spp模块中的注意点
Multi merchant mall system function disassembly lecture 09 - platform end commodity brands
学习率余弦退火衰减之后的loss
[activiti] activiti environment configuration
[vSphere high availability] handling after host failure or isolation
国内外知名源码商城系统盘点
传统的k-means实现
Syntax differences between MySQL and Oracle
学习率优化策略
Could not load library cudnn_cnn_infer64_8.dll. Error code 126Please make sure cudnn_cnn_infer64_8.
第五章神经网络
Subsystem technology and ecology may memorabilia | square one plan launched, Boca launched xcm!
Help transform traditional games into gamefi, and web3games promote a new direction of game development
The SaaS mall system of likeshop single merchant is built, and the code is open source without encryption.
快速打开管理工具的命令
《统计学习方法(第2版)》李航 第15章 奇异值分解 SVD 思维导图笔记 及 课后习题答案(步骤详细)SVD 矩阵奇异值 十五章