Try singular value decomposition with Python

What I want to do: Check out the singular value decomposition of linear algebra

For the $ m $ row $ n $ matrix $ A $

-$ U $: $ m \ times m $ unitary matrix -$ \ Sigma $: $ m \ times n $ real diagonal matrix (component non-negative) -$ V $: $ n \ times n $ unitary matrix

Exists and the following holds

A=U\Sigma \overline{V^T}

Where the overline is the complex conjugate and $ ^ T $ is the transpose.

(Sample) Matrix definition

A=\left(
\begin{matrix}
1 & 2 \\
3 & 4 
\end{matrix}
\right)
> import numpy as np
> A = np.array([[1,2],[3,4]])

For the time being, the contents of ck

> A 
array([[1, 2],
       [3, 4]])

Immediately try SVD

U, s, V = np.linalg.svd(A, full_matrices=True)

There are three return values.

Contents ck

> U
array([[-0.40455358, -0.9145143 ],
       [-0.9145143 ,  0.40455358]])
> s
array([ 5.4649857 ,  0.36596619])
> V
array([[-0.57604844, -0.81741556],
       [ 0.81741556, -0.57604844]])

Somehow, it feels like $ s $ has collapsed, but the entity is only diagonal components, that is,

> np.diag(s)
array([[ 5.4649857 ,  0.        ],
       [ 0.        ,  0.36596619]])

Is a matrix of entities.

Check if it returns

A=U\Sigma \overline{V^T}

I will check.

>np.dot(np.dot(U, np.diag(s)),V)
array([[ 1.,  2.],
       [ 3.,  4.]])

It feels good ♪ ⇒ Here, since the matrix $ V $ is obtained by the execution column, it is not necessary to perform complex conjugate, but it seems that the one that does not take transpose is returned as the return value.

Confirmation just in case

U is a unitary matrix

> np.dot(U, U.T)
array([[  1.00000000e+00,   2.77555756e-16],
       [  2.77555756e-16,   1.00000000e+00]])

It is numerically unavoidable that a value other than $ 0 $ is entered in a place that is not a diagonal component.

V is also a unitary matrix

> np.dot(V, V.T)
array([[ 1.,  0.],
       [ 0.,  1.]])

Recommended Posts

Try singular value decomposition with Python
Try scraping with Python.
Try singular value decomposition of the daimyo matrix
Try running Python with Try Jupyter
Try face recognition with Python
Singular value decomposition (SVD), low-rank approximation (LRA) in Python
Try scraping with Python + Beautiful Soup
Replace dictionary value with Python> update ()
Try python
Try face recognition with python + OpenCV
Try frequency control simulation with Python
Try to reproduce color film with Python
Try logging in to qiita with Python
Try working with binary data in Python
Try using Python with Google Cloud Functions
Try HTML scraping with a Python library
Try calling Python from Ruby with thrift
Try drawing a map with python + cartopy 0.18.0
[Continued] Try PLC register access with Python
Try assigning or switching with Python: lambda
[For beginners] Try web scraping with Python
FizzBuzz with Python3
Scraping with Python
Statistics with python
Scraping with Python
Python with Go
Twilio with Python
Integrate with Python
Play with 2016-Python
Python> try: / except:
AES256 with python
Tested with Python
python starts with ()
with syntax (Python)
Bingo with python
Zundokokiyoshi with python
Excel with Python
Microcomputer with Python
Cast with python
nginxparser: Try parsing nginx config file with Python
Try it with Word Cloud Japanese Python JupyterLab.
Find the mood value with python (Rike Koi)
Try running Google Chrome with Python and Selenium
Low-rank approximation of images by singular value decomposition
Try to solve the man-machine chart with Python
Try to draw a life curve with python
Try to make a "cryptanalysis" cipher with Python
Try to automatically generate Python documents with Sphinx
Try working with Mongo in Python on Mac
[Python3] [Ubuntu16] [Docker] Try face recognition with OpenFace
Try to make a dihedral group with Python
Try to detect fish with python + OpenCV2.4 (unfinished)
Serial communication with Python
Zip, unzip with python
Django 1.11 started with Python3.6
Primality test with Python
Socket communication with Python
Data analysis with python 2
[Python] Try optimizing FX systole parameters with random search
Excel> INTERCEPT ()> Intercept value> Web error> Confirm with python / _, _ with tuple
Try to solve the programming challenge book with python3