998 lines
388 KiB
Plaintext
998 lines
388 KiB
Plaintext
|
{
|
|||
|
"cells": [
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 72,
|
|||
|
"id": "ddfbd19c",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"import numpy as np\n",
|
|||
|
"import matplotlib.pyplot as plt\n",
|
|||
|
"from sklearn.manifold import TSNE\n",
|
|||
|
"from sklearn.datasets import load_digits\n",
|
|||
|
"from sklearn.preprocessing import StandardScaler\n",
|
|||
|
"import time\n",
|
|||
|
"\n",
|
|||
|
"from scipy.sparse.linalg import svds as scipy_svd\n",
|
|||
|
"from numpy.linalg import svd as numpy_svd\n",
|
|||
|
"from sklearn.utils.extmath import randomized_svd as sklearn_svd"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 73,
|
|||
|
"id": "28566ca9",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"plt.rcParams.update({\"font.size\" : 15, \"font.family\" : \"serif\"})"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"id": "ac58d544",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
" ### Задача 1"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 56,
|
|||
|
"id": "fe997d27",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/plain": [
|
|||
|
"array([[-0.28824414, -0.72344481, -0.31466461, ..., 0.48469425,\n",
|
|||
|
" -0.48534312, -1.75019397],\n",
|
|||
|
" [ 0.97365819, -0.3006159 , 0.23759037, ..., 1.7838543 ,\n",
|
|||
|
" 0.98583849, 0.47303252],\n",
|
|||
|
" [ 0.97682293, 0.66719562, 0.34751901, ..., 1.08327426,\n",
|
|||
|
" 1.34790485, 0.82349545],\n",
|
|||
|
" ...,\n",
|
|||
|
" [ 0.45672919, -0.83670329, 0.28055832, ..., -1.27079724,\n",
|
|||
|
" 0.82394745, 0.08654333],\n",
|
|||
|
" [-0.87594766, 0.32259166, -1.46007173, ..., 0.58111975,\n",
|
|||
|
" 0.75498419, -0.69455994],\n",
|
|||
|
" [-2.75542392, -0.99751411, -1.08212821, ..., 1.93992511,\n",
|
|||
|
" -0.38518655, 0.20831918]])"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 56,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"n = 2000\n",
|
|||
|
"A = np.random.normal(loc=0.0, scale=1.0, size=(n, n))\n",
|
|||
|
"A"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 64,
|
|||
|
"id": "0c04f8c3",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"name": "stderr",
|
|||
|
"output_type": "stream",
|
|||
|
"text": [
|
|||
|
"/Users/goloshch/.conda/envs/NPM/lib/python3.10/site-packages/sklearn/utils/extmath.py:368: FutureWarning: If 'random_state' is not supplied, the current default is to use 0 as a fixed seed. This will change to None in version 1.2 leading to non-deterministic results that better reflect nature of the randomized_svd solver. If you want to silence this warning, set 'random_state' to an integer seed or to None explicitly depending if you want your code to be deterministic or not.\n",
|
|||
|
" warnings.warn(\n"
|
|||
|
]
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"#np.linalg.svd\n",
|
|||
|
"t_numpy = %timeit -o -q -n 2 -r 2 numpy_svd(A)\n",
|
|||
|
"u, s, vh = numpy_svd(A)\n",
|
|||
|
"u, s, vh = u[:,:2], s[:2], vh[:2,:]\n",
|
|||
|
"A_svd = u @ np.diag(s) @ vh\n",
|
|||
|
"\n",
|
|||
|
"\n",
|
|||
|
"#scipy.sparse.linalg.svds\n",
|
|||
|
"t_scipy = %timeit -o -q -n 2 -r 2 scipy_svd(A)\n",
|
|||
|
"u, s, vh = scipy_svd(A, k=2)\n",
|
|||
|
"A_svds = u@np.diag(s)@vh\n",
|
|||
|
"\n",
|
|||
|
"#sklearn.utils.extmath.randomized_svd\n",
|
|||
|
"t_sklearn = %timeit -o -q -n 2 -r 2 sklearn_svd(A, n_components=2)\n",
|
|||
|
"u, s, vh = sklearn_svd(A, n_components=2)\n",
|
|||
|
"A_rsvd = u@np.diag(s)@vh"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 66,
|
|||
|
"id": "c7e12c91",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"name": "stdout",
|
|||
|
"output_type": "stream",
|
|||
|
"text": [
|
|||
|
"Error\n",
|
|||
|
"_____________________________________\n",
|
|||
|
"A_svd : 1995.4380988107664\n",
|
|||
|
"A_svds : 1995.4380988107664\n",
|
|||
|
"A_rsvd : 1995.6080648210457\n",
|
|||
|
"\n",
|
|||
|
"Time\n",
|
|||
|
"_____________________________________\n",
|
|||
|
"Time_svd : 2.94 s ± 46.8 ms per loop (mean ± std. dev. of 2 runs, 2 loops each)\n",
|
|||
|
"Time_svds : 563 ms ± 9.18 ms per loop (mean ± std. dev. of 2 runs, 2 loops each)\n",
|
|||
|
"Time_rsvd : 121 ms ± 6.46 ms per loop (mean ± std. dev. of 2 runs, 2 loops each)\n"
|
|||
|
]
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"print(\"Error\")\n",
|
|||
|
"print(\"_____________________________________\")\n",
|
|||
|
"print(\"A_svd : \", np.linalg.norm(A_svd-A, ord=\"fro\"))\n",
|
|||
|
"print(\"A_svds : \", np.linalg.norm(A_svds-A, ord=\"fro\"))\n",
|
|||
|
"print(\"A_rsvd : \", np.linalg.norm(A_rsvd-A, ord=\"fro\"))\n",
|
|||
|
"print()\n",
|
|||
|
"print(\"Time\")\n",
|
|||
|
"print(\"_____________________________________\")\n",
|
|||
|
"print(\"Time_svd : \", t_numpy)\n",
|
|||
|
"print(\"Time_svds : \", t_scipy)\n",
|
|||
|
"print(\"Time_rsvd : \", t_sklearn)"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"id": "a37e1433",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"__ВыводЫ:__\n",
|
|||
|
"\n",
|
|||
|
"- рандомизированный svd работает быстрее всего, он экономит вычисления за счет приближенного ответа\n",
|
|||
|
"\n",
|
|||
|
"\n",
|
|||
|
"- нормы фробениуса для всех вариантов получились очень большие; думаю, что это связано с тем, что матрицы случайные, в них нет каких-то закономерностей, которые часто встречаются в матрицах из реальных задач(для реальных матриц убывание обычно экспоненциальное)\n",
|
|||
|
"\n",
|
|||
|
"\n",
|
|||
|
"- как видно из графика ниже, сингулярные значения убывают медленно, это не позволяет делать хорошие малоранговые приближения"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 76,
|
|||
|
"id": "14d641f9",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA0sAAAGdCAYAAADDvOhtAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAABnV0lEQVR4nO3dd3gU19XH8e9ZVVRpQvQqOpgmOu6OO7jFuFds3B3HyZs4juPgxIkT17jggnHFvdvEvYFtOpjeezXFFNGbdN8/dgUbWcBK2tXsrn6f55lHmtnZ2bODxNHZe+eMOecQERERERGR/+XzOgAREREREZFopGJJRERERESkFCqWRERERERESqFiSUREREREpBQqlkREREREREqR6HUA0aZ27dquadOmXoch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W3Kfd/Np95a7fSpm6W1yGJiMQcFUsiQFKCjw4NsunQIPvAtuLW5nN/2sa8tVuZ+9NWpq3YwsdBXfnqZqXStl4mHRtk06puJl0b16B+9WpevAURkV84r2tDHvh8Pi+PW84/z+nodTgiIjFHxZLIIQS3Ng8ehdqwbQ9zf9oaKKC2MWfNVkYv2EBgFh85mSm0recfeWpXP4uujavTsEaaR+9CRKqy3KxUrujdlJfGLePSnk1oV1+jSyIiZaFiSaSMcjJTyMnM+Z8b7O7eV8jCdduZvHwTs9dsZc6arTy/eCl7C/3NJOpkpnBUw+oc1TA7sFSnZrqm8IlI5P3mxJa8PG4ZT49ezGMXdfE6HBGRmKJiSSQMUpMS6Ngwm44ND07jK74OavKyTUxfVcD0VVv4au6
|
|||
|
"text/plain": [
|
|||
|
"<Figure size 864x432 with 2 Axes>"
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {
|
|||
|
"needs_background": "light"
|
|||
|
},
|
|||
|
"output_type": "display_data"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"u, s, vh = numpy_svd(A)\n",
|
|||
|
"plt.figure(figsize=(12, 6))\n",
|
|||
|
"\n",
|
|||
|
"plt.subplot(121)\n",
|
|||
|
"plt.semilogy(s)\n",
|
|||
|
"plt.xlabel(\"n_component\")\n",
|
|||
|
"plt.ylabel(\"nth singular value\")\n",
|
|||
|
"\n",
|
|||
|
"plt.subplot(122)\n",
|
|||
|
"plt.plot(s)\n",
|
|||
|
"plt.xlabel(\"n_component\")\n",
|
|||
|
"plt.ylabel(\"nth singular value\")\n",
|
|||
|
"\n",
|
|||
|
"plt.tight_layout()"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"id": "b7868f15",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"### Задача 2"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"id": "4369bc2a",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"- $(A^TA)^{-1}=(V\\Sigma^TU^T U \\Sigma V^T)^{-1}=(V\\Sigma^T \\Sigma V^T)^{-1}=(\\Sigma^T \\Sigma V V^T)^{-1} = (\\Sigma^T \\Sigma )^{-1}=\\Sigma^{-2}$\n",
|
|||
|
"\n",
|
|||
|
"\n",
|
|||
|
"- $(A^TA)^{-1}A^T = \\Sigma^{-2}V\\Sigma U^T$\n",
|
|||
|
"\n",
|
|||
|
"\n",
|
|||
|
"- $A(A^TA)^{-1} = U\\Sigma V^T\\Sigma^{-2}$\n",
|
|||
|
"\n",
|
|||
|
"\n",
|
|||
|
"- $A(A^TA)^{-1}A^T = U\\Sigma V^T\\Sigma^{-2}V\\Sigma U^T = \\Sigma^{-2}U\\Sigma V^TV\\Sigma U^T = \\Sigma^{-2}\\Sigma^2=I$"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"id": "4116a2c8",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"### Задача 3"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 349,
|
|||
|
"id": "127916f3",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"name": "stdout",
|
|||
|
"output_type": "stream",
|
|||
|
"text": [
|
|||
|
"[ 0.6 -0.8] [-0.8 -0.6] 14.142135623730951 7.0710678118654755\n",
|
|||
|
"[-0.70710678 -0.70710678] [-0.70710678 0.70710678]\n"
|
|||
|
]
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"#Считаю, что собственные значения и векторы разрешается искать не ручками, а в питончике\n",
|
|||
|
"A = np.array([[-2, 11], [-10, 5]])\n",
|
|||
|
"\n",
|
|||
|
"#1) Считаем правые сингулярные векторы V\n",
|
|||
|
"res = np.linalg.eig(A.T@A)\n",
|
|||
|
"v2, v1 = res[1].T\n",
|
|||
|
"s2, s1 = res[0]**0.5\n",
|
|||
|
"v = np.array([v1, v2]).T\n",
|
|||
|
"\n",
|
|||
|
"#2) Считаем левые сингулярные векторы U\n",
|
|||
|
"u1, u2 = v1@A.T/s1, v2@A.T/s2\n",
|
|||
|
"u = np.array([u1, u2]).T\n",
|
|||
|
"\n",
|
|||
|
"print(v1, v2, s1, s2)\n",
|
|||
|
"print(u1, u2)"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 362,
|
|||
|
"id": "6c037a22",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"name": "stdout",
|
|||
|
"output_type": "stream",
|
|||
|
"text": [
|
|||
|
"Right singular vedctors : [ 0.6 -0.8] [-0.8 -0.6]\n",
|
|||
|
"\n",
|
|||
|
"Left singular vectors : [-0.70710678 -0.70710678] [-0.70710678 0.70710678]\n",
|
|||
|
"\n",
|
|||
|
"Singular values : 14.142135623730951 7.0710678118654755\n"
|
|||
|
]
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"# Меньше минусов\n",
|
|||
|
"v1, v2 = v1, -v2\n",
|
|||
|
"u1, u2 = u1, -u2\n",
|
|||
|
"\n",
|
|||
|
"print(\"Right singular vedctors : \", v1, v2)\n",
|
|||
|
"print()\n",
|
|||
|
"print(\"Left singular vectors : \", u1, u2)\n",
|
|||
|
"print()\n",
|
|||
|
"print(\"Singular values : \", s1, s2)"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 361,
|
|||
|
"id": "38da9e8a",
|
|||
|
"metadata": {
|
|||
|
"scrolled": false
|
|||
|
},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA00AAAGdCAYAAADOopgqAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwg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ufqR3JbQ7yjsvPuJmMMagV8E9lraa39HdgMFAt/T/gtFU0SsMJ7+OkDPGi8cSyu7e0xxhTA60L21/BenGLDceAYUCz8/8Z4JyZHpQveiadjwnvuwRhTBngHePtumzyE97DUF6hrjGljPImMMb3xzgEYdYv59+B1l1rdGPNK+B5bEz5GxBvAq3eTT0R8k75P/8sHvk//BDYBrYwxlcLXLz131lPdNuAe441LlBfoDYTF4Xf+tvDrYuEFeC8iOYJ3E9+GX//PhI/7ZYyph9fd991KCbwbngnjjX/1OLAgkg5G/iW8h7/OeOv0evh7I5Ex5nW8TjpestZG1Zw1Lj2N17zxZqaEX/t3hxDWB/o910UXlxe8PTpz8U6uPIZ3UuM6vC/lxJHcfxfeHlUbfv+38E54PYw34rcN//t5vC/Pw3gnXIaG//3MdY/1ON7h96N4PQ1ViEbegsDU8Mc6DGwAWt3wmP9ZJt7ezsPh0y6H/z3wJstojtdVa8Tz8T1Q5Lrb5+KN8WCBM8CmG+Zvgtdd8Am8HocWATVcv9a66KJL7F70fRrpMpx9n+IdTZmK1/33AWB1eH4b/vwexjvXbFx4Phv+ehwG3rjucbLhHRk5Fp6h7+1kxBvD6sbXNPg23lcJgE/C1+MQMA2vA4MXwx/r+vV5MZL52+ONV/UPXnf
|
|||
|
"text/plain": [
|
|||
|
"<Figure size 864x432 with 2 Axes>"
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {
|
|||
|
"needs_background": "light"
|
|||
|
},
|
|||
|
"output_type": "display_data"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"# Рисовашки\n",
|
|||
|
"t = np.arange(0, 2.01*np.pi, 2*np.pi/100)\n",
|
|||
|
"n = len(t)\n",
|
|||
|
"x = np.cos(t)\n",
|
|||
|
"y = np.sin(t)\n",
|
|||
|
"\n",
|
|||
|
"x_new = np.zeros(n)\n",
|
|||
|
"y_new = np.zeros(n)\n",
|
|||
|
"\n",
|
|||
|
"for i in range(n):\n",
|
|||
|
" x_new[i] = A[0,0]*x[i]+A[0,1]*y[i]\n",
|
|||
|
" y_new[i] = A[1,0]*x[i]+A[1,1]*y[i]\n",
|
|||
|
"\n",
|
|||
|
"plt.figure(figsize=(12, 6))\n",
|
|||
|
"plt.subplot(121)\n",
|
|||
|
"plt.plot(x, y, color=\"black\")\n",
|
|||
|
"plt.plot([0,v1[0]] ,[0,v1[1]], color=\"blue\")\n",
|
|||
|
"plt.plot([0, v2[0]], [0, v2[1]], color=\"red\")\n",
|
|||
|
"plt.xlim(-1.5, 1.5)\n",
|
|||
|
"plt.ylim(-1.5, 1.5)\n",
|
|||
|
"plt.xlabel(\"x\")\n",
|
|||
|
"plt.ylabel(\"y\")\n",
|
|||
|
"plt.title(\"Unit circle\")\n",
|
|||
|
"plt.grid()\n",
|
|||
|
"\n",
|
|||
|
"\n",
|
|||
|
"plt.subplot(122)\n",
|
|||
|
"plt.plot(x_new, y_new, color=\"black\")\n",
|
|||
|
"plt.plot([0,s1*u1[0]] ,[0,s1*u1[1]], color=\"blue\")\n",
|
|||
|
"plt.plot([0, s2 *u2[0]], [0, s2*u2[1]], color=\"red\")\n",
|
|||
|
"plt.xlim(-15, 15)\n",
|
|||
|
"plt.ylim(-15, 15)\n",
|
|||
|
"plt.xlabel(\"x\")\n",
|
|||
|
"plt.ylabel(\"y\")\n",
|
|||
|
"plt.title(\"Unit circle after transform A\")\n",
|
|||
|
"plt.grid()\n",
|
|||
|
"\n",
|
|||
|
"plt.tight_layout()"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"id": "76355bef",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"$||A||_2 = \\sigma_1, \\; ||A||_F = \\sqrt{\\sigma_1^2 + \\sigma_2 ^2}$"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 360,
|
|||
|
"id": "2957d83e",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"name": "stdout",
|
|||
|
"output_type": "stream",
|
|||
|
"text": [
|
|||
|
"A2 = 14.142135623730951\n",
|
|||
|
"AF = 15.811388300841898\n"
|
|||
|
]
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"# Нормы\n",
|
|||
|
"print(\"A2 = \", s1)\n",
|
|||
|
"print(\"AF = \", (s1**2+s2**2)**0.5)"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"id": "839a440f",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"$A^{-1} = V\\Sigma^{-1}U^T$, $\\Sigma^{-1} = \\begin{pmatrix}\n",
|
|||
|
"\\frac{1}{\\sigma_1} & 0\\\\\n",
|
|||
|
"0 & \\frac{1}{\\sigma_2}\\\\\n",
|
|||
|
"\\end{pmatrix}$"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 359,
|
|||
|
"id": "f97fba41",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"name": "stdout",
|
|||
|
"output_type": "stream",
|
|||
|
"text": [
|
|||
|
"[[1.00000000e+00 3.74700271e-16]\n",
|
|||
|
" [7.63278329e-17 1.00000000e+00]]\n",
|
|||
|
"[[ 1.00000000e+00 -1.56125113e-16]\n",
|
|||
|
" [-1.66533454e-16 1.00000000e+00]]\n"
|
|||
|
]
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"# Обратная матрица через SVD\n",
|
|||
|
"v = np.array([v1, v2]).T\n",
|
|||
|
"u = np.array([u1, u2]).T\n",
|
|||
|
"s = np.array([[s1, 0], [0, s2]])\n",
|
|||
|
"sinv = np.array([[1/s1, 0], [0, 1/s2]])\n",
|
|||
|
"Ainv = v@sinv@u.T\n",
|
|||
|
"\n",
|
|||
|
"print(Ainv@A)\n",
|
|||
|
"print(A@Ainv)"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 358,
|
|||
|
"id": "0e1b0097",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/plain": [
|
|||
|
"(array([1.5+9.88685997j, 1.5-9.88685997j]),\n",
|
|||
|
" array([[0.72374686+0.j , 0.72374686-0.j ],\n",
|
|||
|
" [0.23028309+0.65050763j, 0.23028309-0.65050763j]]))"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 358,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"# Собственные значения\n",
|
|||
|
"np.linalg.eig(A)"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"id": "331d2bf0",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"### Задача 4"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"id": "5a9196fc",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"1) $A_{ij} \\simeq h_i \\eta_j \\Leftrightarrow A=h \\eta^T$, по теореме о ранге произведения \n",
|
|||
|
"$rang(h\\eta^T) \\leq rang(h) + rang(\\eta^T) - 1 = 1$, т.е. аппроксимация имеет ранг 1\n",
|
|||
|
"\n",
|
|||
|
"2) По теореме Эккарта-Янга-Мирского лучшим приближением матрицы A ранга r является её обрезанное сингулярное разложение по первым r сингулярным числам, причем $||A-A_r||_F=\\sqrt{\\sum_{i=r+1}^n\\sigma_i^2}$\n",
|
|||
|
"\n",
|
|||
|
"3) SVD-разложение даёт $A = U\\Sigma V^T$, где $U=(u_1 \\;u_2\\;...), \\Sigma = Diag(\\sigma_1, \\sigma_2,...), V=(v_1 \\;v_2\\;...)$, $u_i, v_j$ - векторы-столбцы, причем $\\sigma_i\\geq 0$\n",
|
|||
|
"\n",
|
|||
|
"$A_1 = \\begin{pmatrix}\n",
|
|||
|
"u_1 \\\\\n",
|
|||
|
"\\end{pmatrix}\n",
|
|||
|
"\\begin{pmatrix}\n",
|
|||
|
"\\sigma_1\\\\\n",
|
|||
|
"\\end{pmatrix}\n",
|
|||
|
"\\begin{pmatrix}\n",
|
|||
|
"v_1^T\\\\\n",
|
|||
|
"\\end{pmatrix} = \\sigma_1 u_1 v_1^T$\n",
|
|||
|
"\n",
|
|||
|
"Тогда $h=\\sqrt{\\sigma_1}u_1, \\; \\eta = \\sqrt{\\sigma_1}v_1$(коэффициенты можно и по-другому выбрать, но мне нравится так)\n",
|
|||
|
"\n",
|
|||
|
"4) $\\delta_{err} = \\frac{\\sqrt{\\sum(A_{ij}-h_i \\eta_j)^2}}{\\sqrt{\\sum A_{ij}^2}} = \\frac{||A-h\\eta^T||_F}{||A||_F} = \\frac{\\sqrt{\\sum_{i=2}^n \\sigma_i^2}}{\\sqrt{\\sum_{i=1}^n \\sigma_i^2}} = \\sqrt{1-\\frac{\\sigma_1^2}{\\sum_{i=1}^n \\sigma_i^2}}$(доля необъясненной дисперсии фактически)\n",
|
|||
|
"\n",
|
|||
|
"5) $A_{ij} = \\sum_{\\alpha=1}^K h_{\\alpha i} \\eta_{j \\alpha} \\Leftrightarrow A = \\sum_{i=1}^{rang(A)}\\sigma_i u_i v_i^T$, т.е. $K=rang(A)$"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 327,
|
|||
|
"id": "435bc6dc",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"name": "stdout",
|
|||
|
"output_type": "stream",
|
|||
|
"text": [
|
|||
|
"delta_err : 0.7742251888975445\n",
|
|||
|
"delta_err_formula : 0.7742251888975445\n"
|
|||
|
]
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"A = np.load(\"A.npy\")\n",
|
|||
|
"\n",
|
|||
|
"u, s, vh = np.linalg.svd(A)\n",
|
|||
|
"A_svd = u[:,:1] @ np.diag(s[:1]) @ vh[:1,:]\n",
|
|||
|
"\n",
|
|||
|
"print(\"delta_err : \", np.linalg.norm(A-A_svd, ord=\"fro\")/np.linalg.norm(A, ord=\"fro\"))\n",
|
|||
|
"print(\"delta_err_formula : \", (1- s[0]**2/np.sum(s**2))**0.5)"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 328,
|
|||
|
"id": "55837ecb",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"name": "stdout",
|
|||
|
"output_type": "stream",
|
|||
|
"text": [
|
|||
|
"[5.00299422e+01 4.99770106e+01 2.54470684e+01 2.45000000e+01\n",
|
|||
|
" 1.11272856e-14 9.55930610e-15 8.62751654e-15 4.99613766e-15\n",
|
|||
|
" 4.99613766e-15 4.99613766e-15 4.99613766e-15 4.99613766e-15\n",
|
|||
|
" 4.99613766e-15 4.99613766e-15 4.99613766e-15 4.99613766e-15\n",
|
|||
|
" 4.99613766e-15 4.99613766e-15 4.99613766e-15 4.99613766e-15\n",
|
|||
|
" 4.99613766e-15 4.99613766e-15 4.99613766e-15 4.99613766e-15\n",
|
|||
|
" 4.99613766e-15 4.99613766e-15 4.99613766e-15 4.99613766e-15\n",
|
|||
|
" 4.99613766e-15 4.99613766e-15 4.99613766e-15 4.99613766e-15\n",
|
|||
|
" 4.99613766e-15 4.99613766e-15 4.99613766e-15 4.99613766e-15\n",
|
|||
|
" 4.99613766e-15 4.99613766e-15 4.99613766e-15 4.99613766e-15\n",
|
|||
|
" 4.99613766e-15 4.99613766e-15 4.99613766e-15 4.99613766e-15\n",
|
|||
|
" 4.99613766e-15 4.99613766e-15 4.99613766e-15 3.65548473e-15\n",
|
|||
|
" 3.20651151e-15 1.21059206e-15]\n"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"image/png": "iVBORw0K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QADXA0iaBdwI3BYRWzNqw5TgkYeZFUFPwkPS3ZLWNDeXSFoj6crW/ojYBlwMLJa0jsYy3fuBm3px/pT49iRmVgQ9mTCPiKvGUedJ4JJenC9l9WrZN0Y0s+QleWPElNUrZfaMBCP7psxHT8zMuubwyFit+TRBz3uYWcocHhmr738glOc9zCxdDo+M1auN1cr+lLmZpczhkTGHh5kVgcMjY63nmPvOumaWModHxjzyMLMicHhkrLXayhPmZpYyh0fGapXGyMNLdc0sZQ6PjNU98jCzAnB4ZKw15+GRh5mlzOGRMU+Ym1kRODwy5qW6ZlYEDo+MeeRhZkXg8MiY721lZkXg8MhYpVyiXJInzM0saQ6PHNQrfo65maXN4ZGDerXsOQ8zS5rDIweN8PDIw8zS5fDIQa1S8pyHmSXN4ZGDmkceZpa4St4N6IakU4EngJ1txSMRcVI+LToy9apHHmaWttRGHiPAn0TEr0TErwDvA76Zc5u6VquUGPbIw8wS1rPwkHSNpO2SVoyx/yxJqyWtk7RR0s2Suhr5RMSzEfH5tqKlwKoJNDsX9WqZ3R55mFnCJhweko6V9ABwHjBvjDp9wMPAPRFxIbAIuAK4ZQLnPRroj4h/OtJj5KVe8VJdM0tbL0Yes4EVEbH8EHWWAwJuB4iIXTSCY5mk/lYlSWslbRnl645RjvlB4K970P7MNeY8fNnKzNI14QnziBgChg5T7XJgMCLaf91eD5SBS4E7m8da1MWpF9MYvSSn5pGHmSUuqwnzBcDWjrLnmq+nd3swSb8GPB4Rw4eos1TSoKTBbdu
|
|||
|
"text/plain": [
|
|||
|
"<Figure size 432x288 with 1 Axes>"
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {
|
|||
|
"needs_background": "light"
|
|||
|
},
|
|||
|
"output_type": "display_data"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"plt.semilogy(s)\n",
|
|||
|
"print(s)"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 117,
|
|||
|
"id": "480b8e58",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"name": "stdout",
|
|||
|
"output_type": "stream",
|
|||
|
"text": [
|
|||
|
"delta_err : 3.2502455784278293e-15\n"
|
|||
|
]
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"u, s, vh = np.linalg.svd(A)\n",
|
|||
|
"A_svd = u[:,:4] @ np.diag(s[:4]) @ vh[:4,:]\n",
|
|||
|
"\n",
|
|||
|
"print(\"delta_err : \", np.linalg.norm(A-A_svd, ord=\"fro\")/np.linalg.norm(A, ord=\"fro\"))"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"id": "0f89340f",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"__Вывод:__\n",
|
|||
|
"\n",
|
|||
|
"- По сингулярным числам видно, что ранг матрицы равен 4, ошибка такой аппроксимации это по сути ошибка вычислений\n",
|
|||
|
"\n",
|
|||
|
"\n",
|
|||
|
"- Задачка забавная, я бы за неё больше баллов ставил"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"id": "a8688c28",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"### Задача 5"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 91,
|
|||
|
"id": "4a205d41",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"name": "stdout",
|
|||
|
"output_type": "stream",
|
|||
|
"text": [
|
|||
|
"0.0\n",
|
|||
|
"16.0\n",
|
|||
|
"[ 0. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16.]\n"
|
|||
|
]
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"digits = load_digits()\n",
|
|||
|
"A = digits.data\n",
|
|||
|
"y = digits.target\n",
|
|||
|
"\n",
|
|||
|
"print(A.min())\n",
|
|||
|
"print(A.max())\n",
|
|||
|
"print(np.unique(A))"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 42,
|
|||
|
"id": "98116264",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAaQAAAGoCAYAAAAJjpFOAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAfSklEQVR4nO3dfZBW5Znn8d9l0w2CjJIQzciLYFBcnHUWqwvjGDVKmSEvFTST2kFjdrXMdsaslk4ylSXuVMWt2jWpnRqDNWOYsIrJRA1WTIhuyqCUL0RXB22FivJaBFFA5cUkhiJCN3DtH3R3PcDTT59z5Tmn7/Pw/VRZ0k1ffd8efvLjPJy+29xdAAAMtxOGewMAAEgUEgAgERQSACAJFBIAIAkUEgAgCSOK+KQdNtJHaUwRn7qpOs6J9fHIEw6E1/zdjrGhubZ394bXzGuf9qrH91tZ61UlL4dOie1xyqQd4TXf6f2T0FzP+kPhNfNq9bz0TIit9Wcf3BWa+82httCcJL27IbZX743/npZXo7wUUkijNEYX2OwiPnVTnf6DWDmcNXpneM2f3Xl5aG7c918Ir5nXSn+ytLWk6uTlD5dfEJq7d8Gd4TW/9fac0NxbH90TXjOvVs/L6zdfGJp78T8vDM0t2TMuNCdJP7x0VmjuwDvxPzTl1SgvvGQHAEgChQQASEKmQjKzOWa2wcw2mdn8ojeFaiMvyIO8oN+QhWRmbZLulvRJSTMkXW1mM4reGKqJvCAP8oJaWe6QZkna5O6b3b1H0hJJc4vdFiqMvCAP8oIBWQppgqStNW9v63vfEcysy8y6zay7V/ubtT9UD3lBHuQFA5r2UIO7L3L3TnfvbNfIZn1atCjygjzIy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"
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {
|
|||
|
"needs_background": "light"
|
|||
|
},
|
|||
|
"output_type": "display_data"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"plt.figure(figsize=(6, 6))\n",
|
|||
|
"for i in range(1, 10):\n",
|
|||
|
" plt.subplot(3,3,i)\n",
|
|||
|
" plt.imshow(A[i].reshape(8, 8))\n",
|
|||
|
"plt.tight_layout()"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 43,
|
|||
|
"id": "fefcb6e8",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAaQAAAGoCAYAAAAJjpFOAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAlHElEQVR4nO3dfXTc9ZXf8c/V6MG2bNkY2+C1TWyC4YSQcGC1HLLkYRdCSkIObE8IgSVJQ9p60ywpdLObQtN0255uT9Ldsk4awtYLZB9C1t1AaFhCIWQDedgQggwmBBuDYwy2ebDBNrZlY2lGt39Y8pGNNJrvRb/R9ye9X+f4YMm6fL/6zWfm6jf6zR1zdwEAMNFaJnoDAABINCQAQCZoSACALNCQAABZoCEBALLQWsT/tDKr01vnHZNcZ/0WWq+1N3alYP8xsbpKZSBUJ0m1vkqozqqxY+Ot6d9j9ZVdqu3rjS0YUOns9LY5c5PrrBZbr/VA7HZv2X8wVHfwhPZQnSS1t1ZDddXdsTUHAvHs371Ttf3556UldihVmxHLS2tbLKDVg7HHCElq3xWrq3XEbr6BtvSaenkppCG1zjtGC//LVel1L8buRMc/GLvht13SH6qbPXt/qE6Sdm2dHarreDkW0oPz04/Ni//9y6G1otrmzNWS3/93yXUdO2N3omOf6Av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QAgCzQkAEAWmtaQzOwCM9tgZhvN7NpmrVsGZrbZzB43s7Vm1jPR+8kBeRkdeXk98jK6MuWlKb9DMrOKpKcknS9pq6SHJV3u7usKX7wEzGyzpG53z+WFaxOKvNRHXo5EXuorU16adYZ0lqSN7r7J3fskrZZ
|
|||
|
"text/plain": [
|
|||
|
"<Figure size 432x432 with 9 Axes>"
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {
|
|||
|
"needs_background": "light"
|
|||
|
},
|
|||
|
"output_type": "display_data"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"#Такой вариант нормализации работает так себе\n",
|
|||
|
"#(вычет среднего+деление на стандартное отклонение)\n",
|
|||
|
"ss=StandardScaler()\n",
|
|||
|
"ss.fit(A)\n",
|
|||
|
"A_transform = ss.transform(A)\n",
|
|||
|
"\n",
|
|||
|
"plt.figure(figsize=(6, 6))\n",
|
|||
|
"for i in range(1, 10):\n",
|
|||
|
" plt.subplot(3,3,i)\n",
|
|||
|
" plt.imshow(A_transform[i].reshape(8, 8))\n",
|
|||
|
"plt.tight_layout()"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 143,
|
|||
|
"id": "31c0c6c0",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAaQAAAGoCAYAAAAJjpFOAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAfSklEQVR4nO3dfZBW5Znn8d9l0w2CjJIQzciLYFBcnHUWqwvjGDVKmSEvFTST2kFjdrXMdsaslk4ylSXuVMWt2jWpnRqDNWOYsIrJRA1WTIhuyqCUL0RXB22FivJaBFFA5cUkhiJCN3DtH3R3PcDTT59z5Tmn7/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j7m7tvN7FRJy81svbv/crg3hWSRF+RRmbyUdYe0XdKkmrcn9r0Pktx9e9+/d0paqsMvQRzPyEsD5OUY5KWBKuWlrEJ6SdJZZjbVzDokzZP0aElrJ83MxpjZ2P4fS/qEpNeGd1fDjrwMgrzURV4GUbW8lPKSnbsfMLObJD0uqU3SYndfU8baFXCapKVmJh3+9XjQ3ZcN75aGF3lpiLwchbw0VKm8cHQQACAJnNQAAEgChQQASAKFBABIAoUEAEgChQQASAKFBABIAoUEAEgChQQASAKFBABIAoUEAEgChQQASEIhh6t22EgfpTFFfOqmshGx//xDZ8Z73Db2hGfLsk971eP7raz1ys5LxzmxX7+9vR2hufZf7wvNVUWr5yUqmrORJxwIr7lnbfr3GI3yUkghjdIYXWCzi/jUTdU2/tTQ3PvfPTG8ZscVb4Rny7LSnyx1vbLzcvoPxobmXtw+OTQ38a9a++DpVs9LVDRnZ43eGV5zxXnx35v
|
|||
|
"text/plain": [
|
|||
|
"<Figure size 432x432 with 9 Axes>"
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {
|
|||
|
"needs_background": "light"
|
|||
|
},
|
|||
|
"output_type": "display_data"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"#min-max нормализация\n",
|
|||
|
"#То что надо\n",
|
|||
|
"A_transform = 2*(A/A.max()-0.5)\n",
|
|||
|
"\n",
|
|||
|
"plt.figure(figsize=(6, 6))\n",
|
|||
|
"for i in range(1, 10):\n",
|
|||
|
" plt.subplot(3,3,i)\n",
|
|||
|
" plt.imshow(A_transform[i].reshape(8, 8))\n",
|
|||
|
"plt.tight_layout()"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 159,
|
|||
|
"id": "0cbf466b",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"name": "stdout",
|
|||
|
"output_type": "stream",
|
|||
|
"text": [
|
|||
|
"((1797, 64), (64,), (64, 64))\n"
|
|||
|
]
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"u, s, vh = svd(A, full_matrices=False)\n",
|
|||
|
"v = vh.T\n",
|
|||
|
"print((u.shape, s.shape, v.shape))\n",
|
|||
|
"\n",
|
|||
|
"n = 2\n",
|
|||
|
"u, s, v = u[:,:n], s[:n], v[:,:n]"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 145,
|
|||
|
"id": "71184634",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"name": "stdout",
|
|||
|
"output_type": "stream",
|
|||
|
"text": [
|
|||
|
"(1797, 64)\n"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/plain": [
|
|||
|
"1332.574288788176"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 145,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"A_new = u @ np.diag(s) @ v.T\n",
|
|||
|
"print(A_new.shape)\n",
|
|||
|
"np.linalg.norm(A_new-A)"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 199,
|
|||
|
"id": "11ed6e84",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAaQAAAGoCAYAAAAJjpFOAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAizUlEQVR4nO3de5CddZ3n8c+3T1/TuTQhFyAJkIGAgzMq2AYYQF1QBoERtxZH2MUpdXfi/BEF1yoLq6Z2ardqp+aPXSdOrcOaRazZNZpRhBEplosiUKyKdEK8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wkAEASGEgAgCQwkAAASWAgAQCSwEACACSBgQQASIK5+9T/pWb7JO0Y583zJO2f8oMWX0rn5Tx3n1+vg9GXkJTOC31JX0rnZdy+5DKQJmJmPe7OL+M6BeelOs5LdZyX6jgv1RXlvPCQHQAgCQwkAEASpmMgrZ6GYxYB56U6zkt1nJfqOC/VFeK81P1nSAAAVMNDdgCAJDCQAABJqNtAMrMbzGyLmW01s7vrddwiMLPtZvZbM9tgZj3TvZ4U0Jfx0ZfT0ZfxFakvdfkZkpmVJL0k6aOSeiU9L+l2d9+U+8ELwMy2S+p291SeuDat6MvE6MvJ6MvEitSXel0hLZe01d23uXtZ0lpJt9Tp2Cge+oIs6EuDqNdAWiRpV8XLvSOvwwku6XEzW2dmK6Z7MQmgLxOjLyejLxMrTF+ap3sBkCRd7e67zWyBpCfM7EV3f2a6F4Vk0RdkUZi+1OsKabekJRUvLx55HSS5++6R/++V9KBOPATxTkZfJkBfTkNfJlCkvtRrID0
|
|||
|
"text/plain": [
|
|||
|
"<Figure size 432x432 with 9 Axes>"
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {
|
|||
|
"needs_background": "light"
|
|||
|
},
|
|||
|
"output_type": "display_data"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"plt.figure(figsize=(6, 6))\n",
|
|||
|
"for i in range(1, 10):\n",
|
|||
|
" plt.subplot(3,3,i)\n",
|
|||
|
" plt.imshow(A_new[i].reshape(8, 8))\n",
|
|||
|
"plt.tight_layout()"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 200,
|
|||
|
"id": "a5282d4e",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/plain": [
|
|||
|
"<matplotlib.collections.PathCollection at 0x7fa5e040db10>"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 200,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result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VTMxIXpWTmnixG3ePGe3SnG1kzYHNzSSfW4AoSSecat6oIrPj6dfevbWPXA/iG5421pg5Nl2IR6YzSsaWXmhbUUlHmZf+VYmvf30Xa4f+BYVReASKtWfaNMXzYqbVvjzi66jodSUiFPrEYGNeQlq/96kLqZpRln9DlynC3kjPxZhhCCCfMrmDC/Ius+LQd6WXnfvqxuEHCM8Gv376N8TP6bLtFv2tebMfvFjFsIRaBqSopBFALySjzc/A/z8eTp3Pv3r6e8nk3w0UzYNO7qHpgdC0Vw7Rdms3d1Cw1r2xCKYNrSUVTUF/D0T7cR7o1nPdepUFjhZfYlo9O2H9/bixG3MhyRirQlh7d2MufSMad0Pcuy6WkJ4/Jo70q9nxzvTnJG/l3I+icPn5ILIx4xefi/NnLHPy9OyRF/I2Rz+nj8Old9aiav/rmBWMhASknd9FIu+dBU3D6d/s7IKRd0CQX8ha6UbaqqMOP8Wmac7xh+27Jp3tfHOTeOx+XViIUN1j1xmHBffETf+6yLazmys4toIIE3T2fuZXVMXVqNpqfXFfiLXCiayBzcHYJtnbpE8cEtHaz4cwO27bi7Sqr9XPXpmeSXvLm/S44cJyNn5N+F9LadeuehRMziof/cSGlNHrMuHk39rLLTvl7tlGIyxXk1t8LkxVWMmV7Kh/7zXMJ9CVweNSVPv7ctklYBmg1VU5gxgo+7ty3M4z/a6syypWNkR00sJNIfH/G8ukelrDaPAxvbsS1JLGQS6o0hbdi/sY22QwEKy71MXlKFx68zeXE1m549ij3SqJGkdkrJSffpbg7xyu/3pDyHrqYgT/54G3f+y+IzFjfJkSMTOSP/LqSk2k9zsO/UdpaOREBTQy9th/uZc+kYFl8/7rSup7tUrvj
|
|||
|
"text/plain": [
|
|||
|
"<Figure size 432x432 with 1 Axes>"
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {
|
|||
|
"needs_background": "light"
|
|||
|
},
|
|||
|
"output_type": "display_data"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"X = u@np.diag(s)\n",
|
|||
|
"\n",
|
|||
|
"plt.figure(figsize=(6, 6))\n",
|
|||
|
"\n",
|
|||
|
"plt.scatter(X[:,0], X[:,1], c=y, cmap=\"tab10\")"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 201,
|
|||
|
"id": "dd4293dd",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"name": "stderr",
|
|||
|
"output_type": "stream",
|
|||
|
"text": [
|
|||
|
"/Users/goloshch/.conda/envs/NPM/lib/python3.10/site-packages/sklearn/manifold/_t_sne.py:780: FutureWarning: The default initialization in TSNE will change from 'random' to 'pca' in 1.2.\n",
|
|||
|
" warnings.warn(\n",
|
|||
|
"/Users/goloshch/.conda/envs/NPM/lib/python3.10/site-packages/sklearn/manifold/_t_sne.py:790: FutureWarning: The default learning rate in TSNE will change from 200.0 to 'auto' in 1.2.\n",
|
|||
|
" warnings.warn(\n"
|
|||
|
]
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"u, s, vh = svd(A, full_matrices=False)\n",
|
|||
|
"v = vh.T\n",
|
|||
|
"\n",
|
|||
|
"n = 64\n",
|
|||
|
"u, s, v = u[:,:n], s[:n], v[:,:n]\n",
|
|||
|
"X = u@np.diag(s)\n",
|
|||
|
"\n",
|
|||
|
"X_embedded = TSNE(n_components=2).fit_transform(X)"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 202,
|
|||
|
"id": "2d10f578",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/plain": [
|
|||
|
"Text(0.5, 1.0, '64 признака - максимум')"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 202,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
},
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"image/png": "iVBORw0KGgoAAAANS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sUX/90YlmvFJVtxNh26K5BS8t0720K65sQzB6juk4oSJSrJx4Bt3+8P27Uaa5zMf8n3gSGl5N1HVuJ2drONxm/ZhzvUoChFiRKV5GNAQ40LwxtaIj7A8Eq2ryzH6zH46MnV7FpXFfI1HXVuKnY1hCE6RVG6SrXJ92H7S+r46Kk11Fc0h/W6UkqcTW62ragIy/WEAKdDdZ9UlGhQSb6PWv3lbr56ZRNEoBUkOcNOyZrKsF3b7fLicnhoqnMRl2QJz0UVRQmKSvJ9jKPRzVt/WUp1mSNiZTib3Hzx3w1hu5404LPn1+F1G4ycns9x5w9WD2IVpYeoJN+HuJo9vPz7RTQ3uCNajqMh/E0rLodvYptVn+9ix+oKhkzKxmIzMWh8JkkZ9rCXpyiKT1iSvBAiBXgaOArfTf5VwEbgVaAI2AFcIKWsDkd5R6r1C/ZGPMH3hLpyB0s/2IHQ4bt3tzH1vMGMOj4/2mEpSkwKV++afwIfSSmHAWOA9cBtwGdSymLgM/9rJQQlayqjHUJYSS943QYLXt9CQ3V4Hx4riuITcpIXQiQD04FnAKSULillDTAbeN5/2PPAD0It60gXn2oN+zWFJhCab6RrNG1fGZ6ePIqitBaOmvwAoBx4VgjxvRDiaSFEPJAtpdzrP6YMyA50shDiWiHEUiHE0vLy8jCEE7tGn5CPbu7kRyb8/4IkDYk9wcKkM4q6dF44qUewihI54UjyJmA88ISUchzQyGFNM9I33DFghzwp5ZNSyolSyomZmZlhCCd2ZfZPZNoFxR0eo+mCs34+hsvvnxr0fDZNdS6Wf7IzIt0xgyGBAWNa/+ylIdU
|
|||
|
"text/plain": [
|
|||
|
"<Figure size 432x432 with 1 Axes>"
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {
|
|||
|
"needs_background": "light"
|
|||
|
},
|
|||
|
"output_type": "display_data"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"plt.figure(figsize=(6, 6))\n",
|
|||
|
"\n",
|
|||
|
"plt.scatter(X_embedded[:,0], X_embedded[:,1], c=y, cmap=\"tab10\")\n",
|
|||
|
"plt.title(\"64 признака - максимум\")"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 203,
|
|||
|
"id": "e69350cc",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"name": "stderr",
|
|||
|
"output_type": "stream",
|
|||
|
"text": [
|
|||
|
"/Users/goloshch/.conda/envs/NPM/lib/python3.10/site-packages/sklearn/manifold/_t_sne.py:780: FutureWarning: The default initialization in TSNE will change from 'random' to 'pca' in 1.2.\n",
|
|||
|
" warnings.warn(\n",
|
|||
|
"/Users/goloshch/.conda/envs/NPM/lib/python3.10/site-packages/sklearn/manifold/_t_sne.py:790: FutureWarning: The default learning rate in TSNE will change from 200.0 to 'auto' in 1.2.\n",
|
|||
|
" warnings.warn(\n"
|
|||
|
]
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"u, s, vh = svd(A, full_matrices=False)\n",
|
|||
|
"v = vh.T\n",
|
|||
|
"\n",
|
|||
|
"n = 8\n",
|
|||
|
"u, s, v = u[:,:n], s[:n], v[:,:n]\n",
|
|||
|
"X = u@np.diag(s)\n",
|
|||
|
"\n",
|
|||
|
"X_embedded = TSNE(n_components=2).fit_transform(X)"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 204,
|
|||
|
"id": "27756893",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/plain": [
|
|||
|
"Text(0.5, 1.0, '8 признаков')"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 204,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
},
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXkAAAF1CAYAAAANwZpGAAAAOXRFWHRTb2Z0d2FyZQBNY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HgqGJU2il4JvZi/ez6rSlYxZ+ccNlVsCvKc2Rtg1VK/vxb+2uLYqlA5pe8pZDozo3Y/JiamyJt0OX4u+Jmd1TtbFfPWzB/tZUTaCBShcFjPw4KOT+05lak9p3LpsEu548c7mL97PhbFwtE5RzOnYA42YUM3dCQy5OEkkSHulI1RULh82OXcPv72qN+PyaGNufFq0uXYUL4hotW6RJJgS2hz/1bFikN1YBXWsOefXPwklZ7KZq+PtcTSJ6EPVtWKVbHyzY5v8Bt+PLoHv/S3ea9AILho6EXcMeEO01/eJOqYIm/S5Ui0J0bcttpXDbTsFtmYGDWGG8fcyIKLF3DD2BuwKbaQNprUWFq8tNk+5u6ayydbPsGn+9oUaNUcVsXKKX1P6XA/JibhMEXepEvg8rv4ePPHvLn2TTJjM8OusnvE9sAmQkUZAvbsI3oegV21tziOW3fz9LKnuWr2VZzW9zTirHEhbaSUOFRHyLHlxcuZs2MOK0tWRtXNcVjqMEamjYxafyYmjTFt8iYHnFJXKWfNPIsabw0AVtXKmQPO5LMtn6FJDYkkPSadF459gQu/vJDGZngVydVpXvrYDdZqq9lgicOre4P6V4WKIpQGm7gkINgzZs7g0qGX8tKql4Js+4qiMClzUsNnQxrcNuc2FhQuQBUqPt2HqqhoerBZJtYS2+aVvUWx8OJxL5pmGpNOw1zJmxxQfLqPs2aeRaW3Er3+fx7dw0ebP6JPYh8sIrAOqfJWcedPd4ZcbxHgkYJYBUZZChls2YP
|
|||
|
"text/plain": [
|
|||
|
"<Figure size 432x432 with 1 Axes>"
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {
|
|||
|
"needs_background": "light"
|
|||
|
},
|
|||
|
"output_type": "display_data"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"plt.figure(figsize=(6, 6))\n",
|
|||
|
"\n",
|
|||
|
"plt.scatter(X_embedded[:,0], X_embedded[:,1], c=y, cmap=\"tab10\", s=20)\n",
|
|||
|
"plt.title(\"8 признаков\")"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"id": "97f13c17",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"__Вывод:__\n",
|
|||
|
"\n",
|
|||
|
"- Разложение по 2 компонентам грубовато. Видно, что есть какие-то зачатки кластеризации, но компонент явно недостаточно\n",
|
|||
|
"\n",
|
|||
|
"\n",
|
|||
|
"- Разложение по 8 компонентам даёт хороший результат. С помощью t-SNE можно \"спроектировать\" признаки в двумерное (латентное)пространство, построить кластеры\n",
|
|||
|
"\n",
|
|||
|
"\n",
|
|||
|
"- SVD/PCA помогают снизить размерность задачи "
|
|||
|
]
|
|||
|
}
|
|||
|
],
|
|||
|
"metadata": {
|
|||
|
"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.10.0"
|
|||
|
}
|
|||
|
},
|
|||
|
"nbformat": 4,
|
|||
|
"nbformat_minor": 5
|
|||
|
}
|