1473 lines
653 KiB
Plaintext
1473 lines
653 KiB
Plaintext
|
{
|
||
|
"cells": [
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 45,
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "skip"
|
||
|
}
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"import matplotlib.pyplot as plt\n",
|
||
|
"plt.rcParams.update({\n",
|
||
|
" \"text.usetex\": True,\n",
|
||
|
" \"font.size\": 14,\n",
|
||
|
" \"font.serif\": [\"Palatino\"],\n",
|
||
|
"})"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "slide"
|
||
|
}
|
||
|
},
|
||
|
"source": [
|
||
|
"# Matrix rank "
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "fragment"
|
||
|
}
|
||
|
},
|
||
|
"source": [
|
||
|
"Matrix rank: dimension of the column space $\\equiv$ dimension of the row space"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "fragment"
|
||
|
}
|
||
|
},
|
||
|
"source": [
|
||
|
"- We have not discussed yet, how to compute the matrix rank\n",
|
||
|
"- One (the most reliable but somewhat expensive) way to compute the matrix rank is to perform its SVD decomposition \n",
|
||
|
"- Before we turn to this, lets play with the function matrix_rank from numpy"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 56,
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "slide"
|
||
|
}
|
||
|
},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
|
"100"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 56,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"# A random matrix has full rank\n",
|
||
|
"import numpy as np\n",
|
||
|
"import numpy.linalg as la\n",
|
||
|
"n = 100\n",
|
||
|
"A = np.random.normal(size=(n,n))\n",
|
||
|
"la.matrix_rank(A)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "slide"
|
||
|
}
|
||
|
},
|
||
|
"source": [
|
||
|
"# Lets create a rank-1 matrix "
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 59,
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "fragment"
|
||
|
}
|
||
|
},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
|
"1"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 59,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"u = np.random.normal(size=(n, 1))\n",
|
||
|
"A = u @ u.T\n",
|
||
|
"la.matrix_rank(A)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"$A_{ij} = u_j u_j$"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 60,
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "fragment"
|
||
|
}
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"# Consider a small perturbation of A\n",
|
||
|
"delta_A = 1e-12*np.random.normal(size=(n,n))\n",
|
||
|
"Ap = A + delta_A"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 61,
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "fragment"
|
||
|
}
|
||
|
},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
|
"array([[ 0.40534717, -0.07139809],\n",
|
||
|
" [-0.07139809, 0.0125761 ]])"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 61,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"# upper left corner of A\n",
|
||
|
"A[:2,:2]"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 62,
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "fragment"
|
||
|
}
|
||
|
},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
|
"array([[ 0.40534717, -0.07139809],\n",
|
||
|
" [-0.07139809, 0.0125761 ]])"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 62,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"# upper left corner of Ap\n",
|
||
|
"Ap[:2,:2]"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 63,
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "fragment"
|
||
|
}
|
||
|
},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
|
"84"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 63,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"la.matrix_rank(Ap)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "slide"
|
||
|
}
|
||
|
},
|
||
|
"source": [
|
||
|
"- Matrix rank is very sensitive to small perturbations of a matrix\n",
|
||
|
"- Dimensionality of a space, spanned by a set of vectors can be poorly defined\n",
|
||
|
"- Today we resolve this issue to come with a better understanding of related matrix properties"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "slide"
|
||
|
}
|
||
|
},
|
||
|
"source": [
|
||
|
"## What does it imply if we know that the matrix $A$ has low rank?"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "fragment"
|
||
|
}
|
||
|
},
|
||
|
"source": [
|
||
|
"Consider generic $n\\times n$ matrix $A = \\bigg[a_1\\bigg|a_2\\bigg|...\\bigg|a_n\\bigg]$:\n",
|
||
|
"- It takes $\\mathcal{O}(n^2)$ elements to store $A$\n",
|
||
|
"- It takes $\\mathcal{O}(n^2)$ FLOPs to compute $u=Av$ for a given $v$"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "fragment"
|
||
|
}
|
||
|
},
|
||
|
"source": [
|
||
|
"Consider rank-one matrix $A$\n",
|
||
|
"- It takes $\\mathcal{O}(n)$ elements to store $A$. Indeed, all columns are collinear: \n",
|
||
|
"it takes $n$ elements to store one column $a_1$ and $n-1$ elements to store the proportionality coefficients $b_i$ such that $$a_i = b_i a_1$$\n",
|
||
|
"As a result, the matrix is compressed:\n",
|
||
|
"$$\n",
|
||
|
"A_{ij} = a_i b_j\\quad\\textrm{or}\\quad A=a^T b\n",
|
||
|
"$$\n",
|
||
|
"- It takes $\\mathcal{O}(n)$ flops to compute $u=Av$ for a given $v$. Why?"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "slide"
|
||
|
}
|
||
|
},
|
||
|
"source": [
|
||
|
"# Low-rank approximation"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 65,
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "fragment"
|
||
|
}
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"u = np.random.normal(size=(n, 1))\n",
|
||
|
"A = u @ u.T\n",
|
||
|
"delta_A = 1e-10*np.random.normal(size=(n,n))\n",
|
||
|
"Ap = A + delta_A"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 66,
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "fragment"
|
||
|
}
|
||
|
},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
|
"100"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 66,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"# according to matrix_rank the rank of Ap is almost as high as it can be\n",
|
||
|
"la.matrix_rank(Ap)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 67,
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "fragment"
|
||
|
}
|
||
|
},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"name": "stdout",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"absolute error: 1.0158658489730158e-08\n",
|
||
|
"relative error: 1.2119290778015715e-10\n"
|
||
|
]
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"# what error do we make if we replace Ap by a rank-1 matrix A?\n",
|
||
|
"print(\"absolute error:\", np.linalg.norm(A - Ap))\n",
|
||
|
"print(\"relative error:\", np.linalg.norm(A - Ap)/np.linalg.norm(A))"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "fragment"
|
||
|
}
|
||
|
},
|
||
|
"source": [
|
||
|
"- Thus, rank-1 matrix $A$ provides a very good approximation of a rank-100 matrix $Ap$\n",
|
||
|
"- It is a very synthetic example. Our goal today is to understand how this may work in a general case"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "slide"
|
||
|
}
|
||
|
},
|
||
|
"source": [
|
||
|
"# Geometric considerations "
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "slide"
|
||
|
}
|
||
|
},
|
||
|
"source": [
|
||
|
"- Consider an arbitrary $m\\times n$ matrix $A$. It maps arbitrary $n$-dimensional vector $v$ to $m$-dimensional vector $u$: $u=Av$.\n",
|
||
|
"- Lets inspect the geometric meaning of this fact\n",
|
||
|
"![](geom.png)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "slide"
|
||
|
}
|
||
|
},
|
||
|
"source": [
|
||
|
"## Singular value decomposition\n",
|
||
|
"\n",
|
||
|
"Any $m\\times n$ matrix $A$ can be written as a product of three matrices: \n",
|
||
|
"\n",
|
||
|
"$$ A = U \\Sigma V^*, $$\n",
|
||
|
"\n",
|
||
|
"where, for $K = \\min(m, n)$:\n",
|
||
|
"- $U$ is an $m \\times K$ matrix with orthonormal columns, \n",
|
||
|
"- $V$ is an $n \\times K$ matrix with orthonormal columns,\n",
|
||
|
"- $\\Sigma$ is a diagonal matrix with non-negative elements on the diagonal \n",
|
||
|
"\n",
|
||
|
"Reduced SVD ($m\\geq n$)\n",
|
||
|
"![](reduced.png)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "slide"
|
||
|
}
|
||
|
},
|
||
|
"source": [
|
||
|
"Sometimes its convenient to append the missing columns, so that both matrices ($U$ and $V$) become unitary."
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "fragment"
|
||
|
}
|
||
|
},
|
||
|
"source": [
|
||
|
"Full SVD ($m\\geq n$)\n",
|
||
|
"![](full.png)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "slide"
|
||
|
}
|
||
|
},
|
||
|
"source": [
|
||
|
"- We can write down $A$ element-wise: $$a_{ij} = \\displaystyle{\\sum_{\\alpha=1}^r} \\sigma_\\alpha u_{i\\alpha} v_{j\\alpha}^{*}$$\n",
|
||
|
"- One usually enumerates diagonal elements of $\\Sigma$ in a descending order $\\sigma_1 \\geq \\ldots, \\geq \\sigma_K$.\n",
|
||
|
"- If $\\text{rank}(A) = r$, then: $\\sigma_{r+1} = ... = \\sigma_K = 0.$"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "slide"
|
||
|
}
|
||
|
},
|
||
|
"source": [
|
||
|
"Columns of matrices $U$ and $V$ are known as left and right singular vectors.\n",
|
||
|
"They form orthonormal sets in the space of image ($u_i$) and pre-image ($v_i$) of the matrix $A$. Their geometrical meaning:\n",
|
||
|
"\n",
|
||
|
"$$\\text{ker}(A) = \\mathrm{span}\\{v_{r+1},\\dots,v_K\\}$$\n",
|
||
|
"\n",
|
||
|
"$$\\text{im}(A) = \\mathrm{span}\\{u_{1},\\dots,u_r\\}$$"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "slide"
|
||
|
}
|
||
|
},
|
||
|
"source": [
|
||
|
"# Eckart-Young theorem\n",
|
||
|
"\n",
|
||
|
"The best low-rank approximation can be computed by SVD.\n",
|
||
|
"\n",
|
||
|
"Let $r < \\text{rank}(A)$, $B$ is a matrix of rank $r$ (to be optimized). Then\n",
|
||
|
"\n",
|
||
|
"$$ \\min_{\\text{rank}(B)=r} \\|A - B\\|_2 = \\sigma_{r+1}. $$"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "slide"
|
||
|
}
|
||
|
},
|
||
|
"source": [
|
||
|
"## Low-rank approximation\n",
|
||
|
"\n",
|
||
|
"The best rank-$r$ approximation to $A$ is obtained by setting $\\sigma_{r+1}= 0, \\ldots, \\sigma_K = 0$:\n",
|
||
|
"\n",
|
||
|
"$$A_r = U_r \\Sigma_r V_r^*.$$\n",
|
||
|
"\n",
|
||
|
"The error \n",
|
||
|
"\n",
|
||
|
"$$ \\min_{\\text{rank}(B)=r} \\Vert A - B \\Vert_2 = \\Vert A - A_r \\Vert_2 = \\sigma_{r+1}$$\n",
|
||
|
"\n",
|
||
|
"Thus the faster the singular values decay, the better is accuracy of 'compression' of the matrix into low-rank form."
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "fragment"
|
||
|
}
|
||
|
},
|
||
|
"source": [
|
||
|
"The same holds for Frobenius norm:\n",
|
||
|
"$$\\min_{\\text{rank}(B)=r}\\Vert A - B \\Vert_F = \\Vert A - A_r \\Vert_F = \\sqrt{\\sigma_{r+1}^2 + \\dots + \\sigma_{K}^2}$$"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "slide"
|
||
|
}
|
||
|
},
|
||
|
"source": [
|
||
|
"## Computing SVD\n",
|
||
|
"\n",
|
||
|
"- Algorithms for the computation of the SVD are tricky. Some approaches will be discussed later.\n",
|
||
|
"\n",
|
||
|
"- We are ready to use NumPy and SciPy implementations\n",
|
||
|
"\n",
|
||
|
"- Broadly speaking, one may think of (i) exact computation of complete SVD, (ii) exact computation of 'sparse' SVD, where we need only first $k \\ll n$ singular values and vectors and (iii) randomized SVD (approximate evaluation of the leading subset of singular values and vectors)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 68,
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "slide"
|
||
|
}
|
||
|
},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"name": "stdout",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"Rank of the matrix: 1\n",
|
||
|
"Rank of the matrix: 100\n"
|
||
|
]
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"# Recall: Computing matrix rank\n",
|
||
|
"import numpy as np\n",
|
||
|
"print('Rank of the matrix:', np.linalg.matrix_rank(A))\n",
|
||
|
"print('Rank of the matrix:', np.linalg.matrix_rank(Ap))"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 69,
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "fragment"
|
||
|
}
|
||
|
},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
|
"array([[ 0.62881492, -0.38142909],\n",
|
||
|
" [-0.38142909, 0.2313688 ]])"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 69,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"A[:2,:2]"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 70,
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "fragment"
|
||
|
}
|
||
|
},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
|
"array([[ 0.62881492, -0.38142909],\n",
|
||
|
" [-0.38142909, 0.2313688 ]])"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 70,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"Ap[:2,:2]"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 74,
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "slide"
|
||
|
}
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"u, s, vh = np.linalg.svd(A)\n",
|
||
|
"up, sp, vhp = np.linalg.svd(Ap)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"la.matrix_rank()"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 75,
|
||
|
"metadata": {
|
||
|
"scrolled": true,
|
||
|
"slideshow": {
|
||
|
"slide_type": "fragment"
|
||
|
}
|
||
|
},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
|
"array([8.38222193e+01, 4.53158462e-14, 4.00097651e-14, 3.10833486e-14,\n",
|
||
|
" 2.59425086e-14, 2.13154110e-14, 2.07592143e-14, 1.90293475e-14,\n",
|
||
|
" 1.77971365e-14, 1.46656957e-14])"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 75,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"s[:10]"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 73,
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "fragment"
|
||
|
}
|
||
|
},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
|
"array([8.38222193e+01, 1.99954677e-09, 1.89619187e-09, 1.86088354e-09,\n",
|
||
|
" 1.84812585e-09, 1.81777344e-09, 1.75761017e-09, 1.75596734e-09,\n",
|
||
|
" 1.68481081e-09, 1.66847435e-09])"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 73,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"sp[:10]"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "fragment"
|
||
|
}
|
||
|
},
|
||
|
"source": [
|
||
|
"SVD allows to properly define a numerical rank for a given tolerance $\\epsilon$"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "slide"
|
||
|
}
|
||
|
},
|
||
|
"source": [
|
||
|
"## Singular values of a random Gaussian matrix\n",
|
||
|
"\n",
|
||
|
"What is the singular value decay of a random matrix?"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 23,
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "fragment"
|
||
|
}
|
||
|
},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAtcAAAENCAYAAADEw0mJAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAABBTElEQVR4nO3dd1iUV/YH8O+ZodcBBFTAM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IisTkQylFKJesdhT7Yct8kxnS29hF8OF2H7sSLsOlGM3Scsdd0XLlk2yREBWof6oX1koJZwB6FD80C0CfNja1xyKHWN2Zy5boCwAG9MSIzGR+sOItjXE3++oTMTbCIiokby8/JA/9iwyzbKKStXOJR/FrtPnK5MuHefKEbqzhxU7I/j5WFA+8gAdI0yIb5lEDq3tMx2+3kxjSHHw1dlAz03Nh4igg/WHEDJ+UuYM7673iERERE5PaNBKrdxv7ZLi8rj5y+WYW9OCXbnFGP3idPYcfw0ftx6DF9sPAQAMAhgDg9Al5ZBiG8ZjPioIMS3CEawH7eAJ30xuW4gg0Hw5xs641xpGb5KP4yOLYLwwKC2eodFRETkknw8jegaHYyu0cGVx5RSOFp4DtuPncb2Y6ex41gR1mdf3rUkJtQXPWJC0D06GN2iLTPd/t5Md8h++GprBINB8KfrO+FY0Tn8/YcdMIf7Y3iHCL3DIiIicgsigugQP0SH+GF0fPPK43klF7SEuwi/Hi1C+oF8LP7lmPYzQFx4ALpGBaNdZCC6xwQjoVUIfDy5cJJsgwsam+DCpTJc9/oq5Jy+gIUPDUD7yEC7PC8RuS53WtB
|
||
|
"text/plain": [
|
||
|
"<Figure size 864x288 with 2 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {
|
||
|
"needs_background": "light"
|
||
|
},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"import numpy as np\n",
|
||
|
"import matplotlib.pyplot as plt\n",
|
||
|
"n = 1000\n",
|
||
|
"a = np.random.randn(n, n)\n",
|
||
|
"s = np.linalg.svd(a, compute_uv=False)\n",
|
||
|
"fig, ax = plt.subplots(1, 2, figsize=(12, 4))\n",
|
||
|
"ax[0].plot(s/s[0])\n",
|
||
|
"ax[1].plot(s/s[0])\n",
|
||
|
"ax[1].set_yscale('log')\n",
|
||
|
"ax[0].set_ylabel(r\"$\\sigma_i / \\sigma_0$\", fontsize=16)\n",
|
||
|
"ax[0].set_xlabel(r\"$i$\", fontsize=16)\n",
|
||
|
"ax[1].set_xlabel(r\"$i$\", fontsize=16);"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "slide"
|
||
|
}
|
||
|
},
|
||
|
"source": [
|
||
|
"# Applications of SVD"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "fragment"
|
||
|
}
|
||
|
},
|
||
|
"source": [
|
||
|
"## Dense matrix compression\n",
|
||
|
"\n",
|
||
|
"Dense matrices require $N^2$ elements to be stored. A rank-$r$ approximation can reduces this number of $\\mathcal{O}(Nr)$. Let us consider image compression as an example."
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 76,
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "slide"
|
||
|
}
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"from skimage import data\n",
|
||
|
"from skimage.color import rgb2gray\n",
|
||
|
"from numpy.linalg import svd\n",
|
||
|
"from skimage import img_as_float"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 77,
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "fragment"
|
||
|
}
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"cat = rgb2gray(img_as_float(data.chelsea()))"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 80,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
|
"(300, 451)"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 80,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"cat.shape"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 78,
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "fragment"
|
||
|
}
|
||
|
},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
|
"array([[0.48523098, 0.48523098, 0.47738784, 0.47738784, 0.47738784],\n",
|
||
|
" [0.49699569, 0.49307412, 0.48523098, 0.48130941, 0.48130941],\n",
|
||
|
" [0.50849255, 0.50457098, 0.49475569, 0.49083412, 0.49307412],\n",
|
||
|
" [0.52054 , 0.51269686, 0.50485373, 0.50485373, 0.50064941],\n",
|
||
|
" [0.52894863, 0.52110549, 0.51661843, 0.51269686, 0.50849255]])"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 78,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"cat[:5, :5]"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 81,
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "fragment"
|
||
|
}
|
||
|
},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
|
"<matplotlib.image.AxesImage at 0x2826347c400>"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 81,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
},
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXEAAAD/CAYAAAAHSua4AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAAEAAElEQVR4nOz9x65t2baeB37dDTPNcttF7Ig4lteIl5lKXIkJZCFLpB5BUDFr5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Tdu+Mu3L5jerTAHoUHSi0D2Gjso3CEv59V1gdBphmDQbaCuwkJdaJ0JhYYxbcCfG8YLTTYVd3+kcYeHyNt1meEZTJcRPVqaa7V8/2yhuo+Y+55KK1bvDWFtBETIhFXGbwQomvceM1qmrSEbS+ca7NpL0FKCxJg0YbLkzpJMFlqqCTSNx+iED0aCGRc4lGhcKcAmlM6kpJkmuwB4zoqY5JrRZacbgi67NY3P86wBUyL3OZBKSS9/c3NccTg2KJ3oK0dlayq7orGBxvqyoww0JrBxI10QgD74atkNWpOobaAPjv1YCwAXAJ8j75wECeb3PUVKpRPGZCoXqGxkCgbvDepgqXZqOV8C4EIpLhFkibrV6UWfC3DbQhMW4M5WcEOdROq50JIzLzqzMI/A+mSByGoOEH87nP9OQDzn/E+VUv+TUuonOecviyrltwI4CIhv3ChAGt3C7Z4C7+lYqJYTQNdPbqcymXSZ3L13DN4So2YaHfFoUU3EN4Zo9TJRXRUIlSFrs/CxKigB7/n9T/lcDWaEqEFHwRM1KZI18voXGrPXZJtxqwm9yYy6QXeGsXdc9ysuqg5nR8ZkMSoRs8aoxNqMjNbis2bA8WH
|
||
|
"text/plain": [
|
||
|
"<Figure size 432x288 with 1 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {
|
||
|
"needs_background": "light"
|
||
|
},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"plt.imshow(cat)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 83,
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "slide"
|
||
|
}
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"U, s, Vc = svd(cat, full_matrices=False)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 88,
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "fragment"
|
||
|
}
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"def compress_and_show(k):\n",
|
||
|
" os = cat.shape\n",
|
||
|
" cat_compressed = U[:,:k] @ np.diag(s[:k]) @ Vc[:k,:]\n",
|
||
|
" compression_ratio = 100.0* (k*(os[0] + os[1])+k)/(os[0]*os[1])\n",
|
||
|
" plt.title(\"compression ratio={:.2f}\".format(compression_ratio)+\"%\")\n",
|
||
|
" plt.imshow(cat_compressed)\n",
|
||
|
" plt.axis('off')\n",
|
||
|
" plt.tight_layout()"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 90,
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "fragment"
|
||
|
}
|
||
|
},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAEQCAYAAABLMTQcAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAAEAAElEQVR4nOz92ZItW3aeB36z82Y10e69T5uJzATAriiKBlKXdQe8AVj1BALeQLAyK7O6lFFvAPAJKOhSV0XoAUolZFlRIiUykQ3ytLuJbnXezK4uxnRfK+Lsc04iQRCJrD3NwiJiNb58uc855hj/+Mc/VM6Zd+PdeDfejXfj12vov+0TeDfejXfj3Xg3/tOPd8b93Xg33o1349dwvDPu78a78W68G7+G451xfzfejXfj3fg1HO+M+7vxbrwb78av4Xhn3N+Nv/WhlPpzpdQf/22fxy8z/i6f+7vx6z3eGfd341dh/LfAn/5tn8QvOf6znbtS6veVUv/mb+r5v+p7lFIXSqk/VkrdlZ9/+Vc59rvxNzvs3/YJvBvvRs75f/jbPodvG0qp3wX+OOf8m6eP/+c492I0/wC4/Zt4/pc85gXw58AfA9/POd+Xx96NX5HxznN/N96NX/GRc/6j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bJpXrNNFTD6uI5D1IzBkJLG2igOhI1YEyFp+uBQKjPE4zqd1nrOioSCqmPrG/axzHM70hrPRdXRGk9jamoTOPiKPlhi0rP9DFGTy8ZidBKHUavZhhgljqWPhv3oCNGQis3RWm5ZJKGyEiulVZnomqyz2FWdsS7iXJRNI4EaNG6jqB4y7pDQPoFSZKOLw/jESKdM1jJHVM6kYrBVzoA
|
||
|
"text/plain": [
|
||
|
"<Figure size 432x288 with 1 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {
|
||
|
"needs_background": "light"
|
||
|
},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"compress_and_show(200)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 91,
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "slide"
|
||
|
}
|
||
|
},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAscAAAD7CAYAAACG0TnRAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAyFUlEQVR4nO3de3xcdZ3/8ddnJmmatLknvaVNyiS9t1zStLbcCrSIoFVUCiwq7iq0q67Xn4r4W3/rLrpYXdbVXXVbXH+rLl6g7g+3AkJSLuUuaUBKr5BAofR+mRRoS9Pk+/tjzqRpSNKkmcs5k/fzYZzMOZM5nwyTk3e+/Xy/x5xziIiIiIgIhNJdgIiIiIiIXygci4iIiIh4FI5FRERERDwKxyIiIiIiHoVjERERERGPwrGIiIiIiCcr3QV0VVZW5iZOnJjuMkREBmzdunX7nHPl6a4jlXTOFpEg6+287atwPHHiRBobG9NdhojIgJnZtnTXkGo6Z4tIkPV23lZbhYiIiIiIR+FYRERERMSjcCwiIiI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NliM1vZ2pq4kd5ZFYW88fZxth04nLDnFBE5HcEPx5qQJyKSUs651c65pYWFhQl7zpkVsedq2nYwYc8pInI6Ah+OQ7pCnohI4E0ZnU9VaR4r1jZzvL0j3eWIyBAW+HCsCXkiIqmVjLaKrHCIr71nKlt3v8mX7/ozbQrIIpImGRCONSFPRCSVktFWAfCemWP43CU13P3cDho27k7oc4uI9Ffww7F3qwl5IiLBZmZ8duEkhmeHePrlA+kuR0SGqOCHY7VViIhkjOxwiHMmFPPMKwrHIpI
|
||
|
"text/plain": [
|
||
|
"<Figure size 864x288 with 2 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {
|
||
|
"needs_background": "light"
|
||
|
},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"fig, ax = plt.subplots(1, 2, figsize=(12, 4))\n",
|
||
|
"ax[0].plot(s)\n",
|
||
|
"ax[1].plot(s)\n",
|
||
|
"ax[1].set_yscale('log')"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 92,
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "slide"
|
||
|
}
|
||
|
},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAEQCAYAAABLMTQcAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAAEAAElEQVR4nOz965IkWXbfi/3Wvrh7RGRmZVX3dM8ApIwEz5FJX0FKL6DBG4CmJxDwBqTxCY6RbzA8T8ADPYDMAOoBdIj5IjPJJBMBggQwl+6uyluEX/Zl6cPa7hGZVV3dA4DEcKy2WVVmRoR7uG/fe+21/+u//ktUlU/tU/vUPrVP7Terub/vC/jUPrVP7VP71P7u2yfj/ql9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zlXmFFGFrg22KUfulh1zCTzOPdMcqcUjkvAXo2VKgcfit4H/9XjYJmEqnjp7JAtl9qiCPgXro+uKqCC59Us490/NHp1sES2TJ9x7ukclnipp76jRusqPzhZD3wangxpBoz7rT1TRIJShIPuMaiAfHOWqQBF09uTqUBW0q6RroQzKVZ9I2TPvzGi6WLnazYxLNCcgzoylMuaIiJoBq0BU+9keq18q6gQ/gz86ai/Uq0xVYUwRhxmJEAq1E0r21F6pXRs7wW0TTypIVWpnC2KNZpjdAt29UDobP7UHnBl+t0DpBfViI9+DW2zB8yfBL3aOWTvKoDwdzHDvukT0Fe8rziviKkPXDGl1dDGTsqeUCwOpzSmr0uaMpya32RNV60fnbO46UfA2l4Ovbc45arUFQtv5gq+bbVgdlNXRi7nDodv7wVVyzTzmgVQ9SzWn7XL+R1eoQXDF7IJ6tmtfbYsTm6eyOpS
|
||
|
"text/plain": [
|
||
|
"<Figure size 432x288 with 1 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {
|
||
|
"needs_background": "light"
|
||
|
},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"compress_and_show(50)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "slide"
|
||
|
}
|
||
|
},
|
||
|
"source": [
|
||
|
"# Applications of SVD "
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "fragment"
|
||
|
}
|
||
|
},
|
||
|
"source": [
|
||
|
"## Principal Component Analysis (PCA)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "slide"
|
||
|
}
|
||
|
},
|
||
|
"source": [
|
||
|
"Consider a dataset of points."
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "fragment"
|
||
|
}
|
||
|
},
|
||
|
"source": [
|
||
|
"![](https://i.stack.imgur.com/jPw90.png)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "fragment"
|
||
|
}
|
||
|
},
|
||
|
"source": [
|
||
|
"The two 'properties' of each point in the sample ($x$ and $y$ on this plot) are correlated. Let us think of some new 'property', given by a linear combination $w_1 x + w_2 y$. PCA looks for properties that show as much variation across the data points as possible. Equivalently, PCA looks for properties that allow to reconstruct the original characteristics as well as possible."
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "slide"
|
||
|
}
|
||
|
},
|
||
|
"source": [
|
||
|
"Consider projection of the data points onto a certain (single) direction. Where should one project to maintain the largest variety of the datapoint? Related question: whats the best linear fit?"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "fragment"
|
||
|
}
|
||
|
},
|
||
|
"source": [
|
||
|
"![](https://i.stack.imgur.com/lNHqt.gif)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "slide"
|
||
|
}
|
||
|
},
|
||
|
"source": [
|
||
|
"### Formally:\n",
|
||
|
"The first component should be defined in order to maximize variance. The projections of datapoints $\\mathbf {a}_{{(i)}}$ onto the vector ${\\mathbf {w}}$ are given by $\\mathbf {a}_{{(i)}}\\cdot {\\mathbf {w}}$. Suppose we've already standardized the data, then we need to solve the following optimization problem:\n",
|
||
|
"$$\n",
|
||
|
"{\\underset {\\Vert {\\mathbf {w}}\\Vert =1}{\\operatorname {\\arg \\,max}}}\\,\\left\\{\\sum _{i}\\left({\\mathbf {a}}_{{(i)}}\\cdot {\\mathbf {w}}\\right)^{2}\\right\\}\n",
|
||
|
"$$\n",
|
||
|
"\n",
|
||
|
"or, combining vectors $\\mathbf {a}_{{(i)}}$ into the rows of the matrix $\\mathbf {A}$, we may write:\n",
|
||
|
"\n",
|
||
|
"$$\n",
|
||
|
"{\\underset {\\Vert \\mathbf {w} \\Vert =1}{\\operatorname {\\arg \\,max} }}\\,\\{\\Vert \\mathbf {Aw} \\Vert ^{2}\\}={\\underset {\\Vert \\mathbf {w} \\Vert =1}{\\operatorname {\\arg \\,max} }}\\,\\left\\{\\mathbf {w} ^{\\top}\\mathbf {A^{\\top}} \\mathbf {Aw} \\right\\}\n",
|
||
|
"$$"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "slide"
|
||
|
}
|
||
|
},
|
||
|
"source": [
|
||
|
"The key ingridient is the matrix $A^T A$, proportional to the empirical covariance matrix. It is known that for positive semidefinite matrix $A^\\top A$ the solution is delivered by the eigenvector of $A^\\top A$, corresponding to the largest eigenvalue. We can repeat this procedure and construct another direction, explaining as much variance in orthogonal directions. So, we can conclude, that the following linear operation ($n$ stays for the number of observation points and $d$ for the dimensions of observation vectors):\n",
|
||
|
"\n",
|
||
|
"$$\n",
|
||
|
"\\underset{n \\times d}{A} \\longrightarrow \\underset{n \\times k}{A^\\prime} = \\underset{n \\times d}{A} \\cdot \\underset{d \\times k}{W} \n",
|
||
|
"$$\n",
|
||
|
"\n",
|
||
|
"describes the projection of data onto the $k$ principal components, where $W$ contains first (by the size of eigenvalues) $k$ eigenvectors of $A^\\top A$"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "slide"
|
||
|
}
|
||
|
},
|
||
|
"source": [
|
||
|
"Formally, we may start with SVD decomposition of $A$:\n",
|
||
|
"\n",
|
||
|
"$$A = U \\Sigma W^\\top$$\n",
|
||
|
"\n",
|
||
|
"Then, consider matrix $A^\\top A$:\n",
|
||
|
"\n",
|
||
|
"$$A^\\top A=W \\Sigma^2 W^\\top$$\n",
|
||
|
"\n",
|
||
|
"Which corresponds to the eigendecomposition of matrix $A^\\top A$, where $W$ stands for the matrix of eigenvectors of $A^\\top A$, while $\\Sigma^2$ contains eigenvalues of $A^\\top A$. In other words, columns of $W$ are right singular vectors of $A$.\n",
|
||
|
"\n",
|
||
|
"In the end:\n",
|
||
|
"$$\n",
|
||
|
"A \\longrightarrow A \\cdot W = U \\Sigma W^\\top W = U \\Sigma\n",
|
||
|
"$$\n",
|
||
|
"\n"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "slide"
|
||
|
}
|
||
|
},
|
||
|
"source": [
|
||
|
"# Example of dimensionality reduction via PCA: Wine dataset"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 93,
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "slide"
|
||
|
}
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"import numpy as np\n",
|
||
|
"import matplotlib.pyplot as plt\n",
|
||
|
"from sklearn.datasets import load_wine\n",
|
||
|
"from sklearn.preprocessing import StandardScaler"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 94,
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "fragment"
|
||
|
}
|
||
|
},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"name": "stdout",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"(178, 13) \n",
|
||
|
"\n",
|
||
|
"[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n",
|
||
|
" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n",
|
||
|
" 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n",
|
||
|
" 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2\n",
|
||
|
" 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2]\n"
|
||
|
]
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"wine = load_wine()\n",
|
||
|
"\n",
|
||
|
"A = wine['data']\n",
|
||
|
"print(wine['data'].shape, \"\\n\")\n",
|
||
|
"\n",
|
||
|
"labels = wine['target']\n",
|
||
|
"print(labels)\n",
|
||
|
"\n",
|
||
|
"classes = [0, 1, 2]\n",
|
||
|
"colors = ['red', 'green', 'blue']"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 95,
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "slide"
|
||
|
}
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"# data standardization\n",
|
||
|
"A_std = StandardScaler().fit_transform(A)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 97,
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "fragment"
|
||
|
}
|
||
|
},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
|
"array([[ 1.51861254, -0.5622498 , 0.23205254],\n",
|
||
|
" [ 0.24628963, -0.49941338, -0.82799632],\n",
|
||
|
" [ 0.19687903, 0.02123125, 1.10933436],\n",
|
||
|
" [ 1.69154964, -0.34681064, 0.4879264 ],\n",
|
||
|
" [ 0.29570023, 0.22769377, 1.84040254],\n",
|
||
|
" [ 1.48155459, -0.51736664, 0.30515936],\n",
|
||
|
" [ 1.71625494, -0.4186237 , 0.30515936],\n",
|
||
|
" [ 1.3086175 , -0.16727801, 0.89001391],\n",
|
||
|
" [ 2.25977152, -0.62508622, -0.7183361 ],\n",
|
||
|
" [ 1.0615645 , -0.88540853, -0.352802 ]])"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 97,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"A_std[:10,:3]"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "fragment"
|
||
|
}
|
||
|
},
|
||
|
"source": [
|
||
|
"How can we visually inspect the dataset? Recall that we have 178 datapoints in 13-dimensional space. What if we reduce dimension in some random way? Lets pick two random features."
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 98,
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "fragment"
|
||
|
}
|
||
|
},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"name": "stdout",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"[0 3]\n"
|
||
|
]
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"rank = 2\n",
|
||
|
"ix = np.random.choice(A.shape[1], 2, replace=False)\n",
|
||
|
"print(ix)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 99,
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "slide"
|
||
|
}
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"def inspect_projections(projections):\n",
|
||
|
" for label, colour in zip(classes, colors):\n",
|
||
|
" plt.scatter(projections[labels == label, 0],\n",
|
||
|
" projections[labels == label, 1],\n",
|
||
|
" label = label,\n",
|
||
|
" c = colour)\n",
|
||
|
" plt.legend(loc='best')\n",
|
||
|
" plt.grid()\n",
|
||
|
" plt.show()"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 100,
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "fragment"
|
||
|
}
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"rnd_projections = A[:, ix]"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 102,
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "fragment"
|
||
|
}
|
||
|
},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAD7CAYAAACRxdTpAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAAApi0lEQVR4nO2dbWxc15nf/4cUVZmSQUpULDhSObOjZIECVQKT2i/dFJBAqi1UBEW7YrLecWFnUY+WAhy7QGDBIZq1sh0oNIzKMQp7SX0oXHAW2qUCFLDXxUIURMBCgcKikFpogN2GMoeRYyA2KdKmaFkyefrh3jucubzv99zX+f+AC5Lnvj334cwzZ87zJqSUIIQQki86khaAEEKIemjcCSEkh9C4E0JIDqFxJ4SQHELjTgghOYTGnRBCcsiOuG+4f/9+WSwWfZ1z79497N69OxqB2gDqLxzUXziov3AY+pubm/tUSvk1r+fFbtyLxSJu3Ljh65zZ2VkcO3YsGoHaAOovHNRfOKi/cBj6E0LU/ZzHZRlCCMkhNO6EEJJDaNwJISSHuBp3IcQpIcScEGJeCDEthOht2tcrhBjXtytCi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6ikfKWPPzj3bxqNYSkpiycrsKH3jDe1nobBl2BuyhMhKHZssNgx743rYjbHJYrALklRA495mOC29RBEDH7XjMy7HapocuKqzUhc3vu5rnGQDLsu0GW5LL6pj4KNY6onz+nHfx5Ms/dZNSII6V/s7f4v6xiHLcWD7OMkGnLnnGMMBOPfxHPa/sh/7X9mP+mo
|
||
|
"text/plain": [
|
||
|
"<Figure size 432x288 with 1 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {
|
||
|
"needs_background": "light"
|
||
|
},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"inspect_projections(rnd_projections)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "slide"
|
||
|
}
|
||
|
},
|
||
|
"source": [
|
||
|
"## Lets use PCA for (unsupervised) projection "
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 103,
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "fragment"
|
||
|
}
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"u, s, wh = np.linalg.svd(A_std)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 115,
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "fragment"
|
||
|
}
|
||
|
},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXUAAAD7CAYAAACVMATUAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAcx0lEQVR4nO3df3BU1f3/8ecBFH8bCKGChmICxJJQZYlja4ApBbXORwUtlF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Sap1evXjGLlORQXV3NHXfcwZo1a7j44ot5/PHHGTZsmNtliaSUWCP1HUQelftDHxhjRgNYa1dYa1cAFwJZgf3hrLVl1tp8a21+RkbGiVctCWXPnj1MnDiRSy+9lG3btlFeXs7atWsV6CIuiBXqgfnzUFkRlipeStPIHADnxGoNx0/diIfU19fzwAMP0K9fP5YuXUpxcTHbtm1j0qRJuieLiEuihroz6s5yligGVrkEA90YU+Qce5+mefTA/jSaVs1oXt2DQufNZ82axVVXXcXmzZuZM2cO55xzjtvliaS0lqxTHw6UGGPeB9KttWNCjk0Baq21K5yljqU0Tdmk87/5dfGQ8HnziooKvve977ldlog4Yoa6sx49YkAHLjZyvp8bx7okwezZs4eZM2fy+OOP0717d8rLy7n55ps1zSKSYHTvF4mqvr6e3//+9zz44IM0NDRQVFTEzJkzNc0ikqAU6hKRtZbly5dTVFTErl27uOGGG5g7dy7Z2RFXqYpIgoi1+kVSUHV1NUO
|
||
|
"text/plain": [
|
||
|
"<Figure size 432x288 with 1 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {
|
||
|
"needs_background": "light"
|
||
|
},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"cum_s = np.cumsum(s**2)\n",
|
||
|
"plt.plot(cum_s/cum_s[-1], color = 'black')\n",
|
||
|
"plt.bar(x=np.arange(len(s)), height=s**2/cum_s[-1]);"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "fragment"
|
||
|
}
|
||
|
},
|
||
|
"source": [
|
||
|
"Lets project onto the principal components: $A \\longrightarrow U \\Sigma$"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 110,
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "fragment"
|
||
|
}
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"projections = u[:,:rank] @ np.diag(s[:rank])"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 111,
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "slide"
|
||
|
}
|
||
|
},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXYAAAD7CAYAAAB+B7/XAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAlVklEQVR4nO2dX2wVR5r2n7KNhQ2sjY/348JZH6+Z0V4xfzDfPazJxfBptLsRnrk4YhGsYiZIK3KxChr5YjY7siJHo8yglZLgSEEkPhIbs9kZjYZcBAR3ewORZrmINBOQzYJWM8EHMxDM2sH1XfQ55vicru7q7up/1c9PaoH7dHfVqVP19FtvvVUlpJQghBBiDx1pZ4AQQohZKOyEEGIZFHZCCLEMCjshhFgGhZ0QQiyDwk4IIZbRlXYGAGBwcFCOjIzEns5XX32Fbdu2xZ5OHmHZqGHZuMNyUZNE2dy4ceO+lPLP3T7LhLCPjIzg+vXrsadz7do17N+/P/Z08gjLRg3Lxh2Wi5okykYIsaj6jK4YQgixDAo7IYRYBoWdEEIsg8JOCCGWQWEnhBDLoLATkiOqVWBkBOjocP6tVtPOEckimQh3JIT4U60Ck5PAkyfO34uLzt8AUKmkly+SPWixE5ITpqaei3qDJ0+c84Q0Q2EnJCfcuRPsPCkuFHZCcsLwcLDzpLhQ2AnJCdPTQG/v5nO9vc55QpqhsBOSEyoVYHYWKJcBIZx/Z2c5cEraYVQMITmiUqGQE39osRNCiGVQ2AkhxDIo7IQQYhkUdkIIsQwKOyGEWAaFnRBCLIPCTgghlkFhJ4QQy6CwE0KIZVDYCSHEMijshBBiGRR2QgixDAp7A24mSUgmMNkUi9qsubojwM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
||
|
},
|
||
|
"metadata": {
|
||
|
"needs_background": "light"
|
||
|
},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"inspect_projections(projections)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "fragment"
|
||
|
}
|
||
|
},
|
||
|
"source": [
|
||
|
"Its clear that projections obtained by SVD capture the data variety much better than just two random columns. The resulting projections can be fed to your favourite classification algorithm. In this case, we reduced (in an unsupervised manner) the data in 13-dimensional space to the data in 2-dimensional space!"
|
||
|
]
|
||
|
}
|
||
|
],
|
||
|
"metadata": {
|
||
|
"celltoolbar": "Slideshow",
|
||
|
"kernelspec": {
|
||
|
"display_name": "Python 3 (ipykernel)",
|
||
|
"language": "python",
|
||
|
"name": "python3"
|
||
|
},
|
||
|
"language_info": {
|
||
|
"codemirror_mode": {
|
||
|
"name": "ipython",
|
||
|
"version": 3
|
||
|
},
|
||
|
"file_extension": ".py",
|
||
|
"mimetype": "text/x-python",
|
||
|
"name": "python",
|
||
|
"nbconvert_exporter": "python",
|
||
|
"pygments_lexer": "ipython3",
|
||
|
"version": "3.9.12"
|
||
|
}
|
||
|
},
|
||
|
"nbformat": 4,
|
||
|
"nbformat_minor": 4
|
||
|
}
|