LU decomposition 4 pts
Eigenvalues 4 pts
Neumann series 4 pts
SVD tool 4 pts
In [ ]:
Connected graph 5 pts
Disconnected graph 6 pts
In [ ]:
The aim of this task is to build a face classifier. There are 40 persons in the database. Every person is represented by 10 photos with slightly different facial expression.
Download the database of faces from here
Create training sample.
Import first 9 images for each face ($9\times 40$ images). Represent these pictures as a matrix $F$ with $9\times 40$ columns, where each column is a reshaped 2D picture. Note: use $\verb|np.reshape|$ to reshape matrix into column
Calculate and plot mean face. Subtract it from each column of the matrix $F$
Calculate SVD decomposition of the shifted matrix F and truncate the obtained representaition with first $r$ columns: $U_r S_r V_r^T$.
Here $U_r$ is a matrix with $r$ columns - basis set in a space of faces. $W_r = S_r V_r^T$ is a matrix of coefficients in the basis $U_r$. Note that rank $r$ is a parameter which controls quality of classification. Note: parameter $\verb|full_matrices|$ in $\verb|np.linalg.svd|$ might be helpful
Plot $U_r$ vectors. Make sure to get face-like images. Remark: now you know what eigenfaces are =)
Import testing set which is the rest of photos. Find their coefficients in the basis $U_r$
Compare the calculated vectors of coefficients to vectors in $W_r$ and classify testing faces. As an output give indices of faces that were misclassified.
Similarity of faces is defined by their coefficients similarity which in turn is measured by angle.
In [ ]:
Implement High-Order SVD (HOSVD) algorithm in 3D. As an output give ranks of the 3D Hilbert tensor $$a_{ijk} = \frac{1}{i+j+k + 1}, \quad i,j,k = \overline{0,199}$$ with $10^{-5}$ accuracy. Details can be found here (Fig. 4.3)
In [10]:
import numpy as np
a = np.random.random((200,200))
%timeit np.linalg.svd(a)
In [14]:
2./100**3*14000**3/1000/60
Out[14]:
In [ ]: